huminmin
3 天以前 950dae8b64157cc3850ab64f4e4727dd139a5e3c
撤回生产订单
已修改4个文件
79 ■■■■ 文件已修改
doc/宁夏-中盛建材.sql 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/productionPlan/pojo/ProductOrderPlan.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java 39 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
doc/ÄþÏÄ-ÖÐÊ¢½¨²Ä.sql
@@ -103,6 +103,7 @@
    production_plan_id  bigint not null default 0 comment '生产计划id',
    create_time              datetime null comment '录入时间',
    update_time              datetime null comment '更新时间',
    assigned_quantity DECIMAL(10, 4) default 0 not null comment '下发数量',
    index idx_product_order_id (product_order_id),
    index idx_production_plan_id (production_plan_id),
    unique idx_product_order_production_plan (product_order_id, production_plan_id)
src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
@@ -15,10 +15,15 @@
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.*;
import com.ruoyi.production.service.ProductOrderService;
import com.ruoyi.productionPlan.mapper.ProductOrderPlanMapper;
import com.ruoyi.productionPlan.mapper.ProductionPlanMapper;
import com.ruoyi.productionPlan.pojo.ProductOrderPlan;
import com.ruoyi.productionPlan.pojo.ProductionPlan;
import com.ruoyi.quality.mapper.QualityInspectMapper;
import com.ruoyi.quality.pojo.QualityInspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
@@ -49,6 +54,12 @@
    @Autowired
    private ProductionProductMainMapper productionProductMainMapper;
    @Autowired
    private ProductOrderPlanMapper productOrderPlanMapper;
    @Autowired
    private ProductionPlanMapper productionPlanMapper;
    @Autowired
    private ProductionProductOutputMapper productionProductOutputMapper;
@@ -123,14 +134,25 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean revoke(ProductOrder productOrder) {
        //判断是否产生工单
        List<ProductionProductMain> productionProductMains = productionProductMainMapper.selectList(Wrappers.<ProductionProductMain>lambdaQuery().eq(ProductionProductMain::getProductOrderId, productOrder.getId()));
        if (!productionProductMains.isEmpty()) {
            throw new RuntimeException("生产订单已经报工,不能撤销");
        }
        // todo åˆ¤æ–­æ˜¯å¦äº§ç”ŸæŠ¥å·¥ä¿¡æ¯
        // æŸ¥è¯¢åˆå¹¶çš„生产计划
        List<ProductOrderPlan> productOrderPlans = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, productOrder.getId()));
        if (productOrderPlans.isEmpty()) {
            throw new RuntimeException("合并的生产计划不存在");
        }
        for (ProductOrderPlan productOrderPlan : productOrderPlans) {
            ProductionPlan productionPlan = productionPlanMapper.selectById(productOrderPlan.getProductionPlanId());
            productionPlan.setAssignedQuantity(productionPlan.getAssignedQuantity().subtract(productOrderPlan.getAssignedQuantity()));
            productionPlanMapper.updateById(productionPlan);
        }
        // åˆ é™¤å…³è”关系
        productOrderPlanMapper.delete(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, productOrder.getId()));
        // åˆ é™¤è®¢å•
        productOrderMapper.deleteById(productOrder.getId());
        // todo åˆ é™¤è®¢å•下的工艺路线子表
        return null;
    }
src/main/java/com/ruoyi/productionPlan/pojo/ProductOrderPlan.java
@@ -6,7 +6,10 @@
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
@@ -37,6 +40,10 @@
    @ApiModelProperty("生产计划id")
    private Long productionPlanId;
    @ApiModelProperty(value = "下发数量")
    @Excel(name = "下发数量")
    private BigDecimal assignedQuantity;
    @ApiModelProperty("录入时间")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -107,6 +107,7 @@
        //  æŸ¥è¯¢ä¸»ç”Ÿäº§è®¡åˆ’
        List<ProductionPlan> plans = productionPlanMapper.selectBatchIds(productionPlanDto.getIds());
        plans.sort(Comparator.comparingLong(ProductionPlan::getId));
        //  æ ¡éªŒæ˜¯å¦å­˜åœ¨ä¸åŒçš„产品名称
        String firstProductName = plans.get(0).getProductName();
@@ -128,10 +129,14 @@
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        // åˆ¤æ–­ä¸‹å‘数量是否大于等于方数
        if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalVolume) > 0) {
            log.warn("操作失败,下发数量不能大于方数");
            return false;
            throw new BaseException("操作失败,下发数量不能大于方数");
        }
        // åˆ›å»ºç”Ÿäº§è®¢å•
        ProductOrder productOrder = new ProductOrder();
        productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
        productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
        productOrderService.addProductOrder(productOrder);
        // æ ¹æ®ä¸‹å‘数量,从第一个生产计划开始分配方数
        BigDecimal assignedVolume = BigDecimal.ZERO;
@@ -141,30 +146,28 @@
                continue;
            }
            ProductOrderPlan productOrderPlan = new ProductOrderPlan();
            productOrderPlan.setProductOrderId(productOrder.getId());
            productOrderPlan.setProductionPlanId(plan.getId());
            if (assignedVolume.add(volume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
                // æœ€åŽä¸€ä¸ªè®¡åˆ’,分配剩余方数
                plan.setAssignedQuantity(productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume));
                BigDecimal remainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
                plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume));
                productOrderPlan.setAssignedQuantity(remainingVolume);
                productionPlanMapper.updateById(plan);
                productOrderPlanMapper.insert(productOrderPlan);
                break;
            }
            // åˆ†é…å½“前计划方数
            plan.setAssignedQuantity(volume);
            plan.setAssignedQuantity(plan.getAssignedQuantity().add(volume));
            productOrderPlan.setAssignedQuantity(volume);
            // æ›´æ–°ç”Ÿäº§è®¡åˆ’
            productionPlanMapper.updateById(plan);
            assignedVolume = assignedVolume.add(volume);
        }
        // åˆ›å»ºç”Ÿäº§è®¢å•
        ProductOrder productOrder = new ProductOrder();
        productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
        productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
        productOrderService.addProductOrder(productOrder);
        for (Long planId : productionPlanDto.getIds()) {
            ProductOrderPlan productOrderPlan = new ProductOrderPlan();
            productOrderPlan.setProductOrderId(productOrder.getId());
            productOrderPlan.setProductionPlanId(planId);
            // åˆ›å»ºå…³è”关系
            productOrderPlanMapper.insert(productOrderPlan);
            assignedVolume = assignedVolume.add(volume);
        }
        return true;
    }