浏览代码

计划任务异常钢坯恢复处理

qiangxuan 1 周之前
父节点
当前提交
9bf51acc23

+ 104 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/actualControl/billetActual/billetActual/service/impl/BilletBasicInfoExceptionServiceImpl.java

@@ -24,6 +24,7 @@ import org.jeecg.modules.actualControl.heatsActuals.entity.HeatsActuals;
 import org.jeecg.modules.actualControl.heatsActuals.mapper.HeatsActualsMapper;
 import org.jeecg.modules.actualControl.heatsActuals.service.IHeatsActualsService;
 import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
+import org.jeecg.modules.billet.billetHotsend.entity.RollClubCommon;
 import org.jeecg.modules.billet.billetHotsend.mapper.BilletHotsendBaseMapper;
 import org.jeecg.modules.billet.billetHotsend.service.IBilletHotsendBaseService;
 import org.jeecg.modules.billet.billetHotsendConfig.service.IBilletHotsendTypeConfigService;
@@ -32,10 +33,12 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -76,6 +79,7 @@ public class BilletBasicInfoExceptionServiceImpl extends ServiceImpl<BilletBasic
     RedisTemplate redisTemplate;
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void assemblyHandle(String ccmNo) {
 
         String classShiftGroup = String.format("class:shift:group:%s", ccmNo); // 班组
@@ -99,6 +103,21 @@ public class BilletBasicInfoExceptionServiceImpl extends ServiceImpl<BilletBasic
         List<BilletBasicInfoException> billetBasicInfoExceptionList = baseMapper.selectList(queryWrapper);
         if (oConvertUtils.listIsEmpty(billetBasicInfoExceptionList) || billetBasicInfoExceptionList.size() < 4) {
             log.info("{}{}",  "钢坯实绩异常表数据不足4条!", ccmNo);
+            // 处理非当班的异常钢坯实绩信息 根据ccmNo、班别、班组查询钢坯实绩异常表
+            LambdaQueryWrapper<BilletBasicInfoException> queryWrapper1 = new LambdaQueryWrapper<>();
+            queryWrapper1
+                    .eq(BilletBasicInfoException::getCcmNo, ccmNo) // ccm_no = '5'
+                    .and(wrapper ->
+                            wrapper.ne(BilletBasicInfoException::getShiftGroup, classShiftGroupStr) // shift_group != 1
+                                    .or() // OR 逻辑
+                                    .ne(BilletBasicInfoException::getShift, classShiftStr) // shift != 0
+                    );
+            queryWrapper1.orderByDesc(BilletBasicInfoException::getCreateTime);
+            List<BilletBasicInfoException> notCurrentBilletBasicInfoExceptionList = baseMapper.selectList(queryWrapper1);
+            if (oConvertUtils.listIsNotEmpty(notCurrentBilletBasicInfoExceptionList)){
+                log.info("{}{}", "非当班异常钢坯实绩信息总条数:", notCurrentBilletBasicInfoExceptionList.size());
+                notCurrentShiftBilletHandle(notCurrentBilletBasicInfoExceptionList, ccmNo);
+            }
             return;
         }
         List<BilletBasicInfo> billetBasicInfoList = new ArrayList<>();
@@ -209,10 +228,10 @@ public class BilletBasicInfoExceptionServiceImpl extends ServiceImpl<BilletBasic
             // 收集组批成功后,需要移除的钢坯实绩异常数据
             removeBilletBasicInfoExceptionIds.addAll(idList);
         }
-
+        log.info("定时任务对异常钢坯进行组批:"+ JSON.toJSON(saveBilletBasicInfoList));
         // 批量保存钢坯实绩
         billetBasicInfoService.saveBatch(saveBilletBasicInfoList);
-
+        log.info("异常钢坯组批实绩:"+ JSON.toJSON(saveBilletBasicInfoList));
         // 保存组批实绩
         billetAssemblyNumberService.saveBatch(billetAssemblyNumberList);
 
@@ -235,11 +254,94 @@ public class BilletBasicInfoExceptionServiceImpl extends ServiceImpl<BilletBasic
         }
 
         // 移除组批成功的钢坯实绩异常数据
