From 2837bdd57f72e386bbf9a725e7b3a13e5eb9e930 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期一, 21 八月 2023 09:19:57 +0800
Subject: [PATCH] 修复bug

---
 server/src/main/java/doumeemes/service/ext/impl/WorkorderRecordStandardServiceImpl.java |   89 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 67 insertions(+), 22 deletions(-)

diff --git a/server/src/main/java/doumeemes/service/ext/impl/WorkorderRecordStandardServiceImpl.java b/server/src/main/java/doumeemes/service/ext/impl/WorkorderRecordStandardServiceImpl.java
index 1e0a085..feedfbe 100644
--- a/server/src/main/java/doumeemes/service/ext/impl/WorkorderRecordStandardServiceImpl.java
+++ b/server/src/main/java/doumeemes/service/ext/impl/WorkorderRecordStandardServiceImpl.java
@@ -87,6 +87,8 @@
     private DeviceExtMapper deviceExtMapper;
     @Autowired
     private UnqualifiedRecordMapper unqualifiedRecordMapper;
+    @Autowired
+    private CompanyUserExtMapper companyUserExtMapper;
 
     @Transactional(rollbackFor = {BusinessException.class,Exception.class})
     @Override
@@ -185,6 +187,7 @@
         }
         if(!Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.create)
                 && !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.material)
+                && !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.producing)
                 && !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.check)
                 && !Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.done)){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝璇ュ伐鍗曠姸鎬佸凡娴佽浆锛屼笉鑳借繘琛岃鎿嶄綔锛�");
@@ -295,12 +298,12 @@
         wrModel.setMaterialId(wStock.getMaterialId());
         wrModel.setDepartId(mp.getDepartId());
         wrModel.setCreateTime(DateUtil.getCurrentDate());
-        wrModel.setCreateUser(user.getId());
+        wrModel.setCreateUser(mp.getCreateUser());
         wrModel.setMaterialBatch(mp.getBatch());
         wrModel.setType(Constants.WORKORDER_RECORD_TYPE.materail);
         wrModel.setFactoryId(mp.getFactoryId());
-        wrModel.setProcedureId(mp.getProcedureId());
-        wrModel.setBatch(mp.getBatch());
+        wrModel.setProcedureId(wStock.getProcedureId());
+        wrModel.setBatch(wStock.getBatch());
         wrModel.setUnitId(mp.getUnitId());
         wrModel.setPlanId(mp.getPlanId());
         //TODO 鐩墠浣跨敤宸ヨ涓婚敭瀛樺偍璐т綅涓婚敭
@@ -519,10 +522,27 @@
         if(mp== null){
             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝璇ヨ褰曚笉瀛樺湪锛�");
         }
-
+        Plans plans = plansExtMapper.selectById(mp.getPlanId());
+        if(Objects.isNull(plans)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝宸ュ簭璁″垝璁板綍涓嶅瓨鍦紒");
+        }
+        //鏌ヨ宸ュ簭璁″垝涓� 鎵�鏈夊伐鍗曞凡鎶ュ伐鏁伴噺
+        QueryWorkorderExtDTO dto = new QueryWorkorderExtDTO();
+        dto.setPlanId(mp.getPlanId());
+        dto.setDeleted(Constants.ZERO);
+        dto.setStatus(Constants.WORKORDER_STATUS.baogong);
+        List<WorkorderExtListVO> workorderList = workorderExtMapper.selectList(dto);
+        Integer plansQualifiedNum = 0 , plansUnQualifiedNum = 0;
+        plansQualifiedNum = workorderList.stream().map( workorderExtListVO -> workorderExtListVO.getQualifiedNum()).reduce(Constants.ZERO, Integer::sum);
+        plansUnQualifiedNum = workorderList.stream().map( workorderExtListVO -> workorderExtListVO.getUnqualifiedNum()).reduce(Constants.ZERO, Integer::sum);
+        if((BigDecimal.valueOf(plansQualifiedNum).add(BigDecimal.valueOf(plansUnQualifiedNum).add(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum())
+                .add(autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum()))).compareTo(BigDecimal.valueOf(plans.getNum()))>Constants.ZERO){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝鎶ュ伐鏁伴噺瓒呭嚭宸ュ簭璁″垝鎬绘暟锛�");
+        }
         Workorder param = new Workorder();
 
         param.setPlanId(mp.getPlanId());
+        param.setId(autoWorkReportDTO.getCreateWorkorderRecordDTO().getWorkorderId());
         if(Constants.equalsInteger(mp.getPaused(),Constants.ONE)){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝宸ュ崟宸叉殏鍋滐紒");
         }
@@ -541,13 +561,13 @@
         List<Appliances> updateApplianceProList = new ArrayList<>();
         //寰呮洿鏂板簱瀛橀泦鍚�
         List<WStock> stockList = new ArrayList<>();
+        //澶勭悊浜у嚭鏁版嵁
+        WorkorderRecord workorderRecord = this.createWorkorderRecord(autoWorkReportDTO.getCreateWorkorderRecordDTO(),user,null);
         //鏌ヨ鎶曟枡鍜屾姤宸ヨ褰曞垪琛�
         List<WorkorderRecordExtListVO>  allRecordList = workorderRecordExtMapper.selectAllList(getQueryRecordParam(param));
         if(Objects.isNull(allRecordList)||allRecordList.size()==Constants.ZERO){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈煡璇㈡姇鏂欏拰鎶ュ伐璁板綍!");
         }
-        //澶勭悊浜у嚭鏁版嵁
-        WorkorderRecord workorderRecord = this.createWorkorderRecord(autoWorkReportDTO.getCreateWorkorderRecordDTO(),user);
         //妫�鏌ユ暟鎹俊鎭�
 //        caculateCheckRecord(user, mp,allRecordList);
         QueryBomDetailExtDTO bdparam = initBomParam(user,mp);
@@ -572,6 +592,8 @@
             }
         }
         //鏇存柊宸ュ崟鐘舵�佷负宸叉姤宸�
