Browse Source

装运单信息查询

qiangxuan 3 tháng trước cách đây
mục cha
commit
a2546eea66

+ 8 - 1
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/controller/StorageBillController.java

@@ -23,7 +23,6 @@ import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsendDetailsVo;
 import org.jeecg.modules.billet.billetHotsend.service.IBilletHotsendBaseService;
 import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
 import org.jeecg.modules.billet.operateLog.service.IOperateLogService;
-import org.jeecg.modules.billet.pm.service.IBilletHotsendHostService;
 import org.jeecg.modules.billet.rollClubOne.entity.RollClubOneDetails;
 import org.jeecg.modules.billet.rollClubOne.service.IRollClubOneDetailsService;
 import org.jeecg.modules.billet.rollClubThree.entity.RollClubThreeDetails;
@@ -931,4 +930,12 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 		OnDutyStatistics onDutyStatistics = storageBillService.queryHotChargingOutStatistics(ccmNo);
 		return Result.OK(onDutyStatistics);
 	}
+
+	@ApiOperation(value="当班装运单统计明细-班次实绩", notes="当班装运单统计明细-班次实绩")
+	@GetMapping(value = "/queryOnDutyStorageBillStatistics")
+	public Result<StorageBillStatistics> queryOnDutyStorageBillStatisticsHandle(@RequestParam(name="ccmNo") String ccmNo,
+																	  @RequestParam(name="changeShiftId", required = false) String changeShiftId) {
+		StorageBillStatistics result = storageBillService.queryOnDutyStorageBillStatisticsHandle(ccmNo, changeShiftId);
+		return Result.OK(result);
+	}
 }

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

