|
@@ -1,5 +1,6 @@
|
|
|
package org.jeecg.modules.billet.billetOriginalProductRecord.controller;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ThreadLocalRandom;
|
|
|
import java.util.stream.Collectors;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -27,6 +28,7 @@ import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOrigina
|
|
|
import org.jeecg.modules.billet.billetOriginalProductRecord.service.IBilletOriginalProductRecordService;
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.HeatsActualsInfo;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -111,10 +113,42 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
|
|
|
*/
|
|
|
@AutoLog(value = "钢坯生成原始记录-编辑")
|
|
|
@ApiOperation(value="钢坯生成原始记录-编辑", notes="钢坯生成原始记录-编辑")
|
|
|
- @RequiresPermissions("billetOriginalProductRecord:billet_original_product_record:edit")
|
|
|
+// @RequiresPermissions("billetOriginalProductRecord:billet_original_product_record:edit")
|
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
public Result<String> edit(@RequestBody BilletOriginalProductRecord billetOriginalProductRecord) {
|
|
|
- billetOriginalProductRecordService.updateById(billetOriginalProductRecord);
|
|
|
+ BilletOriginalProductRecord bopr = billetOriginalProductRecordService.getById(billetOriginalProductRecord.getId());
|
|
|
+ if(bopr == null) {
|
|
|
+ return Result.error("未找到对应数据,编辑失败!");
|
|
|
+ }
|
|
|
+ if (bopr.getAmount() != null && !bopr.getAmount().equals(billetOriginalProductRecord.getAmount())) {
|
|
|
+ Integer newTotal = billetOriginalProductRecord.getAmount();
|
|
|
+ // 确保新合计数非负
|
|
|
+ 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);
|
|
|
+ // 复制其他非空字段(忽略流支数和ID)
|
|
|
+ BeanUtils.copyProperties(billetOriginalProductRecord, bopr,
|
|
|
+ "id", "oneStrandSum", "twoStrandSum", "threeStrandSum",
|
|
|
+ "fourStrandSum", "fiveStrandSum", "sixStrandSum",
|
|
|
+ "sevenStrandSum", "eightStrandSum", "amount");
|
|
|
+ // 保存修改
|
|
|
+ billetOriginalProductRecordService.updateById(bopr);
|
|
|
+ }else {
|
|
|
+ billetOriginalProductRecordService.updateById(billetOriginalProductRecord);
|
|
|
+ }
|
|
|
return Result.OK("编辑成功!");
|
|
|
}
|
|
|
|
|
@@ -194,7 +228,6 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
|
|
|
@ApiOperation(value="钢坯原始生产记录查询", notes="钢坯原始生产记录查询")
|
|
|
@GetMapping(value = "/queryBilletRecordByCcmNo")
|
|
|
public Result<List<BilletOriginalProductRecord>> queryHeatsActualsByCcmNo(@RequestParam(name="ccmNo", required = false) String ccmNo) {
|
|
|
- List<BilletOriginalProductRecord> billetOriginalProductRecords = new ArrayList<>();
|
|
|
|
|
|
String classShiftGroup = String.format("class:shift:group:%s", ccmNo); // 班组
|
|
|
String classShift = String.format("class:shift:%s",ccmNo); // 班别
|
|
@@ -204,46 +237,65 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
|
|
|
if (oConvertUtils.isEmpty(shiftGroup) || oConvertUtils.isEmpty(shift)){
|
|
|
return Result.error("班组班别获取为空,钢坯原始生产记录查询失败!");
|
|
|
}
|
|
|
+ // 根据ccmNo、shift、shiftGroup查询最新的交班记录
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(BilletHotsendChangeShift::getCcmNo, ccmNo)
|
|
|
+ .eq(BilletHotsendChangeShift::getShift, shift)
|
|
|
+ .eq(BilletHotsendChangeShift::getShiftGroup, shiftGroup)
|
|
|
+ .isNull(BilletHotsendChangeShift::getChangeShiftTime)
|
|
|
+ .orderByDesc(BilletHotsendChangeShift::getCreateTime)
|
|
|
+ .last("limit 1");
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
|
|
|
+ if (billetHotsendChangeShift == null){
|
|
|
+ log.info("{}{}", "钢坯原始生产记录,交班记录为空!", ccmNo + "失败时间:" + new Date());
|
|
|
+ return Result.error("交班信息为空,钢坯原始生产记录查询失败!");
|
|
|
+ }
|
|
|
//1、 获取当班浇筑炉次详细信息
|
|
|
- List<HeatsActualsInfo> heatsActualsInfoList = queryCurrentHeatsActualsInfo(ccmNo, shift, shiftGroup);
|
|
|
+ List<BilletOriginalProductRecord> billetOriginalProductRecords = new ArrayList<>();
|
|
|
+ List<HeatsActualsInfo> heatsActualsInfoList = queryCurrentHeatsActualsInfo(ccmNo, shift, shiftGroup, billetHotsendChangeShift.getCreateTime());
|
|
|
log.info("原始生产记录,当班浇筑炉次数据信息: " + JSON.toJSON(heatsActualsInfoList));
|
|
|
- if (oConvertUtils.listIsEmpty(heatsActualsInfoList)){
|
|
|
- return Result.OK(billetOriginalProductRecords);
|
|
|
+ if (oConvertUtils.listIsNotEmpty(heatsActualsInfoList)){
|
|
|
+ //2、把获取到的当班浇筑炉次信息heatsActualsInfoList保存到原始生产记录表
|
|
|
+ heatsActualsInfoList.forEach(x -> {
|
|
|
+ BilletOriginalProductRecord billetOriginalProductRecord = new BilletOriginalProductRecord();
|
|
|
+ billetOriginalProductRecord.setId(String.valueOf(IdWorker.getId()));
|
|
|
+ billetOriginalProductRecord.setCcmNo(ccmNo);
|
|
|
+ billetOriginalProductRecord.setHeatNo(x.getHeatNo());
|
|
|
+ billetOriginalProductRecord.setShift(x.getShift());
|
|
|
+ billetOriginalProductRecord.setShiftGroup(x.getShiftGroup());
|
|
|
+ billetOriginalProductRecord.setGrade(x.getBrandNum());
|
|
|
+ billetOriginalProductRecord.setOneStrandSum(x.getOneSum());
|
|
|
+ billetOriginalProductRecord.setTwoStrandSum(x.getTwoSum());
|
|
|
+ billetOriginalProductRecord.setThreeStrandSum(x.getThreeSum());
|
|
|
+ billetOriginalProductRecord.setFourStrandSum(x.getFourSum());
|
|
|
+ billetOriginalProductRecord.setFiveStrandSum(x.getFiveSum());
|
|
|
+ billetOriginalProductRecord.setSixStrandSum(x.getSixSum());
|
|
|
+ billetOriginalProductRecord.setSevenStrandSum(x.getSevenSum());
|
|
|
+ billetOriginalProductRecord.setEightStrandSum(x.getEightSum());
|
|
|
+ String totalInfoJson = x.getTotalInfo();
|
|
|
+ if (oConvertUtils.isEmpty(totalInfoJson)){
|
|
|
+ billetOriginalProductRecord.setAmount(0);// 合计
|
|
|
+ }
|
|
|
+ JSONObject json = JSON.parseObject(totalInfoJson);
|
|
|
+ Integer totalCount = json.getInteger("totalCount");
|
|
|
+ billetOriginalProductRecord.setAmount(totalCount);// 合计
|
|
|
+ billetOriginalProductRecord.setRollClubOneDetails(x.getDirectRolling());// 直轧热送棒一
|
|
|
+ billetOriginalProductRecord.setHotChargeLength(x.getHotCharge());
|
|
|
+ billetOriginalProductRecord.setStackLength(x.getStacking());
|
|
|
+ billetOriginalProductRecord.setLengthDetails(x.getLength());
|
|
|
+ billetOriginalProductRecord.setCreateTime(DateUtils.str2Date(x.getCreateTime(), DateUtils.datetimeFormat.get()));
|
|
|
+ billetOriginalProductRecords.add(billetOriginalProductRecord);
|
|
|
+ });
|
|
|
+ log.info("钢坯原始生产记录信息: " + JSON.toJSON(billetOriginalProductRecords));
|
|
|
+ billetOriginalProductRecordService.saveBatch(billetOriginalProductRecords);
|
|
|
}
|
|
|
- //2、把获取到的当班浇筑炉次信息heatsActualsInfoList保存到原始生产记录表
|
|
|
- heatsActualsInfoList.forEach(x -> {
|
|
|
- BilletOriginalProductRecord billetOriginalProductRecord = new BilletOriginalProductRecord();
|
|
|
- billetOriginalProductRecord.setId(String.valueOf(IdWorker.getId()));
|
|
|
- billetOriginalProductRecord.setCcmNo(ccmNo);
|
|
|
- billetOriginalProductRecord.setHeatNo(x.getHeatNo());
|
|
|
- billetOriginalProductRecord.setShift(x.getShift());
|
|
|
- billetOriginalProductRecord.setShiftGroup(x.getShiftGroup());
|
|
|
- billetOriginalProductRecord.setGrade(x.getBrandNum());
|
|
|
- billetOriginalProductRecord.setOneStrandSum(x.getOneSum());
|
|
|
- billetOriginalProductRecord.setTwoStrandSum(x.getTwoSum());
|
|
|
- billetOriginalProductRecord.setThreeStrandSum(x.getThreeSum());
|
|
|
- billetOriginalProductRecord.setFourStrandSum(x.getFourSum());
|
|
|
- billetOriginalProductRecord.setFiveStrandSum(x.getFiveSum());
|
|
|
- billetOriginalProductRecord.setSixStrandSum(x.getSixSum());
|
|
|
- billetOriginalProductRecord.setSevenStrandSum(x.getSevenSum());
|
|
|
- billetOriginalProductRecord.setEightStrandSum(x.getEightSum());
|
|
|
- String totalInfoJson = x.getTotalInfo();
|
|
|
- if (oConvertUtils.isEmpty(totalInfoJson)){
|
|
|
- billetOriginalProductRecord.setAmount(0);// 合计
|
|
|
- }
|
|
|
- JSONObject json = JSON.parseObject(totalInfoJson);
|
|
|
- Integer totalCount = json.getInteger("totalCount");
|
|
|
- billetOriginalProductRecord.setAmount(totalCount);// 合计
|
|
|
- billetOriginalProductRecord.setRollClubOneDetails(x.getDirectRolling());// 直轧热送棒一
|
|
|
- billetOriginalProductRecord.setHotChargeLength(x.getHotCharge());
|
|
|
- billetOriginalProductRecord.setStackLength(x.getStacking());
|
|
|
- billetOriginalProductRecord.setLengthDetails(x.getLength());
|
|
|
- billetOriginalProductRecord.setCreateTime(new Date());
|
|
|
- billetOriginalProductRecords.add(billetOriginalProductRecord);
|
|
|
- });
|
|
|
- log.info("钢坯原始生产记录信息: " + JSON.toJSON(billetOriginalProductRecords));
|
|
|
- billetOriginalProductRecordService.saveBatch(billetOriginalProductRecords);
|
|
|
- return Result.OK(billetOriginalProductRecords);
|
|
|
+ // 通过铸机号、班组、班别、交班开始时间 查询钢坯生产原始记录
|
|
|
+ List<BilletOriginalProductRecord> billetOriginalProductRecordList = billetOriginalProductRecordService.list(new QueryWrapper<BilletOriginalProductRecord>()
|
|
|
+ .eq("ccm_no", ccmNo)
|
|
|
+ .eq("shift", shift)
|
|
|
+ .eq("shift_group", shiftGroup)
|
|
|
+ .between("create_time", billetHotsendChangeShift.getCreateTime(), new Date()));
|
|
|
+ return Result.OK(billetOriginalProductRecordList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -253,27 +305,14 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
|
|
|
* @param shiftGroup
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<HeatsActualsInfo> queryCurrentHeatsActualsInfo(String ccmNo, String shift, String shiftGroup) {
|
|
|
+ private List<HeatsActualsInfo> queryCurrentHeatsActualsInfo(String ccmNo, String shift, String shiftGroup, Date createTime) {
|
|
|
List<HeatsActualsInfo> heatsActualsInfoList = new ArrayList<>();
|
|
|
- // 根据ccmNo、shift、shiftGroup查询最新的交班记录
|
|
|
- LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(BilletHotsendChangeShift::getCcmNo, ccmNo)
|
|
|
- .eq(BilletHotsendChangeShift::getShift, shift)
|
|
|
- .eq(BilletHotsendChangeShift::getShiftGroup, shiftGroup)
|
|
|
- .isNull(BilletHotsendChangeShift::getChangeShiftTime)
|
|
|
- .orderByDesc(BilletHotsendChangeShift::getCreateTime)
|
|
|
- .last("limit 1");
|
|
|
- BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
|
|
|
- if (billetHotsendChangeShift == null){
|
|
|
- log.info("{}{}", "钢坯原始生产记录,交班记录为空!", ccmNo + "失败时间:" + new Date());
|
|
|
- return heatsActualsInfoList;
|
|
|
- }
|
|
|
//根据ccmNo、shift、shiftGroup、大于billetHotsendChangeShift的创建时间 查询所有炉次传递单BilletHotsend
|
|
|
LambdaQueryWrapper<BilletHotsend> queryWrapper1 = new LambdaQueryWrapper<>();
|
|
|
queryWrapper1.eq(BilletHotsend::getCcmNo, ccmNo)
|
|
|
.eq(BilletHotsend::getShift, shift)
|
|
|
.eq(BilletHotsend::getShiftGroup, shiftGroup)
|
|
|
- .between(BilletHotsend::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date())
|
|
|
+ .between(BilletHotsend::getCreateTime, createTime, new Date())
|
|
|
.orderByDesc(BilletHotsend::getCreateTime);
|
|
|
List<BilletHotsend> billetHotsendList = billetHotsendBaseService.list(queryWrapper1);
|
|
|
if (oConvertUtils.listIsEmpty(billetHotsendList)){
|
|
@@ -571,4 +610,37 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
|
|
|
Collectors.counting()
|
|
|
));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将总数随机分配到指定数量的流中,允许流的数量为0
|
|
|
+ * @param total 总数
|
|
|
+ * @param numStrands 流的数量
|
|
|
+ * @return 分配结果映射(键为流的名称,值为分配的数量)
|
|
|
+ */
|
|
|
+ private Map<String, Integer> allocateRandomly(int total, int numStrands) {
|
|
|
+ // 初始化每个流分配0个
|
|
|
+ List<Integer> allocation = new ArrayList<>(Collections.nCopies(numStrands, 0));
|
|
|
+
|
|
|
+ // 随机分配所有数量
|
|
|
+ Random random = ThreadLocalRandom.current();
|
|
|
+ for (int i = 0; i < total; i++) {
|
|
|
+ // 随机选择一个流增加数量
|
|
|
+ int index = random.nextInt(numStrands);
|
|
|
+ allocation.set(index, allocation.get(index) + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建结果映射
|
|
|
+ Map<String, Integer> result = new HashMap<>();
|
|
|
+ result.put("oneStrandSum", allocation.get(0));
|
|
|
+ result.put("twoStrandSum", allocation.get(1));
|
|
|
+ result.put("threeStrandSum", allocation.get(2));
|
|
|
+ result.put("fourStrandSum", allocation.get(3));
|
|
|
+ result.put("fiveStrandSum", allocation.get(4));
|
|
|
+ result.put("sixStrandSum", allocation.get(5));
|
|
|
+ result.put("sevenStrandSum", allocation.get(6));
|
|
|
+ result.put("eightStrandSum", allocation.get(7));
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|