liyong
3 天以前 f5624a59380db70633eebe3612e2d3c703012b41
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -33,6 +34,7 @@
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -87,34 +89,7 @@
        SysUser user = SecurityUtils.getLoginUser().getUser();
        if (dto.isReportWork()) {
            // 更新逻辑 - 只更新数量
            QueryWrapper<ProductionProductOutput> outputWrapper = new QueryWrapper<>();
            outputWrapper.eq("product_main_id", dto.getProductMainId());
            ProductionProductOutput output = productionProductOutputMapper.selectOne(outputWrapper);
            if (output == null) {
                throw new RuntimeException("产出记录不存在");
            }
            // 查询生产核算记录
            QueryWrapper<SalesLedgerProductionAccounting> accountingWrapper = new QueryWrapper<>();
            accountingWrapper.eq("sales_ledger_work_id", dto.getProductMainId());
            SalesLedgerProductionAccounting accounting = salesLedgerProductionAccountingMapper.selectOne(accountingWrapper);
            if (accounting == null) {
                throw new RuntimeException("生产核算记录不存在");
            }
            // 只更新数量
            if (dto.getQuantity() != null) {
                output.setQuantity(dto.getQuantity());
                productionProductOutputMapper.updateById(output);
                // 更新生产核算记录
                accounting.setFinishedNum(dto.getQuantity());
                salesLedgerProductionAccountingMapper.updateById(accounting);
            }
            return true;
        }
        // 新增逻辑
        ProductionProductMain productionProductMain = new ProductionProductMain();
@@ -165,12 +140,13 @@
        //更新工单
        if (insert > 0) {
            UpdateWrapper<ProductWorkOrder> wrapper = new UpdateWrapper<>();
            wrapper.set("report_work", true)
                    .set("quantity", dto.getQuantity())
                    .set("product_main_id", productionProductMain.getId())
                    .eq("id", dto.getWorkOrderId());
            productWorkOrderMapper.update(null, wrapper);
            Map<String, Object> params = new HashMap<>();
            params.put("quantity", dto.getQuantity());
            params.put("productMainId", productionProductMain.getId());
            params.put("workOrderId", dto.getWorkOrderId());
            params.put("deductQuantity", dto.getQuantity());
            productWorkOrderMapper.updatePlanQuantity(params);
        }
        ProductProcess productProcess = productProcessMapper.selectById(productProcessRouteItem.getProcessId());
        ProductModel productModel = productProcessRouteItem.getProductModelId() != null ?
@@ -252,6 +228,8 @@
    public Boolean removeProductMain(ProductionProductMainDto dto) {
        Long id = dto.getId();
        // 更新工单
        productWorkOrderMapper.rollbackPlanQuantity(id);
        // 删除质检参数和质检记录
        qualityInspectMapper.selectList(
                new LambdaQueryWrapper<QualityInspect>()
@@ -270,9 +248,9 @@
        // 删除关联的核算数据
        salesLedgerProductionAccountingMapper.delete(
                        new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
                                .eq(SalesLedgerProductionAccounting::getSalesLedgerWorkId, id)
                );
                new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
                        .eq(SalesLedgerProductionAccounting::getSalesLedgerWorkId, id)
        );
        // 删除主表
        return productionProductMainMapper.deleteById(id) > 0;