From d143af7023cfd4a0ced6f0ecf04ae3b3a06fd1dc Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期三, 15 四月 2026 13:11:28 +0800
Subject: [PATCH] feat(md): 添加称重盒子维护功能

---
 RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java |  207 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 166 insertions(+), 41 deletions(-)

diff --git a/RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java b/RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java
index eaf9a1c..3ea1446 100644
--- a/RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java
+++ b/RuoYi-Vue-Plus/ruoyi-modules/ruoyi-qa/src/main/java/org/dromara/qa/analy/service/impl/StoreSilkInfoServiceImpl.java
@@ -1,8 +1,6 @@
 package org.dromara.qa.analy.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.baomidou.dynamic.datasource.annotation.DS;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -16,10 +14,10 @@
 import org.dromara.qa.analy.domain.PackerTimeData;
 import org.dromara.qa.analy.domain.RollerTimeData;
 import org.dromara.qa.analy.domain.vo.StoreSilkDetailVo;
-import org.dromara.qa.analy.mapper.RollerTimeDataMapper;
+import org.dromara.qa.analy.service.IRollerTimeDataService;
+import org.dromara.qa.analy.service.IPackerTimeDataService;
 import org.dromara.qa.md.domain.MdShift;
 import org.dromara.qa.md.domain.bo.MdShiftBo;
-import org.dromara.qa.md.mapper.MdShiftMapper;
 import org.dromara.qa.md.service.OracleShiftReader;
 import org.springframework.stereotype.Service;
 import org.dromara.qa.analy.domain.bo.StoreSilkInfoBo;
@@ -27,12 +25,9 @@
 import org.dromara.qa.analy.domain.StoreSilkInfo;
 import org.dromara.qa.analy.mapper.StoreSilkInfoMapper;
 import org.dromara.qa.analy.service.IStoreSilkInfoService;
-import org.dromara.qa.analy.mapper.FeedmatchTimeDataMapper;
-
+import org.dromara.qa.analy.service.IFeedmatchTimeDataService;
 import java.lang.reflect.Field;
 import java.sql.Timestamp;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.*;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -46,16 +41,16 @@
  * @author zhuguifei
  * @date 2026-03-02
  */
