Jelajahi Sumber

装运单完善车次序号处理,新增切换钢种接口

lingpeng.li 3 minggu lalu
induk
melakukan
bf2bb5573a

+ 10 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/shiftConfiguration/controller/ShiftConfigurationController.java

@@ -16,12 +16,11 @@ import org.jeecg.common.system.base.controller.JeecgController;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.billet.shiftConfiguration.dto.SwitchSteelDTO;
 import org.jeecg.modules.billet.shiftConfiguration.entity.ShiftConfiguration;
 import org.jeecg.modules.billet.shiftConfiguration.entity.ShiftConfigurationLog;
 import org.jeecg.modules.billet.shiftConfiguration.service.IShiftConfigurationLogService;
 import org.jeecg.modules.billet.shiftConfiguration.service.IShiftConfigurationService;
-import org.jeecg.modules.billet.storageBill.service.IStorageBillService;
-import org.jeecg.modules.carUnit.service.impl.CarUnitServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.*;
@@ -252,6 +251,15 @@ public class ShiftConfigurationController extends JeecgController<ShiftConfigura
         return Result.OK(result);
     }
 
+    @GetMapping("/switchSteel")
+    @ApiOperation(value = "切换钢种", notes = "切换钢种")
+    public Result<Map<String, String>> switchSteel(@RequestBody SwitchSteelDTO switchSteelDTO) {
+
+        shiftConfigurationService.updateSteelGradeAndCache(switchSteelDTO);
+        return Result.OK("切换钢种成功");
+    }
+
+
     private String getShiftInfoFromRedis(String castingNo, String keyPattern) {
         String key = String.format(keyPattern, castingNo);
         return oConvertUtils.getString(redisTemplate.opsForValue().get(key));

+ 17 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/shiftConfiguration/dto/SwitchSteelDTO.java

@@ -0,0 +1,17 @@
+package org.jeecg.modules.billet.shiftConfiguration.dto;
+
+import lombok.Data;
+
+@Data
+public class SwitchSteelDTO {
+
+    /**
+     * 铸机号
+     */
+    private String ccmNo;
+
+    /**
+     * 牌号
+     */
+    private String brandNum;
+}

+ 5 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/shiftConfiguration/service/IShiftConfigurationService.java

@@ -1,14 +1,17 @@
 package org.jeecg.modules.billet.shiftConfiguration.service;
 
-import org.jeecg.modules.billet.shiftConfiguration.entity.ShiftConfiguration;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.billet.shiftConfiguration.dto.SwitchSteelDTO;
+import org.jeecg.modules.billet.shiftConfiguration.entity.ShiftConfiguration;
 
 /**
  * @Description: 班次配置
  * @Author: jeecg-boot
- * @Date:   2025-04-17
+ * @Date: 2025-04-17
  * @Version: V1.0
  */
 public interface IShiftConfigurationService extends IService<ShiftConfiguration> {
 
+    void updateSteelGradeAndCache(SwitchSteelDTO switchSteelDTO);
+
 }

+ 36 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/shiftConfiguration/service/impl/ShiftConfigurationServiceImpl.java

@@ -1,19 +1,53 @@
 package org.jeecg.modules.billet.shiftConfiguration.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.modules.billet.shiftConfiguration.dto.SwitchSteelDTO;
 import org.jeecg.modules.billet.shiftConfiguration.entity.ShiftConfiguration;
 import org.jeecg.modules.billet.shiftConfiguration.mapper.ShiftConfigurationMapper;
 import org.jeecg.modules.billet.shiftConfiguration.service.IShiftConfigurationService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 /**
  * @Description: 班次配置
  * @Author: jeecg-boot
- * @Date:   2025-04-17
+ * @Date: 2025-04-17
  * @Version: V1.0
  */
 @Service
 public class ShiftConfigurationServiceImpl extends ServiceImpl<ShiftConfigurationMapper, ShiftConfiguration> implements IShiftConfigurationService {
 
+    @Autowired
+    private RedisTemplate<String, String> redisTemplate;
+
+    @Override
+    public void updateSteelGradeAndCache(SwitchSteelDTO switchSteelDTO) {
+        String ccmNo = switchSteelDTO.getCcmNo();
+        String brandNum = switchSteelDTO.getBrandNum();
+
+        // 参数判空
+        if (!StringUtils.hasText(ccmNo) || !StringUtils.hasText(brandNum)) {
+            throw new IllegalArgumentException("铸机号和牌号不能为空");
+        }
+
+        // 更新 Redis 缓存
+        String redisKey = String.format("billet:basic:info:brand:num:%s", ccmNo);
+        redisTemplate.opsForValue().set(redisKey, brandNum);
+
+        // 更新最新一条 ShiftConfiguration 的钢种
+        LambdaQueryWrapper<ShiftConfiguration> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(ShiftConfiguration::getCcmNo, ccmNo)
+                .orderByDesc(ShiftConfiguration::getCreateTime)
+                .last("LIMIT 1");
+
+        ShiftConfiguration latestConfig = this.getOne(queryWrapper);
+        if (latestConfig != null) {
+            latestConfig.setSteelGrade(brandNum);
+            this.updateById(latestConfig);
+        }
+    }
 }

+ 2 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/entity/OnDutyInfo.java

@@ -13,4 +13,6 @@ public class OnDutyInfo {
     private Integer currentCastingFurnaceAmount;
     // 当班浇铸炉总重量
     private BigDecimal currentCastingFurnace;
+    //牌号
+    private String brandNum;
 }

+ 62 - 50
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/service/impl/StorageBillServiceImpl.java

@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@@ -21,7 +20,6 @@ import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBa
 import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoService;
 import org.jeecg.modules.actualControl.heatsActuals.entity.HeatsActuals;
 import org.jeecg.modules.actualControl.heatsActuals.service.IHeatsActualsService;
-import org.jeecg.modules.billet.billetAutoException.entity.BilletAutoException;
 import org.jeecg.modules.billet.billetAutoTmp.entity.BilletAutoTmp;
 import org.jeecg.modules.billet.billetAutoTmp.service.IBilletAutoTmpService;
 import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
@@ -1391,6 +1389,13 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
 
         OnDutyInfo onDutyInfo = new OnDutyInfo();
 
+        String brandNum = String.format("billet:basic:info:brand:num:%s", ccmNo);
+        String brandNumStr = !oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)) : "";
+
+        if(StringUtils.isNotBlank(brandNumStr)){
+            onDutyInfo.setBrandNum(brandNumStr);
+        }
+
         String shiftGroup = "";
         String shift = "";
         BilletHotsendChangeShift billetHotsendChangeShift;
