|
@@ -1,6 +1,6 @@
|
|
package org.jeecg.modules.billet.billetOriginalProductRecord.controller;
|
|
package org.jeecg.modules.billet.billetOriginalProductRecord.controller;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
|
+import java.util.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import org.jeecg.common.api.vo.Result;
|
|
import org.jeecg.common.api.vo.Result;
|
|
@@ -10,10 +10,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
-
|
|
|
|
import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecordDl;
|
|
import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecordDl;
|
|
import org.jeecg.modules.billet.billetOriginalProductRecord.service.IBilletOriginalProductRecordDlService;
|
|
import org.jeecg.modules.billet.billetOriginalProductRecord.service.IBilletOriginalProductRecordDlService;
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
@@ -81,10 +81,43 @@ public class BilletOriginalProductRecordDlController extends JeecgController<Bil
|
|
*/
|
|
*/
|
|
@AutoLog(value = "德龙原始记录-编辑")
|
|
@AutoLog(value = "德龙原始记录-编辑")
|
|
@ApiOperation(value="德龙原始记录-编辑", notes="德龙原始记录-编辑")
|
|
@ApiOperation(value="德龙原始记录-编辑", notes="德龙原始记录-编辑")
|
|
- @RequiresPermissions("billetOriginalProductRecordDl:billet_original_product_record_dl:edit")
|
|
|
|
|
|
+// @RequiresPermissions("billetOriginalProductRecordDl:billet_original_product_record_dl:edit")
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
public Result<String> edit(@RequestBody BilletOriginalProductRecordDl billetOriginalProductRecordDl) {
|
|
public Result<String> edit(@RequestBody BilletOriginalProductRecordDl billetOriginalProductRecordDl) {
|
|
- billetOriginalProductRecordDlService.updateById(billetOriginalProductRecordDl);
|
|
|
|
|
|
+ BilletOriginalProductRecordDl bopr = billetOriginalProductRecordDlService.getById(billetOriginalProductRecordDl.getId());
|
|
|
|
+ if (bopr == null) {
|
|
|
|
+ return Result.error("未找到对应数据,编辑失败!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 检查是否更新了hotChargeLength字段
|
|
|
|
+ boolean hotChargeLengthUpdated = false;
|
|
|
|
+ if (billetOriginalProductRecordDl.getHotChargeLength() != null &&
|
|
|
|
+ !billetOriginalProductRecordDl.getHotChargeLength().equals(bopr.getHotChargeLength())) {
|
|
|
|
+ hotChargeLengthUpdated = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Integer newTotal = billetOriginalProductRecordDl.getAmount();
|
|
|
|
+ if (bopr.getAmount() != null && !bopr.getAmount().equals(newTotal)) {
|
|
|
|
+ // 确保新合计数非负
|
|
|
|
+ if (newTotal < 0) {
|
|
|
|
+ return Result.error("合计数量不能为负数,编辑失败!");
|
|
|
|
+ }
|
|
|
|
+ // 执行随机分配
|
|
|
|
+ Map<String, Integer> strandAllocation = allocateRandomly(newTotal, 8);
|
|
|
|
+ // 将分配结果设置到对象中
|
|
|
|
+ bopr.setOneStrandSum(strandAllocation.get("oneStrandSum"));
|
|
|
|
+ bopr.setTwoStrandSum(strandAllocation.get("twoStrandSum"));
|
|
|
|
+ bopr.setThreeStrandSum(strandAllocation.get("threeStrandSum"));
|
|
|
|
+ bopr.setFourStrandSum(strandAllocation.get("fourStrandSum"));
|
|
|
|
+ bopr.setFiveStrandSum(strandAllocation.get("fiveStrandSum"));
|
|
|
|
+ bopr.setSixStrandSum(strandAllocation.get("sixStrandSum"));
|
|
|
|
+ bopr.setSevenStrandSum(strandAllocation.get("sevenStrandSum"));
|
|
|
|
+ bopr.setEightStrandSum(strandAllocation.get("eightStrandSum"));
|
|
|
|
+ // 更新合计字段
|
|
|
|
+ bopr.setAmount(newTotal);
|
|
|
|
+ }
|
|
|
|
+ // 提取公共逻辑到方法中
|
|
|
|
+ processCommonEditLogic(bopr, billetOriginalProductRecordDl, hotChargeLengthUpdated);
|
|
return Result.OK("编辑成功!");
|
|
return Result.OK("编辑成功!");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -160,4 +193,53 @@ public class BilletOriginalProductRecordDlController extends JeecgController<Bil
|
|
return super.importExcel(request, response, BilletOriginalProductRecordDl.class);
|
|
return super.importExcel(request, response, BilletOriginalProductRecordDl.class);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理编辑操作中的公共逻辑
|
|
|
|
+ */
|
|
|
|
+ private void processCommonEditLogic(BilletOriginalProductRecordDl bopr, BilletOriginalProductRecordDl newRecord, boolean hotChargeLengthUpdated) {
|
|
|
|
+ // 复制所有非空字段(忽略ID和流支数字段)
|
|
|
|
+ String[] ignoreProperties = {"id", "oneStrandSum", "twoStrandSum", "threeStrandSum",
|
|
|
|
+ "fourStrandSum", "fiveStrandSum", "sixStrandSum",
|
|
|
|
+ "sevenStrandSum", "eightStrandSum", "amount"};
|
|
|
|
+ BeanUtils.copyProperties(newRecord, bopr, ignoreProperties);
|
|
|
|
+
|
|
|
|
+ // 如果更新了hotChargeLength,设置is_edit_charge为2
|
|
|
|
+ if (hotChargeLengthUpdated) {
|
|
|
|
+ bopr.setIsEditCharge("2");
|
|
|
|
+ }
|
|
|
|
+ // 保存修改
|
|
|
|
+ billetOriginalProductRecordDlService.updateById(bopr);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 将总数按顺序循环分配到指定数量的流中
|
|
|
|
+ * @param total 总数
|
|
|
|
+ * @param numStrands 流的数量
|
|
|
|
+ * @return 分配结果映射(键为流的名称,值为分配的数量)
|
|
|
|
+ */
|
|
|
|
+ private Map<String, Integer> allocateRandomly(int total, int numStrands) {
|
|
|
|
+ // 初始化每个流分配0个
|
|
|
|
+ List<Integer> allocation = new ArrayList<>(Collections.nCopies(numStrands, 0));
|
|
|
|
+
|
|
|
|
+ // 按顺序循环分配所有数量
|
|
|
|
+ for (int i = 0; i < total; i++) {
|
|
|
|
+ // 计算当前应该分配的流索引(循环使用)
|
|
|
|
+ int index = i % numStrands;
|
|
|
|
+ allocation.set(index, allocation.get(index) + 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 构建结果映射
|
|
|
|
+ Map<String, Integer> result = new HashMap<>();
|
|
|
|
+ result.put("oneStrandSum", numStrands > 0 ? allocation.get(0) : 0);
|
|
|
|
+ result.put("twoStrandSum", numStrands > 1 ? allocation.get(1) : 0);
|
|
|
|
+ result.put("threeStrandSum", numStrands > 2 ? allocation.get(2) : 0);
|
|
|
|
+ result.put("fourStrandSum", numStrands > 3 ? allocation.get(3) : 0);
|
|
|
|
+ result.put("fiveStrandSum", numStrands > 4 ? allocation.get(4) : 0);
|
|
|
|
+ result.put("sixStrandSum", numStrands > 5 ? allocation.get(5) : 0);
|
|
|
|
+ result.put("sevenStrandSum", numStrands > 6 ? allocation.get(6) : 0);
|
|
|
|
+ result.put("eightStrandSum", numStrands > 7 ? allocation.get(7) : 0);
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|