+@DS("oracle_zs")
 @Slf4j
 @RequiredArgsConstructor
 @Service
 public class StoreSilkInfoServiceImpl implements IStoreSilkInfoService {
 
     private final StoreSilkInfoMapper baseMapper;
-    private final FeedmatchTimeDataMapper feedmatchTimeDataMapper;
-    private final RollerTimeDataMapper rollerTimeDataMapper;
-    private final org.dromara.qa.analy.mapper.PackerTimeDataMapper packerTimeDataMapper;
-    private final MdShiftMapper mdShiftMapper;
+    private final IFeedmatchTimeDataService feedmatchTimeDataService;
+    private final IRollerTimeDataService rollerTimeDataService;
+    private final IPackerTimeDataService packerTimeDataService;
     private final OracleShiftReader oracleShiftReader;
 
     /**
@@ -145,19 +140,43 @@
              * - 鏌ヨ涓婄晫浣跨敤 effectiveDistEnd锛氬鏋滃嚭鏂欒繕娌$粨鏉燂紝灏变互褰撳墠鏃堕棿浣滀负涓婄晫锛屼粛鐒惰兘鍙栧埌瀵瑰簲鍏崇郴銆�
              */
             Timestamp targetTime = new Timestamp(distimebegin.getTime() + 10 * 60 * 1000); // 鍑烘枡寮�濮嬪悗10鍒嗛挓
+            String containerStr = StringUtils.isEmpty(containerNum) ? "" : containerNum.trim();
+            //灏忎簬10鐨勬煖鍙疯ˉ0
+            if (containerStr.length() == 1) {
+                containerStr = "0" + containerStr;
+            }
             LambdaQueryWrapper<FeedmatchTimeData> lqw = new LambdaQueryWrapper<>();
+            String finalContainerStr = containerStr;
             lqw.ge(FeedmatchTimeData::getTime, targetTime)
-                    .le(FeedmatchTimeData::getTime, effectiveDistEnd) // 涓嶈兘澶т簬鍑烘枡缁撴潫鏃堕棿锛堝嚭鏂欎腑鍒欎娇鐢ㄥ綋鍓嶆椂闂达級
+                    .le(FeedmatchTimeData::getTime, effectiveDistEnd)
+                    .and(wrapper -> wrapper
+                            .like(FeedmatchTimeData::getFs11, finalContainerStr)
+                            .or()
+                            .like(FeedmatchTimeData::getFs12, finalContainerStr)
+                            .or()
+                            .like(FeedmatchTimeData::getFs21, finalContainerStr)
+                            .or()
+                            .like(FeedmatchTimeData::getFs22, finalContainerStr)
+                            .or()
+                            .like(FeedmatchTimeData::getFs31, finalContainerStr)
+                            .or()
+                            .like(FeedmatchTimeData::getFs32, finalContainerStr)
+                            .or()
+                            .like(FeedmatchTimeData::getFs41, finalContainerStr)
+                            .or()
+                            .like(FeedmatchTimeData::getFs42, finalContainerStr)
+                    )
                     .orderByAsc(FeedmatchTimeData::getTime)
                     .last("LIMIT 1");
-            FeedmatchTimeData feedMatch = feedmatchTimeDataMapper.selectOne(lqw);
+
+            FeedmatchTimeData feedMatch = feedmatchTimeDataService.selectOne(lqw);
             if (feedMatch == null) {
                 // TODO  娣诲姞鎻愮ず
                 continue;
             }
 
             // feedMatch 杞琺ap锛氶�氳繃鍙嶅悜鏄犲皠蹇�熷畾浣嶁�滆鏌滃搴斿摢涓杺涓濇満鈥濄�佲�滆鏈虹粍瀵瑰簲鍝釜绠¢亾鈥�
-            // fsRevMap锛歬ey=鍌ㄤ笣鏌滃彿鏈綅锛堝 1/2/3锛夛紝value=瀛楁鍚嶏紙濡� fs11/fs12...锛�
+            // fsRevMap锛歬ey=鍌ㄤ笣鏌滃彿鍚庝袱浣嶏紙濡� 01/09锛夛紝value=瀛楁鍚嶏紙濡� fs11/fs12...锛�
             Map<String, String> fsRevMap = new HashMap<>();
             // pipeRevMap锛歬ey=鍠備笣鏈哄彿+绠¢亾缁勫悎锛堝 1x / 2x...锛夛紝value=瀛楁鍚嶏紙濡� pipe01/pipe02...锛�
             Map<String, String> pipeRevMap = new HashMap<>();
@@ -173,14 +192,26 @@
                     throw new RuntimeException(e);
                 }
                 if (field.getName().startsWith("fs") && value != null) {
-                    fsRevMap.put(value.toString(), field.getName());
+                    String key = value.toString().trim();
+                    if (key.length() == 1) {
+                        key = "0" + key;
+                    } else if (key.length() > 2) {
+                        key = key.substring(key.length() - 2);
+                    }
+                    fsRevMap.put(key, field.getName());
                 } else if (field.getName().startsWith("pipe") && value != null) {
                     pipeRevMap.put(value.toString(), field.getName());
                     pipeMap.put(field.getName(),value.toString());
                 }
             }
             // 鏍规嵁鍌ㄤ笣鏌滃彿鑾峰彇鍠備笣鏈哄彿