+        log.info("定时任务组批处理后,删除异常钢坯实绩:"+ JSON.toJSON(removeBilletBasicInfoExceptionIds));
+        if (oConvertUtils.listIsNotEmpty(removeBilletBasicInfoExceptionIds)){
+            baseMapper.deleteBatchIds(removeBilletBasicInfoExceptionIds);
+        }
+    }
+
+    /**
+     * 非当前班次异常钢坯实绩,还原
+     * @param notCurrentBilletBasicInfoExceptionList
+     */
+    private void notCurrentShiftBilletHandle(List<BilletBasicInfoException> notCurrentBilletBasicInfoExceptionList, String ccmNo) {
+        List<String> removeBilletBasicInfoExceptionIds = notCurrentBilletBasicInfoExceptionList.stream().map(BilletBasicInfoException::getId).collect(Collectors.toList());
+
+        List<BilletBasicInfo> saveBilletBasicInfoList = new ArrayList<>();
+        for (BilletBasicInfoException billetBasicInfoException : notCurrentBilletBasicInfoExceptionList) {
+            BilletBasicInfo billetBasicInfo = new BilletBasicInfo();
+            BeanUtils.copyProperties(billetBasicInfoException, billetBasicInfo);
+            billetBasicInfo.setId(String.valueOf(IdWorker.getId()));
+            String assemblyNumber = generateUniqueAssemblyNumber(ccmNo, billetBasicInfoException.getHeatNo());
+            billetBasicInfo.setAssemblyNumber(assemblyNumber);
+            saveBilletBasicInfoList.add(billetBasicInfo);
+        }
+
+        Map<String, List<BilletBasicInfo>> rollClubCommonListttt = groupByShiftAndHeatNo(saveBilletBasicInfoList);
+
+        for (Map.Entry<String, List<BilletBasicInfo>> entry : rollClubCommonListttt.entrySet()) {
+
+            String[] parts = entry.getKey().split(",");
+            String heatNo = parts[0];// 炉号
+            String shiftGroup = parts[1];// 班组
+            String shift = parts[2];// 班别
+
+            List<BilletBasicInfo> groupBilletBasicInfoList = entry.getValue();
+            // 计算一次总重量,避免重复计算
+            double totalWeight = groupBilletBasicInfoList.stream()
+                    .mapToDouble(BilletBasicInfo::getBilletWeight)
+                    .sum();
+
+            LambdaQueryWrapper<BilletHotsend> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(BilletHotsend::getCcmNo, ccmNo)
+                    .eq(BilletHotsend::getHeatNo, heatNo)
+                    .eq(BilletHotsend::getShiftGroup, shiftGroup)
+                    .eq(BilletHotsend::getShift, shift);
+            BilletHotsend idExistBh = billetHotsendBaseService.getOne(queryWrapper);
+            // 钢坯热送信息不为空时,更新总支数和累加重量
+            if (idExistBh != null) {
+                idExistBh.setAmountTotal(idExistBh.getAmountTotal() + groupBilletBasicInfoList.size());
+                idExistBh.setBlankOutput(idExistBh.getBlankOutput() + totalWeight);
+                idExistBh.setUpdateTime(new Date());
+                billetHotsendBaseService.updateById(idExistBh);
+            }else {
+                log.info("{}{}", ">>>>>>未找到该炉次传递单信息:", JSON.toJSON(groupBilletBasicInfoList));
+            }
+            // 查询炉次实绩
+            HeatsActuals heatsActuals = heatsActualsService.getOne(new LambdaQueryWrapper<HeatsActuals>()
+                    .eq(HeatsActuals::getHeatsCode, heatNo)
+                    .eq(HeatsActuals::getCasterCode, ccmNo)
+                    .eq(HeatsActuals::getShiftGroup, shiftGroup)
+                    .eq(HeatsActuals::getShift, shift));
+            if (heatsActuals != null){
+                heatsActuals.setBlankOutput(heatsActuals.getBlankOutput() + totalWeight);
+                heatsActuals.setBilletSum(heatsActuals.getBilletSum() + groupBilletBasicInfoList.size());
+                heatsActualsService.updateById(heatsActuals);
+            }else {
+                log.info("{}{}", ">>>>>>未找到该炉次实绩信息:", JSON.toJSON(groupBilletBasicInfoList));
+            }
+
+        }
+        // 未处理的钢坯异常数据,恢复到钢坯实绩表
+        if (oConvertUtils.listIsNotEmpty(saveBilletBasicInfoList)){
+            billetBasicInfoService.saveOrUpdateBatch(saveBilletBasicInfoList);
+        }
+        // 移除钢坯实绩异常数据
         if (oConvertUtils.listIsNotEmpty(removeBilletBasicInfoExceptionIds)){
             baseMapper.deleteBatchIds(removeBilletBasicInfoExceptionIds);
         }
     }
 