@@ -5964,53 +5969,47 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
     public void fillCarNumbersAndShiftInfo(List<StorageBill> bills) {
         if (CollectionUtils.isEmpty(bills)) return;
 
-        // Step 1: 预提取所有用到的条件组合
-        Set<String> shiftKeys = new HashSet<>();
-        Set<String> billKeys = new HashSet<>();
-        for (StorageBill bill : bills) {
-            Date billDate = DateUtils.getStartOfDay(bill.getCreateTime());
-            String shiftKey = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift(), DateFormatUtils.format(billDate, "yyyy-MM-dd"));
-            shiftKeys.add(shiftKey);
-
-            String billKey = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift(), DateFormatUtils.format(billDate, "yyyy-MM-dd"));
-            billKeys.add(billKey);
-        }
+        Set<String> ccmNos = bills.stream().map(StorageBill::getCcmNo).collect(Collectors.toSet());
+        // 查询时间往前扩 1 小时
+        Date minDate = org.apache.commons.lang3.time.DateUtils.addHours(getMinDate(bills), -1);
+        Date maxDate = getMaxDate(bills);
 
-        // Step 2: 批量查询交班记录并缓存
+        // Step 1: 查询交班记录并按 (ccmNo + shiftGroup + shift) 分组
         List<BilletHotsendChangeShift> shiftList = billetHotsendChangeShiftService.lambdaQuery()
-                .in(BilletHotsendChangeShift::getCcmNo, bills.stream().map(StorageBill::getCcmNo).collect(Collectors.toSet()))
-                .between(BilletHotsendChangeShift::getCreateTime, getMinDate(bills), getMaxDate(bills))
+                .in(BilletHotsendChangeShift::getCcmNo, ccmNos)
+                .between(BilletHotsendChangeShift::getCreateTime, minDate, maxDate)
                 .list();
 
