|
|
|
|
@ -23,22 +23,30 @@ import cn.iocoder.yudao.module.mes.controller.admin.itemrequisition.vo.ItemRequi
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.*;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo.PlanRecordRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskStatusEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDetailDO;
|
|
|
|
|
// import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDO;
|
|
|
|
|
// import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDetailDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.itemrequisition.ItemRequisitionDetailDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.organization.OrganizationDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.paigongrecord.PaigongRecordDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.planlinechange.PlanLineChangeRecordDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.planroute.PlanProcessRouteItemDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.planrecord.PlanRecordDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.processroute.ProcessRouteDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.processroute.ProcessRouteItemDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDetailDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.bom.BomMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.bom.BomDetailMapper;
|
|
|
|
|
// import cn.iocoder.yudao.module.mes.dal.mysql.bom.BomMapper;
|
|
|
|
|
// import cn.iocoder.yudao.module.mes.dal.mysql.bom.BomDetailMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.paigongrecord.PaigongRecordMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.plan.PlanMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.planlinechange.PlanLineChangeRecordMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.planroute.PlanProcessRouteItemMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.planrecord.PlanRecordMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.processroute.ProcessRouteItemMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.processroute.ProcessRouteMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.stockindetail.StockInDetailMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.task.TaskMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.redis.no.MesNoRedisDAO;
|
|
|
|
|
@ -76,6 +84,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
|
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PLAN_CODE_EXISTS;
|
|
|
|
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PLAN_NOT_EXISTS;
|
|
|
|
|
|
|
|
|
|
@ -130,9 +139,17 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
@Resource
|
|
|
|
|
private PlanRecordMapper planRecordMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private BomMapper bomMapper;
|
|
|
|
|
private ProcessRouteMapper processRouteMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private BomDetailMapper bomDetailMapper;
|
|
|
|
|
private ProcessRouteItemMapper processRouteItemMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private PlanProcessRouteItemMapper planProcessRouteItemMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private PlanLineChangeRecordMapper planLineChangeRecordMapper;
|
|
|
|
|
// @Resource
|
|
|
|
|
// private BomMapper bomMapper;
|
|
|
|
|
// @Resource
|
|
|
|
|
// private BomDetailMapper bomDetailMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -158,9 +175,10 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
}
|
|
|
|
|
if (plan.getIsEnable() == null) plan.setIsEnable(true);
|
|
|
|
|
if(plan.getPriorityNum()==null) plan.setPriorityNum(1L);
|
|
|
|
|
if (createReqVO.getIsCalculateLoss() == null) {
|
|
|
|
|
createReqVO.setIsCalculateLoss(true);
|
|
|
|
|
}
|
|
|
|
|
fillProcessRouteSnapshot(plan);
|
|
|
|
|
// if (createReqVO.getIsCalculateLoss() == null) {
|
|
|
|
|
// createReqVO.setIsCalculateLoss(true);
|
|
|
|
|
// }
|
|
|
|
|
// todo
|
|
|
|
|
// planMapper.insert(plan);
|
|
|
|
|
// 返回
|
|
|
|
|
@ -169,34 +187,38 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
taskDO.setStatus(TaskStatusEnum.已排产.getValue());
|
|
|
|
|
taskService.updateTask(taskDO);
|
|
|
|
|
}
|
|
|
|
|
List<ItemRequisitionAndStock> list = analysisService.getItemAnalysis(plan); // 产品 num
|
|
|
|
|
Map<Long, BigDecimal> bomYieldRateMap = buildBomYieldRateMap(plan.getProductId(), createReqVO.getIsCalculateLoss());
|
|
|
|
|
List<ItemRequisitionDetailDO> itemRequisitionDetails = new ArrayList<>();
|
|
|
|
|
for (ItemRequisitionAndStock item : list) {
|
|
|
|
|
ItemRequisitionDetailDO detailDO = new ItemRequisitionDetailDO()
|
|
|
|
|
.setProductId(item.getItemId())
|
|
|
|
|
.setUnitId(item.getUnitId())
|
|
|
|
|
.setNumber(calculateLossNumber(item.getItemId(), item.getNumber(), bomYieldRateMap, createReqVO.getIsCalculateLoss()))
|
|
|
|
|
.setIsEnable(true);
|
|
|
|
|
itemRequisitionDetails.add(detailDO);
|
|
|
|
|
}
|
|
|
|
|
ItemRequisitionSaveReqVO saveReqVO = new ItemRequisitionSaveReqVO();
|
|
|
|
|
saveReqVO.setFeedingPipeline(createReqVO.getFeedingPipeline());
|
|
|
|
|
saveReqVO.setWorkerId(createReqVO.getWorkerId());
|
|
|
|
|
saveReqVO.setItemRequisitionDetails(itemRequisitionDetails);
|
|
|
|
|
saveReqVO.setStatus(ItemRequisitionStatusEnum.下达.getValue());
|
|
|
|
|
if (saveReqVO.getRequisitionDate() == null)
|
|
|
|
|
saveReqVO.setRequisitionDate(LocalDateTime.now());
|
|
|
|
|
// // 创建领料单
|
|
|
|
|
Long id = itemRequisitionService.createItemRequisition(saveReqVO);
|
|
|
|
|
// 不再根据产品 BOM 自动生成领料单。analysisService.getItemAnalysis(plan) 内部会查询 BomDetailDO,
|
|
|
|
|
// 产品没有 BOM 时会抛出“产品BOM不存在”,所以 /mes/plan/create 暂时跳过该链路。
|
|
|
|
|
// List<ItemRequisitionAndStock> list = analysisService.getItemAnalysis(plan); // 产品 num
|
|
|
|
|
//// Map<Long, BigDecimal> bomYieldRateMap = buildBomYieldRateMap(plan.getProductId(), createReqVO.getIsCalculateLoss());
|
|
|
|
|
// List<ItemRequisitionDetailDO> itemRequisitionDetails = new ArrayList<>();
|
|
|
|
|
// for (ItemRequisitionAndStock item : list) {
|
|
|
|
|
// ItemRequisitionDetailDO detailDO = new ItemRequisitionDetailDO().builder()
|
|
|
|
|
// .productId(item.getItemId())
|
|
|
|
|
// .unitId(item.getUnitId())
|
|
|
|
|
// .number(item.getNumber())
|
|
|
|
|
// .isEnable(true)
|
|
|
|
|
// .build();
|
|
|
|
|
// itemRequisitionDetails.add(detailDO);
|
|
|
|
|
// }
|
|
|
|
|
// ItemRequisitionSaveReqVO saveReqVO = new ItemRequisitionSaveReqVO();
|
|
|
|
|
// saveReqVO.setFeedingPipeline(createReqVO.getFeedingPipeline());
|
|
|
|
|
// saveReqVO.setWorkerId(createReqVO.getWorkerId());
|
|
|
|
|
// saveReqVO.setItemRequisitionDetails(itemRequisitionDetails);
|
|
|
|
|
// saveReqVO.setStatus(ItemRequisitionStatusEnum.下达.getValue());
|
|
|
|
|
// if (saveReqVO.getRequisitionDate() == null)
|
|
|
|
|
// saveReqVO.setRequisitionDate(LocalDateTime.now());
|
|
|
|
|
//// // 创建领料单
|
|
|
|
|
// Long id = itemRequisitionService.createItemRequisition(saveReqVO);
|
|
|
|
|
//更新计划状态
|
|
|
|
|
plan.setStatus(PlanStatusEnum.已排产.getValue());
|
|
|
|
|
plan.setIsEnable(true);
|
|
|
|
|
plan.setProductionManagerId(createReqVO.getWorkerId());
|
|
|
|
|
plan.setFeedingPipeline(createReqVO.getFeedingPipeline());
|
|
|
|
|
plan.setStartTime(LocalDateTime.now());
|
|
|
|
|
plan.setRequisitionId(id);
|
|
|
|
|
// plan.setRequisitionId(id);
|
|
|
|
|
planMapper.insert(plan);
|
|
|
|
|
savePlanProcessRouteItems(plan.getId(), plan.getProcessRouteId(), createReqVO.getProcessRouteItems());
|
|
|
|
|
//添加计划操作记录
|
|
|
|
|
PlanRecordDO planRecordDO = new PlanRecordDO();
|
|
|
|
|
planRecordDO.setTaskId(plan.getTaskId());
|
|
|
|
|
@ -256,71 +278,71 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saveReqVO.setPlanId(plan.getId());
|
|
|
|
|
saveReqVO.setId(id);
|
|
|
|
|
itemRequisitionService.updateItemRequisition(saveReqVO);
|
|
|
|
|
// 创建入领料出库单
|
|
|
|
|
ErpStockOutSaveReqVO stockOut = new ErpStockOutSaveReqVO();
|
|
|
|
|
List<ErpStockOutSaveReqVOItem> itemList = new ArrayList<>();
|
|
|
|
|
stockOut.setOutTime(LocalDateTime.now());
|
|
|
|
|
stockOut.setOutType("领料出库");
|
|
|
|
|
|
|
|
|
|
ErpWarehouseDO warehouse = erpWarehouseMapper.selectOne(
|
|
|
|
|
Wrappers.<ErpWarehouseDO>lambdaQuery()
|
|
|
|
|
.orderByDesc(ErpWarehouseDO::getCreateTime)
|
|
|
|
|
.last("limit 1")
|
|
|
|
|
);
|
|
|
|
|
for (ItemRequisitionAndStock requisition : list) {
|
|
|
|
|
ErpStockOutSaveReqVOItem item = new ErpStockOutSaveReqVOItem();
|
|
|
|
|
item.setWarehouseId(warehouse.getId());
|
|
|
|
|
item.setProductId(requisition.getItemId());
|
|
|
|
|
item.setCount(calculateLossNumber(requisition.getItemId(), requisition.getNumber(), bomYieldRateMap, createReqVO.getIsCalculateLoss()));
|
|
|
|
|
itemList.add(item);
|
|
|
|
|
}
|
|
|
|
|
stockOut.setItems(itemList);
|
|
|
|
|
stockOut.setPlanCode(StringUtils.isEmpty(plan.getCode()) ? code : plan.getCode());
|
|
|
|
|
stockOutService.createStockOut(stockOut);
|
|
|
|
|
// saveReqVO.setPlanId(plan.getId());
|
|
|
|
|
// saveReqVO.setId(id);
|
|
|
|
|
// itemRequisitionService.updateItemRequisition(saveReqVO);
|
|
|
|
|
// // 创建入领料出库单
|
|
|
|
|
// ErpStockOutSaveReqVO stockOut = new ErpStockOutSaveReqVO();
|
|
|
|
|
// List<ErpStockOutSaveReqVOItem> itemList = new ArrayList<>();
|
|
|
|
|
// stockOut.setOutTime(LocalDateTime.now());
|
|
|
|
|
// stockOut.setOutType("领料出库");
|
|
|
|
|
//
|
|
|
|
|
// ErpWarehouseDO warehouse = erpWarehouseMapper.selectOne(
|
|
|
|
|
// Wrappers.<ErpWarehouseDO>lambdaQuery()
|
|
|
|
|
// .orderByDesc(ErpWarehouseDO::getCreateTime)
|
|
|
|
|
// .last("limit 1")
|
|
|
|
|
// );
|
|
|
|
|
// for (ItemRequisitionAndStock requisition : list) {
|
|
|
|
|
// ErpStockOutSaveReqVOItem item = new ErpStockOutSaveReqVOItem();
|
|
|
|
|
// item.setWarehouseId(warehouse.getId());
|
|
|
|
|
// item.setProductId(requisition.getItemId());
|
|
|
|
|
// item.setCount(requisition.getNumber());
|
|
|
|
|
// itemList.add(item);
|
|
|
|
|
// }
|
|
|
|
|
// stockOut.setItems(itemList);
|
|
|
|
|
// stockOut.setPlanCode(StringUtils.isEmpty(plan.getCode()) ? code : plan.getCode());
|
|
|
|
|
// stockOutService.createStockOut(stockOut);
|
|
|
|
|
return plan.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<Long, BigDecimal> buildBomYieldRateMap(Long productId, Boolean isCalculateLoss) {
|
|
|
|
|
if (!Boolean.TRUE.equals(isCalculateLoss) || productId == null) {
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
}
|
|
|
|
|
BomDO bomDO = bomMapper.selectByProductId(productId);
|
|
|
|
|
if (bomDO == null || bomDO.getId() == null) {
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
}
|
|
|
|
|
List<BomDetailDO> bomDetails = bomDetailMapper.selectList(
|
|
|
|
|
Wrappers.<BomDetailDO>lambdaQuery()
|
|
|
|
|
.eq(BomDetailDO::getBomId, bomDO.getId())
|
|
|
|
|
.eq(BomDetailDO::getIsEnable, true)
|
|
|
|
|
);
|
|
|
|
|
if (CollUtil.isEmpty(bomDetails)) {
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
}
|
|
|
|
|
return bomDetails.stream()
|
|
|
|
|
.filter(detail -> detail.getProductId() != null)
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
BomDetailDO::getProductId,
|
|
|
|
|
BomDetailDO::getYieldRate,
|
|
|
|
|
(first, second) -> first
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal calculateLossNumber(Long itemId, BigDecimal originalNumber,
|
|
|
|
|
Map<Long, BigDecimal> bomYieldRateMap,
|
|
|
|
|
Boolean isCalculateLoss) {
|
|
|
|
|
if (!Boolean.TRUE.equals(isCalculateLoss) || itemId == null || originalNumber == null) {
|
|
|
|
|
return originalNumber;
|
|
|
|
|
}
|
|
|
|
|
BigDecimal yieldRate = bomYieldRateMap.get(itemId);
|
|
|
|
|
if (yieldRate == null) {
|
|
|
|
|
return originalNumber;
|
|
|
|
|
}
|
|
|
|
|
BigDecimal rate = yieldRate.divide(BigDecimal.valueOf(100), 8, RoundingMode.HALF_UP);
|
|
|
|
|
return originalNumber.multiply(BigDecimal.ONE.add(rate)).stripTrailingZeros();
|
|
|
|
|
}
|
|
|
|
|
// private Map<Long, BigDecimal> buildBomYieldRateMap(Long productId, Boolean isCalculateLoss) {
|
|
|
|
|
// if (!Boolean.TRUE.equals(isCalculateLoss) || productId == null) {
|
|
|
|
|
// return Collections.emptyMap();
|
|
|
|
|
// }
|
|
|
|
|
// BomDO bomDO = bomMapper.selectByProductId(productId);
|
|
|
|
|
// if (bomDO == null || bomDO.getId() == null) {
|
|
|
|
|
// return Collections.emptyMap();
|
|
|
|
|
// }
|
|
|
|
|
// List<BomDetailDO> bomDetails = bomDetailMapper.selectList(
|
|
|
|
|
// Wrappers.<BomDetailDO>lambdaQuery()
|
|
|
|
|
// .eq(BomDetailDO::getBomId, bomDO.getId())
|
|
|
|
|
// .eq(BomDetailDO::getIsEnable, true)
|
|
|
|
|
// );
|
|
|
|
|
// if (CollUtil.isEmpty(bomDetails)) {
|
|
|
|
|
// return Collections.emptyMap();
|
|
|
|
|
// }
|
|
|
|
|
// return bomDetails.stream()
|
|
|
|
|
// .filter(detail -> detail.getProductId() != null)
|
|
|
|
|
// .collect(Collectors.toMap(
|
|
|
|
|
// BomDetailDO::getProductId,
|
|
|
|
|
// BomDetailDO::getYieldRate,
|
|
|
|
|
// (first, second) -> first
|
|
|
|
|
// ));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// private BigDecimal calculateLossNumber(Long itemId, BigDecimal originalNumber,
|
|
|
|
|
// Map<Long, BigDecimal> bomYieldRateMap,
|
|
|
|
|
// Boolean isCalculateLoss) {
|
|
|
|
|
// if (!Boolean.TRUE.equals(isCalculateLoss) || itemId == null || originalNumber == null) {
|
|
|
|
|
// return originalNumber;
|
|
|
|
|
// }
|
|
|
|
|
// BigDecimal yieldRate = bomYieldRateMap.get(itemId);
|
|
|
|
|
// if (yieldRate == null) {
|
|
|
|
|
// return originalNumber;
|
|
|
|
|
// }
|
|
|
|
|
// BigDecimal rate = yieldRate.divide(BigDecimal.valueOf(100), 8, RoundingMode.HALF_UP);
|
|
|
|
|
// return originalNumber.multiply(BigDecimal.ONE.add(rate)).stripTrailingZeros();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@ -354,7 +376,65 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
TaskDetailDO taskDetailDO = taskService.getTaskDetail(updateObj.getTaskDetailId());
|
|
|
|
|
updateObj.setProductId(taskDetailDO.getProductId());
|
|
|
|
|
}
|
|
|
|
|
fillProcessRouteSnapshot(updateObj);
|
|
|
|
|
planMapper.updateById(updateObj);
|
|
|
|
|
if (updateReqVO.getProcessRouteItems() != null || updateReqVO.getProcessRouteId() != null) {
|
|
|
|
|
planProcessRouteItemMapper.deleteByPlanId(updateReqVO.getId());
|
|
|
|
|
savePlanProcessRouteItems(updateReqVO.getId(), updateObj.getProcessRouteId(), updateReqVO.getProcessRouteItems());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fillProcessRouteSnapshot(PlanDO plan) {
|
|
|
|
|
if (plan.getProcessRouteId() == null) {
|
|
|
|
|
plan.setProcessRouteName(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ProcessRouteDO processRoute = processRouteMapper.selectById(plan.getProcessRouteId());
|
|
|
|
|
plan.setProcessRouteName(processRoute == null ? null : processRoute.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void savePlanProcessRouteItems(Long planId, Long processRouteId, List<PlanProcessRouteItemSaveReqVO> reqItems) {
|
|
|
|
|
if (planId == null || processRouteId == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<ProcessRouteItemDO> routeItems = processRouteItemMapper.selectListByRouteId(processRouteId);
|
|
|
|
|
if (CollUtil.isEmpty(routeItems)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<Long, PlanProcessRouteItemSaveReqVO> reqItemMap = Optional.ofNullable(reqItems)
|
|
|
|
|
.orElse(Collections.emptyList())
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(item -> item.getProcessRouteItemId() != null)
|
|
|
|
|
.collect(Collectors.toMap(PlanProcessRouteItemSaveReqVO::getProcessRouteItemId, item -> item, (first, second) -> second));
|
|
|
|
|
|
|
|
|
|
Set<Long> deviceIds = Optional.ofNullable(reqItems)
|
|
|
|
|
.orElse(Collections.emptyList())
|
|
|
|
|
.stream()
|
|
|
|
|
.map(PlanProcessRouteItemSaveReqVO::getDeviceId)
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
Map<Long, DeviceLedgerDO> deviceMap = CollUtil.isEmpty(deviceIds) ? Collections.emptyMap()
|
|
|
|
|
: deviceLedgerMapper.selectBatchIds(deviceIds).stream()
|
|
|
|
|
.collect(Collectors.toMap(DeviceLedgerDO::getId, item -> item, (first, second) -> first));
|
|
|
|
|
|
|
|
|
|
for (ProcessRouteItemDO routeItem : routeItems) {
|
|
|
|
|
PlanProcessRouteItemSaveReqVO reqItem = reqItemMap.get(routeItem.getId());
|
|
|
|
|
DeviceLedgerDO device = reqItem == null || reqItem.getDeviceId() == null ? null : deviceMap.get(reqItem.getDeviceId());
|
|
|
|
|
|
|
|
|
|
PlanProcessRouteItemDO planRouteItem = new PlanProcessRouteItemDO();
|
|
|
|
|
planRouteItem.setPlanId(planId);
|
|
|
|
|
planRouteItem.setProcessRouteId(processRouteId);
|
|
|
|
|
planRouteItem.setProcessRouteItemId(routeItem.getId());
|
|
|
|
|
planRouteItem.setSort(reqItem != null && reqItem.getSort() != null ? reqItem.getSort() : routeItem.getSort());
|
|
|
|
|
planRouteItem.setProcessParameterId(routeItem.getProcessParameterId());
|
|
|
|
|
planRouteItem.setProcessParameterCode(routeItem.getProcessParameterCode());
|
|
|
|
|
planRouteItem.setProcessParameterName(routeItem.getProcessParameterName());
|
|
|
|
|
planRouteItem.setDeviceId(reqItem == null ? null : reqItem.getDeviceId());
|
|
|
|
|
planRouteItem.setDeviceName(device == null ? null : device.getDeviceName());
|
|
|
|
|
planRouteItem.setRemark(reqItem == null ? routeItem.getRemark() : reqItem.getRemark());
|
|
|
|
|
planProcessRouteItemMapper.insert(planRouteItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -411,6 +491,8 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
} else {
|
|
|
|
|
planRespVO.setDeviceName(null);
|
|
|
|
|
}
|
|
|
|
|
planRespVO.setProcessRouteItems(BeanUtils.toBean(
|
|
|
|
|
planProcessRouteItemMapper.selectListByPlanId(planDO.getId()), PlanProcessRouteItemRespVO.class));
|
|
|
|
|
|
|
|
|
|
return planRespVO;
|
|
|
|
|
}
|
|
|
|
|
@ -619,7 +701,7 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
convertSet(list, PlanDO::getTaskId));
|
|
|
|
|
Map<Long, OrganizationDO> organizationMap = organizationService.getMap(
|
|
|
|
|
convertSet(list, PlanDO::getFeedingPipeline));
|
|
|
|
|
return BeanUtils.toBean(list, PlanRespVO.class, item -> {
|
|
|
|
|
List<PlanRespVO> respList = BeanUtils.toBean(list, PlanRespVO.class, item -> {
|
|
|
|
|
MapUtils.findAndThen(map, item.getProductId(),
|
|
|
|
|
product -> item.setProductName(product.getName()));
|
|
|
|
|
|
|
|
|
|
@ -632,6 +714,27 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
MapUtils.findAndThen(organizationMap, item.getFeedingPipeline(),
|
|
|
|
|
organization -> item.setFeedingPipelineName(organization.getName()));
|
|
|
|
|
});
|
|
|
|
|
fillPlanProcessRouteItems(respList);
|
|
|
|
|
return respList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fillPlanProcessRouteItems(List<PlanRespVO> list) {
|
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Set<Long> planIds = list.stream().map(PlanRespVO::getId).filter(Objects::nonNull).collect(Collectors.toSet());
|
|
|
|
|
if (CollUtil.isEmpty(planIds)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<PlanProcessRouteItemDO> routeItems = planProcessRouteItemMapper.selectList(
|
|
|
|
|
Wrappers.<PlanProcessRouteItemDO>lambdaQuery()
|
|
|
|
|
.in(PlanProcessRouteItemDO::getPlanId, planIds)
|
|
|
|
|
.orderByAsc(PlanProcessRouteItemDO::getSort)
|
|
|
|
|
.orderByAsc(PlanProcessRouteItemDO::getId));
|
|
|
|
|
Map<Long, List<PlanProcessRouteItemRespVO>> routeItemMap = routeItems.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(PlanProcessRouteItemDO::getPlanId, LinkedHashMap::new,
|
|
|
|
|
Collectors.mapping(item -> BeanUtils.toBean(item, PlanProcessRouteItemRespVO.class), Collectors.toList())));
|
|
|
|
|
list.forEach(item -> item.setProcessRouteItems(routeItemMap.getOrDefault(item.getId(), Collections.emptyList())));
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public List<PlanDO> buildProgress(List<PlanDO> list){
|
|
|
|
|
@ -672,11 +775,12 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
|
|
|
|
|
List<ItemRequisitionDetailDO> itemRequisitionDetails = new ArrayList<>();
|
|
|
|
|
for (ItemRequisitionAndStock item : list) {
|
|
|
|
|
ItemRequisitionDetailDO detailDO = new ItemRequisitionDetailDO()
|
|
|
|
|
.setProductId(item.getItemId())
|
|
|
|
|
.setUnitId(item.getUnitId())
|
|
|
|
|
.setNumber(item.getNumber())
|
|
|
|
|
.setIsEnable(true);
|
|
|
|
|
ItemRequisitionDetailDO detailDO = new ItemRequisitionDetailDO().builder()
|
|
|
|
|
.productId(item.getItemId())
|
|
|
|
|
.unitId(item.getUnitId())
|
|
|
|
|
.number(item.getNumber())
|
|
|
|
|
.isEnable(true)
|
|
|
|
|
.build();
|
|
|
|
|
itemRequisitionDetails.add(detailDO);
|
|
|
|
|
}
|
|
|
|
|
saveReqVO.setItemRequisitionDetails(itemRequisitionDetails);
|
|
|
|
|
@ -700,12 +804,13 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean arrangePlanNum(ItemRequisitionSaveReqVO saveReqVO, PlanDO planDO) {
|
|
|
|
|
// 创建派工记录
|
|
|
|
|
PaigongRecordDO paigongRecordDO = new PaigongRecordDO()
|
|
|
|
|
.setPaigongNum(saveReqVO.getPaigongNum())
|
|
|
|
|
.setPipeline(saveReqVO.getPipeline())
|
|
|
|
|
.setIsPreProduction(saveReqVO.getIsPreProduction())
|
|
|
|
|
.setPlanId(planDO.getId())
|
|
|
|
|
.setPaigongTime(LocalDateTime.now());
|
|
|
|
|
PaigongRecordDO paigongRecordDO = new PaigongRecordDO().builder()
|
|
|
|
|
.paigongNum(saveReqVO.getPaigongNum())
|
|
|
|
|
.pipeline(saveReqVO.getPipeline())
|
|
|
|
|
.isPreProduction(saveReqVO.getIsPreProduction())
|
|
|
|
|
.planId(planDO.getId())
|
|
|
|
|
.paigongTime(LocalDateTime.now())
|
|
|
|
|
.build();
|
|
|
|
|
paigongRecordMapper.insert(paigongRecordDO);
|
|
|
|
|
// 更新未派工数量
|
|
|
|
|
planDO.setNoPaigongNumber(planDO.getPlanNumber()-saveReqVO.getPaigongNum());
|
|
|
|
|
@ -877,6 +982,44 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
return new PageResult<>(page.getRecords(), page.getTotal());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void changeLine(PlanLineChangeReqVO reqVO) {
|
|
|
|
|
PlanDO plan = planMapper.selectById(reqVO.getPlanId());
|
|
|
|
|
if (plan == null) {
|
|
|
|
|
throw exception(PLAN_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
PlanProcessRouteItemDO planRouteItem = planProcessRouteItemMapper.selectById(reqVO.getPlanProcessRouteItemId());
|
|
|
|
|
if (planRouteItem == null || !Objects.equals(planRouteItem.getPlanId(), reqVO.getPlanId())) {
|
|
|
|
|
throw exception(PLAN_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
DeviceLedgerDO afterDevice = deviceLedgerMapper.selectById(reqVO.getDeviceId());
|
|
|
|
|
|
|
|
|
|
PlanLineChangeRecordDO record = new PlanLineChangeRecordDO();
|
|
|
|
|
record.setPlanId(plan.getId());
|
|
|
|
|
record.setPlanProcessRouteItemId(planRouteItem.getId());
|
|
|
|
|
record.setProcessParameterId(planRouteItem.getProcessParameterId());
|
|
|
|
|
record.setProcessParameterName(planRouteItem.getProcessParameterName());
|
|
|
|
|
record.setBeforeDeviceId(planRouteItem.getDeviceId());
|
|
|
|
|
record.setBeforeDeviceName(planRouteItem.getDeviceName());
|
|
|
|
|
record.setAfterDeviceId(reqVO.getDeviceId());
|
|
|
|
|
record.setAfterDeviceName(afterDevice == null ? null : afterDevice.getDeviceName());
|
|
|
|
|
record.setChangeTime(LocalDateTime.now());
|
|
|
|
|
record.setOperatorUserId(getLoginUserId());
|
|
|
|
|
record.setPassNumber(plan.getPassNumber());
|
|
|
|
|
record.setRemark(reqVO.getRemark());
|
|
|
|
|
planLineChangeRecordMapper.insert(record);
|
|
|
|
|
|
|
|
|
|
planRouteItem.setDeviceId(reqVO.getDeviceId());
|
|
|
|
|
planRouteItem.setDeviceName(afterDevice == null ? null : afterDevice.getDeviceName());
|
|
|
|
|
planProcessRouteItemMapper.updateById(planRouteItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<PlanLineChangeRecordRespVO> getLineChangeRecordList(Long planId) {
|
|
|
|
|
return BeanUtils.toBean(planLineChangeRecordMapper.selectListByPlanId(planId), PlanLineChangeRecordRespVO.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|