diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteController.java index 8a7f29b..02191d3 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteController.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteController.java @@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteDO; import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; @@ -53,6 +54,19 @@ public class MesProRouteController { return success(true); } + @PutMapping("/update-status") + @Operation(summary = "更新工艺路线状态") + @Parameters({ + @Parameter(name = "id", description = "编号", required = true), + @Parameter(name = "status", description = "状态", required = true) + }) + @PreAuthorize("@ss.hasPermission('mes:pro-route:update')") + public CommonResult updateRouteStatus(@RequestParam("id") Long id, + @RequestParam("status") Integer status) { + routeService.updateRouteStatus(id, status); + return success(true); + } + @DeleteMapping("/delete") @Operation(summary = "删除工艺路线") @Parameter(name = "id", description = "编号", required = true) diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProcessController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProcessController.java index 5915be4..13e2875 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProcessController.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProcessController.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.mes.controller.admin.pro.route; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.process.MesProRouteProcessRespVO; import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.process.MesProRouteProcessSaveReqVO; @@ -18,11 +20,14 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - MES 工艺路线工序") @RestController @@ -81,42 +86,23 @@ public class MesProRouteProcessController { // ==================== 拼接 VO ==================== private List buildRouteProcessRespVOList(List list) { - // TODO @AI:collutil 去判断空; - if (list.isEmpty()) { - return List.of(); + if (CollUtil.isEmpty(list)) { + return Collections.emptyList(); } - // 批量查询工序信息 - // TODO @AI:我记得有 CollUtil 可以搞多个的; - List processIds = new ArrayList<>(); - for (MesProRouteProcessDO item : list) { - processIds.add(item.getProcessId()); - if (item.getNextProcessId() != null) { - processIds.add(item.getNextProcessId()); - } - } - // TODO @AI:processService.getProcessMap 直接返回 Map 就好了; - List processList = processService.getProcessList(processIds); - Map processMap = convertMap(processList, MesProProcessDO::getId); - // 拼装 - List result = BeanUtils.toBean(list, MesProRouteProcessRespVO.class); - for (MesProRouteProcessRespVO vo : result) { - // TODO @AI:MapUtil findMap - MesProProcessDO process = processMap.get(vo.getProcessId()); - if (process != null) { - vo.setProcessCode(process.getCode()).setProcessName(process.getName()); - } - // TODO @AI:MapUtil findMap - if (vo.getNextProcessId() != null) { - MesProProcessDO nextProcess = processMap.get(vo.getNextProcessId()); - if (nextProcess != null) { - vo.setNextProcessName(nextProcess.getName()); - } - } - } - return result; + // 1. 批量获取关联数据 + Set processIds = convertSet(list, MesProRouteProcessDO::getProcessId); + list.forEach(item -> { if (item.getNextProcessId() != null) processIds.add(item.getNextProcessId()); }); + Map processMap = convertMap( + processService.getProcessList(new ArrayList<>(processIds)), MesProProcessDO::getId); + // 2. 拼接 VO + return BeanUtils.toBean(list, MesProRouteProcessRespVO.class, vo -> { + MapUtils.findAndThen(processMap, vo.getProcessId(), + process -> vo.setProcessCode(process.getCode()).setProcessName(process.getName())); + MapUtils.findAndThen(processMap, vo.getNextProcessId(), + nextProcess -> vo.setNextProcessName(nextProcess.getName())); + }); } - // TODO @AI:需要的地方,直接调用 buildRouteProcessRespVOList; private MesProRouteProcessRespVO buildRouteProcessRespVO(MesProRouteProcessDO routeProcess) { if (routeProcess == null) { return null; diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProductBomController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProductBomController.java index cb46a2e..6fc55bc 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProductBomController.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProductBomController.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.mes.controller.admin.pro.route; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.productbom.MesProRouteProductBomRespVO; import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.productbom.MesProRouteProductBomSaveReqVO; @@ -20,11 +22,12 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.Collections; import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; @Tag(name = "管理后台 - MES 工艺路线产品 BOM") @@ -93,35 +96,24 @@ public class MesProRouteProductBomController { // ==================== 拼接 VO ==================== - // TODO @AI:参考 /Users/yunai/Java/yudao-all-in-one/ruoyi-vue-pro/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProcessController.java 的 todo; - private List buildRouteProductBomRespVOList(List list) { - if (list.isEmpty()) { - return List.of(); - } - // 批量查询物料信息 - List itemIds = convertList(list, MesProRouteProductBomDO::getItemId); - List itemList = itemService.getItemList(itemIds); - Map itemMap = convertMap(itemList, MesMdItemDO::getId); - // 批量查询单位信息 - List unitMeasureIds = convertList(itemList, MesMdItemDO::getUnitMeasureId); - Map unitMap = convertMap( - unitMeasureService.getUnitMeasureList(unitMeasureIds), MesMdUnitMeasureDO::getId); - // 拼装 - List result = BeanUtils.toBean(list, MesProRouteProductBomRespVO.class); - for (MesProRouteProductBomRespVO vo : result) { - MesMdItemDO item = itemMap.get(vo.getItemId()); - if (item != null) { - vo.setItemCode(item.getCode()); - vo.setItemName(item.getName()); - vo.setSpecification(item.getSpecification()); - MesMdUnitMeasureDO unit = unitMap.get(item.getUnitMeasureId()); - if (unit != null) { - vo.setUnitName(unit.getName()); - } - } + if (CollUtil.isEmpty(list)) { + return Collections.emptyList(); } - return result; + // 1. 批量获取关联数据 + Map itemMap = itemService.getItemMap( + convertSet(list, MesProRouteProductBomDO::getItemId)); + Map unitMap = unitMeasureService.getUnitMeasureMap( + convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId)); + // 2. 拼接 VO + return BeanUtils.toBean(list, MesProRouteProductBomRespVO.class, vo -> { + MapUtils.findAndThen(itemMap, vo.getItemId(), item -> { + vo.setItemCode(item.getCode()).setItemName(item.getName()) + .setSpecification(item.getSpecification()); + MapUtils.findAndThen(unitMap, item.getUnitMeasureId(), + unit -> vo.setUnitName(unit.getName())); + }); + }); } private MesProRouteProductBomRespVO buildRouteProductBomRespVO(MesProRouteProductBomDO routeProductBom) { diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProductController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProductController.java index cceee7e..59a5e24 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProductController.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProductController.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.mes.controller.admin.pro.route; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.product.MesProRouteProductRespVO; import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.product.MesProRouteProductSaveReqVO; @@ -19,11 +21,12 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.Collections; import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; @Tag(name = "管理后台 - MES 工艺路线产品") @@ -84,35 +87,25 @@ public class MesProRouteProductController { } // ==================== 拼接 VO ==================== - // TODO @AI:参考 /Users/yunai/Java/yudao-all-in-one/ruoyi-vue-pro/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/route/MesProRouteProcessController.java 的 todo; private List buildRouteProductRespVOList(List list) { - if (list.isEmpty()) { - return List.of(); + if (CollUtil.isEmpty(list)) { + return Collections.emptyList(); } - // 批量查询物料信息 - List itemIds = convertList(list, MesProRouteProductDO::getItemId); - List itemList = itemService.getItemList(itemIds); - Map itemMap = convertMap(itemList, MesMdItemDO::getId); - // 批量查询单位信息 - List unitMeasureIds = convertList(itemList, MesMdItemDO::getUnitMeasureId); - Map unitMap = convertMap( - unitMeasureService.getUnitMeasureList(unitMeasureIds), MesMdUnitMeasureDO::getId); - // 拼装 - List result = BeanUtils.toBean(list, MesProRouteProductRespVO.class); - for (MesProRouteProductRespVO vo : result) { - MesMdItemDO item = itemMap.get(vo.getItemId()); - if (item != null) { - vo.setItemCode(item.getCode()); - vo.setItemName(item.getName()); - vo.setSpecification(item.getSpecification()); - MesMdUnitMeasureDO unit = unitMap.get(item.getUnitMeasureId()); - if (unit != null) { - vo.setUnitName(unit.getName()); - } - } - } - return result; + // 1. 批量获取关联数据 + Map itemMap = itemService.getItemMap( + convertSet(list, MesProRouteProductDO::getItemId)); + Map unitMap = unitMeasureService.getUnitMeasureMap( + convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId)); + // 2. 拼接 VO + return BeanUtils.toBean(list, MesProRouteProductRespVO.class, vo -> { + MapUtils.findAndThen(itemMap, vo.getItemId(), item -> { + vo.setItemCode(item.getCode()).setItemName(item.getName()) + .setSpecification(item.getSpecification()); + MapUtils.findAndThen(unitMap, item.getUnitMeasureId(), + unit -> vo.setUnitName(unit.getName())); + }); + }); } private MesProRouteProductRespVO buildRouteProductRespVO(MesProRouteProductDO routeProduct) { diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProcessDO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProcessDO.java index c037a84..5b612e5 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProcessDO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProcessDO.java @@ -26,23 +26,26 @@ public class MesProRouteProcessDO extends BaseDO { */ @TableId private Long id; - // TODO @AI:外链 @ 加下,参考别的模块 /** * 工艺路线编号 + * + * 关联 {@link MesProRouteDO#getId()} */ private Long routeId; - // TODO @AI:外链 @ 加下,参考别的模块 /** * 工序编号 + * + * 关联 {@link cn.iocoder.yudao.module.mes.dal.dataobject.pro.MesProProcessDO#getId()} */ private Long processId; /** * 序号 */ private Integer sort; - // TODO @AI:外链 @ 加下,参考别的模块 /** * 下一道工序编号 + * + * 关联 {@link cn.iocoder.yudao.module.mes.dal.dataobject.pro.MesProProcessDO#getId()} */ private Long nextProcessId; /** diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProductBomDO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProductBomDO.java index 02cdf85..cab8c39 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProductBomDO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProductBomDO.java @@ -28,24 +28,28 @@ public class MesProRouteProductBomDO extends BaseDO { */ @TableId private Long id; - // TODO @AI:外链 @ 加下,参考别的模块 /** * 工艺路线编号 + * + * 关联 {@link MesProRouteDO#getId()} */ private Long routeId; - // TODO @AI:外链 @ 加下,参考别的模块 /** * 工序编号 + * + * 关联 {@link cn.iocoder.yudao.module.mes.dal.dataobject.pro.MesProProcessDO#getId()} */ private Long processId; - // TODO @AI:外链 @ 加下,参考别的模块 /** * 产品物料编号 + * + * 关联 {@link cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO#getId()} */ private Long productId; - // TODO @AI:外链 @ 加下,参考别的模块 /** * BOM 物料编号 + * + * 关联 {@link cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO#getId()} */ private Long itemId; /** diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProductDO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProductDO.java index 64dc6ac..43f46e1 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProductDO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/pro/route/MesProRouteProductDO.java @@ -28,14 +28,16 @@ public class MesProRouteProductDO extends BaseDO { */ @TableId private Long id; - // TODO @AI:外链 @ 加下,参考别的模块 /** * 工艺路线编号 + * + * 关联 {@link MesProRouteDO#getId()} */ private Long routeId; - // TODO @AI:外链 @ 加下,参考别的模块 /** * 产品物料编号 + * + * 关联 {@link cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO#getId()} */ private Long itemId; /** @@ -48,8 +50,10 @@ public class MesProRouteProductDO extends BaseDO { private BigDecimal productionTime; /** * 时间单位 + * + * 字典类型 mes_time_unit_type */ - // TODO @AI:外链 @ 加下,字典 + 枚举类; + // TODO @AI:外链 @ 加下,字典 + 枚举类;(需要枚举出来。在 dictconstants 里) private String timeUnitType; /** * 备注 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessService.java index 8f4b07a..e5b1b01 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessService.java @@ -38,4 +38,11 @@ public interface MesProRouteProcessService { */ List getRouteProcessListByRouteId(Long routeId); + /** + * 按工艺路线删除工序(级联删除使用) + * + * @param routeId 工艺路线编号 + */ + void deleteRouteProcessByRouteId(Long routeId); + } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessServiceImpl.java index 591b3b6..05300c5 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessServiceImpl.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.mes.service.pro.route; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.process.MesProRouteProcessSaveReqVO; -import cn.iocoder.yudao.module.mes.dal.dataobject.pro.MesProProcessDO; import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO; import cn.iocoder.yudao.module.mes.dal.mysql.pro.MesProRouteProcessMapper; import cn.iocoder.yudao.module.mes.service.pro.MesProProcessService; @@ -18,7 +18,6 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; -// TODO @AI:参考别的模块,需要校验下相关的工艺路线、工序是否存在;(别的 route 也是);最好对方 service 提供校验方法; /** * MES 工艺路线工序 Service 实现类 * @@ -31,16 +30,23 @@ public class MesProRouteProcessServiceImpl implements MesProRouteProcessService @Resource private MesProRouteProcessMapper routeProcessMapper; - // TODO @AI:貌似没用到?是不是应该要用下哈? @Resource @Lazy private MesProProcessService processService; + @Resource + @Lazy + private MesProRouteService routeService; + @Override @Transactional(rollbackFor = Exception.class) public Long createRouteProcess(MesProRouteProcessSaveReqVO createReqVO) { - // 1. 校验 - validateRouteProcessCreate(createReqVO); + // 1.1 校验工艺路线、工序存在 + validateRouteAndProcessExists(createReqVO.getRouteId(), createReqVO.getProcessId()); + // 1.2 校验唯一性 + validateSortUnique(null, createReqVO.getRouteId(), createReqVO.getSort()); + validateProcessUnique(null, createReqVO.getRouteId(), createReqVO.getProcessId()); + validateKeyProcessUnique(null, createReqVO.getRouteId(), createReqVO.getKeyFlag()); // 2. 插入 MesProRouteProcessDO routeProcess = BeanUtils.toBean(createReqVO, MesProRouteProcessDO.class); @@ -56,8 +62,12 @@ public class MesProRouteProcessServiceImpl implements MesProRouteProcessService public void updateRouteProcess(MesProRouteProcessSaveReqVO updateReqVO) { // 1.1 校验存在 validateRouteProcessExists(updateReqVO.getId()); - // 1.2 校验唯一性 - validateRouteProcessUpdate(updateReqVO); + // 1.2 校验工艺路线、工序存在 + validateRouteAndProcessExists(updateReqVO.getRouteId(), updateReqVO.getProcessId()); + // 1.3 校验唯一性 + validateSortUnique(updateReqVO.getId(), updateReqVO.getRouteId(), updateReqVO.getSort()); + validateProcessUnique(updateReqVO.getId(), updateReqVO.getRouteId(), updateReqVO.getProcessId()); + validateKeyProcessUnique(updateReqVO.getId(), updateReqVO.getRouteId(), updateReqVO.getKeyFlag()); // 2. 更新 MesProRouteProcessDO updateObj = BeanUtils.toBean(updateReqVO, MesProRouteProcessDO.class); @@ -88,8 +98,7 @@ public class MesProRouteProcessServiceImpl implements MesProRouteProcessService */ private void rebuildProcessChain(Long routeId) { List list = routeProcessMapper.selectListByRouteId(routeId); - // TODO @AI:CollUtil isEmpty; - if (list.isEmpty()) { + if (CollUtil.isEmpty(list)) { return; } // 按 sort 排序 @@ -111,45 +120,36 @@ public class MesProRouteProcessServiceImpl implements MesProRouteProcessService } } - // TODO @AI:参考别的模块,拆分为多个模块 - private void validateRouteProcessCreate(MesProRouteProcessSaveReqVO reqVO) { - // 序号唯一 - MesProRouteProcessDO existing = routeProcessMapper.selectByRouteIdAndSort(reqVO.getRouteId(), reqVO.getSort()); - if (existing != null) { - throw exception(PRO_ROUTE_PROCESS_SORT_DUPLICATE); - } - // 工序不重复 - existing = routeProcessMapper.selectByRouteIdAndProcessId(reqVO.getRouteId(), reqVO.getProcessId()); - if (existing != null) { - throw exception(PRO_ROUTE_PROCESS_DUPLICATE); + private void validateRouteAndProcessExists(Long routeId, Long processId) { + if (routeService.getRoute(routeId) == null) { + throw exception(PRO_ROUTE_NOT_EXISTS); } - // 关键工序唯一 - if (Boolean.TRUE.equals(reqVO.getKeyFlag())) { - existing = routeProcessMapper.selectKeyProcessByRouteId(reqVO.getRouteId()); - if (existing != null) { - throw exception(PRO_ROUTE_PROCESS_KEY_DUPLICATE); - } + if (processService.getProcess(processId) == null) { + throw exception(PRO_ROUTE_PROCESS_NOT_EXISTS); } } - // TODO @AI:参考别的模块,拆分为多个模块 - private void validateRouteProcessUpdate(MesProRouteProcessSaveReqVO reqVO) { - // 序号唯一(排除自身) - MesProRouteProcessDO existing = routeProcessMapper.selectByRouteIdAndSort(reqVO.getRouteId(), reqVO.getSort()); - if (existing != null && !existing.getId().equals(reqVO.getId())) { + private void validateSortUnique(Long id, Long routeId, Integer sort) { + MesProRouteProcessDO existing = routeProcessMapper.selectByRouteIdAndSort(routeId, sort); + if (existing != null && !existing.getId().equals(id)) { throw exception(PRO_ROUTE_PROCESS_SORT_DUPLICATE); } - // 工序不重复(排除自身) - existing = routeProcessMapper.selectByRouteIdAndProcessId(reqVO.getRouteId(), reqVO.getProcessId()); - if (existing != null && !existing.getId().equals(reqVO.getId())) { + } + + private void validateProcessUnique(Long id, Long routeId, Long processId) { + MesProRouteProcessDO existing = routeProcessMapper.selectByRouteIdAndProcessId(routeId, processId); + if (existing != null && !existing.getId().equals(id)) { throw exception(PRO_ROUTE_PROCESS_DUPLICATE); } - // 关键工序唯一(排除自身) - if (Boolean.TRUE.equals(reqVO.getKeyFlag())) { - existing = routeProcessMapper.selectKeyProcessByRouteId(reqVO.getRouteId()); - if (existing != null && !existing.getId().equals(reqVO.getId())) { - throw exception(PRO_ROUTE_PROCESS_KEY_DUPLICATE); - } + } + + private void validateKeyProcessUnique(Long id, Long routeId, Boolean keyFlag) { + if (!Boolean.TRUE.equals(keyFlag)) { + return; + } + MesProRouteProcessDO existing = routeProcessMapper.selectKeyProcessByRouteId(routeId); + if (existing != null && !existing.getId().equals(id)) { + throw exception(PRO_ROUTE_PROCESS_KEY_DUPLICATE); } } @@ -163,4 +163,9 @@ public class MesProRouteProcessServiceImpl implements MesProRouteProcessService return routeProcessMapper.selectListByRouteId(routeId); } + @Override + public void deleteRouteProcessByRouteId(Long routeId) { + routeProcessMapper.deleteByRouteId(routeId); + } + } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductBomService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductBomService.java index 42baf8b..d2781fd 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductBomService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductBomService.java @@ -38,4 +38,19 @@ public interface MesProRouteProductBomService { */ List getRouteProductBomList(Long routeId, Long processId, Long productId); + /** + * 按工艺路线删除产品 BOM(级联删除使用) + * + * @param routeId 工艺路线编号 + */ + void deleteRouteProductBomByRouteId(Long routeId); + + /** + * 按工艺路线和产品删除 BOM(产品删除时级联使用) + * + * @param routeId 工艺路线编号 + * @param productId 产品物料编号 + */ + void deleteRouteProductBomByRouteIdAndProductId(Long routeId, Long productId); + } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductBomServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductBomServiceImpl.java index 80b2732..1cf6907 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductBomServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductBomServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.mes.service.pro.route; +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.productbom.MesProRouteProductBomSaveReqVO; import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductBomDO; @@ -65,7 +66,7 @@ public class MesProRouteProductBomServiceImpl implements MesProRouteProductBomSe if (existing == null) { return; } - if (id == null || !existing.getId().equals(id)) { + if (ObjUtil.notEqual(existing.getId(), id)) { throw exception(PRO_ROUTE_PRODUCT_BOM_DUPLICATE); } } @@ -80,4 +81,14 @@ public class MesProRouteProductBomServiceImpl implements MesProRouteProductBomSe return routeProductBomMapper.selectList(routeId, processId, productId); } + @Override + public void deleteRouteProductBomByRouteId(Long routeId) { + routeProductBomMapper.deleteByRouteId(routeId); + } + + @Override + public void deleteRouteProductBomByRouteIdAndProductId(Long routeId, Long productId) { + routeProductBomMapper.deleteByRouteIdAndProductId(routeId, productId); + } + } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductService.java index f4b78c0..220df6a 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductService.java @@ -38,4 +38,11 @@ public interface MesProRouteProductService { */ List getRouteProductListByRouteId(Long routeId); + /** + * 按工艺路线删除产品(级联删除使用) + * + * @param routeId 工艺路线编号 + */ + void deleteRouteProductByRouteId(Long routeId); + } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductServiceImpl.java index fce5266..004f128 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProductServiceImpl.java @@ -1,11 +1,12 @@ package cn.iocoder.yudao.module.mes.service.pro.route; +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.product.MesProRouteProductSaveReqVO; import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductDO; -import cn.iocoder.yudao.module.mes.dal.mysql.pro.MesProRouteProductBomMapper; import cn.iocoder.yudao.module.mes.dal.mysql.pro.MesProRouteProductMapper; import jakarta.annotation.Resource; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -27,9 +28,9 @@ public class MesProRouteProductServiceImpl implements MesProRouteProductService @Resource private MesProRouteProductMapper routeProductMapper; - // TODO @AI:别人模块的操作,需要通过 service; @Resource - private MesProRouteProductBomMapper routeProductBomMapper; + @Lazy + private MesProRouteProductBomService routeProductBomService; @Override public Long createRouteProduct(MesProRouteProductSaveReqVO createReqVO) { @@ -58,14 +59,11 @@ public class MesProRouteProductServiceImpl implements MesProRouteProductService @Transactional(rollbackFor = Exception.class) public void deleteRouteProduct(Long id) { // 1. 校验存在 - // TODO @AI:复用 validateRouteProductExists 方法; MesProRouteProductDO routeProduct = routeProductMapper.selectById(id); - if (routeProduct == null) { - throw exception(PRO_ROUTE_PRODUCT_NOT_EXISTS); - } + validateRouteProductExists(routeProduct); // 2.1 级联删除关联的 BOM - routeProductBomMapper.deleteByRouteIdAndProductId(routeProduct.getRouteId(), routeProduct.getItemId()); + routeProductBomService.deleteRouteProductBomByRouteIdAndProductId(routeProduct.getRouteId(), routeProduct.getItemId()); // 2.2 删除产品关联 routeProductMapper.deleteById(id); } @@ -76,13 +74,18 @@ public class MesProRouteProductServiceImpl implements MesProRouteProductService } } + private void validateRouteProductExists(MesProRouteProductDO routeProduct) { + if (routeProduct == null) { + throw exception(PRO_ROUTE_PRODUCT_NOT_EXISTS); + } + } + private void validateItemUnique(Long id, Long itemId) { MesProRouteProductDO existing = routeProductMapper.selectByItemId(itemId); if (existing == null) { return; } - // TODO @AI:notEquals - if (id == null || !existing.getId().equals(id)) { + if (ObjUtil.notEqual(existing.getId(), id)) { throw exception(PRO_ROUTE_PRODUCT_ITEM_DUPLICATE); } } @@ -97,4 +100,9 @@ public class MesProRouteProductServiceImpl implements MesProRouteProductService return routeProductMapper.selectListByRouteId(routeId); } + @Override + public void deleteRouteProductByRouteId(Long routeId) { + routeProductMapper.deleteByRouteId(routeId); + } + } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteService.java index b1beac3..d879232 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteService.java @@ -26,6 +26,14 @@ public interface MesProRouteService { void updateRoute(@Valid MesProRouteSaveReqVO updateReqVO); /** + * 更新工艺路线状态(启用/禁用) + * + * @param id 编号 + * @param status 状态 + */ + void updateRouteStatus(Long id, Integer status); + + /** * 删除工艺路线 */ void deleteRoute(Long id); diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteServiceImpl.java index 1e6338d..b0d6576 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteServiceImpl.java @@ -1,5 +1,8 @@ package cn.iocoder.yudao.module.mes.service.pro.route; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.BooleanUtil; +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; @@ -10,10 +13,8 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductDO; import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductBomDO; import cn.iocoder.yudao.module.mes.dal.mysql.pro.MesProRouteMapper; -import cn.iocoder.yudao.module.mes.dal.mysql.pro.MesProRouteProcessMapper; -import cn.iocoder.yudao.module.mes.dal.mysql.pro.MesProRouteProductBomMapper; -import cn.iocoder.yudao.module.mes.dal.mysql.pro.MesProRouteProductMapper; import jakarta.annotation.Resource; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -35,13 +36,15 @@ public class MesProRouteServiceImpl implements MesProRouteService { @Resource private MesProRouteMapper routeMapper; - // todo @AI:不要直接使用对方模块的 mapper,而是通过 service; @Resource - private MesProRouteProcessMapper routeProcessMapper; + @Lazy + private MesProRouteProcessService routeProcessService; @Resource - private MesProRouteProductMapper routeProductMapper; + @Lazy + private MesProRouteProductService routeProductService; @Resource - private MesProRouteProductBomMapper routeProductBomMapper; + @Lazy + private MesProRouteProductBomService routeProductBomService; @Override public Long createRoute(MesProRouteSaveReqVO createReqVO) { @@ -59,11 +62,6 @@ public class MesProRouteServiceImpl implements MesProRouteService { validateRouteExists(updateReqVO.getId()); // 1.2 校验编码唯一性 validateRouteCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); - // 1.3 启用时的校验 - // TODO @AI:开启禁用,独立接口;保持更新接口的独立; - if (CommonStatusEnum.ENABLE.getStatus().equals(updateReqVO.getStatus())) { - validateRouteEnable(updateReqVO.getId()); - } // 2. 更新 MesProRouteDO updateObj = BeanUtils.toBean(updateReqVO, MesProRouteDO.class); @@ -71,15 +69,28 @@ public class MesProRouteServiceImpl implements MesProRouteService { } @Override + public void updateRouteStatus(Long id, Integer status) { + // 1.1 校验存在 + validateRouteExists(id); + // 1.2 启用时的校验 + if (CommonStatusEnum.ENABLE.getStatus().equals(status)) { + validateRouteEnable(id); + } + + // 2. 更新状态 + routeMapper.updateById(new MesProRouteDO().setId(id).setStatus(status)); + } + + @Override @Transactional(rollbackFor = Exception.class) public void deleteRoute(Long id) { // 1. 校验存在 validateRouteExists(id); // 2.1 级联删除 - routeProcessMapper.deleteByRouteId(id); - routeProductMapper.deleteByRouteId(id); - routeProductBomMapper.deleteByRouteId(id); + routeProcessService.deleteRouteProcessByRouteId(id); + routeProductService.deleteRouteProductByRouteId(id); + routeProductBomService.deleteRouteProductBomByRouteId(id); // 2.2 删除工艺路线 routeMapper.deleteById(id); } @@ -95,8 +106,7 @@ public class MesProRouteServiceImpl implements MesProRouteService { if (route == null) { return; } - // TODO @AI:ObjUtil notequals; - if (id == null || !route.getId().equals(id)) { + if (ObjUtil.notEqual(route.getId(), id)) { throw exception(PRO_ROUTE_CODE_DUPLICATE); } } @@ -106,23 +116,21 @@ public class MesProRouteServiceImpl implements MesProRouteService { */ private void validateRouteEnable(Long routeId) { // 1. 必须有工序 - List processList = routeProcessMapper.selectListByRouteId(routeId); - if (processList.isEmpty()) { + List processList = routeProcessService.getRouteProcessListByRouteId(routeId); + if (CollUtil.isEmpty(processList)) { throw exception(PRO_ROUTE_ENABLE_NO_PROCESS); } // 2. 必须有关键工序 boolean hasKeyProcess = processList.stream().anyMatch(MesProRouteProcessDO::getKeyFlag); - // TODO @AI:BooleanUtils.isFalue(hasKeyProcess) - if (!hasKeyProcess) { + if (BooleanUtil.isFalse(hasKeyProcess)) { throw exception(PRO_ROUTE_ENABLE_NO_KEY_PROCESS); } // 3. 所有产品必须配置了 BOM 消耗 - List productList = routeProductMapper.selectListByRouteId(routeId); + List productList = routeProductService.getRouteProductListByRouteId(routeId); for (MesProRouteProductDO product : productList) { - List bomList = routeProductBomMapper - .selectListByRouteIdAndProductId(routeId, product.getItemId()); - // TODO @AI:CollUtil.isEmpty(bomList) - if (bomList.isEmpty()) { + List bomList = routeProductBomService + .getRouteProductBomList(routeId, null, product.getItemId()); + if (CollUtil.isEmpty(bomList)) { throw exception(PRO_ROUTE_ENABLE_PRODUCT_NO_BOM, product.getItemId()); } } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/MesQcTemplateServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/MesQcTemplateServiceImpl.java index 4964052..a54f3ba 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/MesQcTemplateServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/MesQcTemplateServiceImpl.java @@ -53,7 +53,8 @@ public class MesQcTemplateServiceImpl implements MesQcTemplateService { public Long createTemplate(MesQcTemplateSaveReqVO createReqVO) { // 校验编码唯一 validateTemplateCodeUnique(null, createReqVO.getCode()); - // 插入(types 由 IntegerListTypeHandler 自动做 List↔逗号字符串转换,enableFlag Boolean↔bit 自动映射) + + // 插入 MesQcTemplateDO template = BeanUtils.toBean(createReqVO, MesQcTemplateDO.class); templateMapper.insert(template); return template.getId();