update 订单下发逻辑更新加字段与校验

master
yinq 2 months ago
parent 56f8352afb
commit 80756d6111

@ -18,10 +18,12 @@ public class DynamicBaseSqlProvider {
case "prod_plan_info":
sql.INTO_COLUMNS("plan_code", "material_id", "material_bom_version", "plan_amount", "dispatch_amount",
"process_id", "plan_begin_time", "plan_end_time", "release_type", "release_id", "shift_id",
"import_flag", "class_team_id", "model_code", "create_dept", "create_by", "create_time");
"import_flag", "class_team_id", "model_code", "create_dept", "create_by", "create_time",
"product_order_id", "dispatch_code", "process_order", "material_bom_id");
sql.INTO_VALUES("#{entity.planCode}", "#{entity.materialId}", "#{entity.materialBomVersion}", "#{entity.planAmount}", "#{entity.dispatchAmount}",
"#{entity.processId}", "#{entity.planBeginTime}", "#{entity.planEndTime}", "#{entity.releaseType}", "#{entity.releaseId}", "#{entity.shiftId}",
"#{entity.importFlag}", "#{entity.classTeamId}", "#{entity.modelCode}", "#{entity.createDept}", "#{entity.createBy}", "#{entity.createTime}");
"#{entity.importFlag}", "#{entity.classTeamId}", "#{entity.modelCode}", "#{entity.createDept}", "#{entity.createBy}", "#{entity.createTime}",
"#{entity.productOrderId}", "#{entity.dispatchCode}", "#{entity.processOrder}", "#{entity.materialBomId}");
break;
case "prod_product_plan_detail":
sql.INTO_COLUMNS("plan_detail_code", "plan_id", "plan_code", "user_id", "user_name",

@ -105,13 +105,13 @@ public class ProdMaterialBomController extends BaseController {
*
* @param materialBomIds
*/
// @SaCheckPermission("mes:materialBom:remove")
// @Log(title = "物料BOM信息", businessType = BusinessType.DELETE)
// @DeleteMapping("/{materialBomIds}")
// public R<Void> remove(@NotEmpty(message = "主键不能为空")
// @PathVariable Long[] materialBomIds) {
// return toAjax(prodMaterialBomService.deleteWithValidByIds(List.of(materialBomIds), true));
// }
@SaCheckPermission("mes:materialBom:remove")
@Log(title = "物料BOM信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{materialBomIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] materialBomIds) {
return toAjax(prodMaterialBomService.deleteWithValidByIds(List.of(materialBomIds), true));
}
/**
* BOM

@ -131,13 +131,23 @@ public class ProdPlanInfoController extends BaseController {
/**
*
*
* @return orderCode
* @return dispatchCode
*/
@GetMapping(value = "/getDispatchCode")
public R<Void> getDispatchCode() {
public R<String> getDispatchCode() {
return R.ok(prodPlanInfoService.getDispatchCode());
}
/**
* 使
*
* @return planCode
*/
@GetMapping(value = "/getPlanCode")
public R<String> getPlanCode() {
return R.ok(prodPlanInfoService.getPlanCode());
}
/**
*
*

@ -1,30 +1,34 @@
package org.dromara.mes.domain.vo;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.dromara.mes.domain.ProdPlanInfo;
import org.dromara.mes.domain.bo.ProdPlanInfoBo;
import java.util.List;
@Data
public class MesProductPlanEditVo {
//生产工单ID
@NotBlank(message = "生产工单Id必须输入")
/**
* ID
*/
@NotNull(message = "生产工单Id必须输入")
private Long productOrderId;
//此次生产派工数量
/**
*
*/
private Long dispatchAmount;
//保存的生产计划
@NotBlank(message = "没有修改的生产派工提交")
/**
*
* releaseIdmachineIds
*/
@NotEmpty(message = "没有修改的生产派工提交")
private List<ProdPlanInfoBo> mesProductPlanList;
//待删除的生产计划ID
private Long[] toDeletedPlanIds;
/**
* Ids
* ID
*/
private Long[] machineIds;
private Long[] toDeletedPlanIds;
}

@ -78,6 +78,13 @@ public interface IProdPlanInfoService {
*/
String getDispatchCode();
/**
* 使
*
* @return
*/
String getPlanCode();
/**
* ,join process
*

@ -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;
}

@ -3,13 +3,17 @@ package org.dromara.qms;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
@EnableDubbo
@SpringBootApplication
public class HwmomQmsApplication {
public static void main(String[] args) {
SpringApplication.run(HwmomQmsApplication.class, args);
SpringApplication application = new SpringApplication(HwmomQmsApplication.class);
application.setApplicationStartup(new BufferingApplicationStartup(2048));
application.run(args);
System.out.println("(♥◠‿◠)ノ゙ 质量模块启动成功 ლ(´ڡ`ლ)゙ ");
}
}

Loading…
Cancel
Save