-        Map<String, BilletHotsendChangeShift> shiftMap = shiftList.stream()
-                .collect(Collectors.toMap(
-                        s -> String.join("_", s.getCcmNo(), s.getShiftGroup(), s.getShift(), DateFormatUtils.format(DateUtils.getStartOfDay(s.getCreateTime()), "yyyy-MM-dd")),
-                        Function.identity(),
-                        (v1, v2) -> v1 // 取较早的那个记录
-                ));
+        Map<String, List<BilletHotsendChangeShift>> shiftGroupMap = shiftList.stream()
+                .collect(Collectors.groupingBy(s -> String.join("_", s.getCcmNo(), s.getShiftGroup(), s.getShift())));
 
-        // Step 3: 批量查询所有相关的 StorageBill
+        // Step 2: 查询所有相关 StorageBill 并按 key 分组 (含车牌)
         List<StorageBill> allRelatedBills = this.lambdaQuery()
-                .in(StorageBill::getCcmNo, bills.stream().map(StorageBill::getCcmNo).collect(Collectors.toSet()))
-                .between(StorageBill::getCreateTime, getMinDate(bills), getMaxDate(bills))
+                .in(StorageBill::getCcmNo, ccmNos)
+                .between(StorageBill::getCreateTime, minDate, maxDate)
                 .list();
 
-        // 多级 map 存储 [ccmNo+shiftGroup+shift+licensePlate+day] -> List<StorageBill>
         Map<String, List<StorageBill>> billGroupMap = allRelatedBills.stream().collect(Collectors.groupingBy(b ->
                 String.join("_", b.getCcmNo(), b.getShiftGroup(), b.getShift(), Optional.ofNullable(b.getLicensePlate()).orElse(""),
                         DateFormatUtils.format(DateUtils.getStartOfDay(b.getCreateTime()), "yyyy-MM-dd"))
         ));
 
-        // Step 4: 处理每条 bill
         for (StorageBill bill : bills) {
-            // 生成一个新的对象
-            StorageBill newBill = new StorageBill();
-            newBill.setBtype(bill.getBtype());
-            newBill.setId(bill.getId());
-            String key = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift(),
-                    DateFormatUtils.format(DateUtils.getStartOfDay(bill.getCreateTime()), "yyyy-MM-dd"));
+            // 获取所属班次的交班记录候选项
+            String groupKey = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift());
+            List<BilletHotsendChangeShift> candidates = shiftGroupMap.getOrDefault(groupKey, Collections.emptyList());
+
+            // 匹配交班记录:createTime <= bill.createTime < changeShiftTime
+            BilletHotsendChangeShift shiftRecord = candidates.stream()
+                    .filter(s -> {
+                        Date start = s.getCreateTime();
+                        Date end = Optional.ofNullable(s.getChangeShiftTime())
+                                .orElse(DateUtils.addDays(DateUtils.getStartOfDay(start), 1));
+                        return !bill.getCreateTime().before(start) && bill.getCreateTime().before(end);
+                    })
+                    .findFirst()
+                    .orElse(null);
 
-            BilletHotsendChangeShift shiftRecord = shiftMap.get(key);
             if (shiftRecord == null) {
                 log.warn("未找到交班记录,跳过: {}", bill.getId());
                 continue;
@@ -6018,15 +6017,14 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
 
             Date shiftStart = shiftRecord.getCreateTime();
             Date shiftEnd = Optional.ofNullable(shiftRecord.getChangeShiftTime())
-                    .orElse(DateUtils.addDays(DateUtils.getStartOfDay(bill.getCreateTime()), 1));
+                    .orElse(DateUtils.addDays(DateUtils.getStartOfDay(shiftStart), 1));
 
             boolean licensePlateInvalid = bill.getLicensePlateStatus() != null && bill.getLicensePlateStatus() == 1;
-
             boolean needCalcCarNum = !licensePlateInvalid && (bill.getCarNum() == null || bill.getCarNum() == 0);
             boolean needCalcCarAllNum = bill.getCarAllNum() == null || bill.getCarAllNum() == 0;
             boolean updated = false;
 
-            // 查对应车次列表
+            // 查询当前车牌的对应车次列表
             String carNumKey = String.join("_", bill.getCcmNo(), bill.getShiftGroup(), bill.getShift(),
                     Optional.ofNullable(bill.getLicensePlate()).orElse(""),
                     DateFormatUtils.format(DateUtils.getStartOfDay(bill.getCreateTime()), "yyyy-MM-dd"));
@@ -6035,12 +6033,16 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
                     .sorted(Comparator.comparing(StorageBill::getCreateTime))
                     .collect(Collectors.toList());
 
+            StorageBill updateBill = new StorageBill();
+            updateBill.setId(bill.getId());
+            updateBill.setBtype(bill.getBtype());
+
             if (needCalcCarNum) {
                 long index = relatedBills.stream()
                         .filter(b -> !b.getId().equals(bill.getId()))
                         .filter(b -> b.getCreateTime().before(bill.getCreateTime()))
                         .count();
-                newBill.setCarNum((int) index + 1);
+                updateBill.setCarNum((int) index + 1);
                 updated = true;
             }
 
@@ -6057,29 +6059,39 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
                         .filter(b -> !b.getId().equals(bill.getId()))
                         .filter(b -> b.getCreateTime().before(bill.getCreateTime()))
                         .count();
-                newBill.setCarAllNum((int) totalIndex + 1);
+                updateBill.setCarAllNum((int) totalIndex + 1);
                 updated = true;
             }
 
             if (updated) {
-                update(newBill, new UpdateWrapper<StorageBill>()
-                        .eq("id", newBill.getId())
-                        .set("car_num", newBill.getCarNum())
-                        .set("car_all_num", newBill.getCarAllNum()));
+                UpdateWrapper<StorageBill> updateWrapper = new UpdateWrapper<>();
+                updateWrapper.eq("id", updateBill.getId());
+
+                if (needCalcCarNum) {
+                    updateWrapper.set("car_num", updateBill.getCarNum());
+                }
+
+                if (needCalcCarAllNum) {
+                    updateWrapper.set("car_all_num", updateBill.getCarAllNum());
+                }
+
+                update(updateBill, updateWrapper);
             }
 
