| | |
| | | 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 |
| | |
| | | public class ProductionProductMainServiceImpl extends ServiceImpl<ProductionProductMainMapper, ProductionProductMain> implements ProductionProductMainService { |
| | | |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | private final ProductionMachineRecordMapper productionMachineRecordMapper; |
| | | private IQualityInspectService qualityInspectService; |
| | | private ProductionProductMainMapper productionProductMainMapper; |
| | | |
| | |
| | | |
| | | 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); |
| | | if (ObjectUtils.isNotEmpty(dto.getStartTime()) && ObjectUtils.isNotEmpty(dto.getEndTime())) { |
| | | productionProductMain.setStartTime(dto.getStartTime()); |
| | |
| | | } |
| | | 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; |
| | | } |
| | | |
| | |
| | | //对应的过程检或者出厂检 |
| | | int inspectType = 1; |
| | | String process = productProcess.getName();//工序 |
| | | if (productProcessRouteItem.getDragSort() == productProcessRouteItems.size()) { |
| | | if (productProcessRouteItem.getDragSort() == (productProcessRouteItems.size()-1)) { |
| | | //最后一道工序生成出厂检 |
| | | inspectType = 2; |
| | | process = null; |
| | |
| | | } |
| | | } 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(); |
| | | ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(productionProductMain.getWorkOrderId()); |
| | | String userIds = productWorkOrder.getUserIds(); |
| | | if (ObjectUtils.isNotEmpty(userIds)) { |
| | | for (String s : userIds.split(",")) { |
| | | SalesLedgerProductionAccounting salesLedgerProductionAccounting = SalesLedgerProductionAccounting.builder() |
| | | .productMainId(productionProductMain.getId()) |
| | | .schedulingUserId(Long.parseLong(s)) |
| | | .schedulingUserName(userMapper.selectUserById(Long.parseLong(s)).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); |
| | | } |
| | | } |
| | | } |