| | |
| | | import com.ruoyi.quality.mapper.*; |
| | | import com.ruoyi.quality.pojo.*; |
| | | import com.ruoyi.quality.service.IQualityInspectService; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.aop.framework.AopContext; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.hutool.core.date.LocalDateTimeUtil.between; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public class ProductionProductMainServiceImpl extends ServiceImpl<ProductionProductMainMapper, ProductionProductMain> implements ProductionProductMainService { |
| | | |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | private final ProductionMachineRecordMapper productionMachineRecordMapper; |
| | | private IQualityInspectService qualityInspectService; |
| | | private ProductionProductMainMapper productionProductMainMapper; |
| | | |
| | |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(dto.getWorkOrderId()); |
| | | |
| | | SysUser user = userMapper.selectUserById(dto.getUserId()); |
| | | ProductionProductMain productionProductMain = new ProductionProductMain(); |
| | | //当前工艺路线对应的工序详情 |
| | | ProductProcessRouteItem productProcessRouteItem = productProcessRouteItemMapper.selectById(dto.getProductProcessRouteItemId()); |
| | |
| | | productionProductMain.setProductNo(productNo); |
| | | |
| | | // 修改班组信息 以第一人作为原先setUserId setUserName |
| | | Assert.isTrue(CollUtil.isNotEmpty(dto.getTeamList()),"班组信息不能为空"); |
| | | Assert.isTrue(CollUtil.isNotEmpty(dto.getTeamList()), "班组信息不能为空"); |
| | | |
| | | productionProductMain.setTeamIds(dto.getTeamList().stream().map(ProductionProductMainDto.Team::getUserId).map(String::valueOf).collect(Collectors.joining(","))); |
| | | productionProductMain.setTeamNames(dto.getTeamList().stream().map(ProductionProductMainDto.Team::getUserName).collect(Collectors.joining(","))); |
| | | |
| | | productionProductMain.setUserId(dto.getTeamList().get(0).getUserId()); |
| | | productionProductMain.setUserName(dto.getTeamList().get(0).getUserName()); |
| | | |
| | | //报工人 是 谁报工就是是谁 |
| | | productionProductMain.setUserId(SecurityUtils.getUserId()); |
| | | productionProductMain.setUserName(SecurityUtils.getLoginUser().getNickName()); |
| | | |
| | | |
| | | productionProductMain.setProductProcessRouteItemId(dto.getProductProcessRouteItemId()); |
| | | productionProductMain.setWorkOrderId(dto.getWorkOrderId()); |
| | | productionProductMain.setAuditUserId(dto.getAuditUserId()); |
| | | productionProductMain.setAuditUserName(dto.getAuditUserName()); |
| | | // productionProductMain.setAuditUserId(dto.getAuditUserId()); |
| | | // productionProductMain.setAuditUserName(dto.getAuditUserName()); |
| | | productionProductMain.setStatus(0); |
| | | productionProductMain.setStartTime(productWorkOrder.getStartProductTime()); |
| | | productionProductMain.setEndTime(now); |
| | | productionProductMain.setDeviceId(productProcess.getDeviceId()); |
| | | productionProductMain.setDeviceName(productProcess.getDeviceName()); |
| | | if (ObjectUtils.isNotEmpty(dto.getStartTime()) && ObjectUtils.isNotEmpty(dto.getEndTime())) { |
| | | productionProductMain.setStartTime(dto.getStartTime()); |
| | | productionProductMain.setEndTime(dto.getEndTime()); |
| | | } else { |
| | | productionProductMain.setStartTime(productWorkOrder.getStartProductTime()); |
| | | productionProductMain.setEndTime(now); |
| | | } |
| | | productionProductMain.setDeviceId(dto.getDeviceId()); |
| | | productionProductMain.setDeviceName(dto.getDeviceName()); |
| | | |
| | | // 审批人为自己 直接通过审批 |
| | | productionProductMain.setAuditUserName(SecurityUtils.getUsername()); |
| | | productionProductMain.setAuditUserId(SecurityUtils.getUserId()); |
| | | |
| | | productionProductMainMapper.insert(productionProductMain); |
| | | /*新增报工投入表*/ |
| | | List<ProductStructureDto> productStructureDtos = productStructureMapper.listBybomAndProcess(productProcessRoute.getBomId(), productProcess.getId()); |
| | |
| | | productStructureDtos.add(productStructureDto); |
| | | } |
| | | for (ProductStructureDto productStructureDto : productStructureDtos) { |
| | | |
| | | ProductionProductInput productionProductInput = new ProductionProductInput(); |
| | | productionProductInput.setProductModelId(productStructureDto.getProductModelId()); |
| | | productionProductInput.setQuantity(productStructureDto.getUnitQuantity().multiply(dto.getQuantity())); |
| | | productionProductInput.setProductMainId(productionProductMain.getId()); |
| | | productionProductInputMapper.insert(productionProductInput); |
| | | // stockUtils.substractStock(productStructureDto.getProductModelId(), productionProductInput.getQuantity(), StockOutQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_OUT.getCode(), productionProductMain.getId()); |
| | | |
| | | } |
| | | /*新增报工产出表*/ |
| | | ProductionProductOutput productionProductOutput = new ProductionProductOutput(); |
| | |
| | | productionProductOutput.setQuantity(dto.getQuantity() != null ? dto.getQuantity() : BigDecimal.ZERO); |
| | | productionProductOutput.setScrapQty(dto.getScrapQty() != null ? dto.getScrapQty() : BigDecimal.ZERO); |
| | | productionProductOutput.setReplenishQty(dto.getReplenishQty()); |
| | | productionProductOutput.setAddQty(dto.getAddQty() != null ? dto.getAddQty() : BigDecimal.ZERO); |
| | | productionProductOutputMapper.insert(productionProductOutput); |
| | | //合格数量=报工数量-报废数量 |
| | | BigDecimal productQty = productionProductOutput.getQuantity().subtract(productionProductOutput.getScrapQty()); |
| | |
| | | if (ObjectUtils.isNull(productWorkOrder.getActualStartTime())) { |
| | | productWorkOrder.setActualStartTime(LocalDate.now());//实际开始时间 |
| | | } |
| | | if (productWorkOrder.getCompleteQuantity().compareTo(productWorkOrder.getPlanQuantity()) == 0) { |
| | | if (productWorkOrder.getCompleteQuantity().compareTo(productWorkOrder.getPlanQuantity()) >= 0) { |
| | | productWorkOrder.setActualEndTime(LocalDate.now());//实际结束时间 |
| | | } |
| | | productWorkOrder.setEndProductTime(now); |
| | |
| | | if (ObjectUtils.isNull(productOrder.getStartTime())) { |
| | | productOrder.setStartTime(now);//开始时间 |
| | | } |
| | | if (productProcessRouteItem.getDragSort() == productProcessRouteItems.size()) { |
| | | if (productProcessRouteItem.getDragSort() >= productProcessRouteItems.size() -1 ) { |
| | | //如果是最后一道工序报工之后生产订单完成数量+ |
| | | productOrder.setCompleteQuantity(productOrder.getCompleteQuantity().add(productQty)); |
| | | if (productOrder.getCompleteQuantity().compareTo(productOrder.getQuantity()) == 0) { |
| | | if (productOrder.getCompleteQuantity().compareTo(productOrder.getQuantity()) >= 0) { |
| | | productOrder.setEndTime(now);//结束时间 |
| | | } |
| | | } |
| | | productOrderMapper.updateById(productOrder); |
| | | } |
| | | |
| | | //nextAddProductMain(productionProductOutput) // 由于需要审核,所以需要拆封下来 |
| | | ProductAuditVo productAuditVo = new ProductAuditVo(); |
| | | productAuditVo.setId(productionProductMain.getId()); |
| | | productAuditVo.setAuditStatus(AuditEnum.AUDIT_SUCCESS); |
| | | productAuditVo.setAuditOpinion(""); |
| | | ((ProductionProductMainService) AopContext.currentProxy()).auditProductMain(productAuditVo); |
| | | // nextAddProductMain(productionProductOutput) // 由于需要审核,所以需要拆封下来 |
| | | return true; |
| | | } |
| | | |
| | |
| | | ProductionProductMain productionProductMain = productionProductMainMapper.selectById(productAuditVo.getId()); |
| | | |
| | | // 当前审批人 要与当前登录人为同一人 |
| | | if(productionProductMain.getAuditUserId() != -1){ |
| | | if (productionProductMain.getAuditUserId() != -1) { |
| | | Assert.isTrue(SecurityUtils.getUserId().equals(productionProductMain.getAuditUserId()), "当前登录用户不是当前审批人"); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void nextAddProductMain(@NotNull ProductionProductOutput productionProductOutput){ |
| | | public void nextAddProductMain(@NotNull ProductionProductOutput productionProductOutput) { |
| | | //合格数量=报工数量-报废数量 |
| | | ProductionProductMain productionProductMain = productionProductMainMapper.selectById(productionProductOutput.getProductMainId()); |
| | | BigDecimal productQty = productionProductOutput.getQuantity().subtract(productionProductOutput.getScrapQty()); |
| | |
| | | //对应的过程检或者出厂检 |
| | | int inspectType = 1; |
| | | String process = productProcess.getName();//工序 |
| | | if (productProcessRouteItem.getDragSort() == productProcessRouteItems.size()) { |
| | | if (productProcessRouteItem.getDragSort() == (productProcessRouteItems.size()-1)) { |
| | | //最后一道工序生成出厂检 |
| | | inspectType = 2; |
| | | process = null; |
| | |
| | | qualityInspectParamMapper.insert(param); |
| | | }); |
| | | } |
| | | }else { |
| | | } else { |
| | | //直接入库 |
| | | stockUtils.addStock(productProcessRouteItem.getProductModelId(), productQty, StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(), productionProductMain.getId(),"-","-","-"); |
| | | if (productProcessRouteItem.getDragSort() == (productProcessRouteItems.size()-1)) { |
| | | //最后一道工序才会入库 |
| | | stockUtils.addStock(productProcessRouteItem.getProductModelId(), productQty, StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(), productionProductMain.getId(), "-", "-", "-"); |
| | | } |
| | | } |
| | | |
| | | /*添加生产核算 区分工序是计件还是计时*/ |
| | | BigDecimal workHours = productProcess.getSalaryQuota(); |
| | | |
| | | SalesLedgerProductionAccounting salesLedgerProductionAccounting = SalesLedgerProductionAccounting.builder() |
| | | .productMainId(productionProductMain.getId()) |
| | | .schedulingUserId(productionProductMain.getUserId()) |
| | | .schedulingUserName(userMapper.selectUserById(productionProductMain.getUserId()).getNickName()) |
| | | .finishedNum(productQty) |
| | | .workHours(workHours) |
| | | .process(productProcess.getName()) |
| | | .schedulingDate(LocalDate.now()) |
| | | .tenantId(productionProductOutput.getTenantId()) |
| | | .build(); |
| | | salesLedgerProductionAccountingMapper.insert(salesLedgerProductionAccounting); |
| | | List<ProductionMachineRecord> productionMachineRecords = productionMachineRecordMapper.selectList(Wrappers.<ProductionMachineRecord>lambdaQuery().eq(ProductionMachineRecord::getWorkOrderId, productionProductMain.getWorkOrderId())); |
| | | if (ObjectUtils.isNotEmpty(productionMachineRecords)) { |
| | | for (ProductionMachineRecord productionMachineRecord : productionMachineRecords) { |
| | | //说明已经添加过了,不添加了 |
| | | if (productionMachineRecord.getReportStatus()) { |
| | | continue; |
| | | } |
| | | for (String s : productionMachineRecord.getOperatorId().split(",")) { |
| | | Long minutes = 0L; |
| | | if (productionMachineRecord.getMachineStartTime() != null) { |
| | | minutes = between(productionMachineRecord.getMachineStartTime(), LocalDateTime.now()).toMinutes(); |
| | | } |
| | | SalesLedgerProductionAccounting salesLedgerProductionAccounting = SalesLedgerProductionAccounting.builder() |
| | | .productMainId(productionProductMain.getId()) |
| | | .schedulingUserId(Long.parseLong(s)) |
| | | .schedulingUserName(Optional.of(userMapper.selectUserById(Long.parseLong(s))).orElse(new SysUser()).getNickName()) |
| | | .finishedNum(productQty) |
| | | .workHours(workHours) |
| | | .process(productProcess.getName()) |
| | | .schedulingDate(LocalDate.now()) |
| | | .tenantId(productionProductOutput.getTenantId()) |
| | | .deviceId(productionMachineRecord.getMachineId()) |
| | | .workHour(minutes) |
| | | .build(); |
| | | salesLedgerProductionAccountingMapper.insert(salesLedgerProductionAccounting); |
| | | } |
| | | productionMachineRecord.setReportStatus(true); |
| | | productionMachineRecordMapper.updateById(productionMachineRecord); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //如果报废数量>0,需要进入报废的库存 |
| | | if (ObjectUtils.isNotEmpty(productionProductOutput.getScrapQty())) { |
| | | if (productionProductOutput.getScrapQty().compareTo(BigDecimal.ZERO) > 0) { |
| | | stockUtils.addUnStock(productModel.getId(), productionProductOutput.getScrapQty(), StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(), productionProductMain.getId(),"-","-","-"); |
| | | stockUtils.addUnStock(productModel.getId(), productionProductOutput.getScrapQty(), StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(), productionProductMain.getId(), "-", "-", "-"); |
| | | } |
| | | } |
| | | } |
| | |
| | | public Boolean removeProductMain(Long id) { |
| | | //判断该条报工是否不合格处理,如果不合格处理了,则不允许删除 |
| | | List<QualityInspect> qualityInspects = qualityInspectMapper.selectList(Wrappers.<QualityInspect>lambdaQuery().eq(QualityInspect::getProductMainId, id)); |
| | | if (qualityInspects.size() > 0){ |
| | | if (qualityInspects.size() > 0) { |
| | | List<QualityUnqualified> qualityUnqualifieds = qualityUnqualifiedMapper.selectList(Wrappers.<QualityUnqualified>lambdaQuery() |
| | | .in(QualityUnqualified::getInspectId, qualityInspects.stream().map(QualityInspect::getId).collect(Collectors.toList()))); |
| | | if (qualityUnqualifieds.size() > 0 && qualityUnqualifieds.get(0).getInspectState()==1) { |
| | | if (qualityUnqualifieds.size() > 0 && qualityUnqualifieds.get(0).getInspectState() == 1) { |
| | | throw new ServiceException("该条报工已经不合格处理了,不允许删除"); |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | BigDecimal validQuantity = outputQty.subtract(scrapQty); |
| | | if(productionProductMain.getAuditStatus() != 2){ |
| | | if (productionProductMain.getAuditStatus() != 2) { |
| | | productWorkOrder.setCompleteQuantity(completeQty.subtract(validQuantity).max(BigDecimal.ZERO)); |
| | | } |
| | | productWorkOrder.setActualEndTime(null); |
| | |
| | | new LambdaQueryWrapper<QualityInspectParam>() |
| | | .eq(QualityInspectParam::getInspectId, q.getId())); |
| | | qualityInspectMapper.deleteById(q.getId()); |
| | | stockUtils.deleteStockInRecord(q.getId(), StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode()); |
| | | stockUtils.deleteStockInRecord(q.getId(), StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode()); |
| | | }); |
| | | |
| | | // 删除产出记录 |