gongchunyi
昨天 843d20d3b513c3513b77cfd623368571f9345e3c
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -24,6 +24,7 @@
import com.ruoyi.productionPlan.dto.ProductionPlanDto;
import com.ruoyi.productionPlan.dto.ProductionPlanImportDto;
import com.ruoyi.productionPlan.dto.ProductionPlanSummaryDto;
import com.ruoyi.productionPlan.enums.DataSourceTypeEnum;
import com.ruoyi.productionPlan.mapper.ProductOrderPlanMapper;
import com.ruoyi.productionPlan.mapper.ProductionPlanMapper;
import com.ruoyi.productionPlan.pojo.ProductOrderPlan;
@@ -45,7 +46,6 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import static com.ruoyi.productionPlan.enums.DataSourceTypeEnum.PRODUCTION_FORECAST;
/**
 * <br>
@@ -166,6 +166,7 @@
            if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
                // 最后一个计划,分配剩余方数
                BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
                plan.setStatus(1);
                plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume));
                productOrderPlan.setAssignedQuantity(lastRemainingVolume);
                productionPlanMapper.updateById(plan);
@@ -174,6 +175,7 @@
            }
            // 分配当前计划方数
            plan.setStatus(1);
            plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume));
            productOrderPlan.setAssignedQuantity(remainingVolume);
            // 更新生产计划
@@ -188,7 +190,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean add(ProductionPlanDto productionPlanDto) {
        productionPlanDto.setDataSourceType(PRODUCTION_FORECAST.getCode());
        productionPlanDto.setDataSourceType(DataSourceTypeEnum.MANUAL.getCode());
        productionPlanMapper.insert(productionPlanDto);
        return true;
    }
@@ -196,6 +198,10 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean update(ProductionPlanDto productionPlanDto) {
        // 已下发状态,不能编辑
        if (productionPlanDto.getStatus() == 1) {
            throw new BaseException("已下发状态,不能编辑");
        }
        // 查询是否有关联订单
        boolean hasProductOrderPlan = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().eq(ProductOrderPlan::getProductionPlanId, productionPlanDto.getId())).stream().anyMatch(p -> p.getProductOrderId() != null);
        if (hasProductOrderPlan) {
@@ -212,6 +218,10 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(List<Long> ids) {
        // 如果存在已下发的计划,则不能删除
        if (productionPlanMapper.selectList(Wrappers.<ProductionPlan>lambdaQuery().in(ProductionPlan::getId, ids).eq(ProductionPlan::getStatus, 1)).stream().anyMatch(p -> p.getStatus() == 1)) {
            throw new BaseException("删除失败,存在已下发的计划");
        }
        // 如果有关联订单,则不能删除
        if (productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductionPlanId, ids)).stream().anyMatch(p -> p.getProductOrderId() != null)) {
            throw new BaseException("删除失败,存在关联订单");
@@ -226,7 +236,7 @@
    @Transactional(rollbackFor = Exception.class)
    public void syncProdData(Integer dataSyncType) {
        if (!syncLock.tryLock()) {
            log.warn("同步正在进行中,本次 {} 同步请求被跳过", dataSyncType == 1 ? "手动" : "定时任务");
            log.warn("同步正在进行中,本次 {} 同步请求被跳过", dataSyncType == 1 ? "手动同步" : "定时任务同步");
            return;
        }
@@ -389,7 +399,6 @@
                plan.setCustomerName(formData.getString("textField_lbkozohg"));
                String materialCode = row.getString("textField_l9xo62q5");
                plan.setMaterialCode(materialCode);
                // 根据物料编码查询物料信息表,关联物料ID
                if (StringUtils.isNotEmpty(materialCode)) {
                    LambdaQueryWrapper<ProductMaterialSku> skuQueryWrapper = new LambdaQueryWrapper<>();
@@ -397,15 +406,6 @@
                    ProductMaterialSku sku = productMaterialSkuService.getOne(skuQueryWrapper);
                    if (sku != null) {
                        plan.setProductMaterialSkuId(sku.getId());
                        if (sku.getMaterialId() != null) {
                            // 设置产品名称
                            ProductMaterial material = productMaterialService.getById(sku.getMaterialId());
                            if (material != null) {
                                plan.setProductName(material.getMaterialName());
                            }
                        }
                        // 设置规格型号
                        plan.setProductSpec(sku.getSpecification());
                    }
                }
@@ -453,8 +453,7 @@
                plan.setFormCreatedTime(parseUtcTime(item.getString("createdTimeGMT")));
                plan.setFormModifiedTime(parseUtcTime(item.getString("modifiedTimeGMT")));
                plan.setDataSyncType(dataSyncType);
                plan.setDataSourceType(1);
                plan.setDataSourceType(DataSourceTypeEnum.DING_TALK.getCode());
                plan.setCreateTime(now);
                plan.setUpdateTime(now);
                plan.setTotalCount(totalCount);
@@ -553,8 +552,7 @@
            entity.setAssignedQuantity(BigDecimal.ZERO);
            entity.setCreateTime(LocalDateTime.now());
            entity.setUpdateTime(LocalDateTime.now());
            entity.setDataSourceType(2);
            entity.setDataSyncType(1);
            entity.setDataSourceType(DataSourceTypeEnum.DING_TALK.getCode());
            // 根据物料编码填充关联ID
            if (StringUtils.isNotEmpty(dto.getMaterialCode())) {
@@ -563,13 +561,6 @@
                ProductMaterialSku sku = productMaterialSkuService.getOne(skuQueryWrapper);
                if (sku != null) {
                    entity.setProductMaterialSkuId(sku.getId());
                    if (sku.getMaterialId() != null) {
                        ProductMaterial material = productMaterialService.getById(sku.getMaterialId());
                        if (material != null) {
                            entity.setProductName(material.getMaterialName());
                        }
                    }
                    entity.setProductSpec(sku.getSpecification());
                }
            }