|
|
|
|
@ -21,6 +21,8 @@ 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.deviceledger.DeviceLedgerDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.itemrequisition.ItemRequisitionDetailDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.organization.OrganizationDO;
|
|
|
|
|
@ -30,6 +32,8 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.planrecord.PlanRecordDO;
|
|
|
|
|
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.paigongrecord.PaigongRecordMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.plan.PlanMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.planrecord.PlanRecordMapper;
|
|
|
|
|
@ -59,6 +63,7 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
@ -120,6 +125,10 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private PlanRecordMapper planRecordMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private BomMapper bomMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private BomDetailMapper bomDetailMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -145,6 +154,9 @@ 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);
|
|
|
|
|
}
|
|
|
|
|
// todo
|
|
|
|
|
// planMapper.insert(plan);
|
|
|
|
|
// 返回
|
|
|
|
|
@ -154,12 +166,13 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
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(item.getNumber())
|
|
|
|
|
.setNumber(calculateLossNumber(item.getItemId(), item.getNumber(), bomYieldRateMap, createReqVO.getIsCalculateLoss()))
|
|
|
|
|
.setIsEnable(true);
|
|
|
|
|
itemRequisitionDetails.add(detailDO);
|
|
|
|
|
}
|
|
|
|
|
@ -257,7 +270,7 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
ErpStockOutSaveReqVO.Item item = new ErpStockOutSaveReqVO.Item();
|
|
|
|
|
item.setWarehouseId(warehouse.getId());
|
|
|
|
|
item.setProductId(requisition.getItemId());
|
|
|
|
|
item.setCount(requisition.getNumber());
|
|
|
|
|
item.setCount(calculateLossNumber(requisition.getItemId(), requisition.getNumber(), bomYieldRateMap, createReqVO.getIsCalculateLoss()));
|
|
|
|
|
itemList.add(item);
|
|
|
|
|
}
|
|
|
|
|
stockOut.setItems(itemList);
|
|
|
|
|
@ -266,6 +279,45 @@ public class PlanServiceImpl implements PlanService {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void createPlanStockIn(PlanStatusUpdateVO statusUpdateVO,PlanDO planDO) {
|
|
|
|
|
|