| | |
| | | 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.*; |
| | | import doumeemes.dao.ext.*; |
| | |
| | | |
| | | 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实现 |
| | |
| | | private WorkorderHistoryExtMapper workorderHistoryExtMapper; |
| | | @Autowired |
| | | private WorkorderRecordExtMapper workorderRecordExtMapper; |
| | | |
| | | @Autowired |
| | | private WorkorderMapper workorderMapper; |
| | | @Autowired |
| | | private RouteProcedureExtMapper routeProcedureExtMapper; |
| | | @Autowired |
| | |
| | | private WStockExtService wStockExtService; |
| | | @Autowired |
| | | private WorkorderRecordStandardService workorderRecordStandardService; |
| | | @Autowired |
| | | private UnqualifiedRecordMapper unqualifiedRecordMapper; |
| | | @Autowired |
| | | private CompanyUserExtMapper companyUserExtMapper; |
| | | |
| | | @Override |
| | | public PlansExtListVO findById(Integer id){ |
| | |
| | | // //统计已完工数量 |
| | | // param.setStatus(Constants.WORKORDER_STATUS.done); |
| | | // plan.setDoneNum(workorderExtMapper.sumOrderNum(param)); |
| | | QueryBomExtDTO bb = new QueryBomExtDTO(); |
| | | bb.setDepartId(plan.getDepartId()); |
| | | bb.setDeleted(Constants.ZERO); |
| | | bb.setRootDepartId(user.getRootDepartment().getId()); |
| | | bb.setMaterialId(plan.getMaterialId()); |
| | | bb.setProcedureId(plan.getProcedureId()); |
| | | BomExtListVO versionBom = bomExtMapper.selectByModel( bb); |
| | | if(versionBom == null || StringUtils.isBlank(versionBom.getVersion()) || versionBom.getBomVersionId() == null){ |
| | | plan.setHasBom(Constants.ZERO); |
| | | }else { |
| | | plan.setBomType(Constants.formatIntegerNum(versionBom.getType())); |
| | | plan.setHasBom(Constants.ONE); |
| | | } |
| | | return plan; |
| | | } |
| | | |
| | |
| | | initPlanStatisticInfo(t); |
| | | PlansExtListH5VO plan = new PlansExtListH5VO(); |
| | | BeanUtils.copyProperties(t,plan); |
| | | // plan.setDoneNum(); |
| | | plan.setWorkorderList(workorderExtService.findByPlanId(plan,true)); |
| | | return plan; |
| | | } |
| | |
| | | // 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | if(Constants.equalsInteger(mp.getPaused(),Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,计划已暂停!"); |
| | | } |
| | | if(Constants.formatIntegerNum(mp.getDistributNum())+thisPlanNum > Constants.formatIntegerNum(mp.getNum())){ |
| | | if(Constants.formatIntegerNum(mp.getWorkorderDistributNum())+thisPlanNum > Constants.formatIntegerNum(mp.getNum())){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,累计分配数量大于计划数量!"); |
| | | } |
| | | if(!Constants.equalsInteger(mp.getStatus(),Constants.PLAN_STATUS.publish)&&!Constants.equalsInteger(mp.getStatus(),Constants.PLAN_STATUS.distribute)){ |
| | |
| | | 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()); |
| | |
| | | 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())); |
| | |
| | | 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); |
| | |
| | | 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{ |
| | |
| | | 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(); |
| | |
| | | } |
| | | /** |
| | | * 恢复计划 |
| | | * @param p |
| | | * @param |
| | | */ |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | @Override |
| | |
| | | @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 = workorderExtMapper.selectList(new QueryWrapper<Workorder>().eq("PLAN_ID",plans.getId()).notIn("STATUS",7,8)); |
| | | List<Workorder> workorderList = workorderMapper.selectList(new QueryWrapper<Workorder>().eq("PLAN_ID",plans.getId()) |
| | | .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){ |
| | |
| | | workorderRecordStandardService.createMaterialStandard(createMaterialDTO); |
| | | } |
| | | //工单产出记录 |
| | | workorderRecordStandardService.createWorkorderRecord(autoWorkReportDTO.getCreateWorkorderRecordDTO(),user); |
| | | autoWorkReportDTO.getCreateWorkorderRecordDTO().setWorkorderId(workorder.getId()); |
| | | 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); |
| | |
| | | } |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |