From 1f4e7d0f73a73e7350cf5a1df279d5f30904c5d5 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期三, 06 十二月 2023 08:41:32 +0800
Subject: [PATCH] bug

---
 server/src/main/java/doumeemes/service/ext/impl/PlansExtServiceImpl.java |  130 +++++++++++++++++++++++++++++++++----------
 1 files changed, 99 insertions(+), 31 deletions(-)

diff --git a/server/src/main/java/doumeemes/service/ext/impl/PlansExtServiceImpl.java b/server/src/main/java/doumeemes/service/ext/impl/PlansExtServiceImpl.java
index e3229c1..c3ecd72 100644
--- a/server/src/main/java/doumeemes/service/ext/impl/PlansExtServiceImpl.java
+++ b/server/src/main/java/doumeemes/service/ext/impl/PlansExtServiceImpl.java
@@ -16,6 +16,7 @@
 import doumeemes.core.utils.excel.EasyExcelUtil;
 import doumeemes.core.utils.redis.RedisUtil;
 import doumeemes.dao.business.PlansMapper;
+import doumeemes.dao.business.UnqualifiedRecordMapper;
 import doumeemes.dao.business.WorkorderMapper;
 import doumeemes.dao.business.dto.*;
 import doumeemes.dao.business.model.*;
@@ -36,10 +37,7 @@
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * 鐢熶骇璁″垝Service瀹炵幇
@@ -92,6 +90,10 @@
     private WStockExtService  wStockExtService;
     @Autowired
     private WorkorderRecordStandardService workorderRecordStandardService;
+    @Autowired
+    private UnqualifiedRecordMapper unqualifiedRecordMapper;
+    @Autowired
+    private CompanyUserExtMapper companyUserExtMapper;
 
     @Override
     public  PlansExtListVO findById(Integer id){
@@ -125,7 +127,7 @@
         if(user.getProcedureIds()!=null){
             pageWrap.setProcedureIds(user.getProcedureIds());
         }else{
-            pageWrap.setUserId(user.getId());
+            pageWrap.setCreateUser(user.getId());
         }
         List<PlansExtListVO> result = plansExtMapper.selectList(pageWrap);
         if(result==null||result.size()==0){
@@ -164,6 +166,7 @@
         initPlanStatisticInfo(t);
         PlansExtListH5VO plan = new PlansExtListH5VO();
         BeanUtils.copyProperties(t,plan);
+//        plan.setDoneNum();
         plan.setWorkorderList(workorderExtService.findByPlanId(plan,true));
         return plan;
     }
@@ -187,12 +190,6 @@
             pageWrap.getModel().setCreateUser(user.getId());
             //鍚﹀垯璧版暟鎹潈闄�
             pageWrap.getModel().setDepartIds(dataPermission);
-         /*   if(dataPermission.size() == 0){
-                //鍙兘鐪嬭嚜宸辩殑
-                pageWrap.getModel().setCreateUser(user.getId());
-            }else{
-
-            }*/
         }
         if(user.getProcedureIds()!=null){
             pageWrap.getModel().setProcedureIds(user.getProcedureIds());
@@ -213,12 +210,12 @@
 //                p.setDistributNum(tp.getDistributNum());
 //                p.setDoneNum(tp.getDoneNum());
                 p.setIsStock(wStockExtService.isStockForPlan(p));
+                p.setHasExpire(false);
+                p.setStatus(Constants.formatIntegerNum(p.getStatus()));
                 if ( !p.getStatus().equals(Constants.PLAN_STATUS.done) &&
                         !p.getStatus().equals(Constants.PLAN_STATUS.close)){
                     if (Objects.nonNull(p.getPlanDate())){
                         p.setHasExpire(DateUtil.toDateLocalDateTime(p.getWorkPlanPlanDate()).toLocalDate().isBefore(LocalDate.now()));
-                    }else {
-                        p.setHasExpire(false);
                     }
                 }
             }
@@ -638,7 +635,7 @@
         List<WorkorderHistory> whList = new ArrayList<>();
         Workorder order = new Workorder();
         order.setCreateTime(DateUtil.getCurrentDate());
