wangxuan 7 months ago
parent
commit
c686752551

+ 8 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxPmqManagementMapService.java

@@ -2,6 +2,9 @@ package com.rongwei.bscommon.sys.service;
 
 import com.rongwei.bsentity.domain.ZhcxPmqManagementMapDo;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.rongwei.rwcommon.base.R;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +16,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface ZhcxPmqManagementMapService extends IService<ZhcxPmqManagementMapDo> {
 
+    /**
+     * 第一层 异步更新关闭状态
+     * @param id MANAGEMENT_id
+     */
+    void updateClosedStateInFirstFloor(List<String> ids);
 }

+ 2 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxPmqManagementRecoredService.java

@@ -57,4 +57,6 @@ public interface ZhcxPmqManagementRecoredService extends IService<ZhcxPmqManagem
      * @param list 前端数据
      */
     R updateBatchList(List<ZhcxPmqManagementDistributionDTO> list);
+
+    R updateBatchList(List<ZhcxPmqManagementDistributionDTO> list,String status,String dispatchstatus);
 }

+ 11 - 9
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxPmqManagementDistributionDetailServiceImpl.java

@@ -48,6 +48,7 @@ public class ZhcxPmqManagementDistributionDetailServiceImpl extends ServiceImpl<
     private ZhcxPmqManagementLogService logService;
 
     @Override
+    //@Async("batchSaveThreadPool")
     public R updateClosedStateInFirstFloor(String id) {
         // 根据pid获取第二层未关闭的数量
         String closeStatus = baseMapper.getNotClosedStateInSecondFloorByPid(id);
@@ -76,15 +77,16 @@ public class ZhcxPmqManagementDistributionDetailServiceImpl extends ServiceImpl<
         // 去更新第一层的状态
         //updateClosedStateInFirstFloor(recoredDo.getPmqmid());
         // 异步去更新 第一层状态
-        Thread thread = new Thread(() -> {
-            try {
-                updateClosedStateInFirstFloor(recoredDo.getPmqmid());
-            } catch (Exception e) {
-                e.printStackTrace();
-                log.info("异步去更新第一层状态异常..." + e.getMessage());
-            }
-        });
-        thread.start(); // 启动线程
+//        Thread thread = new Thread(() -> {
+//            try {
+//                updateClosedStateInFirstFloor(recoredDo.getPmqmid());
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//                log.info("异步去更新第一层状态异常..." + e.getMessage());
+//            }
+//        });
+//        thread.start(); // 启动线程
+        updateClosedStateInFirstFloor(recoredDo.getPmqmid());
         return R.ok("更新第二层状态成功");
     }
 

+ 18 - 13
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxPmqManagementDistributionServiceImpl.java

@@ -61,6 +61,7 @@ public class ZhcxPmqManagementDistributionServiceImpl extends ServiceImpl<ZhcxPm
         // 派单集合
         List<ZhcxPmqManagementDistributionDetailDo> addList = new ArrayList<>();
         List<ZhcxPmqManagementDistributionDetailDo> updateList = new ArrayList<>();
+        List<String> detailIds = new ArrayList<>();
         // 正文如下
         for (ZhcxPmqManagementDistributionDo zhcxPmqManagementDistributionDo : baseList) {
             // 防止脏数据
@@ -94,12 +95,14 @@ public class ZhcxPmqManagementDistributionServiceImpl extends ServiceImpl<ZhcxPm
                         .setSupplement(zhcxPmqManagementDistributionDo.getSupplement())
                         .setStatus(zhcxPmqManagementDistributionDo.getStatus()); //派单状态
                 addList.add(add);
+                detailIds.add(add.getId());
             }else {
                // 更新
                 ZhcxPmqManagementDistributionDetailDo detailDo = details.get(0);
                 detailDo.setEstimatedclosedata(zhcxPmqManagementDistributionDo.getEstimatedclosedata())
                         .setSupplement(zhcxPmqManagementDistributionDo.getSupplement());
                 updateList.add(detailDo);
+                detailIds.add(detailDo.getId());
             }
         }
         // 操作派单表
@@ -109,20 +112,20 @@ public class ZhcxPmqManagementDistributionServiceImpl extends ServiceImpl<ZhcxPm
         if(!updateList.isEmpty()){
             detailService.updateBatchById(updateList);
         }