-            // 更新交班 outCarNum(依赖 carAllNum,不管车牌状态)
-            if (shiftRecord.getOutCarNum() == null || shiftRecord.getOutCarNum() == 0) {
-                UpdateWrapper<BilletHotsendChangeShift> updateWrapper = new UpdateWrapper<>();
-                updateWrapper.eq("id", shiftRecord.getId())
-                        .set("out_car_num", bill.getCarAllNum());
 
-                billetHotsendChangeShiftService.update(null, updateWrapper);
+            // 更新 shiftRecord.outCarNum
+            if (shiftRecord.getOutCarNum() == null || shiftRecord.getOutCarNum() == 0) {
+                billetHotsendChangeShiftService.update(
+                        null,
+                        new UpdateWrapper<BilletHotsendChangeShift>()
+                                .eq("id", shiftRecord.getId())
+                                .set("out_car_num", bill.getCarAllNum())
+                );
             }
         }
-
     }
 
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String destinationSwitchHandle(StorageBill storageBill, String destination, String typeConfigId) {

+ 9 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/carUnit/service/impl/CarUnitServiceImpl.java

@@ -218,7 +218,10 @@ public class CarUnitServiceImpl extends ServiceImpl<CarUnitMapper, CarUnit> impl
                 totalWeight = totalWeight.add(weight);
 
                 String spec = Optional.ofNullable(billets.get(0).getSpec()).orElse("Unknown");
-                String brandNum = Optional.ofNullable(billets.get(0).getBrandNum()).orElse("HRB400E");
+                String originBrandNum = billets.get(0).getBrandNum();
+                String brandNum = Optional.ofNullable(originBrandNum)
+                        .map(bn -> sysDictService.queryDictTextByKey("billet_spec", bn))
+                        .orElseGet(() -> sysDictService.queryDictTextByKey("billet_spec", "5"));
                 Date latestUpdateTime = billets.stream()
                         .map(BilletBasicInfo::getUpdateTime)
                         .filter(Objects::nonNull)
@@ -296,7 +299,11 @@ public class CarUnitServiceImpl extends ServiceImpl<CarUnitMapper, CarUnit> impl
                 totalWeight = totalWeight.add(weight);
 
                 String spec = Optional.ofNullable(billets.get(0).getSpec()).orElse("Unknown");
-                String brandNum = Optional.ofNullable(billets.get(0).getBrandNum()).orElse("HRB400E");
+                String originBrandNum = billets.get(0).getBrandNum();
+                String brandNum = Optional.ofNullable(originBrandNum)
+                        .map(bn -> sysDictService.queryDictTextByKey("billet_spec", bn))
+                        .orElseGet(() -> sysDictService.queryDictTextByKey("billet_spec", "5"));
+
                 Date latestUpdateTime = billets.stream()
                         .map(BilletBasicInfo::getUpdateTime)
                         .filter(Objects::nonNull)