From 4f39e676277d7a66e13d172288032ce16bb18e8c Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期三, 22 四月 2026 17:05:30 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_河南_鹤壁天沐钢化玻璃厂' into dev_河南_鹤壁天沐钢化玻璃厂

---
 src/main/java/com/ruoyi/approve/service/impl/ApproveProcessServiceImpl.java |  565 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 519 insertions(+), 46 deletions(-)

diff --git a/src/main/java/com/ruoyi/approve/service/impl/ApproveProcessServiceImpl.java b/src/main/java/com/ruoyi/approve/service/impl/ApproveProcessServiceImpl.java
index 404d594..6ccf2a6 100644
--- a/src/main/java/com/ruoyi/approve/service/impl/ApproveProcessServiceImpl.java
+++ b/src/main/java/com/ruoyi/approve/service/impl/ApproveProcessServiceImpl.java
@@ -3,6 +3,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.approve.mapper.ApproveNodeMapper;
@@ -19,11 +20,24 @@
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.other.service.impl.TempFileServiceImpl;
 import com.ruoyi.project.system.domain.SysDept;
+import com.ruoyi.project.system.domain.SysNotice;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
 import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.project.system.service.ISysNoticeService;
+import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
+import com.ruoyi.purchase.pojo.PurchaseLedger;
+import com.ruoyi.quality.mapper.QualityInspectMapper;
+import com.ruoyi.quality.pojo.QualityInspect;
 import com.ruoyi.sales.mapper.CommonFileMapper;
+import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.mapper.ShippingInfoMapper;
+import com.ruoyi.sales.mapper.SalesLedgerMapper;
+import com.ruoyi.sales.pojo.SalesLedger;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import com.ruoyi.sales.pojo.CommonFile;
+import com.ruoyi.sales.pojo.ShippingInfo;
+import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
 import lombok.AllArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.BeanUtils;