-        List<ZhcxPmqManagementDistributionDetailDo> resultList = new ArrayList<>();
-        resultList.addAll(addList);
-        resultList.addAll(updateList);
+        //List<ZhcxPmqManagementDistributionDetailDo> resultList = new ArrayList<>();
+        //resultList.addAll(addList);
+        //resultList.addAll(updateList);
         // 拿到第三层子表的id
-        List<String> detailIds = resultList.stream().map(ZhcxPmqManagementDistributionDetailDo::getId).collect(Collectors.toList());
+        //List<String> detailIds = resultList.stream().map(ZhcxPmqManagementDistributionDetailDo::getId).collect(Collectors.toList());
         String nowDate = DateUtil.formatDateTime(new Date());
         // 可能会涉及到改派
-        boolean dispatchTochange = dispatchTochange(pid, detailIds, nowDate);
+        dispatchTochange(pid, detailIds, nowDate);
         // 操作记录
-        if(dispatchTochange){
-            logService.logForSecondFloor(pid,"派单改派");
-        }else{
-            logService.logForSecondFloor(pid,"派单");
-        }
+//        if(dispatchTochange){
+//            logService.logForSecondFloor(pid,"派单改派");
+//        }else{
+//            logService.logForSecondFloor(pid,"派单");
+//        }
         // 派单状态
         String dispatchStatus = (baseMapper.selectListByPid(pid).isEmpty())? "1" : "2";
         // 更新第二层的派单状态 (新增派单状态:  部分派单=2,未派单=0,已派单=1)
@@ -132,7 +135,7 @@ public class ZhcxPmqManagementDistributionServiceImpl extends ServiceImpl<ZhcxPm
         return R.ok("派单成功");
     }
 
-    private boolean dispatchTochange(String pid,List<String> baseList,String nowDate){
+    private void dispatchTochange(String pid,List<String> baseList,String nowDate){
         LambdaQueryWrapper<ZhcxPmqManagementDistributionDetailDo> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(ZhcxPmqManagementDistributionDetailDo::getDeleted,"0")
                 .eq(ZhcxPmqManagementDistributionDetailDo::getPid,pid);
@@ -150,11 +153,13 @@ public class ZhcxPmqManagementDistributionServiceImpl extends ServiceImpl<ZhcxPm
                 }
             }
         }
+        // 操作记录
         if(!resultList.isEmpty()){
             baseMapper.deleteBatchIdsForDispatchTochange(resultList,nowDate);
-            return true;
+            logService.logForSecondFloor(pid,"派单改派");
+        }else {
+            logService.logForSecondFloor(pid,"派单");
         }
-        return false;
     }
 
     @Override

+ 5 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxPmqManagementLogServiceImpl.java

@@ -17,6 +17,8 @@ import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
@@ -41,6 +43,7 @@ public class ZhcxPmqManagementLogServiceImpl extends ServiceImpl<ZhcxPmqManageme
     private ZhcxPmqManagementRecoredService recoredService;
 
     @Override
+    @Async("batchSaveThreadPool")
     public R logForSecondFloor(String id, String type) {
         ZhcxPmqManagementRecoredDo recoredDo = recoredService.getById(id);
         Date nowDate = DateUtil.parse(DateUtil.now(), "yyyy-MM-dd HH:mm:ss");
@@ -63,6 +66,7 @@ public class ZhcxPmqManagementLogServiceImpl extends ServiceImpl<ZhcxPmqManageme
     }
 
     @Override
+    @Async("batchSaveThreadPool")
     public R logFoThirdFloor(String id, String type) {
         ZhcxPmqManagementDistributionDetailDo detailDo = detailService.getById(id);
         ZhcxPmqManagementRecoredDo recoredDo = recoredService.getById(detailDo.getPid());
@@ -88,6 +92,7 @@ public class ZhcxPmqManagementLogServiceImpl extends ServiceImpl<ZhcxPmqManageme
     }
 
     @Override