+
+    /**
+     * 根据班组班别对钢坯信息进行分组
+     * @param billetBasicInfoList
+     * @return
+     */
+    public static Map<String, List<BilletBasicInfo>> groupByShiftAndHeatNo(List<BilletBasicInfo> billetBasicInfoList) {
+        return billetBasicInfoList.stream().collect(Collectors.groupingBy(x -> x.getHeatNo() + "," + x.getShiftGroup() + "," + x.getShift()));
+    }
+
     /**
      * 生成唯一的坯号
      *

+ 5 - 5
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/actualControl/billetActual/billetActual/service/impl/BilletBasicInfoServiceImpl.java

@@ -486,11 +486,10 @@ public class BilletBasicInfoServiceImpl extends ServiceImpl<BilletBasicInfoMappe
                     .collect(Collectors.toList());
 
             resultList.addAll(billetBasicInfoList);
-
             if (oConvertUtils.listIsNotEmpty(resultList) && resultList.size() >= 4) {
                 int size = resultList.size();
                 int maxProcessed = (size / 4) * 4; // 计算可处理的最大4的倍数
-                List<BilletBasicInfo> remainingBillets = new ArrayList<>(); // 存储剩余的坯子
+
                 for (int i = 0; i < maxProcessed; i += 4) {
                     int start = i;
                     int end = Math.min(i + 4, maxProcessed);
@@ -499,7 +498,8 @@ public class BilletBasicInfoServiceImpl extends ServiceImpl<BilletBasicInfoMappe
                 }
                 // 提取剩余不足4个的坯子, 并更新组批号到数据库中
                 if (size > maxProcessed) {
-                    remainingBillets = billetBasicInfoList.subList(maxProcessed, size);
+                    // 存储剩余的坯子
+                    List<BilletBasicInfo> remainingBillets = resultList.subList(maxProcessed, size);
                     // 处理当前分组数据
                     updateBilletBasicInfoAsendAssemblyHandle(remainingBillets, billetBasicInfoAdd);
                 }
@@ -508,7 +508,6 @@ public class BilletBasicInfoServiceImpl extends ServiceImpl<BilletBasicInfoMappe
             if (oConvertUtils.listIsNotEmpty(billetBasicInfoList) && billetBasicInfoList.size() >= 4) {
                 int size = billetBasicInfoList.size();
                 int maxProcessed = (size / 4) * 4; // 计算可处理的最大4的倍数
-                List<BilletBasicInfo> remainingBillets = new ArrayList<>(); // 存储剩余的坯子
                 for (int i = 0; i < maxProcessed; i += 4) {
                     int start = i;
                     int end = Math.min(i + 4, maxProcessed);
@@ -517,7 +516,8 @@ public class BilletBasicInfoServiceImpl extends ServiceImpl<BilletBasicInfoMappe
                 }
                 // 提取剩余不足4个的坯子, 并更新组批号到数据库中
                 if (size > maxProcessed) {
-                    remainingBillets = billetBasicInfoList.subList(maxProcessed, size);
+                    // 存储剩余的坯子
+                    List<BilletBasicInfo> remainingBillets = billetBasicInfoList.subList(maxProcessed, size);
                     // 处理当前分组数据
                     updateBilletBasicInfoAsendAssemblyHandle(remainingBillets, billetBasicInfoAdd);
                 }