@@ -42,28 +56,45 @@
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 @Service
-@RequiredArgsConstructor
+//@RequiredArgsConstructor
 public class ApproveProcessServiceImpl extends ServiceImpl<ApproveProcessMapper, ApproveProcess> implements IApproveProcessService {
     private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMdd");
 
-    private final StringRedisTemplate redisTemplate;
+    @Autowired
+    private  StringRedisTemplate redisTemplate;
+    @Autowired
+    private  DailyRedisCounter dailyRedisCounter;
+    @Autowired
+    private  SysDeptMapper sysDeptMapper;
+    @Autowired
+    private  IApproveNodeService approveNodeService;
+    @Autowired
+    private  SysUserMapper sysUserMapper;
+    @Autowired
+    private  ApproveProcessMapper approveProcessMapper;
+    @Autowired
+    private  TempFileServiceImpl tempFileService;
+    @Autowired
+    private  CommonFileMapper commonFileMapper;
+    @Autowired
+    private  CommonFileServiceImpl commonFileService;
+    @Autowired
+    private  ISysNoticeService sysNoticeService;
 
-    private final DailyRedisCounter dailyRedisCounter;
-
-    private final SysDeptMapper sysDeptMapper;
-    private final IApproveNodeService approveNodeService;
-    private final SysUserMapper sysUserMapper;
-    private final ApproveProcessMapper approveProcessMapper;
-    private final TempFileServiceImpl tempFileService;
-    private final CommonFileMapper commonFileMapper;
+    @Autowired
+    private SalesLedgerMapper salesLedgerMapper;
 
     @Override
-    public void addApprove(ApproveProcessVO approveProcessVO) throws  Exception {
+    public void addApprove(ApproveProcessVO approveProcessVO) throws Exception {
         SysUser sysUser = sysUserMapper.selectUserById(approveProcessVO.getApproveUser());
         SysDept sysDept = sysDeptMapper.selectDeptById(approveProcessVO.getApproveDeptId());
         String[] split = approveProcessVO.getApproveUserIds().split(",");
@@ -71,9 +102,9 @@
                 .map(Long::valueOf)  // 灏嗘瘡涓� String 杞崲涓� Long
                 .collect(Collectors.toList());
         List<SysUser> sysUsers = sysUserMapper.selectUserByIds(longList);
-        if(CollectionUtils.isEmpty(sysUsers)) throw new RuntimeException("瀹℃牳鐢ㄦ埛涓嶅瓨鍦�");
-        if(sysDept == null) throw new RuntimeException("閮ㄩ棬涓嶅瓨鍦�");
-        if(sysUser == null) throw new RuntimeException("鐢宠浜轰笉瀛樺湪");
+        if (CollectionUtils.isEmpty(sysUsers)) throw new RuntimeException("瀹℃牳鐢ㄦ埛涓嶅瓨鍦�");
+        if (sysDept == null) throw new RuntimeException("閮ㄩ棬涓嶅瓨鍦�");
+        if (sysUser == null) throw new RuntimeException("鐢宠浜轰笉瀛樺湪");
         String today = LocalDate.now().format(DATE_FORMAT);
         Long approveId = dailyRedisCounter.incrementAndGetByDb();
         String formattedCount = String.format("%03d", approveId);
@@ -89,9 +120,12 @@
         approveProcess.setApproveUserNames(sysUsers.stream().map(SysUser::getNickName).collect(Collectors.joining(",")));
         approveProcess.setApproveTime(StringUtils.isEmpty(approveProcessVO.getApproveTime()) ? null : dateFormat.parse(approveProcessVO.getApproveTime()));
         approveProcess.setApproveReason(approveProcessVO.getApproveReason());
+        approveProcess.setApproveRemark(approveProcessVO.getApproveRemark());
         approveProcess.setDeviceRepairId(approveProcessVO.getDeviceRepairId());
         approveProcess.setMaintenancePrice(approveProcessVO.getMaintenancePrice());
-        approveProcess.setApproveOverTime(null);
+        approveProcess.setPrice(approveProcessVO.getPrice());
+        approveProcess.setStartDate(approveProcessVO.getStartDate());
+        approveProcess.setEndDate(approveProcessVO.getEndDate());
         approveProcess.setApproveStatus(0);
         approveProcess.setApproveDelete(0);
         approveProcess.setApproveType(approveProcessVO.getApproveType());
@@ -106,21 +140,34 @@
                 .get(0)
                 .getNickName());
         // 璁剧疆鐘舵�佷负閲嶆柊鎻愪氦
-        if(approveProcessVO.getId() != null){
+        if (approveProcessVO.getId() != null) {
             ApproveProcess approveProcess1 = approveProcessMapper.selectById(approveProcessVO.getId());
             approveProcess1.setApproveStatus(4);
             approveProcessMapper.updateById(approveProcess1);
         }
         save(approveProcess);
         //鍒濆鍖栧鎵硅妭鐐�
-        approveNodeService.initApproveNodes(approveProcessVO.getApproveUserIds(),approveID,approveProcessVO.getApproveDeptId());
+        approveNodeService.initApproveNodes(approveProcessVO.getApproveUserIds(), approveID, approveProcessVO.getApproveDeptId());
         // 闄勪欢缁戝畾
         tempFileService.migrateTempFilesToFormal(approveProcess.getId(), approveProcessVO.getTempFileIds(), FileNameType.ApproveProcess.getValue());
+        /*娑堟伅閫氱煡*/
+        String id = approveProcessVO.getApproveUserIds().split(",")[0];
+        if (approveProcess.getApproveType()==8){
+            sysNoticeService.simpleNoticeByUser(approveProcessType(approveProcess.getApproveType()),
+                    approveProcess.getApproveId() + "娴佺▼缂栧彿鐨勫鎵归渶瑕佹偍瀹℃牳!!!!!",
+                    Arrays.asList(Long.valueOf(id)),
+                    "/safeProduction/safeWorkApproval?approveType=" + approveProcess.getApproveType() + "&approveId=" + approveProcess.getApproveId());
+        }else {
+            sysNoticeService.simpleNoticeByUser(approveProcessType(approveProcess.getApproveType()),
+                    approveProcess.getApproveId() + "娴佺▼缂栧彿鐨勫鎵归渶瑕佹偍瀹℃牳!!!!!",
+                    Arrays.asList(Long.valueOf(id)),
+                    "/collaborativeApproval/approvalProcess?approveType=" + approveProcess.getApproveType() + "&approveId=" + approveProcess.getApproveId());
+        }
     }
 
     @Override
     public List<SysDept> selectDeptListByDeptIds(Long[] deptIds) {
-        List<SysDept> sysDeptList =new ArrayList<SysDept>();
+        List<SysDept> sysDeptList = new ArrayList<SysDept>();
         for (Long deptId : deptIds) {
             SysDept sysDept = sysDeptMapper.selectDeptById(deptId);
             sysDeptList.add(sysDept);
@@ -128,48 +175,436 @@
         return sysDeptList;
     }
 
+    @Autowired
+    private PurchaseLedgerMapper purchaseLedgerMapper;
+
+    @Autowired
+    private ShippingInfoMapper shippingInfoMapper;
+
+    @Autowired
+    private SalesLedgerProductMapper salesLedgerProductMapper;
+
+    @Autowired
+    private QualityInspectMapper qualityInspectMapper;
+
     @Override
-    public IPage<ApproveProcess> listAll(Page page,ApproveProcess approveProcess) {
-        IPage<ApproveProcess> approveProcessIPage = approveProcessMapper.listPage(page,approveProcess);
+    public IPage<ApproveProcess> listAll(Page page, ApproveProcess approveProcess) {
+        IPage<ApproveProcess> approveProcessIPage = approveProcessMapper.listPage(page, approveProcess);
         List<ApproveProcess> records = approveProcessIPage.getRecords();
+
         for (ApproveProcess record : records) {
-            List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
-                    .eq(CommonFile::getCommonId, record.getId())
-                    .eq(CommonFile::getType, FileNameType.ApproveProcess.getValue()));
-            record.setCommonFileList(commonFiles);
+            List<CommonFile> allFiles = new ArrayList<>();
+
+            //  閲囪喘瀹℃壒鏌ヨ
+            if (record.getApproveType() == 5) {
+                String contractNo = record.getApproveReason();
+                PurchaseLedger ledger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>()
+                        .eq(PurchaseLedger::getPurchaseContractNumber, contractNo)
+                        .last("limit 1"));
+
+                if (ledger != null) {
+                    allFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
+                            .eq(CommonFile::getCommonId, ledger.getId())
+                            .eq(CommonFile::getType, FileNameType.PURCHASE.getValue()));
+                }
+            }
+
+            //  鍙戣揣瀹℃壒鏌ヨ
+            else if (record.getApproveType() == 7) {
+                String reason = record.getApproveReason(); // 鏍煎紡涓� "xx:CONTRACT_NO"
+                if (StringUtils.hasText(reason) && reason.contains(":")) {
+                    // 鎻愬彇鍐掑彿鍚庨潰鐨勬爣璇嗙 (鍙兘鏄悎鍚屽彿鎴栧彂璐у崟鍙�)
+                    String identifier = reason.split(":")[1];
+                    // 1. 浼樺厛灏濊瘯鎵鹃攢鍞彴璐� (鏂伴�昏緫锛氬悎鍚屽彿鍚屾瀹℃壒)
+                    SalesLedger ledger = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>()
+                            .eq(SalesLedger::getSalesContractNo, identifier)
+                            .last("limit 1"));
+                    if (ledger != null) {
+                        allFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
+                                .eq(CommonFile::getCommonId, ledger.getId())
+                                .eq(CommonFile::getType, FileNameType.SALE.getValue()));
+                    } else {
+                        // 2. 鍥為��鍒版棫閫昏緫锛氬彂璐у崟鍙�
+                        ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
+                                .eq(ShippingInfo::getShippingNo, identifier)
+                                .last("limit 1"));
+                        if (shippingInfo != null) {
+                            allFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
+                                    .eq(CommonFile::getCommonId, shippingInfo.getSalesLedgerId())
+                                    .eq(CommonFile::getType, FileNameType.SALE.getValue()));
+                        }
+                    }
+                }
+            }
+
+            //  鏌ヨ瀹℃壒鍗曡嚜韬殑闄勪欢
+            else {
+                allFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
+                        .eq(CommonFile::getCommonId, record.getId())
+                        .eq(CommonFile::getType, FileNameType.ApproveProcess.getValue()));
+            }
+
+            record.setCommonFileList(allFiles);
         }
         return approveProcessIPage;
     }
 