+    @Async("batchSaveThreadPool")
     public R logFoThirdFloor(String id, String type,String description) {
         ZhcxPmqManagementDistributionDetailDo detailDo = detailService.getById(id);
         ZhcxPmqManagementRecoredDo recoredDo = recoredService.getById(detailDo.getPid());

+ 33 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxPmqManagementMapServiceImpl.java

@@ -1,11 +1,21 @@
 package com.rongwei.bscommon.sys.service.impl;
 
+import com.rongwei.bscommon.sys.dao.ZhcxPmqManagementDistributionDetailDao;
+import com.rongwei.bscommon.sys.service.ZhcxPmqManagementService;
+import com.rongwei.bsentity.domain.ZhcxPmqManagementDo;
 import com.rongwei.bsentity.domain.ZhcxPmqManagementMapDo;
 import com.rongwei.bscommon.sys.dao.ZhcxPmqManagementMapDao;
 import com.rongwei.bscommon.sys.service.ZhcxPmqManagementMapService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.rongwei.rwcommon.base.R;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Objects;
+
 /**
  * <p>
  * 三单管理_字段映射 服务实现类
@@ -15,6 +25,29 @@ import org.springframework.stereotype.Service;
  * @since 2024-10-30
  */
 @Service
+@Slf4j
 public class ZhcxPmqManagementMapServiceImpl extends ServiceImpl<ZhcxPmqManagementMapDao, ZhcxPmqManagementMapDo> implements ZhcxPmqManagementMapService {
 
+    @Autowired
+    private ZhcxPmqManagementService managementService;
+
+    @Autowired
+    private ZhcxPmqManagementDistributionDetailDao detailDao;
+
+    @Override
+    @Async("batchSaveThreadPool")
+    public void updateClosedStateInFirstFloor(List<String> ids) {
+        if (!ids.isEmpty()) {
+            for (String id : ids) {
+                String closeStatus = detailDao.getNotClosedStateInSecondFloorByPid(id);
+                ZhcxPmqManagementDo managementDo = managementService.getById(id);
+                if(!Objects.isNull(managementDo)){
+                    managementDo.setClosestatus(closeStatus);
+                    // 更新主表状态
+                    managementService.updateById(managementDo);
+                    log.info("更新第一层状态成功");
+                }
+            }
+        }
+    }
 }

+ 70 - 5
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxPmqManagementRecoredServiceImpl.java

@@ -4,15 +4,12 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.io.FileUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.rongwei.bscommon.sys.dao.ZhcxPmqManagementDistributionDao;
-import com.rongwei.bscommon.sys.service.ZhcxPmqManagementDistributionDetailService;
-import com.rongwei.bscommon.sys.service.ZhcxPmqManagementDistributionService;
-import com.rongwei.bscommon.sys.service.ZhcxPmqManagementService;
+import com.rongwei.bscommon.sys.service.*;
 import com.rongwei.bscommon.sys.utils.CommonUtils;
 import com.rongwei.bsentity.domain.ZhcxPmqManagementDistributionDetailDo;
 import com.rongwei.bsentity.domain.ZhcxPmqManagementDistributionDo;
 import com.rongwei.bsentity.domain.ZhcxPmqManagementRecoredDo;
 import com.rongwei.bscommon.sys.dao.ZhcxPmqManagementRecoredDao;
-import com.rongwei.bscommon.sys.service.ZhcxPmqManagementRecoredService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.rongwei.bsentity.dto.ZhcxPmqManagementDistributionDTO;
 import com.rongwei.bsentity.dto.sqlServer.JuFileInfoDto;
@@ -70,7 +67,7 @@ public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqMana
     private ZhcxPmqManagementDistributionDetailService zhcxPmqManagementDistributionDetailService;
 
     @Autowired
-    private ZhcxPmqManagementDistributionDao zhcxPmqManagementDistributionDao;
+    private ZhcxPmqManagementMapService managementMapService;
 
     @Autowired
     private SysFileItemService sysFileItemService;
@@ -505,4 +502,72 @@ public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqMana
         }
         return R.ok("批量派单成功");
     }
