| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.pojo.Product; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.ruoyi.framework.config.AliDingConfig; |
| | | import com.ruoyi.production.pojo.ProductOrder; |
| | | import com.ruoyi.production.service.ProductOrderService; |
| | | import com.ruoyi.productionPlan.dto.ProductionPlanDto; |
| | | import com.ruoyi.productionPlan.dto.ProductionPlanSummaryDto; |
| | | import com.ruoyi.productionPlan.mapper.ProductionPlanMapper; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | |
| | | @Autowired |
| | | private ProductionPlanMapper productionPlanMapper; |
| | | |
| | | @Autowired |
| | | private ProductOrderService productOrderService; |
| | | |
| | | /** |
| | | * 同步锁,确保手动和定时任务不同时执行 |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 合并生产计划 |
| | | */ |
| | | @Override |
| | | public boolean combine(ProductionPlanDto productionPlanDto) { |
| | | if (productionPlanDto.getIds() == null || productionPlanDto.getIds().isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | // 查询主生产计划 |
| | | List<ProductionPlan> plans = productionPlanMapper.selectBatchIds(productionPlanDto.getIds()); |
| | | |
| | | // 校验是否存在不同的产品名称 |
| | | String firstProductName = plans.get(0).getProductName(); |
| | | if (plans.stream().anyMatch(p -> !p.getProductName().equals(firstProductName))) { |
| | | log.warn("合并失败,存在不同的产品名称"); |
| | | return false; |
| | | } |
| | | |
| | | // 校验是否存在不同的产品规格 |
| | | String firstProductSpec = plans.get(0).getProductSpec(); |
| | | if (plans.stream().anyMatch(p -> !p.getProductSpec().equals(firstProductSpec))) { |
| | | log.warn("合并失败,存在不同的产品规格"); |
| | | return false; |
| | | } |
| | | |
| | | |
| | | // 叠加方数 |
| | | BigDecimal totalVolume = plans.stream() |
| | | .map(ProductionPlan::getVolume) |
| | | .filter(v -> v != null) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | // 创建生产订单 |
| | | ProductOrder productOrder = new ProductOrder(); |
| | | // 合并生产计划ids |
| | | String combineIds = StringUtils.join(productionPlanDto.getIds(), ","); |
| | | productOrder.setCombineProductionPlanIds(combineIds); |
| | | // 下发数量 |
| | | productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity()); |
| | | productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime()); |
| | | productOrderService.addProductOrder(productOrder); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 同步数据 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |