|
|
|
|
@ -19,11 +19,16 @@ import org.dromara.mes.domain.bo.ProdPlanInfoBo;
|
|
|
|
|
import org.dromara.mes.domain.vo.MesProductPlanEditVo;
|
|
|
|
|
import org.dromara.mes.domain.vo.PlanMonitorVo;
|
|
|
|
|
import org.dromara.mes.domain.vo.ProdPlanInfoVo;
|
|
|
|
|
import org.dromara.mes.domain.vo.ProdOrderInfoVo;
|
|
|
|
|
import org.dromara.mes.domain.vo.ShiftGroupVo;
|
|
|
|
|
import org.dromara.mes.enums.PlanEventEnum;
|
|
|
|
|
import org.dromara.mes.enums.PlanStatusEnum;
|
|
|
|
|
import org.dromara.mes.mapper.ProdPlanInfoMapper;
|
|
|
|
|
import org.dromara.mes.service.IProdPlanInfoService;
|
|
|
|
|
import org.dromara.mes.service.IProdOrderInfoService;
|
|
|
|
|
import org.dromara.mes.domain.bo.ProdOrderInfoBo;
|
|
|
|
|
import org.dromara.system.api.RemoteCodeRuleService;
|
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
@ -59,6 +64,12 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
|
|
|
|
|
|
|
|
|
|
private final DictService dictService;//字典服务服务
|
|
|
|
|
|
|
|
|
|
@Autowired(required = false)
|
|
|
|
|
private IProdOrderInfoService prodOrderInfoService;
|
|
|
|
|
|
|
|
|
|
@DubboReference
|
|
|
|
|
private RemoteCodeRuleService remoteCodeRuleService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private StateMachineFactory<PlanStatusEnum, PlanEventEnum> stateMachineFactory;
|
|
|
|
|
@ -213,6 +224,26 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
|
|
|
|
|
return Seq.getId(Seq.mesPlanCodeSeqType, Seq.mesPlanCodeCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取工单编号(使用编码规则生成)
|
|
|
|
|
* 编码规则代码:5(生产工单编号)
|
|
|
|
|
*
|
|
|
|
|
* @return 工单编号
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String getPlanCode() {
|
|
|
|
|
try {
|
|
|
|
|
if (remoteCodeRuleService != null) {
|
|
|
|
|
// 使用编码规则生成工单编号,编码规则代码为 "5"
|
|
|
|
|
return remoteCodeRuleService.selectCodeRuleCode("5");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.warn("使用编码规则生成工单编号失败,使用默认方式: {}", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
// 如果编码规则服务不可用,使用默认方式生成
|
|
|
|
|
return Seq.getId(Seq.mesPlanCodeSeqType, Seq.mesPlanCodeCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询生产派工列表,join process
|
|
|
|
|
*
|
|
|
|
|
@ -248,35 +279,83 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int orderAddMesProductPlanList(MesProductPlanEditVo mesProductPlanEditVo) {
|
|
|
|
|
Long[] machineIds = mesProductPlanEditVo.getMachineIds();
|
|
|
|
|
//要新增的派工数据列表
|
|
|
|
|
Long productOrderId = mesProductPlanEditVo.getProductOrderId();
|
|
|
|
|
Long dispatchAmount = mesProductPlanEditVo.getDispatchAmount();
|
|
|
|
|
List<ProdPlanInfoBo> mesProductPlanList = mesProductPlanEditVo.getMesProductPlanList();
|
|
|
|
|
Long[] toDeletedPlanIds = mesProductPlanEditVo.getToDeletedPlanIds();
|
|
|
|
|
|
|
|
|
|
// 参数校验
|
|
|
|
|
if (productOrderId == null) {
|
|
|
|
|
throw new ServiceException("生产订单ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtils.isEmpty(mesProductPlanList)) {
|
|
|
|
|
throw new ServiceException("无有效的派工数据提交");
|
|
|
|
|
}else {
|
|
|
|
|
for (ProdPlanInfoBo mesProductPlanBo : mesProductPlanList) {
|
|
|
|
|
//设置编号
|
|
|
|
|
mesProductPlanBo.setProductOrderId(mesProductPlanEditVo.getProductOrderId());
|
|
|
|
|
mesProductPlanBo.setPlanCode(getDispatchCode());
|
|
|
|
|
mesProductPlanBo.setDispatchAmount(mesProductPlanBo.getPlanAmount());
|
|
|
|
|
mesProductPlanBo.setImportFlag("0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (dispatchAmount == null || dispatchAmount <= 0) {
|
|
|
|
|
throw new ServiceException("派工数量必须大于0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除待删除的计划
|
|
|
|
|
if (toDeletedPlanIds != null) {
|
|
|
|
|
for (Long planId : toDeletedPlanIds) {
|
|
|
|
|
this.deleteWithValidByIds(List.of(planId), false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 保存派工数据
|
|
|
|
|
int successCount = 0;
|
|
|
|
|
for (Long machineId : machineIds) {
|
|
|
|
|
for (ProdPlanInfoBo productPlanBo : mesProductPlanList) {
|
|
|
|
|
productPlanBo.setReleaseId(machineId);
|
|
|
|
|
boolean flag = this.insertByBo(productPlanBo);
|
|
|
|
|
if (flag) {
|
|
|
|
|
successCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (ProdPlanInfoBo planBo : mesProductPlanList) {
|
|
|
|
|
// 设置公共字段
|
|
|
|
|
planBo.setProductOrderId(productOrderId);
|
|
|
|
|
planBo.setImportFlag("0");
|
|
|
|
|
|
|
|
|
|
// 为每个工序生成不同的工单编号(如果前端没有传,则后端生成)
|
|
|
|
|
if (StringUtils.isBlank(planBo.getPlanCode())) {
|
|
|
|
|
String planCode = getPlanCode();
|
|
|
|
|
planBo.setPlanCode(planCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 确保releaseType设置为工位类型
|
|
|
|
|
if (StringUtils.isBlank(planBo.getReleaseType())) {
|
|
|
|
|
planBo.setReleaseType("3"); // 工位类型
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存数据
|
|
|
|
|
boolean flag = this.insertByBo(planBo);
|
|
|
|
|
if (flag) {
|
|
|
|
|
successCount++;
|
|
|
|
|
} else {
|
|
|
|
|
throw new ServiceException(String.format("保存派工数据失败:工序 %s", planBo.getProcessId()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (successCount == 0) {
|
|
|
|
|
throw new ServiceException("派工数据保存失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新订单的已派工数量(累加每个组第一个工序的数量)
|
|
|
|
|
if (prodOrderInfoService != null) {
|
|
|
|
|
try {
|
|
|
|
|
Map<Long, List<ProdPlanInfoBo>> processIdMap = mesProductPlanList.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(ProdPlanInfoBo::getProcessId));
|
|
|
|
|
List<ProdPlanInfoBo> planInfoBoList = processIdMap.get(mesProductPlanList.get(0).getProcessId());
|
|
|
|
|
BigDecimal totalDispatchAmount = planInfoBoList.stream()
|
|
|
|
|
.map(ProdPlanInfoBo::getDispatchAmount)
|
|
|
|
|
.filter(Objects::nonNull) // 过滤掉null值
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
ProdOrderInfoVo orderInfo = prodOrderInfoService.queryById(productOrderId);
|
|
|
|
|
if (orderInfo != null) {
|
|
|
|
|
ProdOrderInfoBo orderBo = new ProdOrderInfoBo();
|
|
|
|
|
orderBo.setProductOrderId(productOrderId);
|
|
|
|
|
long amount = orderInfo.getDispatchAmount() + Long.parseLong(totalDispatchAmount.toString());
|
|
|
|
|
orderBo.setDispatchAmount(amount);
|
|
|
|
|
prodOrderInfoService.updateByBo(orderBo);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.warn("更新订单派工数量失败: {}", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return successCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|