liyong
2026-04-28 2c51e2bac7e271f6bd1a7da060e4ffd327d5a8d2
feat(production): 更新生产核算逻辑以支持设备和工时计算

- 引入 ProductionMachineRecordMapper 来查询机器记录
- 将原来的按工单用户分配改为按机器操作员分配
- 添加工时计算功能,使用 hutool 工具计算时间差
- 在销售台账生产核算实体中新增 deviceId 和 workHour 字段
- 集成 Swagger API 文档注解支持
- 重构生产核算数据插入逻辑以支持多操作员和设备关联
已修改2个文件
48 ■■■■■ 文件已修改
src/main/java/com/ruoyi/production/pojo/SalesLedgerProductionAccounting.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/pojo/SalesLedgerProductionAccounting.java
@@ -1,6 +1,7 @@
package com.ruoyi.production.pojo;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
@@ -90,4 +91,10 @@
    @TableField(fill = FieldFill.INSERT)
    private Long deptId;
    private Long deviceId;
    @ApiModelProperty("工时")
    private Long workHour;
}
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;
@@ -368,21 +371,29 @@
            /*添加生产核算        区分工序是计件还是计时*/
            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) {
                    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);
                    }
                }
            }
        }