-        order.setCreateUser(user.getId());
+        order.setCreateUser(param.getCreateUser());
         order.setDeleted(Constants.ZERO);
         order.setStatus(Constants.WORKORDER_STATUS.create);
         order.setPlanId(mp.getId());
@@ -658,6 +655,8 @@
         order.setUrgent(mp.getUrgent());
         order.setFactoryId(mp.getFactoryId());
         order.setBackorderId(mp.getBackorderId());
+        order.setUnqualifiedNum(param.getUnqualifiedNum());
+        order.setQualifiedNum(param.getQualifiedNum());
         order.setOriginId(systemDictDataBiz.queryByCode(Constants.WORKORDER_SOURCE,Constants.WORKORDER_SOURCE_PLAN).getId());
         //宸ュ崟缂栫爜
         order.setCode(workorderExtService.getNextCode(user.getCompany().getId()));
@@ -665,9 +664,9 @@
         order.setQrcodeId(barcodeParamExtService.getByType(user.getCompany().getId(),mp.getDepartId(),Constants.BARCODEPARAM_TYPE.workorder));
         order.setProUserList(param.getProUserList());
         order.setProGroupId(param.getProGroupId());
-        //鏌ヨ鐢熶骇鐝粍鍜屼汉鍛樻槸鍚﹀悎娉�
-        checkUserAndGroup(order,mp,user);
         workorderExtMapper.insert(order);
+        //鏌ヨ鐢熶骇鐝粍鍜屼汉鍛樻槸鍚﹀悎娉�
+        checkUserAndGroupNew(order,mp,user);
         //宸ュ崟鍘嗗彶鏁版嵁
         whList.add(WorkorderExtServiceImpl.initHistoryByModel(order,user.getId(),Constants.WORKORDER_HISTORY_STATUS.create));
         workorderHistoryExtMapper.insertBatch(whList);
@@ -678,6 +677,34 @@
             workorderUserExtMapper.insert(wu);
         }
         return order;