+
+    @Override
+    public R updateBatchList(List<ZhcxPmqManagementDistributionDTO> list,String status,String dispatchstatus) {
+        String pids = list.get(0).getPid();
+        if(StringUtils.isEmpty(pids)){
+            return R.error("数据异常,请联系管理员");
+        }
+        String[] pidStr = pids.split(",");
+        // 第2.5层集合
+        List<ZhcxPmqManagementDistributionDo> resultList1 = new ArrayList<>();
+        // 第三层集合
+        List<ZhcxPmqManagementDistributionDetailDo> resultList2 = new ArrayList<>();
+        // 第一层主表ID
+        List<String> managementIds = new ArrayList<>();
+        for (String pid : pidStr) {
+            // 第二层数据
+            ZhcxPmqManagementRecoredDo recoredDo = this.getById(pid);
+            for (ZhcxPmqManagementDistributionDTO zhcxPmqManagementDistributionDTO : list) {
+                ZhcxPmqManagementDistributionDo result = new ZhcxPmqManagementDistributionDo();
+                String distributionId = SecurityUtil.getUUID();
+                result.setId(distributionId);
+                result.setPid(pid);
+                result.setProjectid(zhcxPmqManagementDistributionDTO.getProjectid());
+                result.setProjectname(zhcxPmqManagementDistributionDTO.getProjectname());
+                result.setProjectno(zhcxPmqManagementDistributionDTO.getProjectno());
+                result.setMachineid(zhcxPmqManagementDistributionDTO.getMachineid());
+                result.setMachineno(zhcxPmqManagementDistributionDTO.getMachineno());
+                result.setConfirmerid(zhcxPmqManagementDistributionDTO.getConfirmerid());
+                result.setConfirmer(zhcxPmqManagementDistributionDTO.getConfirmer());
+                // 关闭状态
+                result.setStatus(status);
+                if(!StringUtils.isEmpty(String.valueOf(recoredDo.getSeqno()))) {
+                    result.setSerialnumber(String.valueOf(recoredDo.getSeqno()));
+                }
+                if(!StringUtils.isEmpty(zhcxPmqManagementDistributionDTO.getSupplement())) {
+                    result.setSupplement(zhcxPmqManagementDistributionDTO.getSupplement());
+                }
+                result.setRemark("批量派单");
+                resultList1.add(result);
+                // 第三层数据
+                ZhcxPmqManagementDistributionDetailDo bean = new ZhcxPmqManagementDistributionDetailDo();
+                BeanUtil.copyProperties(result,bean);
+                bean.setDistributid(distributionId);
+                bean.setId(SecurityUtil.getUUID());
+                resultList2.add(bean);
+            }
+            // 更新第二层表数据
+            recoredDo.setClosestatus(status);
+            recoredDo.setDispatchstatus(dispatchstatus);
+            this.updateById(recoredDo);
+
+            managementIds.add(recoredDo.getPmqmid());
+        }
+        // 保存2.5层 3层数据
+        if(!resultList1.isEmpty()){
+            zhcxPmqManagementDistributionService.saveBatch(resultList1);
+            zhcxPmqManagementDistributionDetailService.saveBatch(resultList2);
+        }
+        // 如果关闭状态为 已关闭/NA 需要去同步更新第一层的状态
+        if(status.equals("已关闭") || status.equals("NA")){
+            List<String> ids = managementIds.stream().distinct().collect(Collectors.toList());
+            if(!ids.isEmpty()){
+                // 异步去更新第一层状态
+                managementMapService.updateClosedStateInFirstFloor(ids);
+            }
+        }
+        return R.ok("批量派单成功");
+    }
 }

+ 10 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/sqlServer/DistributionDTO.java

@@ -5,8 +5,18 @@ import lombok.Data;
 
 import java.util.List;
 
+/**
+ * 三单批量派单接收实体类
+ */
 @Data
 public class DistributionDTO {
 
+    //第二层表数据
     List<ZhcxPmqManagementDistributionDTO> list;
+
+    // 关闭状态
+    String status;
+
+    // 派单状态
+    String dispatchstatus;
 }

+ 3 - 1
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxPmqManagementRecoredController.java

@@ -91,8 +91,10 @@ public class ZhcxPmqManagementRecoredController {
     public R updateBatchList(@RequestBody DistributionDTO dto){
         try {
             if(dto.getList().isEmpty()){return R.error("空数组");}
+            if(dto.getStatus().isEmpty()){return R.error("关闭状态为空");}
+            if(dto.getDispatchstatus().isEmpty()){return R.error("派单状态为空");}
             log.info("三单派单页面批量派单处理数据接口->集合大小:{}",dto.getList().size());
-            return managementRecoredService.updateBatchList(dto.getList());
+            return managementRecoredService.updateBatchList(dto.getList(),dto.getStatus(),dto.getDispatchstatus());
         } catch (Exception e) {
             log.info(String.valueOf(e));
             return R.error("三单派单批量派单失败");