Bläddra i källkod

56机交班合并

qiangxuan 3 månader sedan
förälder
incheckning
f8818eb9fa

+ 1 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/controller/BilletHotsendChangeShiftController.java

@@ -91,8 +91,7 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 	@PostMapping(value = "/add")
 	public Result<String> add(@RequestBody BilletHotsendChangeShift billetHotsendChangeShiftVo) {
 		LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapperCS = new LambdaQueryWrapper<>();
-		queryWrapperCS.eq(BilletHotsendChangeShift::getCcmNo, billetHotsendChangeShiftVo.getCcmNo())
-				.between(BilletHotsendChangeShift::getCreateTime, DateUtils.getStartOfDay(), DateUtils.getEndOfDay());
+		queryWrapperCS.between(BilletHotsendChangeShift::getCreateTime, DateUtils.getStartOfDay(), DateUtils.getEndOfDay());
 		List<BilletHotsendChangeShift> billetHotsendChangeShiftList = billetHotsendChangeShiftService.list(queryWrapperCS);
 
 		String nextShift = String.join(",", billetHotsendChangeShiftVo.getShift(), billetHotsendChangeShiftVo.getShiftGroup());

+ 76 - 77
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/service/impl/BilletHotsendChangeShiftServiceImpl.java

@@ -18,10 +18,7 @@ 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.Optional;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -53,84 +50,86 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
             result.put("fail", "参数无效,交班操作失败!");
             return result;
         }