+        mp.setUnqualifiedNum(autoWorkReportDTO.getCreateWorkorderRecordDTO().getUnQualifiedNum().intValue());
+        mp.setQualifiedNum(autoWorkReportDTO.getCreateWorkorderRecordDTO().getQualifiedNum().intValue());
         updateOrderInfo(user,mp,Constants.WORKORDER_HISTORY_STATUS.baogong);
 
         //鎵归噺鎻掑叆鍑哄叆搴撴槑缁嗚褰�
@@ -705,8 +727,12 @@
             List<WOutbound> outboundList = new ArrayList<>();
             //濡傛灉闇�瑕佹姇鏂欑殑鐗╂枡闆嗗悎锛屽湪搴撳瓨涓鎵炬姇鏂欐潵婧�
             for(WStock model : materialList){
+                List<WStock> useList = allList.stream().filter(wStock -> Constants.equalsInteger(model.getMaterialId(),wStock.getMaterialId())).collect(Collectors.toList());
+                BigDecimal wStockNum = useList.stream().map(s -> s.getNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
+                if(wStockNum.compareTo(Constants.formatBigdecimal(model.getNum()))<Constants.ZERO){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝鐢熶骇鐗╂枡涓嶈冻锛屾棤娉曡繘琛岃鎿嶄綔锛�");
+                }
                 for(WStock ts : allList){
-
                     if(Constants.equalsInteger(model.getMaterialId(),ts.getMaterialId())){
                         //杩橀渶瑕佹姇鏂欐暟閲�
                         BigDecimal actNum = Constants.formatBigdecimal(model.getNum()).subtract(Constants.formatBigdecimal(model.getTNum()));
@@ -830,13 +856,14 @@
             if (bomDetailList == null || bomDetailList.size() == 0) {
                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "瀵逛笉璧凤紝璇ョ敓浜х墿鏂欑殑bom閰嶇疆鏈夎锛岃鑱旂郴绠$悊鍛橈紒");
             }
-//            for (BomDetailExtListVO i :bomDetailList) {
-//                //鏌ヨ鏄惁鎶曟枡
-//                if(workorderRecordExtMapper.selectCount(new QueryWrapper<WorkorderRecord>()
-//                        .eq("DELETED",Constants.ZERO).eq("MATERIAL_ID",i.getMaterialId()).eq("TYPE",Constants.ZERO))<=0){
-//                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀛樺湪鏈姇鏂橞OM鐗╂枡锛屾棤娉曡繘琛屾姤宸�");
-//                }
-//            }
+            for (BomDetailExtListVO i :bomDetailList) {
+                //鏌ヨ鏄惁鎶曟枡
+                if(workorderRecordExtMapper.selectCount(new QueryWrapper<WorkorderRecord>()
+                                .eq("WORKORDER_ID",mp.getId())
+                        .eq("DELETED",Constants.ZERO).eq("MATERIAL_ID",i.getMaterialId()).eq("TYPE",Constants.ZERO))<=0){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀛樺湪鏈姇鏂橞OM鐗╂枡锛屾棤娉曡繘琛屾姤宸�");
+                }
+            }
         }
 
         WOutbound outbound = new WOutbound();
@@ -1115,7 +1142,7 @@
                 //濡傛灉鏄骇鍑�
                 mp.setHasProduceNum(Constants.formatBigdecimal(tModel.getNum()).intValue()+Constants.formatIntegerNum(mp.getHasProduceNum()));
                 //浜у嚭鍚堟牸
-               this.createOutDetail(user,outbound,mp,tModel,Constants.ZERO,detailList,stockList);
+                this.createOutDetail(user,outbound,mp,tModel,Constants.ZERO,detailList,stockList);
                //浜у嚭涓嶈壇
                 this.createOutDetail(user,outbound,mp,tModel,Constants.ONE,detailList,stockList);
             }
@@ -1149,6 +1176,9 @@
         detail.setWarehouseId(outbound.getWarehouseId());
         detail.setLocationId(mp.getFinishWarehouseLocationId());
         detail.setNum(BigDecimal.valueOf(doneType.equals(Constants.ZERO)?tModel.getQualifiedNum():tModel.getUnqualifiedNum()));
+        if(detail.getNum().compareTo(BigDecimal.ZERO)==Constants.ZERO){
+            return;
+        }
         detail.setStatus(Constants.ONE);
         detail.setDoneNum(detail.getNum());
         detail.setDoneDate(new Date());
@@ -1467,7 +1497,7 @@
 
     @Override
     @Transactional(rollbackFor = {BusinessException.class,Exception.class})
-    public WorkorderRecord createWorkorderRecord(CreateWorkorderRecordDTO createWorkorderRecordDTO, LoginUserInfo loginUserInfo){
+    public WorkorderRecord createWorkorderRecord(CreateWorkorderRecordDTO createWorkorderRecordDTO, LoginUserInfo loginUserInfo ,Integer userId){
         Workorder workorder  = workorderExtMapper.selectById(createWorkorderRecordDTO.getWorkorderId());
         if(Objects.isNull(workorder)){
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝鏈煡璇㈠埌璇ュ伐鍗曚俊鎭紒");
@@ -1496,11 +1526,24 @@
         //鏁版嵁瀛樺偍
         workorderRecord = new WorkorderRecord();
         workorderRecord.setDeleted(Constants.ZERO);
-        workorderRecord.setCreateUser(loginUserInfo.getId());
+        if(!Objects.isNull(userId)){
+            CompanyUser companyUser = new CompanyUser();
+            companyUser.setUserId(userId);
+            companyUser.setRootDepartId(loginUserInfo.getRootDepartment().getId());
+            companyUser =     companyUserExtMapper.selectOne(new QueryWrapper<>(companyUser).last("limit 1"));
+            if(Objects.isNull(companyUser)){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝鏈煡璇㈠埌鐢熶骇浜哄憳瀵瑰簲浼佷笟鐢ㄦ埛淇℃伅锛�");
+            }
+            workorderRecord.setCreateUser(userId);
+            workorderRecord.setRootDepartId(loginUserInfo.getRootDepartment().getId());
+            workorderRecord.setDepartId(loginUserInfo.getCurComDepartment().getId());
+        }else{
+            workorderRecord.setCreateUser(loginUserInfo.getId());
+            workorderRecord.setRootDepartId(loginUserInfo.getRootDepartment().getId());
+            workorderRecord.setDepartId(loginUserInfo.getCurComDepartment().getId());
+        }
         workorderRecord.setCreateTime(new Date());
         workorderRecord.setNum(num);
-        workorderRecord.setRootDepartId(loginUserInfo.getRootDepartment().getId());
-        workorderRecord.setDepartId(loginUserInfo.getCurComDepartment().getId());
         workorderRecord.setPlanId(workorder.getPlanId());
         workorderRecord.setWorkorderId(createWorkorderRecordDTO.getWorkorderId());
         workorderRecord.setBatch(workorder.getBatch());
@@ -1515,7 +1558,7 @@
         workorderRecord.setQualifiedNum(createWorkorderRecordDTO.getQualifiedNum());
         //璁$畻宸ヨ祫淇℃伅
         SalaryParam salaryParam = salaryParamMapper.selectOne(new QueryWrapper<SalaryParam>().eq("DELETED",Constants.ZERO).eq("MATERIAL_ID",workorderRecord.getMaterialId())
-                .eq("DEPART_ID",workorderRecord.getFactoryId()).eq("PROCEDURE_ID",workorderRecord.getProcedureId()).last(" limit 1  "));
+                .eq("DEPART_ID",workorderRecord.getFactoryId()).eq("PROCEDURE_ID",workorderRecord.getProcedureId()).eq("TYPE",createWorkorderRecordDTO.getType()).last(" limit 1  "));
         if(!Objects.isNull(salaryParam)){
             workorderRecord.setSalaryPrice(salaryParam.getSalary());
             workorderRecord.setSalaryType(salaryParam.getType());
@@ -1525,8 +1568,10 @@
                 workorderRecord.setSalaryNum(salaryParam.getNum());
                 workorderRecord.setSalary(salaryParam.getSalary().multiply(salaryParam.getUnqualified()==Constants.ONE?num:createWorkorderRecordDTO.getQualifiedNum()));
             }else{
-                workorderRecord.setDuration(createWorkorderRecordDTO.getDuration());
-                workorderRecord.setSalary(BigDecimal.valueOf(createWorkorderRecordDTO.getDuration()).multiply(salaryParam.getSalary()).divide(new BigDecimal(3600),BigDecimal.ROUND_HALF_UP));
+                if(!Objects.isNull(createWorkorderRecordDTO.getDuration())&&Constants.formatIntegerNum(createWorkorderRecordDTO.getDuration())>Constants.ZERO){
+                    workorderRecord.setDuration(createWorkorderRecordDTO.getDuration());
+                    workorderRecord.setSalary(BigDecimal.valueOf(createWorkorderRecordDTO.getDuration()).multiply(salaryParam.getSalary()).divide(new BigDecimal(3600),BigDecimal.ROUND_HALF_UP));
+                }
             }
         }
         //鎻掑叆宸ュ崟鎿嶄綔璁板綍锛屽苟涓斿垽鏂槸鍚︽洿鏀逛负宸ュ崟鐨勭姸鎬併�愮敓浜т腑銆�

--
Gitblit v1.9.3