-            String fsNum = fsRevMap.get(containerNum);
+            String containerKey = StringUtils.isEmpty(containerNum) ? "" : containerNum.trim();
+            if (containerKey.length() == 1) {
+                containerKey = "0" + containerKey;
+            } else if (containerKey.length() > 2) {
+                containerKey = containerKey.substring(containerKey.length() - 2);
+            }
+            String fsNum = fsRevMap.get(containerKey);
             if (StringUtils.isEmpty(fsNum)) {
                 // TODO   鍠備笣鏈哄彿绌鸿繑鍥炰俊鎭�
                 continue;
@@ -219,9 +250,12 @@
             // 鍗峰寘浜ч噺缁熻
             Double rollerOutput = 0.0;
             Double packerOutput = 0.0;
-            // 鏄庣粏鍒楄〃
+            // 鏄庣粏鍒楄〃锛堜粎瀛樻渶缁堟鏁扮粨鏋滐級
             List<StoreSilkDetailVo> rollerDetailList = new ArrayList<>();
             List<StoreSilkDetailVo> packerDetailList = new ArrayList<>();
+            // 鎿嶄綔璁板綍鍒楄〃锛堝瓨鎵�鏈夊鍑忚繃绋嬶級
+            List<StoreSilkDetailVo> rollerRecordList = new ArrayList<>();
+            List<StoreSilkDetailVo> packerRecordList = new ArrayList<>();
 
             for (int s = 0; s < distShiftList.size(); s++) {
                 MdShiftBo shiftBo = distShiftList.get(s);
@@ -341,11 +375,24 @@
                             .isNotNull(RollerTimeData::getQty)
                             .gt(RollerTimeData::getQty, 0)
                             .last("LIMIT 1");
-
-                    RollerTimeData rData = rollerTimeDataMapper.selectOne(rlqw);
-                    if (rData != null) {
+                    RollerTimeData rData = rollerTimeDataService.selectOne(rlqw);
+                    if (rData != null && (rData.getDacUpTime() == null || (!rData.getDacUpTime().before(stimDate) && !rData.getDacUpTime().after(etimDate)))) {
                         // 鍏堟妸缁熻缁撴潫鏃跺埢绱鍊煎姞杩涙潵锛歝urrent = Qty(calcEnd)
                         currentRollerOutput += rData.getQty();
+
+                        // 璁板綍杩囩▼锛氱彮娆℃埅姝㈢疮璁�
+                        StoreSilkDetailVo endRecord = new StoreSilkDetailVo();
+                        endRecord.setFsNum(fsNum.substring(2, 3));
+                        endRecord.setSiloNum(containerNum);
+                        endRecord.setPipeNum(channel);
+                        endRecord.setEquNo(equNo);
+                        endRecord.setShiftCode(shift);
+                        endRecord.setShiftStartTime(calcStartDate);
+                        endRecord.setShiftEndTime(calcEndDate);
+                        endRecord.setOutput(rData.getQty());
+                        endRecord.setCalcType("鐝鎴绱");
+                        endRecord.setHitTime(rData.getTime());
+                        rollerRecordList.add(endRecord);
 
                         // 2) 鎵b�滃ご鈥濓細濡傛灉缁熻寮�濮嬫椂鍒绘櫄浜庣彮娆″紑濮嬶紝鍒欏噺鍘� Qty(calcStart)
                         if (calcStartDate.after(stimDate)) {
@@ -362,9 +409,23 @@
                                 .gt(RollerTimeData::getQty, 0)
                                 .last("LIMIT 1");
 
-                            RollerTimeData rBeginData = rollerTimeDataMapper.selectOne(beginRlqw);
-                            if (rBeginData != null) {
+                            RollerTimeData rBeginData = rollerTimeDataService.selectOne(beginRlqw);
+                            if (rBeginData != null && (rBeginData.getDacUpTime() == null || (!rBeginData.getDacUpTime().before(stimDate) && !rBeginData.getDacUpTime().after(etimDate)))) {
                                 currentRollerOutput -= rBeginData.getQty();
+
+                                // 璁板綍杩囩▼锛氭墸闄ゅご閮ㄤ骇閲�
+                                StoreSilkDetailVo beginRecord = new StoreSilkDetailVo();
+                                beginRecord.setFsNum(fsNum.substring(2, 3));
+                                beginRecord.setSiloNum(containerNum);
+                                beginRecord.setPipeNum(channel);
+                                beginRecord.setEquNo(equNo);
+                                beginRecord.setShiftCode(shift);
+                                beginRecord.setShiftStartTime(calcStartDate);
+                                beginRecord.setShiftEndTime(calcEndDate);
+                                beginRecord.setOutput(-rBeginData.getQty()); // 璐熸暟琛ㄧず鎵i櫎
+                                beginRecord.setCalcType("鎵i櫎鍑烘枡鍓嶇疮璁�");
+                                beginRecord.setHitTime(rBeginData.getTime());
+                                rollerRecordList.add(beginRecord);
                             }
                         }
                     }
@@ -392,14 +453,28 @@
                             .eq(PackerTimeData::getKey, packerKey)
                             .ge(PackerTimeData::getTime, tenMinBeforeCalcEnd)
                             .orderByDesc(PackerTimeData::getTime)
-                            .isNotNull(PackerTimeData::getTsQty)
-                            .gt(PackerTimeData::getTsQty, 0)
+                            .isNotNull(PackerTimeData::getQty)
+                            .gt(PackerTimeData::getQty, 0)
                             .last("LIMIT 1");
 
-                    PackerTimeData pData = packerTimeDataMapper.selectOne(plqw);
-                    if (pData != null) {
+                    PackerTimeData pData = packerTimeDataService.selectOne(plqw);
+                    if (pData != null && (pData.getDacUpTime() == null || (!pData.getDacUpTime().before(stimDate) && !pData.getDacUpTime().after(etimDate)))) {
                         // 鍏堟妸缁熻缁撴潫鏃跺埢绱鍊煎姞杩涙潵锛歝urrent = Qty(calcEnd)
-                        currentPackerOutput += pData.getTsQty();
+                        currentPackerOutput += pData.getQty();
+
+                        // 璁板綍杩囩▼锛氱彮娆℃埅姝㈢疮璁�
+                        StoreSilkDetailVo endRecord = new StoreSilkDetailVo();
+                        endRecord.setFsNum(fsNum.substring(2, 3));
+                        endRecord.setSiloNum(containerNum);
+                        endRecord.setPipeNum(channel);
+                        endRecord.setEquNo(equNo);
+                        endRecord.setShiftCode(shift);
+                        endRecord.setShiftStartTime(calcStartDate);
+                        endRecord.setShiftEndTime(calcEndDate);
+                        endRecord.setOutput(pData.getQty());
+                        endRecord.setCalcType("鐝鎴绱");
+                        endRecord.setHitTime(pData.getTime());
+                        packerRecordList.add(endRecord);
 
                         // 2) 鎵b�滃ご鈥濓細濡傛灉缁熻寮�濮嬫椂鍒绘櫄浜庣彮娆″紑濮嬶紝鍒欏噺鍘� Qty(calcStart)
                         if (calcStartDate.after(stimDate)) {
@@ -412,13 +487,27 @@
                                 .eq(PackerTimeData::getKey, packerKey)
                                 .ge(PackerTimeData::getTime, tenMinBeforeCalcStart)
                                 .orderByDesc(PackerTimeData::getTime)
-                                .isNotNull(PackerTimeData::getTsQty)
-                                .gt(PackerTimeData::getTsQty, 0)
+                                .isNotNull(PackerTimeData::getQty)
+                                .gt(PackerTimeData::getQty, 0)
                                 .last("LIMIT 1");
 
-                            PackerTimeData pBeginData = packerTimeDataMapper.selectOne(beginPlqw);
-                            if (pBeginData != null) {
-                                currentPackerOutput -= pBeginData.getTsQty();
+                            PackerTimeData pBeginData = packerTimeDataService.selectOne(beginPlqw);
+                            if (pBeginData != null && (pBeginData.getDacUpTime() == null || (!pBeginData.getDacUpTime().before(stimDate) && !pBeginData.getDacUpTime().after(etimDate)))) {
+                                currentPackerOutput -= pBeginData.getQty();
+
+                                // 璁板綍杩囩▼锛氭墸闄ゅご閮ㄤ骇閲�
+                                StoreSilkDetailVo beginRecord = new StoreSilkDetailVo();
+                                beginRecord.setFsNum(fsNum.substring(2, 3));
+                                beginRecord.setSiloNum(containerNum);
+                                beginRecord.setPipeNum(channel);
+                                beginRecord.setEquNo(equNo);
+                                beginRecord.setShiftCode(shift);
+                                beginRecord.setShiftStartTime(calcStartDate);
+                                beginRecord.setShiftEndTime(calcEndDate);
+                                beginRecord.setOutput(-pBeginData.getQty()); // 璐熸暟琛ㄧず鎵i櫎
+                                beginRecord.setCalcType("鎵i櫎鍑烘枡鍓嶇疮璁�");
+                                beginRecord.setHitTime(pBeginData.getTime());
+                                packerRecordList.add(beginRecord);
                             }
                         }
                     }
@@ -444,6 +533,8 @@
             storeSilkInfoVo.setPackerOutput(packerOutput);
             storeSilkInfoVo.setRollerDetailList(rollerDetailList);
             storeSilkInfoVo.setPackerDetailList(packerDetailList);
+            storeSilkInfoVo.setRollerRecordList(rollerRecordList);
+            storeSilkInfoVo.setPackerRecordList(packerRecordList);
 
         }
 
@@ -556,15 +647,50 @@
     private LambdaQueryWrapper<StoreSilkInfo> buildQueryWrapper(StoreSilkInfoBo bo) {
         Map<String, Object> params = bo.getParams();
         LambdaQueryWrapper<StoreSilkInfo> lqw = Wrappers.lambdaQuery();
-        lqw.orderByAsc(StoreSilkInfo::getId);
         lqw.like(StringUtils.isNotBlank(bo.getMaterialname()), StoreSilkInfo::getMaterialname, bo.getMaterialname());
-        lqw.eq(StringUtils.isNotBlank(bo.getBatchcode()), StoreSilkInfo::getBatchcode, bo.getBatchcode());
-        lqw.eq(bo.getActualstarttime() != null, StoreSilkInfo::getActualstarttime, bo.getActualstarttime());
+        lqw.like(StringUtils.isNotBlank(bo.getBatchcode()), StoreSilkInfo::getBatchcode, bo.getBatchcode());
+        if (bo.getActualstarttime() != null) {
+            ZoneId zone = ZoneId.systemDefault();
+            LocalDate day = bo.getActualstarttime().toInstant().atZone(zone).toLocalDate();
+            Date dayStart = Date.from(day.atStartOfDay(zone).toInstant());
+            Date nextDayStart = Date.from(day.plusDays(1).atStartOfDay(zone).toInstant());
+            lqw.ge(StoreSilkInfo::getActualstarttime, dayStart);
+            lqw.lt(StoreSilkInfo::getActualstarttime, nextDayStart);
+        }
         lqw.eq(bo.getDistimebegin() != null, StoreSilkInfo::getDistimebegin, bo.getDistimebegin());
         lqw.eq(bo.getDistimeend() != null, StoreSilkInfo::getDistimeend, bo.getDistimeend());
-        lqw.eq(StringUtils.isNotBlank(bo.getSiloid()), StoreSilkInfo::getSiloid, bo.getSiloid());
-        lqw.between(params.get("beginTime") != null && params.get("endTime") != null,
-                StoreSilkInfo::getDistimeend, params.get("beginTime"), params.get("endTime"));
+        if (StringUtils.isNotBlank(bo.getSiloid())) {
+            // 鏀寔澶氫釜鏌滃彿鏌ヨ锛屼互閫楀彿鍒嗛殧
+            String[] siloids = bo.getSiloid().split(",");
+            lqw.and(wrapper -> {
+                for (String val : siloids) {
+                    val = val.trim();
+                    if (StringUtils.isBlank(val)) {
+                        continue;
+                    }
+                    String finalVal = val;
+                    // 浣跨敤 OR 杩炴帴澶氫釜鏌滃彿鏉′欢
+                    wrapper.or(w -> {
+                        try {
+                            int num = Integer.parseInt(finalVal);
+                            String padded = String.format("%02d", num);
+                            // 鍖归厤 _1 鎴� _01 (鍏煎涓嶈ˉ闆跺拰琛ラ浂鐨勬儏鍐�)
+                            w.likeLeft(StoreSilkInfo::getSiloid, "_" + num)
+                                    .or()
+                                    .likeLeft(StoreSilkInfo::getSiloid, "_" + padded);
+                        } catch (NumberFormatException e) {
+                            // 闈炴暟瀛楀垯鎸夊師鍊煎尮閰�
+                            w.eq(StoreSilkInfo::getSiloid, finalVal);
+                        }
+                    });
+                }
+            });
+        }
+        if (params.get("beginTime") != null && params.get("endTime") != null) {
+            lqw.apply("distimeend BETWEEN TO_DATE({0}, 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE({1}, 'YYYY-MM-DD HH24:MI:SS')",
+                    params.get("beginTime"),
+                    params.get("endTime"));
+        }
         return lqw;
     }
 
@@ -580,7 +706,6 @@
         validEntityBeforeSave(add);
         boolean flag = baseMapper.insert(add) > 0;
         if (flag) {
-            bo.setId(add.getId());
         }
         return flag;
     }

--
Gitblit v1.9.3