+    }
+
+
+    private void checkUserAndGroupNew(Workorder param, PlansExtListVO  model,LoginUserInfo user) throws BusinessException{
+        QueryDeviceExtDTO ud = new QueryDeviceExtDTO();
+        ud.setDeleted(Constants.ZERO);
+        ud.setId(param.getProGroupId());
+        ud.setRootDepartId(user.getRootDepartment().getId());
+        //鏌ヨ鐢ㄦ埛璁惧鍏宠仈鍏崇郴
+        DeviceExtListVO d = deviceExtMapper.selectByModel( ud );
+        if(d == null){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝鐢熶骇璁惧淇℃伅涓嶆纭紝璇峰埛鏂伴〉闈㈤噸璇曪紒");
+        }
+
+        List<WorkorderUser> userList = new ArrayList<>();
+        for(Integer userId : param.getProUserList()){
+            WorkorderUser u = new WorkorderUser();
+            u.setProUserId(userId);
+            u.setPlanId(model.getId());
+            u.setCreateUser(user.getId());
+            u.setDeleted(Constants.ZERO);
+            u.setCreateTime(DateUtil.getCurrentDate());
+            u.setRootDepartId(model.getRootDepartId());
+            u.setDepartId(model.getDepartId());
+            userList.add(u);
+        }
+        param.setWorkorderUserList(userList);
+
     }
 
     private void checkUserAndGroup(Workorder param, PlansExtListVO  model,LoginUserInfo user) throws BusinessException{
@@ -702,9 +729,9 @@
         if(ulist == null){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝鐢熶骇浜哄憳淇℃伅涓嶆纭紝璇峰埛鏂伴〉闈㈤噸璇曪紒");
         }
-        if(ulist.size() < param.getProUserList().size()){
-            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝瀛樺湪鐢熶骇浜哄憳淇℃伅涓嶆纭紝璇峰埛鏂伴〉闈㈤噸璇曪紒");
-        }
+//        if(ulist.size() < param.getProUserList().size()){
+//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝瀛樺湪鐢熶骇浜哄憳淇℃伅涓嶆纭紝璇峰埛鏂伴〉闈㈤噸璇曪紒");
+//        }
         List<WorkorderUser> userList = new ArrayList<>();
         for(UserDeviceExtListVO uModel : ulist){
             WorkorderUser u = new WorkorderUser();
@@ -1531,7 +1558,7 @@
     }
     /**
      * 鎭㈠璁″垝
-     * @param p
+     * @param
      */
     @Transactional(rollbackFor = {BusinessException.class,Exception.class})
     @Override
@@ -1582,42 +1609,54 @@
     @Transactional(rollbackFor = {BusinessException.class,Exception.class})
     @Override
     public void autoWorkReport(LoginUserInfo user, AutoWorkReportDTO autoWorkReportDTO){
+        if(Objects.isNull(autoWorkReportDTO)
+            || Objects.isNull(autoWorkReportDTO.getCreateWorkorderRecordDTO())
+            || Objects.isNull(autoWorkReportDTO.getProUserList())
+            || Objects.isNull(autoWorkReportDTO.getProUserList().size()==0)
+            || Objects.isNull(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum())|| autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum().compareTo(BigDecimal.ZERO) < Constants.ZERO
+            || Objects.isNull(autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum())|| autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum().compareTo(BigDecimal.ZERO) < Constants.ZERO){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
         //鏌ヨ宸ュ伐搴忚鍒掔姸鎬�
         Plans plans = plansExtMapper.selectById(autoWorkReportDTO.getPlansId());
         if(Objects.isNull(plans)){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌宸ュ簭璁″垝鏁版嵁");
         }
-        if(!(plans.getStatus().equals(Constants.PLAN_STATUS.create)||plans.getStatus().equals(Constants.PLAN_STATUS.distribute))){
+        if(!(plans.getStatus().equals(Constants.PLAN_STATUS.create)||plans.getStatus().equals(Constants.PLAN_STATUS.publish)||plans.getStatus().equals(Constants.PLAN_STATUS.distribute))){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"宸ュ簭璁″垝宸叉祦杞紝鏃犳硶鎿嶄綔");
         }
         if(plans.getPaused().equals(Constants.ONE)){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"宸ュ簭璁″垝宸叉殏鍋滐紝鏃犳硶鎿嶄綔");
         }
         if(Objects.isNull(autoWorkReportDTO.getCreateWorkorderRecordDTO())){
-            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍙傛暟閿欒锛氫骇鍑烘暟鎹�");
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍙傛暟閿欒锛氫骇鍑烘暟鎹�");
         }
         //鏌ヨ宸ュ簭璁″垝宸插垎閰嶆暟閲�
         List<Workorder> workorderList = workorderMapper.selectList(new QueryWrapper<Workorder>().eq("PLAN_ID",plans.getId())
-                .notIn("STATUS",7,8));
+                .eq("STATUS",Constants.WORKORDER_STATUS.baogong));
         //鏈浜у嚭鏁伴噺
         BigDecimal num = autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum().add(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum());
         if(num.compareTo(BigDecimal.ZERO)<=Constants.ZERO){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍙傛暟閿欒锛氫骇鍑烘暟鎹�");
         }
         //宸ュ崟宸插垎閰嶆暟閲�
-        Integer produceNum = workorderList.stream().map(s -> s.getPlanNum()).reduce(Constants.ZERO, Integer::sum);
+        Integer produceNum = workorderList.stream().map(s -> s.getUnqualifiedNum() + s.getQualifiedNum()).reduce(Constants.ZERO, Integer::sum);
         Integer surplusNum = plans.getNum() - produceNum;
         if(num.compareTo(BigDecimal.valueOf(surplusNum))>0){
-            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鍙傛暟閿欒锛氳秴鍑哄伐鍗曞墿浣欏彲鍒嗛厤鏁伴噺");
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瓒呭嚭褰撳墠宸ュ簭璁″垝鍙姤宸ユ暟閲�");
         }
         Workorder param = new Workorder();
         param.setPlanId(autoWorkReportDTO.getPlansId());
         param.setPlanDate(new Date());
+//        CompanyUser companyUser= companyUserExtMapper.selectById(autoWorkReportDTO.getProUserList().get(Constants.ZERO));
+        param.setCreateUser(autoWorkReportDTO.getProUserList().get(Constants.ZERO));
         param.setProGroupId(autoWorkReportDTO.getProGroupId());
         param.setProUserList(autoWorkReportDTO.getProUserList());
-        param.setPlanNum(plans.getNum());
+        param.setPlanNum(num.intValue());
         //鐢熸垚宸ュ崟淇℃伅
-        Workorder workorder = this.distributeDone(user,param,plans.getNum());
+        param.setUnqualifiedNum(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum().intValue());
+        param.setQualifiedNum(autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum().intValue());
+        Workorder workorder = this.distributeDone(user,param,num.intValue());
         //宸ュ崟鎶曟枡璁板綍
         CreateMaterialDTO createMaterialDTO = new CreateMaterialDTO();
         if(!Objects.isNull(autoWorkReportDTO.getRecordList())&&autoWorkReportDTO.getRecordList().size()>Constants.ZERO){
@@ -1627,9 +1666,9 @@
         }
         //宸ュ崟浜у嚭璁板綍
         autoWorkReportDTO.getCreateWorkorderRecordDTO().setWorkorderId(workorder.getId());
-        workorderRecordStandardService.createWorkorderRecord(autoWorkReportDTO.getCreateWorkorderRecordDTO(),user);
+        WorkorderRecord workorderRecord = workorderRecordStandardService.createWorkorderRecord(autoWorkReportDTO.getCreateWorkorderRecordDTO(),user,autoWorkReportDTO.getProUserList().get(Constants.ZERO));
         //宸ュ崟鎶ュ伐
-        workorderRecordStandardService.comfirmDone(workorder);
+        workorderRecordStandardService.comfirmDone(workorder,false);
         //鏇存柊宸ュ崟鐘舵��
         if(num.compareTo(BigDecimal.valueOf(surplusNum))==Constants.ZERO){
             plans.setStatus(Constants.PLAN_STATUS.done);
@@ -1639,8 +1678,37 @@
             }
         }
         plansExtMapper.updateById(plans);
