|  |  |  | 
|---|
|  |  |  | import doumeemes.dao.business.BackOrderDetailMapper; | 
|---|
|  |  |  | import doumeemes.dao.business.BackorderMapper; | 
|---|
|  |  |  | import doumeemes.dao.business.SalaryParamMapper; | 
|---|
|  |  |  | import doumeemes.dao.business.dto.CreateMaterialDTO; | 
|---|
|  |  |  | import doumeemes.dao.business.dto.CreateWorkorderRecordDTO; | 
|---|
|  |  |  | import doumeemes.dao.business.dto.DealWorkorderRecordDTO; | 
|---|
|  |  |  | import doumeemes.dao.business.dto.MaterialListDTO; | 
|---|
|  |  |  | import doumeemes.dao.business.UnqualifiedRecordMapper; | 
|---|
|  |  |  | import doumeemes.dao.business.dto.*; | 
|---|
|  |  |  | import doumeemes.dao.business.model.*; | 
|---|
|  |  |  | import doumeemes.dao.ext.*; | 
|---|
|  |  |  | import doumeemes.dao.ext.bean.EndCheckApBean; | 
|---|
|  |  |  | 
|---|
|  |  |  | private PlansExtMapper plansExtMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceExtMapper deviceExtMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UnqualifiedRecordMapper unqualifiedRecordMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public  Integer comfirmDone(Workorder param){ | 
|---|
|  |  |  | public  Integer comfirmDone(Workorder param,Boolean needCheck){ | 
|---|
|  |  |  | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工单已暂停!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //如果需要完工检才能检验 | 
|---|
|  |  |  | if(Constants.equalsInteger(mp.getNeedcheck(),Constants.ZERO)){ | 
|---|
|  |  |  | if(Constants.equalsInteger(mp.getNeedcheck(),Constants.ZERO)&&needCheck){ | 
|---|
|  |  |  | //只有已完工状态才能确认报工 | 
|---|
|  |  |  | if(!Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.done)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!"); | 
|---|
|  |  |  | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | return param.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public  Workorder comfirmDoneNew(AutoWorkReportDTO autoWorkReportDTO, Boolean needCheck){ | 
|---|
|  |  |  | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Objects.isNull(autoWorkReportDTO) | 
|---|
|  |  |  | || Objects.isNull(autoWorkReportDTO.getCreateWorkorderRecordDTO()) | 
|---|
|  |  |  | || 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(autoWorkReportDTO.getCreateWorkorderRecordDTO().getWorkorderId()== null ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请按要求填写和选择提交数据!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Workorder mp = new Workorder(); | 
|---|
|  |  |  | mp.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | mp.setId(autoWorkReportDTO.getCreateWorkorderRecordDTO().getWorkorderId()); | 
|---|
|  |  |  | mp.setRootDepartId(user.getRootDepartment().getId()); | 
|---|
|  |  |  | mp = workorderExtMapper.selectOne(mp); | 
|---|
|  |  |  | if(mp== null){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该记录不存在!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Workorder param = new Workorder(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | param.setPlanId(mp.getPlanId()); | 
|---|
|  |  |  | if(Constants.equalsInteger(mp.getPaused(),Constants.ONE)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工单已暂停!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //如果需要完工检才能检验 | 
|---|
|  |  |  | if(Constants.equalsInteger(mp.getNeedcheck(),Constants.ZERO)&&needCheck){ | 
|---|
|  |  |  | //只有已完工状态才能确认报工 | 
|---|
|  |  |  | if(!Constants.equalsInteger(mp.getStatus(),Constants.WORKORDER_STATUS.done)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单状态已流转,不能进行该操作!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //出入库明细记录集合 | 
|---|
|  |  |  | List<WOutboundDetail> outboundDetailList = new ArrayList<>(); | 
|---|
|  |  |  | //待更新工装集合投料 | 
|---|
|  |  |  | List<Appliances> updateApplianceList = new ArrayList<>(); | 
|---|
|  |  |  | //待更新工装集合产出 | 
|---|
|  |  |  | List<Appliances> updateApplianceProList = new ArrayList<>(); | 
|---|
|  |  |  | //待更新库存集合 | 
|---|
|  |  |  | List<WStock> stockList = new ArrayList<>(); | 
|---|
|  |  |  | //查询投料和报工记录列表 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | if(mp.getBomModel()!=null&&Constants.equalsInteger(mp.getBomModel().getType(),Constants.BOM_TYPE.pull)){ | 
|---|
|  |  |  | //如果是拉式投料,系统根据BOM自动扣减库存 | 
|---|
|  |  |  | dealApplianceMateialPull(mp,user,bdparam,updateApplianceList, stockList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(allRecordList!=null && allRecordList.size()>0){ | 
|---|
|  |  |  | if(mp.getBomModel()==null||Constants.equalsInteger(mp.getBomModel().getType(),Constants.BOM_TYPE.push)){ | 
|---|
|  |  |  | //如果是推式投料,走正常生产手动投料 | 
|---|
|  |  |  | dealApplianceMateial(mp,user,bdparam,allRecordList,updateApplianceList, outboundDetailList,stockList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //处理产出数据 | 
|---|
|  |  |  | dealAppliancePro(mp,user,allRecordList,updateApplianceList,updateApplianceProList, outboundDetailList,stockList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //如果有没bom配置,检查产出(包含检验的不良和报废品)和投料数量是否相等匹配,不一致提示错误 | 
|---|
|  |  |  | if(bdparam==null){ | 
|---|
|  |  |  | //投料数量 和 产出数量不相等 | 
|---|
|  |  |  | if(Constants.formatBigdecimal(mp.getHasMaterialNum()).intValue() != Constants.formatIntegerNum(mp.getHasProduceNum())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,该工单投料和产出数量不一致,请确认后重试!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新工单状态为已报工 | 
|---|
|  |  |  | updateOrderInfo(user,mp,Constants.WORKORDER_HISTORY_STATUS.baogong); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //批量插入出入库明细记录 | 
|---|
|  |  |  | if(outboundDetailList!=null && outboundDetailList.size()>0){ | 
|---|
|  |  |  | wOutboundDetailExtMapper.insertBatch(outboundDetailList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(stockList != null && stockList.size()>0){ | 
|---|
|  |  |  | for(WStock s : stockList){ | 
|---|
|  |  |  | WStock s1 = new WStock(); | 
|---|
|  |  |  | s1.setLocationId(s.getLocationId()); | 
|---|
|  |  |  | s1.setWarehouseId(s.getWarehouseId()); | 
|---|
|  |  |  | s1.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | s1.setMaterialId(s.getMaterialId()); | 
|---|
|  |  |  | s1.setQualityType(s.getQualityType()); | 
|---|
|  |  |  | s1.setProcedureId(s.getProcedureId()); | 
|---|
|  |  |  | if(StringUtils.isBlank(s.getBatch() )){ | 
|---|
|  |  |  | s1 = wStockExtMapper.selectOne(new QueryWrapper<>(s1).isNull("batch").last(" limit 1")); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | s1.setBatch(s.getBatch()); | 
|---|
|  |  |  | s1 = wStockExtMapper.selectOne(new QueryWrapper<>(s1).last(" limit 1")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(s1 ==null){ | 
|---|
|  |  |  | //如果库存记录不存在,插入数据 | 
|---|
|  |  |  | s.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | s.setCreateTime(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | s.setCreateUser(user.getId()); | 
|---|
|  |  |  | s.setRootDepartId(mp.getRootDepartId()); | 
|---|
|  |  |  | if(Constants.formatBigdecimal(s.getNum()).compareTo(new BigDecimal(0)) == -1){ | 
|---|
|  |  |  | //如果库存不足 | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,仓库余料不足,请联系仓库管理员!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wStockExtMapper.insert(s); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //如果库存记录存在,则更新库存量 | 
|---|
|  |  |  | s.setId(s1.getId()); | 
|---|
|  |  |  | s.setUpdateTime(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | s.setUpdateUser(user.getId()); | 
|---|
|  |  |  | s.setNum(Constants.formatBigdecimal(s1.getNum()).add(Constants.formatBigdecimal(s.getNum()))); | 
|---|
|  |  |  | if(Constants.formatBigdecimal(s.getNum()).compareTo(new BigDecimal(0)) == -1){ | 
|---|
|  |  |  | //如果库存不足 | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,仓库余料不足,请联系仓库管理员!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wStockExtMapper.updateById(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存储报工不良项数据 | 
|---|
|  |  |  | 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(mp.getRootDepartId()); | 
|---|
|  |  |  | unqualifiedRecord.setDepartId(mp.getDepartId()); | 
|---|
|  |  |  | unqualifiedRecord.setWorkorderId(mp.getId()); | 
|---|
|  |  |  | unqualifiedRecord.setRecordId(workorderRecord.getId()); | 
|---|
|  |  |  | unqualifiedRecord.setCategoryId(createUnqualifiedDTO.getCategoryId()); | 
|---|
|  |  |  | unqualifiedRecord.setUnqualifiedNum(createUnqualifiedDTO.getUnQualifiedNum()); | 
|---|
|  |  |  | unqualifiedRecordMapper.insert(unqualifiedRecord); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return param; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private QueryWorkorderRecordExtDTO getQueryRecordParam(Workorder param) { | 
|---|
|  |  |  | QueryWorkorderRecordExtDTO mParam = new QueryWorkorderRecordExtDTO(); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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(),"存在未投料BOM物料,无法进行报工"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    private void dealAppliancePro(Workorder mp | 
|---|
|  |  |  | //            , LoginUserInfo user | 
|---|
|  |  |  | //            , List<WorkorderRecordExtListVO> allRecordList | 
|---|
|  |  |  | //            , List<Appliances> updateApplianceList | 
|---|
|  |  |  | //            , List<Appliances> updateApplianceProList | 
|---|
|  |  |  | //            ,   List<WOutboundDetail> outboundDetailList | 
|---|
|  |  |  | //            ,   List<WStock> stockList) { | 
|---|
|  |  |  | //        WOutbound outbound = new WOutbound(); | 
|---|
|  |  |  | //        outbound.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | //        outbound.setCreateTime(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | //        outbound.setDealDate(outbound.getCreateTime()); | 
|---|
|  |  |  | //        outbound.setValidDate(outbound.getCreateTime()); | 
|---|
|  |  |  | //        outbound.setCreateUser(user.getId()); | 
|---|
|  |  |  | //        outbound.setRootDepartId(mp.getRootDepartId()); | 
|---|
|  |  |  | //        outbound.setDepartId(mp.getDepartId()); | 
|---|
|  |  |  | //        outbound.setStatus(Constants.WOUTBOUND_STATUS.dealed); | 
|---|
|  |  |  | //        outbound.setType(Constants.WOUTBOUND_TYPE.in); | 
|---|
|  |  |  | //        //2022年7月1日14:42:41 加入单据类别 | 
|---|
|  |  |  | //        outbound.setBillType(Constants.WOUTBOUND_BILLTYPE.workerOrderIn); | 
|---|
|  |  |  | //        outbound.setCode(wOutboundService.getNextInCode(user.getCompany().getId())); | 
|---|
|  |  |  | //        outbound.setOrigin(Constants.ONE); | 
|---|
|  |  |  | //        outbound.setOriginType(Constants.WOUTBOUND_ORIGIN_TYPE.produce); | 
|---|
|  |  |  | //        outbound.setOriginCode(mp.getCode()); | 
|---|
|  |  |  | //        outbound.setOriginId(mp.getId()); | 
|---|
|  |  |  | //        outbound.setPlanDate(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | //        outbound.setProcedureId(mp.getProcedureId()); | 
|---|
|  |  |  | //        outbound.setUserId(user.getId()); | 
|---|
|  |  |  | //        outbound.setWarehouseId(mp.getFinishWarehouseId()); | 
|---|
|  |  |  | //        wOutboundService.create(outbound); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        List<WOutboundDetail> detailList = new ArrayList<>(); | 
|---|
|  |  |  | //        List<WOutboundRecord> recordList = new ArrayList<>(); | 
|---|
|  |  |  | //        for(WorkorderRecordExtListVO tModel :allRecordList){ | 
|---|
|  |  |  | //            if(Constants.equalsInteger(tModel.getType(),Constants.WORKORDER_RECORD_TYPE.produce)){ | 
|---|
|  |  |  | //                if(tModel.getNum().compareTo(BigDecimal.ZERO)<=Constants.ZERO){ | 
|---|
|  |  |  | //                    continue; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                //如果是产出 | 
|---|
|  |  |  | //                mp.setHasProduceNum(Constants.formatBigdecimal(tModel.getNum()).intValue()+Constants.formatIntegerNum(mp.getHasProduceNum())); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                //物料+批次+工序+质量属性去重 | 
|---|
|  |  |  | //                WOutboundDetail detail =getWoutbondDetailByList(tModel,detailList); | 
|---|
|  |  |  | //                if(detail!=null){ | 
|---|
|  |  |  | //                    detail.setNum(Constants.formatBigdecimal(detail.getNum()).add(tModel.getNum())); | 
|---|
|  |  |  | //                }else{ | 
|---|
|  |  |  | //                    detail = new WOutboundDetail(); | 
|---|
|  |  |  | //                    detail.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | //                    detail.setCreateTime(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | //                    detail.setCreateUser(user.getId()); | 
|---|
|  |  |  | //                    detail.setOutboundId(outbound.getId()); | 
|---|
|  |  |  | //                    detail.setRootDepartId(outbound.getRootDepartId()); | 
|---|
|  |  |  | //                    detail.setWarehouseId(outbound.getWarehouseId()); | 
|---|
|  |  |  | //                    detail.setLocationId(mp.getFinishWarehouseLocationId()); | 
|---|
|  |  |  | //                    detail.setNum(tModel.getNum()); | 
|---|
|  |  |  | //                    detail.setStatus(Constants.ONE); | 
|---|
|  |  |  | //                    detail.setDoneNum(tModel.getNum()); | 
|---|
|  |  |  | //                    detail.setDoneDate(new Date()); | 
|---|
|  |  |  | //                    detail.setUnitId(tModel.getUnitId()); | 
|---|
|  |  |  | //                    detail.setBatch(tModel.getMaterialBatch()); | 
|---|
|  |  |  | //                    detail.setProcedureId(tModel.getProcedureId()); | 
|---|
|  |  |  | //                    detail.setMaterialId(tModel.getMaterialId()); | 
|---|
|  |  |  | //                    detail.setQualityType(tModel.getDoneType()); | 
|---|
|  |  |  | //                    detail.setWOutboundRecordInList(new ArrayList<>()); | 
|---|
|  |  |  | //                    detailList.add(detail); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                WOutboundRecord record = new WOutboundRecord(); | 
|---|
|  |  |  | //                record.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | //                record.setCreateTime(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | //                record.setCreateUser(user.getId()); | 
|---|
|  |  |  | //                record.setAppliancesId(tModel.getAppliancesId()); | 
|---|
|  |  |  | //                record.setBatch(detail.getBatch()); | 
|---|
|  |  |  | //                record.setRootDepartId(mp.getRootDepartId()); | 
|---|
|  |  |  | //                record.setNum(tModel.getNum()); | 
|---|
|  |  |  | //                record.setOutboundId(detail.getOutboundId()); | 
|---|
|  |  |  | //                record.setUnitId(detail.getUnitId()); | 
|---|
|  |  |  | //                record.setWarehouseId(detail.getWarehouseId()); | 
|---|
|  |  |  | //                record.setMaterialId(detail.getMaterialId()); | 
|---|
|  |  |  | //                record.setProcedureId(detail.getProcedureId()); | 
|---|
|  |  |  | //                record.setLocationId(detail.getLocationId()); | 
|---|
|  |  |  | //                record.setQualityType(detail.getQualityType()); | 
|---|
|  |  |  | //                detail.getWOutboundRecordInList().add(record); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                WStock stock = getFromStockList(mp.getFinishWarehouseLocationId(),detail.getWarehouseId(),detail.getMaterialId(),detail.getBatch(), | 
|---|
|  |  |  | //                        tModel.getProcedureId(),tModel.getDoneType(),stockList); | 
|---|
|  |  |  | //                if(stock!=null){ | 
|---|
|  |  |  | //                    //如果库存对象已存在,直接增加对应的库存量 | 
|---|
|  |  |  | //                    stock.setNum(Constants.formatBigdecimal(stock.getNum()).add(Constants.formatBigdecimal(tModel.getNum()))); | 
|---|
|  |  |  | //                }else{ | 
|---|
|  |  |  | //                    stock = new WStock(); | 
|---|
|  |  |  | //                    stock.setMaterialId(detail.getMaterialId()); | 
|---|
|  |  |  | //                    stock.setBatch(detail.getBatch()); | 
|---|
|  |  |  | //                    stock.setWarehouseId(outbound.getWarehouseId()); | 
|---|
|  |  |  | //                    stock.setLocationId(mp.getFinishWarehouseLocationId()); | 
|---|
|  |  |  | //                    stock.setUnitId(detail.getUnitId()); | 
|---|
|  |  |  | //                    stock.setNum(Constants.formatBigdecimal(tModel.getNum())); | 
|---|
|  |  |  | //                    stock.setProcedureId(tModel.getProcedureId()); | 
|---|
|  |  |  | //                    stock.setQualityType(tModel.getDoneType()); | 
|---|
|  |  |  | //                    //待更新库存信息 | 
|---|
|  |  |  | //                    stockList.add(stock); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        for(WOutboundDetail detail : detailList){ | 
|---|
|  |  |  | //            wOutboundDetailExtMapper.insert(detail); | 
|---|
|  |  |  | //            //记录库存变动记录 | 
|---|
|  |  |  | //            wStockRecordExtService.saveRecord(Constants.ONE,detail.getId(),user); | 
|---|
|  |  |  | //            if(detail.getWOutboundRecordInList()!=null){ | 
|---|
|  |  |  | //                for(WOutboundRecord r : detail.getWOutboundRecordInList()){ | 
|---|
|  |  |  | //                    r.setDetailId(detail.getId()); | 
|---|
|  |  |  | //                    wOutboundRecordExtMapper.insert(r); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        if(Constants.formatIntegerNum(mp.getHasProduceNum()) >Constants.formatIntegerNum(mp.getPlanNum())){ | 
|---|
|  |  |  | //            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单的产出数量不能大于工单计划数量!"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void dealAppliancePro(Workorder mp | 
|---|
|  |  |  | , LoginUserInfo user | 
|---|
|  |  |  | , List<WorkorderRecordExtListVO> allRecordList | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //如果是产出 | 
|---|
|  |  |  | mp.setHasProduceNum(Constants.formatBigdecimal(tModel.getNum()).intValue()+Constants.formatIntegerNum(mp.getHasProduceNum())); | 
|---|
|  |  |  | if(tModel.getDoneType() == null){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,工装器具【"+tModel.getAmodel().getCode()+"】产出质量属性为空,无法报工!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!Constants.equalsInteger(tModel.getDoneType(),Constants.ZERO)){ | 
|---|
|  |  |  | //如果不良,累计工单的不良产出 | 
|---|
|  |  |  | mp.setUnqualifiedNum(Constants.formatIntegerNum(mp.getUnqualifiedNum())+(Constants.formatBigdecimal(tModel.getNum()).intValue())); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //如果是合格,累计工单的合格数量 | 
|---|
|  |  |  | mp.setQualifiedNum(Constants.formatIntegerNum(mp.getQualifiedNum())+(Constants.formatBigdecimal(tModel.getNum()).intValue())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //物料+批次+工序+质量属性去重 | 
|---|
|  |  |  | WOutboundDetail detail =getWoutbondDetailByList(tModel,detailList); | 
|---|
|  |  |  | if(detail!=null){ | 
|---|
|  |  |  | detail.setNum(Constants.formatBigdecimal(detail.getNum()).add(tModel.getNum())); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | detail = new WOutboundDetail(); | 
|---|
|  |  |  | detail.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | detail.setCreateTime(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | detail.setCreateUser(user.getId()); | 
|---|
|  |  |  | detail.setOutboundId(outbound.getId()); | 
|---|
|  |  |  | detail.setRootDepartId(outbound.getRootDepartId()); | 
|---|
|  |  |  | detail.setWarehouseId(outbound.getWarehouseId()); | 
|---|
|  |  |  | detail.setLocationId(mp.getFinishWarehouseLocationId()); | 
|---|
|  |  |  | detail.setNum(tModel.getNum()); | 
|---|
|  |  |  | detail.setStatus(Constants.ONE); | 
|---|
|  |  |  | detail.setDoneNum(tModel.getNum()); | 
|---|
|  |  |  | detail.setDoneDate(new Date()); | 
|---|
|  |  |  | detail.setUnitId(tModel.getUnitId()); | 
|---|
|  |  |  | detail.setBatch(tModel.getMaterialBatch()); | 
|---|
|  |  |  | detail.setProcedureId(tModel.getProcedureId()); | 
|---|
|  |  |  | detail.setMaterialId(tModel.getMaterialId()); | 
|---|
|  |  |  | detail.setQualityType(tModel.getDoneType()); | 
|---|
|  |  |  | detail.setWOutboundRecordInList(new ArrayList<>()); | 
|---|
|  |  |  | detailList.add(detail); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WOutboundRecord record = new WOutboundRecord(); | 
|---|
|  |  |  | record.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | record.setCreateTime(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | record.setCreateUser(user.getId()); | 
|---|
|  |  |  | record.setAppliancesId(tModel.getAppliancesId()); | 
|---|
|  |  |  | record.setBatch(detail.getBatch()); | 
|---|
|  |  |  | record.setRootDepartId(mp.getRootDepartId()); | 
|---|
|  |  |  | record.setNum(tModel.getNum()); | 
|---|
|  |  |  | record.setOutboundId(detail.getOutboundId()); | 
|---|
|  |  |  | record.setUnitId(detail.getUnitId()); | 
|---|
|  |  |  | record.setWarehouseId(detail.getWarehouseId()); | 
|---|
|  |  |  | record.setMaterialId(detail.getMaterialId()); | 
|---|
|  |  |  | record.setProcedureId(detail.getProcedureId()); | 
|---|
|  |  |  | record.setLocationId(detail.getLocationId()); | 
|---|
|  |  |  | record.setQualityType(detail.getQualityType()); | 
|---|
|  |  |  | detail.getWOutboundRecordInList().add(record); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WStock stock = getFromStockList(mp.getFinishWarehouseLocationId(),detail.getWarehouseId(),detail.getMaterialId(),detail.getBatch(), | 
|---|
|  |  |  | tModel.getProcedureId(),tModel.getDoneType(),stockList); | 
|---|
|  |  |  | if(stock!=null){ | 
|---|
|  |  |  | //如果库存对象已存在,直接增加对应的库存量 | 
|---|
|  |  |  | stock.setNum(Constants.formatBigdecimal(stock.getNum()).add(Constants.formatBigdecimal(tModel.getNum()))); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | stock = new WStock(); | 
|---|
|  |  |  | stock.setMaterialId(detail.getMaterialId()); | 
|---|
|  |  |  | stock.setBatch(detail.getBatch()); | 
|---|
|  |  |  | stock.setWarehouseId(outbound.getWarehouseId()); | 
|---|
|  |  |  | stock.setLocationId(mp.getFinishWarehouseLocationId()); | 
|---|
|  |  |  | stock.setUnitId(detail.getUnitId()); | 
|---|
|  |  |  | stock.setNum(Constants.formatBigdecimal(tModel.getNum())); | 
|---|
|  |  |  | stock.setProcedureId(tModel.getProcedureId()); | 
|---|
|  |  |  | stock.setQualityType(tModel.getDoneType()); | 
|---|
|  |  |  | //待更新库存信息 | 
|---|
|  |  |  | stockList.add(stock); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //产出合格 | 
|---|
|  |  |  | this.createOutDetail(user,outbound,mp,tModel,Constants.ZERO,detailList,stockList); | 
|---|
|  |  |  | //产出不良 | 
|---|
|  |  |  | this.createOutDetail(user,outbound,mp,tModel,Constants.ONE,detailList,stockList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(WOutboundDetail detail : detailList){ | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该工单的产出数量不能大于工单计划数量!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void createOutDetail(LoginUserInfo user,WOutbound outbound,Workorder mp,WorkorderRecordExtListVO tModel,Integer doneType | 
|---|
|  |  |  | ,List<WOutboundDetail> detailList,List<WStock> stockList ){ | 
|---|
|  |  |  | //物料+批次+工序+质量属性去重 | 
|---|
|  |  |  | WOutboundDetail detail =  new WOutboundDetail(); | 
|---|
|  |  |  | detail.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | detail.setCreateTime(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | detail.setCreateUser(user.getId()); | 
|---|
|  |  |  | detail.setOutboundId(outbound.getId()); | 
|---|
|  |  |  | detail.setRootDepartId(outbound.getRootDepartId()); | 
|---|
|  |  |  | detail.setWarehouseId(outbound.getWarehouseId()); | 
|---|
|  |  |  | detail.setLocationId(mp.getFinishWarehouseLocationId()); | 
|---|
|  |  |  | detail.setNum(BigDecimal.valueOf(doneType.equals(Constants.ZERO)?tModel.getQualifiedNum():tModel.getUnqualifiedNum())); | 
|---|
|  |  |  | detail.setStatus(Constants.ONE); | 
|---|
|  |  |  | detail.setDoneNum(detail.getNum()); | 
|---|
|  |  |  | detail.setDoneDate(new Date()); | 
|---|
|  |  |  | detail.setUnitId(tModel.getUnitId()); | 
|---|
|  |  |  | detail.setBatch(tModel.getMaterialBatch()); | 
|---|
|  |  |  | detail.setProcedureId(tModel.getProcedureId()); | 
|---|
|  |  |  | detail.setMaterialId(tModel.getMaterialId()); | 
|---|
|  |  |  | detail.setQualityType(doneType); | 
|---|
|  |  |  | detail.setWOutboundRecordInList(new ArrayList<>()); | 
|---|
|  |  |  | detailList.add(detail); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WOutboundRecord record = new WOutboundRecord(); | 
|---|
|  |  |  | record.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | record.setCreateTime(DateUtil.getCurrentDate()); | 
|---|
|  |  |  | record.setCreateUser(user.getId()); | 
|---|
|  |  |  | record.setAppliancesId(tModel.getAppliancesId()); | 
|---|
|  |  |  | record.setBatch(detail.getBatch()); | 
|---|
|  |  |  | record.setRootDepartId(mp.getRootDepartId()); | 
|---|
|  |  |  | record.setNum(detail.getNum()); | 
|---|
|  |  |  | record.setOutboundId(detail.getOutboundId()); | 
|---|
|  |  |  | record.setUnitId(detail.getUnitId()); | 
|---|
|  |  |  | record.setWarehouseId(detail.getWarehouseId()); | 
|---|
|  |  |  | record.setMaterialId(detail.getMaterialId()); | 
|---|
|  |  |  | record.setProcedureId(detail.getProcedureId()); | 
|---|
|  |  |  | record.setLocationId(detail.getLocationId()); | 
|---|
|  |  |  | record.setQualityType(detail.getQualityType()); | 
|---|
|  |  |  | detail.getWOutboundRecordInList().add(record); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WStock stock = getFromStockList(mp.getFinishWarehouseLocationId(),detail.getWarehouseId(),detail.getMaterialId(),detail.getBatch(), | 
|---|
|  |  |  | tModel.getProcedureId(),doneType,stockList); | 
|---|
|  |  |  | if(stock!=null){ | 
|---|
|  |  |  | //如果库存对象已存在,直接增加对应的库存量 | 
|---|
|  |  |  | stock.setNum(Constants.formatBigdecimal(stock.getNum()).add(Constants.formatBigdecimal(detail.getNum()))); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | stock = new WStock(); | 
|---|
|  |  |  | stock.setMaterialId(detail.getMaterialId()); | 
|---|
|  |  |  | stock.setBatch(detail.getBatch()); | 
|---|
|  |  |  | stock.setWarehouseId(outbound.getWarehouseId()); | 
|---|
|  |  |  | stock.setLocationId(mp.getFinishWarehouseLocationId()); | 
|---|
|  |  |  | stock.setUnitId(detail.getUnitId()); | 
|---|
|  |  |  | stock.setNum(Constants.formatBigdecimal(detail.getNum())); | 
|---|
|  |  |  | stock.setProcedureId(tModel.getProcedureId()); | 
|---|
|  |  |  | stock.setQualityType(doneType); | 
|---|
|  |  |  | //待更新库存信息 | 
|---|
|  |  |  | stockList.add(stock); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private WStock initMaterialNum(Integer materialId, BigDecimal num) { | 
|---|
|  |  |  | WStock s = new WStock(); | 
|---|
|  |  |  | 
|---|
|  |  |  | //计算工资信息 | 
|---|
|  |  |  | 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  ")); | 
|---|
|  |  |  | if(Objects.isNull(salaryParam)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未配置工资绩效配置!"); | 
|---|
|  |  |  | if(!Objects.isNull(salaryParam)){ | 
|---|
|  |  |  | workorderRecord.setSalaryPrice(salaryParam.getSalary()); | 
|---|
|  |  |  | workorderRecord.setSalaryType(salaryParam.getType()); | 
|---|
|  |  |  | workorderRecord.setSalaryUnqualified(salaryParam.getUnqualified()); | 
|---|
|  |  |  | //计件工资 | 
|---|
|  |  |  | if(salaryParam.getType().equals(Constants.ZERO)){ | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | workorderRecord.setSalaryPrice(salaryParam.getSalary()); | 
|---|
|  |  |  | workorderRecord.setSalaryType(salaryParam.getType()); | 
|---|
|  |  |  | workorderRecord.setSalaryUnqualified(salaryParam.getUnqualified()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //计件工资 | 
|---|
|  |  |  | if(salaryParam.getType().equals(Constants.ZERO)){ | 
|---|
|  |  |  | workorderRecord.setSalaryNum(salaryParam.getNum()); | 
|---|
|  |  |  | workorderRecord.setSalary(salaryParam.getSalary().multiply(salaryParam.getUnqualified()==Constants.ZERO?num:createWorkorderRecordDTO.getUnQualifiedNum())); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | workorderRecord.setDuration(createWorkorderRecordDTO.getDuration()); | 
|---|
|  |  |  | workorderRecord.setSalary(BigDecimal.valueOf(createWorkorderRecordDTO.getDuration()).multiply(salaryParam.getSalary()).divide(new BigDecimal(3600))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //插入工单操作记录,并且判断是否更改为工单的状态【生产中】 | 
|---|
|  |  |  | updateOrderInfo(loginUserInfo,workorder,Constants.WORKORDER_HISTORY_STATUS.produce); | 
|---|
|  |  |  | workorderRecordExtMapper.insert(workorderRecord); | 
|---|