+        List<String> ccmNoList = Arrays.asList("5", "6");
+        for (String ccmNo : ccmNoList){
+            String keyShiftGroup = String.format("class:shift:group:%s", ccmNo);
+            String keyShift = String.format("class:shift:%s", ccmNo);
+            // 保存旧的缓存值,用于异常回滚
+            String oldShiftGroup = Optional.ofNullable(redisTemplate.opsForValue().get(keyShiftGroup))
+                    .map(Object::toString)
+                    .orElse(null);
+            String oldShift = Optional.ofNullable(redisTemplate.opsForValue().get(keyShift))
+                    .map(Object::toString)
+                    .orElse(null);
 
-        String keyShiftGroup = String.format("class:shift:group:%s", billetHotsendChangeShiftVo.getCcmNo());
-        String keyShift = String.format("class:shift:%s", billetHotsendChangeShiftVo.getCcmNo());
-        // 保存旧的缓存值,用于异常回滚
-        String oldShiftGroup = Optional.ofNullable(redisTemplate.opsForValue().get(keyShiftGroup))
-                .map(Object::toString)
-                .orElse(null);
-        String oldShift = Optional.ofNullable(redisTemplate.opsForValue().get(keyShift))
-                .map(Object::toString)
-                .orElse(null);
+            try {
+                // 先更新班组班别缓存
+                redisTemplate.opsForValue().set(keyShiftGroup, billetHotsendChangeShiftVo.getShiftGroup());
+                redisTemplate.opsForValue().set(keyShift, billetHotsendChangeShiftVo.getShift());
 
-        try {
-            // 先更新班组班别缓存
-            redisTemplate.opsForValue().set(keyShiftGroup, billetHotsendChangeShiftVo.getShiftGroup());
-            redisTemplate.opsForValue().set(keyShift, billetHotsendChangeShiftVo.getShift());
-
-            // 获取当前班组班别
-            BilletHotsendChangeShift billetHotsendChangeShift = baseMapper.selectOne(new LambdaQueryWrapper<BilletHotsendChangeShift>()
-                    .eq(BilletHotsendChangeShift::getCcmNo, billetHotsendChangeShiftVo.getCcmNo())
-                    .orderByDesc(BilletHotsendChangeShift::getCreateTime).last("limit 1"));
-            if (oConvertUtils.isEmpty(billetHotsendChangeShift)) {
-                result.put("fail", "当班信息查询为空,交班操作失败!");
-                return result;
-            }
-            // 更新当前班次的交班时间,相当于上一个班交班的结束时间
-            billetHotsendChangeShift.setChangeShiftTime(new Date());
-            billetHotsendChangeShift.setUpdateTime(new Date());
-            baseMapper.updateById(billetHotsendChangeShift);
-            // 获取当前最新炉号
-            if (oConvertUtils.isNotEmpty(billetHotsendChangeShift.getHeatNo())) {
-                // 根据当前炉号、铸机号、班组、班别查询总生产的钢坯数
-                LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<BilletBasicInfo>()
-                        .eq(BilletBasicInfo::getCcmNo, Integer.valueOf(billetHotsendChangeShiftVo.getCcmNo()))
-                        .eq(BilletBasicInfo::getHeatNo, billetHotsendChangeShift.getHeatNo())
-                        .eq(BilletBasicInfo::getShift, billetHotsendChangeShift.getShift())
-                        .eq(BilletBasicInfo::getShiftGroup, billetHotsendChangeShift.getShiftGroup())
-                        .isNull(BilletBasicInfo::getBelongTable)
-                        .isNull(BilletBasicInfo::getBhtcId)
-                        .orderByAsc(BilletBasicInfo::getCreateTime);
-                List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapper);
-                List<BilletBasicInfo> updateBilletBasicInfo = extractRemainderData(billetBasicInfoList);
-                if (oConvertUtils.listIsNotEmpty(updateBilletBasicInfo)){
-                    updateBilletBasicInfo.forEach(x -> {
-                        x.setShift(billetHotsendChangeShiftVo.getShift());
-                        x.setShiftGroup(billetHotsendChangeShiftVo.getShiftGroup());
-                        x.setUpdateTime(new Date());
-                    });
-                    log.info("交班判定该钢坯到新的班组:{}", JSON.toJSON(updateBilletBasicInfo));
-                    billetBasicInfoService.saveOrUpdateBatch(updateBilletBasicInfo);
+                // 获取当前班组班别
+                BilletHotsendChangeShift billetHotsendChangeShift = baseMapper.selectOne(new LambdaQueryWrapper<BilletHotsendChangeShift>()
+                        .eq(BilletHotsendChangeShift::getCcmNo, ccmNo)
+                        .orderByDesc(BilletHotsendChangeShift::getCreateTime).last("limit 1"));
+                if (oConvertUtils.isEmpty(billetHotsendChangeShift)) {
+                    result.put("fail", "当班信息查询为空,交班操作失败!");
+                    return result;
+                }
+                // 更新当前班次的交班时间,相当于上一个班交班的结束时间
+                billetHotsendChangeShift.setChangeShiftTime(new Date());
+                billetHotsendChangeShift.setUpdateTime(new Date());
+                baseMapper.updateById(billetHotsendChangeShift);
+                // 获取当前最新炉号
+                if (oConvertUtils.isNotEmpty(billetHotsendChangeShift.getHeatNo())) {
+                    // 根据当前炉号、铸机号、班组、班别查询总生产的钢坯数
+                    LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<BilletBasicInfo>()
+                            .eq(BilletBasicInfo::getCcmNo, Integer.valueOf(ccmNo))
+                            .eq(BilletBasicInfo::getHeatNo, billetHotsendChangeShift.getHeatNo())
+                            .eq(BilletBasicInfo::getShift, billetHotsendChangeShift.getShift())
+                            .eq(BilletBasicInfo::getShiftGroup, billetHotsendChangeShift.getShiftGroup())
+                            .isNull(BilletBasicInfo::getBelongTable)
+                            .isNull(BilletBasicInfo::getBhtcId)
+                            .orderByAsc(BilletBasicInfo::getCreateTime);
+                    List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapper);
+                    List<BilletBasicInfo> updateBilletBasicInfo = extractRemainderData(billetBasicInfoList);
+                    if (oConvertUtils.listIsNotEmpty(updateBilletBasicInfo)){
+                        updateBilletBasicInfo.forEach(x -> {
+                            x.setShift(billetHotsendChangeShiftVo.getShift());
+                            x.setShiftGroup(billetHotsendChangeShiftVo.getShiftGroup());
+                            x.setUpdateTime(new Date());
+                        });
+                        log.info("交班判定该钢坯到新的班组:{}", JSON.toJSON(updateBilletBasicInfo));
+                        billetBasicInfoService.saveOrUpdateBatch(updateBilletBasicInfo);
+                    }
                 }
-            }
 
-            // 生成新的交班记录 初始化并保存入库
-            BilletHotsendChangeShift billetHotsendChangeShift1 = new BilletHotsendChangeShift();
-            billetHotsendChangeShift1.setId(String.valueOf(IdWorker.getId()));
-            billetHotsendChangeShift1.setCcmNo(billetHotsendChangeShiftVo.getCcmNo());
-            billetHotsendChangeShift1.setShift(billetHotsendChangeShiftVo.getShift());
-            billetHotsendChangeShift1.setShiftGroup(billetHotsendChangeShiftVo.getShiftGroup());
-            billetHotsendChangeShift1.setHotfeignAmount(0); // 当前热装支数
-            billetHotsendChangeShift1.setProductAmount(0); // 当前生产支数
-            billetHotsendChangeShift1.setHotsendAmount(0); // 当前热送支数
-            billetHotsendChangeShift1.setStackAmount(0); // 当前起垛支数
-            billetHotsendChangeShift1.setOutCarNum(0); // 车次
-            billetHotsendChangeShift1.setShiftSum(0); // 当班总数
-            billetHotsendChangeShift1.setShiftProduct(0d); // 当班总重
-            billetHotsendChangeShift1.setWasteAmount(0); // 当前废品支数
-            billetHotsendChangeShift1.setCreateTime(new Date());
-            baseMapper.insert(billetHotsendChangeShift1);
-            operateLogService.add(billetHotsendChangeShift1, null, BilletHotsendChangeShift.class);
-            result.put("success", "交班操作成功!");
-        } catch (Exception e) {
-            log.error("交班操作出现异常", e);
-            // 回滚缓存
-            if (oldShiftGroup != null && oldShift != null) {
-                redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
-                redisTemplate.opsForValue().set(keyShift, oldShift);
+                // 生成新的交班记录 初始化并保存入库
+                BilletHotsendChangeShift billetHotsendChangeShift1 = new BilletHotsendChangeShift();
+                billetHotsendChangeShift1.setId(String.valueOf(IdWorker.getId()));
+                billetHotsendChangeShift1.setCcmNo(ccmNo);
+                billetHotsendChangeShift1.setShift(billetHotsendChangeShiftVo.getShift());
+                billetHotsendChangeShift1.setShiftGroup(billetHotsendChangeShiftVo.getShiftGroup());
+                billetHotsendChangeShift1.setHotfeignAmount(0); // 当前热装支数
+                billetHotsendChangeShift1.setProductAmount(0); // 当前生产支数
+                billetHotsendChangeShift1.setHotsendAmount(0); // 当前热送支数
+                billetHotsendChangeShift1.setStackAmount(0); // 当前起垛支数
+                billetHotsendChangeShift1.setOutCarNum(0); // 车次
+                billetHotsendChangeShift1.setShiftSum(0); // 当班总数
+                billetHotsendChangeShift1.setShiftProduct(0d); // 当班总重
+                billetHotsendChangeShift1.setWasteAmount(0); // 当前废品支数
+                billetHotsendChangeShift1.setCreateTime(new Date());
+                baseMapper.insert(billetHotsendChangeShift1);
+                operateLogService.add(billetHotsendChangeShift1, null, BilletHotsendChangeShift.class);
+                result.put("success", "交班操作成功!");
+            } catch (Exception e) {
+                log.error("交班操作出现异常", e);
+                // 回滚缓存
+                if (oldShiftGroup != null && oldShift != null) {
+                    redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
+                    redisTemplate.opsForValue().set(keyShift, oldShift);
+                }
+                result.put("fail", "交班操作失败,出现异常!");
             }
-            result.put("fail", "交班操作失败,出现异常!");
         }
         return result;
     }