-
-
+        //鍙戦�佹秷鎭槦鍒楀鐞嗗垎浜搷浣�
+        workorderExtService.statisticNum(workorder);
+        //瀛樺偍鎶ュ伐涓嶈壇椤规暟鎹�
+        if(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum().compareTo(BigDecimal.ZERO)<=Constants.ZERO){
+            if(!Objects.isNull(autoWorkReportDTO.getCreateUnqualifiedDTOList())&&autoWorkReportDTO.getCreateUnqualifiedDTOList().size()>Constants.ZERO){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"涓嶈壇椤归敊璇細璇锋鏌ヤ笉鑹」鏁版嵁");
+            }
+        }else{
+            List<CreateUnqualifiedDTO> createUnqualifiedDTOList = autoWorkReportDTO.getCreateUnqualifiedDTOList();
+            BigDecimal unqualified = createUnqualifiedDTOList.stream().map(s -> s.getUnQualifiedNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
+            if(unqualified.compareTo(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum())!=Constants.ZERO){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"涓嶈壇椤归敊璇細璇锋鏌ヤ笉鑹」鏁版嵁");
+            }
+            for (CreateUnqualifiedDTO createUnqualifiedDTO:createUnqualifiedDTOList) {
+                if(createUnqualifiedDTO.getUnQualifiedNum().compareTo(BigDecimal.ZERO)==Constants.ZERO
+                ||Objects.isNull(createUnqualifiedDTO.getCategoryId())){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"涓嶈壇椤归敊璇細璇锋鏌ヤ笉鑹」鏁版嵁");
+                }
+                UnqualifiedRecord unqualifiedRecord = new UnqualifiedRecord();
+                unqualifiedRecord.setDeleted(Constants.ZERO);
+                unqualifiedRecord.setCreateUser(user.getId());
+                unqualifiedRecord.setCreateTime(new Date());
+                unqualifiedRecord.setRootDepartId(plans.getRootDepartId());
+                unqualifiedRecord.setDepartId(plans.getDepartId());
+                unqualifiedRecord.setWorkorderId(workorder.getId());
+                unqualifiedRecord.setRecordId(workorderRecord.getId());
+                unqualifiedRecord.setCategoryId(createUnqualifiedDTO.getCategoryId());
+                unqualifiedRecord.setUnqualifiedNum(createUnqualifiedDTO.getUnQualifiedNum());
+                unqualifiedRecordMapper.insert(unqualifiedRecord);
+            }
+        }
     }
 
 

--
Gitblit v1.9.3