buhuazhen
2026-05-20 5862905480f0887b84194722b2b2b6a7f979df43
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -48,12 +48,15 @@
import java.util.Objects;
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;
@@ -158,8 +161,8 @@
        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());
@@ -170,6 +173,11 @@
        }
        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());
@@ -181,14 +189,12 @@
            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();
@@ -227,8 +233,12 @@
            }
            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;
    }
@@ -368,21 +378,34 @@
            /*添加生产核算        区分工序是计件还是计时*/
            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(userMapper.selectUserById(Long.parseLong(s)).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);
                }
            }
        }