@@ -14,8 +14,8 @@ public class DetailStatistics {
     @ApiModelProperty(value = "总重量")
     private Double blankOutput;
 
-    /**出坯量*/
-    @ApiModelProperty(value = "总重量")
+    /**定尺*/
+    @ApiModelProperty(value = "定尺")
     private String size;
 
     public DetailStatistics(Integer amountTotal, Double blankOutput, String size) {

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

@@ -0,0 +1,40 @@
+package org.jeecg.modules.billet.storageBill.entity;
+
+import lombok.Data;
+import org.jeecg.modules.billet.rollHeight.entity.DestinationStatisticsDetails;
+
+import java.util.List;
+
+@Data
+public class StorageBillStatistics {
+
+    // 装运总数
+    private Integer storageSum;
+    // 装运总重
+    private Double storageTotalWeight;
+
+
+    // 棒二装运总数
+    private Integer rollClubTwoSum;
+    // 棒三装运总数
+    private Integer rollClubThreeSum;
+    // 上若装运总数
+    private Integer rollOutShippSum;
+
+
+    // 棒二装运总重
+    private Double rollClubTwoTotalWeight;
+    // 棒二装运总重
+    private Double rollClubThreeTotalWeight;
+    // 棒二装运总重
+    private Double rollOutShippTotalWeight;
+
+
+    // 棒二明细
+    private List<DestinationStatisticsDetails> rollClubTwoStatisticsList;
+    // 棒三明细
+    private List<DestinationStatisticsDetails> rollClubThreeStatisticsList;
+    // 上若明细
+    private List<DestinationStatisticsDetails> rollOutShippStatisticsList;
+
+}

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

@@ -58,4 +58,6 @@ public interface IStorageBillService extends IService<StorageBill> {
     OnDutyDetailStatistics queryOnDutyDeatailHandle(String ccmNo, String changeShiftId);
 
     List<OnDutySizeVo> queryOnDutySize(String ccmNo, String changeShiftId);
+
+    StorageBillStatistics queryOnDutyStorageBillStatisticsHandle(String ccmNo, String changeShiftId);
 }

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

@@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections.CollectionUtils;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfo;
@@ -1460,6 +1459,7 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
         queryWrapper2.eq(StorageBill::getCcmNo, ccmNo)
                 .eq(StorageBill::getShift, shift)
                 .eq(StorageBill::getShiftGroup, shiftGroup)
+                .notIn(StorageBill::getLicensePlate, Arrays.asList("辊道", "堆垛辊道"))
                 .isNull(StorageBill::getOutTime);
         // 检查 billetHotsendChangeShift 是否为空
         if (oConvertUtils.isEmpty(changeShiftId)) {
@@ -1577,6 +1577,7 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
         queryWrapper2.eq(StorageBill::getCcmNo, ccmNo)
                 .eq(StorageBill::getShift, shift)
                 .eq(StorageBill::getShiftGroup, shiftGroup)
+                .notIn(StorageBill::getLicensePlate, Arrays.asList("辊道", "堆垛辊道"))
                 .gt(StorageBill::getAmountTotal, 0);
         // 检查 billetHotsendChangeShift 是否为空
         if (oConvertUtils.isEmpty(changeShiftId)) {
@@ -2300,6 +2301,230 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
         return onDutySizeVoList;
     }
 
+    @Override
+    public StorageBillStatistics queryOnDutyStorageBillStatisticsHandle(String ccmNo, String changeShiftId) {
+
+        StorageBillStatistics storageBillStatistics = new StorageBillStatistics();
+
+        String shiftGroup = "";
+        String shift = "";
+        BilletHotsendChangeShift billetHotsendChangeShift;
+        if(oConvertUtils.isEmpty(changeShiftId)){
+            // 从 Redis 获取班次信息
+            shiftGroup = getShiftInfo(ccmNo, "class:shift:group:%s");
+            shift = getShiftInfo(ccmNo, "class:shift:%s");
+            // 根据铸机号、缓存中的当前班次,倒序最新一条,获取交班记录中的创建时间
+            LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(BilletHotsendChangeShift::getCcmNo, ccmNo)
+                    .eq(BilletHotsendChangeShift::getShift, shift)
+                    .eq(BilletHotsendChangeShift::getShiftGroup, shiftGroup)
+                    .orderByDesc(BilletHotsendChangeShift::getCreateTime)
+                    .last("limit 1");
+            billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
+            if (billetHotsendChangeShift == null){
+                log.info("查询当班装运单信息失败,交班记录为空!{} 失败时间:{}", ccmNo, new Date());
+                return storageBillStatistics;
+            }
+        }else {
+            // 根据铸机号、交班记录ID,获取交班记录中的班别、班次、创建时间
+            LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(BilletHotsendChangeShift::getId, changeShiftId).eq(BilletHotsendChangeShift::getCcmNo, ccmNo);
+            billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
+            if (billetHotsendChangeShift == null){
+                log.info("查询当班装运单信息失败,交班记录为空!{} 失败时间:{}", ccmNo, new Date());
+                return storageBillStatistics;
+            }
+            shiftGroup = billetHotsendChangeShift.getShiftGroup();
+            shift = billetHotsendChangeShift.getShift();
+        }
+
+        // 根据铸机号、班组、班别,amountTotal不等于0 ,查询当班装运单信息
+        LambdaQueryWrapper<StorageBill> queryWrapper2 = new LambdaQueryWrapper<>();
+        queryWrapper2.eq(StorageBill::getCcmNo, ccmNo)
+                .eq(StorageBill::getShift, shift)
+                .eq(StorageBill::getShiftGroup, shiftGroup)
+                .notIn(StorageBill::getLicensePlate, Arrays.asList("辊道", "堆垛辊道"))
+                .gt(StorageBill::getAmountTotal, 0);
+        // 检查 billetHotsendChangeShift 是否为空
+        if (oConvertUtils.isEmpty(changeShiftId)) {
+            // 当 changeShiftId 为空时,时间范围从 createTime 到当前时间
+            queryWrapper2.between(StorageBill::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
+        } else {
+            // 当 changeShiftId 不为空时,时间范围从 createTime 到 updateTime
+            queryWrapper2.between(StorageBill::getCreateTime, billetHotsendChangeShift.getCreateTime(), billetHotsendChangeShift.getChangeShiftTime());
+        }
+        List<StorageBill> storageBillList = baseMapper.selectList(queryWrapper2);
+        if (oConvertUtils.listIsEmpty(storageBillList)){
+            log.info("{}{}", "查询当班装运单信息为空!", ccmNo);
+            storageBillStatistics.setStorageSum(0);
+            storageBillStatistics.setStorageTotalWeight(0.0);
+            storageBillStatistics.setRollClubTwoSum(0);
+            storageBillStatistics.setRollClubThreeSum(0);
+            storageBillStatistics.setRollClubTwoTotalWeight(0.0);
+            storageBillStatistics.setRollClubThreeTotalWeight(0.0);
+            storageBillStatistics.setRollOutShippSum(0);
+            storageBillStatistics.setRollOutShippTotalWeight(0.0);
+            return storageBillStatistics;
+        }
+
+
+        List<DestinationStatisticsDetails> rollClubTwoStatisticsList = new ArrayList<>();
+
+        List<DestinationStatisticsDetails> rollClubThreeStatisticsList = new ArrayList<>();
+
+        List<DestinationStatisticsDetails> rollOutShippStatisticsList = new ArrayList<>();
+
+
+        List<RollClubTwoDetails> rollClubTwoDetailsListAll = new ArrayList<>();
+        List<RollClubThreeDetails> rollClubThreeDetailsListAll = new ArrayList<>();
+        List<RollOutShippDetails> rollOutShippDetailsListAll = new ArrayList<>();
+
+        for (StorageBill storageBill : storageBillList) {
+            if ("棒二".equals(storageBill.getDestination())) {
+                LambdaQueryWrapper<RollClubTwoDetails> queryWrapper3 = new LambdaQueryWrapper<>();
+                queryWrapper3.eq(RollClubTwoDetails::getCcmNo, ccmNo).eq(RollClubTwoDetails::getStorageBillId, storageBill.getId());
+                List<RollClubTwoDetails> rollClubTwoDetailsList = rollClubTwoDetailsService.list(queryWrapper3);
+                if (oConvertUtils.listIsNotEmpty(rollClubTwoDetailsList)) {
+                    rollClubTwoDetailsListAll.addAll(rollClubTwoDetailsList);
+                }
+            }
+
+            if ("棒三".equals(storageBill.getDestination())) {
+                LambdaQueryWrapper<RollClubThreeDetails> queryWrapper3 = new LambdaQueryWrapper<>();
+                queryWrapper3.eq(RollClubThreeDetails::getCcmNo, ccmNo).eq(RollClubThreeDetails::getStorageBillId, storageBill.getId());
+                List<RollClubThreeDetails> rollClubThreeDetailsList = rollClubThreeDetailsService.list(queryWrapper3);
+                if (oConvertUtils.listIsNotEmpty(rollClubThreeDetailsList)) {
+                    rollClubThreeDetailsListAll.addAll(rollClubThreeDetailsList);
+                }
+            }
+
+            if ("上若".equals(storageBill.getDestination())) {
+                LambdaQueryWrapper<RollOutShippDetails> queryWrapper3 = new LambdaQueryWrapper<>();
+                queryWrapper3.eq(RollOutShippDetails::getCcmNo, ccmNo).eq(RollOutShippDetails::getStorageBillId, storageBill.getId());
+                List<RollOutShippDetails> rollOutShippDetailsList = rollOutShippDetailsService.list(queryWrapper3);
+                if (oConvertUtils.listIsNotEmpty(rollOutShippDetailsList)) {
+                    rollOutShippDetailsListAll.addAll(rollOutShippDetailsList);
+                }
+            }
+        }
+        if (oConvertUtils.listIsNotEmpty(rollClubTwoDetailsListAll)){
+            List<DestinationStatisticsDetails> currentList1 = rollClubTwoDetailsListAll.stream()
+                    .collect(Collectors.groupingBy(RollClubTwoDetails::getSize, Collectors.toList()))
+                    .entrySet().stream()
+                    .map(entry -> {
+                        String size = entry.getKey();
+                        List<RollClubTwoDetails> group = entry.getValue();
+                        Integer nums = group.size();
+                        boolean shouldMultiply = group.stream().anyMatch(detail -> detail.getStackAddr() != null);
+                        if (shouldMultiply) {
+                            nums = nums * 4;
+                        }
+                        Double totalBlankOutput = group.stream().mapToDouble(RollClubTwoDetails::getBlankOutput).sum();
+                        BigDecimal bd = BigDecimal.valueOf(totalBlankOutput).setScale(4, BigDecimal.ROUND_HALF_UP);
+                        double finalBlankOutput = bd.doubleValue();
+                        String ccmNos = group.isEmpty() ? null : group.get(0).getCcmNo();
+                        return new DestinationStatisticsDetails(size, nums, finalBlankOutput, ccmNos);
+                    }).collect(Collectors.toList());
+            rollClubTwoStatisticsList.addAll(currentList1);
+        }
+
+        if (oConvertUtils.listIsNotEmpty(rollClubThreeDetailsListAll)){
+            List<DestinationStatisticsDetails> currentList2 = rollClubThreeDetailsListAll.stream()
+                    .collect(Collectors.groupingBy(RollClubThreeDetails::getSize, Collectors.toList()))
+                    .entrySet().stream()
+                    .map(entry -> {
+                        String size = entry.getKey();
+                        List<RollClubThreeDetails> group = entry.getValue();
+                        Integer nums = group.size();
+                        boolean shouldMultiply = group.stream().anyMatch(detail -> detail.getStackAddr() != null);
+                        if (shouldMultiply) {
+                            nums = nums * 4;
+                        }
+                        Double totalBlankOutput = group.stream().mapToDouble(RollClubThreeDetails::getBlankOutput).sum();
+                        BigDecimal bd = BigDecimal.valueOf(totalBlankOutput).setScale(4, BigDecimal.ROUND_HALF_UP);
+                        double finalBlankOutput = bd.doubleValue();
+                        String ccmNos = group.isEmpty() ? null : group.get(0).getCcmNo();
+                        return new DestinationStatisticsDetails(size, nums, finalBlankOutput, ccmNos);
+                    }).collect(Collectors.toList());
+            rollClubThreeStatisticsList.addAll(currentList2);
+        }
+
+        if (oConvertUtils.listIsNotEmpty(rollOutShippDetailsListAll)){
+            List<DestinationStatisticsDetails> currentList3 = rollOutShippDetailsListAll.stream()
+                    .collect(Collectors.groupingBy(RollOutShippDetails::getSize, Collectors.toList()))
+                    .entrySet().stream()
+                    .map(entry -> {
+                        String size = entry.getKey();
+                        List<RollOutShippDetails> group = entry.getValue();
+                        Integer nums = group.size();
+                        boolean shouldMultiply = group.stream().anyMatch(detail -> detail.getStackAddr() != null);
+                        if (shouldMultiply) {
+                            nums = nums * 4;
+                        }
+                        Double totalBlankOutput = group.stream().mapToDouble(RollOutShippDetails::getBlankOutput).sum();
+                        BigDecimal bd = BigDecimal.valueOf(totalBlankOutput).setScale(4, BigDecimal.ROUND_HALF_UP);
+                        double finalBlankOutput = bd.doubleValue();
+                        String ccmNos = group.isEmpty() ? null : group.get(0).getCcmNo();
+                        return new DestinationStatisticsDetails(size, nums, finalBlankOutput, ccmNos);
+                    }).collect(Collectors.toList());
+            rollOutShippStatisticsList.addAll(currentList3);
+        }
+
+        // 计算各个列表的数量总和
+        int rollClubTwoSum = calculateIntSum(rollClubTwoStatisticsList);
+        int rollClubThreeSum = calculateIntSum(rollClubThreeStatisticsList);
+        int rollOutShippSum = calculateIntSum(rollOutShippStatisticsList);
+
+        // 计算各个列表的重量总和
+        double rollClubTwoTotalWeight = calculateDoubleSum(rollClubTwoStatisticsList);
+        double rollClubThreeTotalWeight = calculateDoubleSum(rollClubThreeStatisticsList);
+        double rollOutShippTotalWeight = calculateDoubleSum(rollOutShippStatisticsList);
+
+        // 计算装运总数和总重
+        int storageSum = rollClubTwoSum + rollClubThreeSum + rollOutShippSum;
+        double storageTotalWeight = rollClubTwoTotalWeight + rollClubThreeTotalWeight + rollOutShippTotalWeight;
+        // 使用 String.format 方法保留 4 位小数
+        String formattedWeight = String.format("%.4f", storageTotalWeight);
+
+        // 将格式化后的字符串转换回 double 类型
+        storageTotalWeight = Double.parseDouble(formattedWeight);
+
+        storageBillStatistics.setStorageSum(storageSum);
+        storageBillStatistics.setStorageTotalWeight(storageTotalWeight);
+
+        storageBillStatistics.setRollClubTwoSum(rollClubTwoSum);
+        storageBillStatistics.setRollClubThreeSum(rollClubThreeSum);
+        storageBillStatistics.setRollOutShippSum(rollOutShippSum);
+
+        storageBillStatistics.setRollClubTwoTotalWeight(rollClubTwoTotalWeight);
+        storageBillStatistics.setRollClubThreeTotalWeight(rollClubThreeTotalWeight);
+        storageBillStatistics.setRollOutShippTotalWeight(rollOutShippTotalWeight);
+
+
+        storageBillStatistics.setRollClubTwoStatisticsList(rollClubTwoStatisticsList);
+        storageBillStatistics.setRollClubThreeStatisticsList(rollClubThreeStatisticsList);
+        storageBillStatistics.setRollOutShippStatisticsList(rollOutShippStatisticsList);
+
+        return storageBillStatistics;
+    }
+
+
+    // 计算整数总和的方法
+    private int calculateIntSum(List<DestinationStatisticsDetails> list) {
+        if (list == null) {
+            return 0;
+        }
+        return list.stream().mapToInt(DestinationStatisticsDetails::getNums).sum();
+    }
+
+    // 计算双精度浮点数总和的方法
+    private double calculateDoubleSum(List<DestinationStatisticsDetails> list) {
+        if (list == null) {
+            return 0.0;
+        }
+        return list.stream().mapToDouble(DestinationStatisticsDetails::getBlankOutput).sum();
+    }
+
 
     /**
      * 生成综合唯一编码