-    @Override
-    public void delApprove(Long[] ids) {
-        for (Long id : ids) {
-            UpdateWrapper<ApproveProcess> queryWrapper = new UpdateWrapper<>();
-            queryWrapper.lambda().set(ApproveProcess::getApproveDelete, 1)
-                    .eq(ApproveProcess::getApproveId, id);
-            update(queryWrapper);
-            // 鍒犻櫎鍏宠仈鐨勫鎵硅妭鐐�
-            approveNodeService.delApproveNodeByApproveId(id);
+    public void delByIds(List<Long> ids) {
+        for (Long approveId : ids) {
+
+            //  閫昏緫鍒犻櫎瀹℃壒娴佺▼
+            update(new UpdateWrapper<ApproveProcess>()
+                    .lambda()
+                    .set(ApproveProcess::getApproveDelete, 1)
+                    .eq(ApproveProcess::getId, approveId));
+            // 鍒犻櫎瀵瑰簲鐨勯檮浠�
+            commonFileService.deleteByBusinessId(approveId, FileNameType.ApproveProcess.getValue());
+            ApproveProcess approveProcess = approveProcessMapper.selectById(approveId);
+
+            //  鍒犻櫎瀹℃壒鑺傜偣
+            approveNodeService.delApproveNodeByApproveId(approveProcess.getApproveId());
+
+            //  鍙煡鏈�鏂颁竴鏉″鎵规祦绋�
+            ApproveProcess latestProcess = approveProcessMapper.selectOne(
+                    new LambdaQueryWrapper<ApproveProcess>()
+                            .eq(ApproveProcess::getApproveId, approveId)
+                            .orderByDesc(ApproveProcess::getCreateTime)
+                            .last("LIMIT 1"));
+
+            if (latestProcess == null) {
+                continue;
+            }
+
+
+            //  鍒犻櫎瀵瑰簲鐨勬秷鎭�氱煡
+            sysNoticeService.remove(new LambdaQueryWrapper<SysNotice>()
+                    .eq(SysNotice::getNoticeTitle, approveProcessType(latestProcess.getApproveType()))
+                    .eq(SysNotice::getSenderId, latestProcess.getApproveUser())
+                    .apply("CAST(notice_content AS CHAR) LIKE CONCAT('%', {0}, '%')", latestProcess.getApproveId()));
         }
 
+    }
+
+    @Override
+    public void delApprove(List<Long> ids) {
+        for (Long approveId : ids) {
+            ApproveProcess approveProcess = approveProcessMapper.selectOne(new LambdaQueryWrapper<ApproveProcess>()
+                    .eq(ApproveProcess::getApproveId, approveId)
+                    .eq(ApproveProcess::getApproveDelete, 0)
+                    .last("LIMIT 1"));
+            //  閫昏緫鍒犻櫎瀹℃壒娴佺▼
+            update(new UpdateWrapper<ApproveProcess>()
+                    .lambda()
+                    .set(ApproveProcess::getApproveDelete, 1)
+                    .eq(ApproveProcess::getApproveId, approveId));
+            // 鍒犻櫎瀵瑰簲鐨勯檮浠�
+            commonFileService.deleteByBusinessId(approveProcess.getId(), FileNameType.ApproveProcess.getValue());
+            //  鍒犻櫎瀹℃壒鑺傜偣
+            approveNodeService.delApproveNodeByApproveId(approveId.toString());
+
+            //  鍙煡鏈�鏂颁竴鏉″鎵规祦绋�
+            ApproveProcess latestProcess = approveProcessMapper.selectOne(
+                    new LambdaQueryWrapper<ApproveProcess>()
+                            .eq(ApproveProcess::getApproveId, approveId)
+                            .orderByDesc(ApproveProcess::getCreateTime)
+                            .last("LIMIT 1"));
+
+            if (latestProcess == null) {
+                continue;
+            }
+
+            //  鍒犻櫎瀵瑰簲鐨勬秷鎭�氱煡
+            sysNoticeService.remove(new LambdaQueryWrapper<SysNotice>()
+                            .eq(SysNotice::getNoticeTitle, approveProcessType(latestProcess.getApproveType()))
+                            .eq(SysNotice::getSenderId, latestProcess.getApproveUser())
+                            .apply("CAST(notice_content AS CHAR) LIKE CONCAT('%', {0}, '%')", latestProcess.getApproveId()));
+        }
 
     }
 
     @Override
     public ApproveProcess getApproveById(String id) {
-        LambdaQueryWrapper<ApproveProcess> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(ApproveProcess::getApproveId, id);
-        queryWrapper.eq(ApproveProcess::getApproveDelete, 0);
-        queryWrapper.eq(ApproveProcess::getTenantId, SecurityUtils.getLoginUser().getTenantId());
-        queryWrapper.last("limit 1");
-        ApproveProcess one = getOne(queryWrapper);
+        ApproveProcess one = approveProcessMapper.selectList(Wrappers.<ApproveProcess>lambdaQuery()
+                .eq(ApproveProcess::getApproveId,id)
+                .eq(ApproveProcess::getApproveDelete,0)).get(0);
         one.setCommonFileList(commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
                 .eq(CommonFile::getCommonId, one.getId())
                 .eq(CommonFile::getType, FileNameType.ApproveProcess.getValue())));
         return one;
     }
 
-    private final ApproveNodeMapper approveNodeMapper;
+    @Override
+    public Map<String, Object> getStockInOrderInfo(String approveId) {
+        ApproveProcess approveProcess = getStockInApproveProcess(approveId);
+        StockInBusinessContext context = parseStockInContext(approveProcess);
+        if (context == null) {
+            throw new RuntimeException("褰撳墠瀹℃壒鍗曟湭缁戝畾鍏ュ簱涓氬姟鏁版嵁");
+        }
+        Map<String, Object> result = new HashMap<>();
+        result.put("approveId", approveProcess.getApproveId());
+        result.put("approveType", approveProcess.getApproveType());
+        result.put("businessType", context.businessType);
+        if (context.purchaseLedgerId != null) {
+            PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(context.purchaseLedgerId);
+            if (purchaseLedger == null) {
+                throw new RuntimeException("鍏宠仈閲囪喘璁㈠崟涓嶅瓨鍦�");
+            }
+            result.put("orderInfo", purchaseLedger);
+            return result;
+        }
+        if (context.salesLedgerId != null) {
+            SalesLedger salesLedger = salesLedgerMapper.selectById(context.salesLedgerId);
+            if (salesLedger == null) {
+                throw new RuntimeException("鍏宠仈閿�鍞鍗曚笉瀛樺湪");
+            }
+            result.put("orderInfo", salesLedger);
+            return result;
+        }
+        throw new RuntimeException("鏈В鏋愬埌璁㈠崟淇℃伅");
+    }
+
+    @Override
+    public List<?> getStockInProductList(String approveId) {
+        ApproveProcess approveProcess = getStockInApproveProcess(approveId);
+        StockInBusinessContext context = parseStockInContext(approveProcess);
+        if (context == null) {
+            throw new RuntimeException("褰撳墠瀹℃壒鍗曟湭缁戝畾鍏ュ簱浜у搧鏁版嵁");
+        }
+        List<SalesLedgerProduct> matchedProducts;
+        if (context.purchaseLedgerId != null) {
+            matchedProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>()
+                    .eq(SalesLedgerProduct::getSalesLedgerId, context.purchaseLedgerId)
+                    .eq(SalesLedgerProduct::getType, 2)
+                    .orderByAsc(SalesLedgerProduct::getId));
+            return matchedProducts;
+        }
+        if (context.salesLedgerId != null) {
+            LambdaQueryWrapper<SalesLedgerProduct> wrapper = new LambdaQueryWrapper<SalesLedgerProduct>()
+                    .eq(SalesLedgerProduct::getSalesLedgerId, context.salesLedgerId)
+                    .eq(SalesLedgerProduct::getType, 1)
+                    .orderByAsc(SalesLedgerProduct::getId);
+            if (!context.productIds.isEmpty()) {
+                wrapper.in(SalesLedgerProduct::getId, context.productIds);
+            }
+            matchedProducts = salesLedgerProductMapper.selectList(wrapper);
+            attachRequestedQty(matchedProducts, context);
+            return matchedProducts;
+        }
+        if (!context.productIds.isEmpty()) {
+            matchedProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>()
+                    .in(SalesLedgerProduct::getId, context.productIds)
+                    .orderByAsc(SalesLedgerProduct::getId));
+            attachRequestedQty(matchedProducts, context);
+            return matchedProducts;
+        }
+        return Collections.emptyList();
+    }
+
+    private ApproveProcess getStockInApproveProcess(String approveId) {
+        if (!StringUtils.hasText(approveId)) {
+            throw new RuntimeException("瀹℃壒缂栧彿涓嶈兘涓虹┖");
+        }
+        ApproveProcess approveProcess = approveProcessMapper.selectOne(new LambdaQueryWrapper<ApproveProcess>()
+                .eq(ApproveProcess::getApproveId, approveId)
+                .eq(ApproveProcess::getApproveDelete, 0)
+                .orderByDesc(ApproveProcess::getCreateTime)
+                .last("limit 1"));
+        if (approveProcess == null) {
+            throw new RuntimeException("瀹℃壒鍗曚笉瀛樺湪");
+        }
+        if (!Objects.equals(approveProcess.getApproveType(), 9)) {
+            throw new RuntimeException("褰撳墠瀹℃壒鍗曚笉鏄叆搴撳鎵�");
+        }
+        return approveProcess;
+    }
+
+    private StockInBusinessContext parseStockInContext(ApproveProcess approveProcess) {
+        if (approveProcess == null) {
+            return null;
+        }
+        String remark = approveProcess.getApproveRemark();
+        if (StringUtils.hasText(remark) && remark.startsWith("qualityQualifiedInbound:")) {
+            String[] split = remark.split(":");
+            if (split.length >= 3) {
+                StockInBusinessContext context = new StockInBusinessContext();
+                context.businessType = "PURCHASE_QUALITY";
+                context.purchaseLedgerId = parseLongSafely(split[2]);
+                return context;
+            }
+        }
+        if (StringUtils.hasText(remark) && remark.startsWith("salesStock:")) {
+            String[] split = remark.split(":");
+            if (split.length >= 3) {
+                StockInBusinessContext context = new StockInBusinessContext();
+                context.businessType = "SALES_STOCK";
+                context.salesLedgerId = parseLongSafely(split[1]);
+                context.productIds = Arrays.stream(split[2].split(","))
+                        .filter(StringUtils::hasText)
+                        .map(this::parseLongSafely)
+                        .filter(Objects::nonNull)
+                        .collect(Collectors.toList());
+                return context;
+            }
+        }
+        if (StringUtils.hasText(remark) && (remark.startsWith("scanQualified:") || remark.startsWith("scanUnqualified:"))) {
+            String[] split = remark.split(":");
+            if (split.length >= 3) {
+                StockInBusinessContext context = new StockInBusinessContext();
+                context.businessType = remark.startsWith("scanQualified:") ? "SALES_SCAN_QUALIFIED" : "SALES_SCAN_UNQUALIFIED";
+                context.salesLedgerId = parseLongSafely(split[1]);
+                parseProductLineQty(split[2], context);
+                return context;
+            }
+        }
+        String reason = approveProcess.getApproveReason();
+        if (!StringUtils.hasText(reason)) {
+            return null;
+        }
+        if (reason.startsWith("鍘熸潗鏂欒川妫�鍏ュ簱瀹℃壒:")) {
+            String[] split = reason.split(":");
+            if (split.length >= 3) {
+                StockInBusinessContext context = new StockInBusinessContext();
+                context.businessType = "PURCHASE_QUALITY";
+                context.purchaseLedgerId = parseLongSafely(split[2]);
+                return context;
+            }
+            if (split.length >= 2) {
+                Long inspectId = parseLongSafely(split[1]);
+                if (inspectId != null) {
+                    QualityInspect inspect = qualityInspectMapper.selectById(inspectId);
+                    if (inspect != null) {
+                        StockInBusinessContext context = new StockInBusinessContext();
+                        context.businessType = "PURCHASE_QUALITY";
+                        context.purchaseLedgerId = inspect.getPurchaseLedgerId();
+                        return context;
+                    }
+                }
+            }
+        }
+        if (reason.startsWith("鍏ュ簱瀹℃壒:")) {
+            String[] split = reason.split(":");
+            if (split.length >= 4) {
+                StockInBusinessContext context = new StockInBusinessContext();
+                context.businessType = "SALES_STOCK";
+                context.salesLedgerId = parseLongSafely(split[2]);
+                context.productIds = Arrays.stream(split[3].split(","))
+                        .filter(StringUtils::hasText)
+                        .map(this::parseLongSafely)
+                        .filter(Objects::nonNull)
+                        .collect(Collectors.toList());
+                return context;
+            }
+        }
+        return null;
+    }
+
+    private void parseProductLineQty(String lines, StockInBusinessContext context) {
+        if (!StringUtils.hasText(lines) || context == null) {
+            return;
+        }
+        String[] items = lines.split(",");
+        for (String item : items) {
+            if (!StringUtils.hasText(item)) {
+                continue;
+            }
+            String[] pair = item.split("@");
+            Long lineId = parseLongSafely(pair[0]);
+            if (lineId == null) {
+                continue;
+            }
+            context.productIds.add(lineId);
+            if (pair.length >= 2 && StringUtils.hasText(pair[1])) {
+                context.requestedQtyByProductId.put(lineId, pair[1]);
+            }
+        }
+    }
+
+    private void attachRequestedQty(List<SalesLedgerProduct> products, StockInBusinessContext context) {
+        if (products == null || products.isEmpty() || context == null || context.requestedQtyByProductId.isEmpty()) {
+            return;
+        }
+        for (SalesLedgerProduct product : products) {
+            if (product == null || product.getId() == null) {
+                continue;
+            }
+            String requestedQty = context.requestedQtyByProductId.get(product.getId());
+            if (requestedQty != null) {
+                product.setRemark(StringUtils.hasText(product.getRemark())
+                        ? product.getRemark() + "锛涘鎵圭敵璇锋暟閲�:" + requestedQty
+                        : "瀹℃壒鐢宠鏁伴噺:" + requestedQty);
+            }
+        }
+    }
+
+    private Long parseLongSafely(String value) {
+        if (!StringUtils.hasText(value)) {
+            return null;
+        }
+        try {
+            return Long.valueOf(value);
+        } catch (Exception ignored) {
+            return null;
+        }
+    }
+
+    private static class StockInBusinessContext {
+        private String businessType;
+        private Long purchaseLedgerId;
+        private Long salesLedgerId;
+        private List<Long> productIds = new ArrayList<>();
+        private final Map<Long, String> requestedQtyByProductId = new HashMap<>();
+    }
+
+    @Autowired
+    private ApproveNodeMapper approveNodeMapper;
+
+    // 鎶ヤ环瀹℃壒缂栬緫瀹℃牳浜�
+    public void updateApproveUser(ApproveGetAndUpdateVo approveGetAndUpdateVo) {
+        LambdaQueryWrapper<ApproveProcess> approveProcessLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        approveProcessLambdaQueryWrapper.eq(ApproveProcess::getApproveType, approveGetAndUpdateVo.getApproveType())
+                .eq(ApproveProcess::getApproveReason, approveGetAndUpdateVo.getApproveReason())
+                .last("limit 1");
+        ApproveProcess approveProcess = approveProcessMapper.selectOne(approveProcessLambdaQueryWrapper);
+        if (approveProcess == null) throw new RuntimeException("璇烽�夋嫨瀹℃壒浜�");
+        String[] split = approveGetAndUpdateVo.getApproveUserIds().split(",");
+        if (split.length == 0) {
+            throw new RuntimeException("璇烽�夋嫨瀹℃壒浜�");
+        }
+        List<SysUser> sysUsers = sysUserMapper.selectUserByIds(Arrays.asList(split).stream().map(Long::parseLong).collect(Collectors.toList()));
+        if (CollectionUtils.isEmpty(sysUsers)) throw new RuntimeException("璇烽�夋嫨瀹℃壒浜�");
+        //瀹℃牳涓笉鍙互缂栬緫瀹℃牳浜�
+        if (approveProcess.getApproveStatus() != 1) {
+            approveProcess.setApproveUserCurrentId(Long.parseLong(split[0]));
+            approveProcess.setApproveUserCurrentName(sysUsers.stream().filter(user -> user.getUserId().equals(Long.parseLong(split[0]))).collect(Collectors.toList()).get(0).getNickName());
+        }
+        if (approveGetAndUpdateVo.getApproveStatus() != null) {
+            approveProcess.setApproveStatus(approveGetAndUpdateVo.getApproveStatus());
+        }
+        approveProcess.setApproveUserIds(approveGetAndUpdateVo.getApproveUserIds());
+        updateById(approveProcess);
+        //淇敼瀹℃壒浜�
+        // 鍏堝垹闄� 鍚庢柊澧�
+        LambdaQueryWrapper<ApproveNode> approveNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        approveNodeLambdaQueryWrapper.eq(ApproveNode::getApproveProcessId, approveProcess.getApproveId())
+                .eq(ApproveNode::getDeleteFlag, 0)
+//                .eq(ApproveNode::getTenantId, SecurityUtils.getLoginUser().getTenantId())
+                .orderByAsc(ApproveNode::getApproveNodeOrder);
+        approveNodeMapper.delete(approveNodeLambdaQueryWrapper);
+        approveNodeService.initApproveNodes(approveGetAndUpdateVo.getApproveUserIds(), approveProcess.getApproveId(), approveProcess.getTenantId());
+        /*娑堟伅閫氱煡*/
+        String id = approveProcess.getApproveUserIds().split(",")[0];
+        if (approveProcess.getApproveType()==8){
+            sysNoticeService.simpleNoticeByUser(approveProcessType(approveProcess.getApproveType()),
+                    approveProcess.getApproveId() + "娴佺▼缂栧彿鐨勫鎵归渶瑕佹偍瀹℃牳!!!!!",
+                    Arrays.asList(Long.valueOf(id)),
+                    "/safeProduction/safeWorkApproval?approveType=" + approveProcess.getApproveType() + "&approveId=" + approveProcess.getApproveId());
+        }else {
+            sysNoticeService.simpleNoticeByUser(approveProcessType(approveProcess.getApproveType()),
+                    approveProcess.getApproveId() + "娴佺▼缂栧彿鐨勫鎵归渶瑕佹偍瀹℃牳!!!!!",
+                    Arrays.asList(Long.valueOf(id)),
+                    "/collaborativeApproval/approvalProcess?approveType=" + approveProcess.getApproveType() + "&approveId=" + approveProcess.getApproveId());
+        }
+    }
 
 
     @Override
@@ -180,16 +615,16 @@
         approve.setApproveReason(approveGetAndUpdateVo.getApproveReason());
         SysUser sysUser = sysUserMapper.selectUserById(approveGetAndUpdateVo.getApproveUser());
         String[] split = approveGetAndUpdateVo.getApproveUserIds().split(",");
-        if(split.length == 0){
+        if (split.length == 0) {
             throw new RuntimeException("璇烽�夋嫨瀹℃壒浜�");
         }
         List<SysUser> sysUsers = sysUserMapper.selectUserByIds(Arrays.asList(split).stream().map(Long::parseLong).collect(Collectors.toList()));
-        if(CollectionUtils.isEmpty(sysUsers)) throw new RuntimeException("璇烽�夋嫨瀹℃壒浜�");
-        if(sysUser == null) throw new RuntimeException("鐢宠浜轰笉瀛樺湪");
+        if (CollectionUtils.isEmpty(sysUsers)) throw new RuntimeException("璇烽�夋嫨瀹℃壒浜�");
+        if (sysUser == null) throw new RuntimeException("鐢宠浜轰笉瀛樺湪");
         approve.setApproveUserName(sysUser.getNickName());
         approve.setApproveUser(sysUser.getUserId());
         //瀹℃牳涓笉鍙互缂栬緫瀹℃牳浜�
-        if(approve.getApproveStatus() != 1){
+        if (approve.getApproveStatus() != 1) {
             approve.setApproveUserCurrentId(Long.parseLong(split[0]));
             approve.setApproveUserCurrentName(sysUsers.stream().filter(user -> user.getUserId().equals(Long.parseLong(split[0]))).collect(Collectors.toList()).get(0).getNickName());
         }
@@ -199,10 +634,10 @@
         LambdaQueryWrapper<ApproveNode> approveNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
         approveNodeLambdaQueryWrapper.eq(ApproveNode::getApproveProcessId, approve.getApproveId())
                 .eq(ApproveNode::getDeleteFlag, 0)
-                .eq(ApproveNode::getTenantId, SecurityUtils.getLoginUser().getTenantId())
+//                .eq(ApproveNode::getTenantId, SecurityUtils.getLoginUser().getTenantId())
                 .orderByAsc(ApproveNode::getApproveNodeOrder);
         approveNodeMapper.delete(approveNodeLambdaQueryWrapper);
-        approveNodeService.initApproveNodes(approveGetAndUpdateVo.getApproveUserIds(),approve.getApproveId(),approve.getTenantId());
+        approveNodeService.initApproveNodes(approveGetAndUpdateVo.getApproveUserIds(), approve.getApproveId(), approve.getTenantId());
 
 //        int i = 0;
 //        for (ApproveNode approveNode : list) {
@@ -221,7 +656,45 @@
 //            i++;
 //        }
         tempFileService.migrateTempFilesToFormal(approve.getId(), approveGetAndUpdateVo.getTempFileIds(), FileNameType.ApproveProcess.getValue());
+        /*娑堟伅閫氱煡*/
+        String id = approve.getApproveUserIds().split(",")[0];
+        if (approve.getApproveType()==8){
+            sysNoticeService.simpleNoticeByUser(approveProcessType(approve.getApproveType()),
+                    approve.getApproveId() + "娴佺▼缂栧彿鐨勫鎵归渶瑕佹偍瀹℃牳!!!!!",
+                    Arrays.asList(Long.valueOf(id)),
+                    "/safeProduction/safeWorkApproval?approveType=" + approve.getApproveType() + "&approveId=" + approve.getApproveId());
+        }else {
+            sysNoticeService.simpleNoticeByUser(approveProcessType(approve.getApproveType()),
+                    approve.getApproveId() + "娴佺▼缂栧彿鐨勫鎵归渶瑕佹偍瀹℃牳!!!!!",
+                    Arrays.asList(Long.valueOf(id)),
+                    "/collaborativeApproval/approvalProcess?approveType=" + approve.getApproveType() + "&approveId=" + approve.getApproveId());
+        }
+
     }
 
 
+    //瀹℃壒绫诲瀷鑾峰彇(涓庡墠绔〉闈㈠搴�)
+    private String approveProcessType(Integer approveType) {
+        switch (approveType) {
+            case 1:
+                return "鍏嚭绠$悊";
+            case 2:
+                return "璇峰亣绠$悊";
+            case 3:
+                return "鍑哄樊绠$悊";
+            case 4:
+                return "鎶ラ攢绠$悊";
+            case 5:
+                return "閲囪喘瀹℃壒";
+            case 6:
+                return "鎶ヤ环瀹℃壒";
+            case 7:
+                return "鍙戣揣瀹℃壒";
+            case 8:
+                return "鍗遍櫓浣滀笟瀹℃壒";
+            case 9:
+                return "鍏ュ簱瀹℃壒";
+        }
+        return null;
+    }
 }

--
Gitblit v1.9.3