Commit 620f432fc8e8d39790a4f5af7a46c6421cb5618d

Authored by YunaiV
1 parent 03b421a8

✨ feat(mes): 新增物料、客户和供应商启用状态校验

新增了对物料、客户和供应商的启用状态校验功能,确保在相关操作中只处理启用的记录。此变更提高了系统的健壮性,避免了对禁用记录的误操作。
Showing 38 changed files with 151 additions and 43 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
... ... @@ -30,6 +30,7 @@ public interface ErrorCodeConstants {
30 30 ErrorCode MD_ITEM_NAME_DUPLICATE = new ErrorCode(1_040_102_002, "物料名称已存在");
31 31 ErrorCode MD_ITEM_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_040_102_003, "导入物料数据不能为空");
32 32 ErrorCode MD_ITEM_BATCH_REQUIRED = new ErrorCode(1_040_102_004, "当前物料启用了批次管理,请选择批次");
  33 + ErrorCode MD_ITEM_IS_DISABLE = new ErrorCode(1_040_102_005, "物料已禁用");
33 34  
34 35 // ========== MES 基础数据-物料批次属性配置(1-040-102-100) ==========
35 36 ErrorCode MD_ITEM_BATCH_CONFIG_NOT_EXISTS = new ErrorCode(1_040_102_100, "物料批次属性配置不存在");
... ... @@ -62,6 +63,7 @@ public interface ErrorCodeConstants {
62 63 ErrorCode MD_CLIENT_NAME_DUPLICATE = new ErrorCode(1_040_103_002, "客户名称已存在");
63 64 ErrorCode MD_CLIENT_NICKNAME_DUPLICATE = new ErrorCode(1_040_103_003, "客户简称已存在");
64 65 ErrorCode MD_CLIENT_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_040_103_004, "导入客户数据不能为空");
  66 + ErrorCode MD_CLIENT_IS_DISABLE = new ErrorCode(1_040_103_005, "客户已禁用");
65 67  
66 68 // ========== MES 基础数据-供应商(1-040-104-000) ==========
67 69 ErrorCode MD_VENDOR_NOT_EXISTS = new ErrorCode(1_040_104_000, "供应商不存在");
... ... @@ -70,6 +72,7 @@ public interface ErrorCodeConstants {
70 72 ErrorCode MD_VENDOR_NICKNAME_DUPLICATE = new ErrorCode(1_040_104_003, "供应商简称已存在");
71 73 ErrorCode MD_VENDOR_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_040_104_004, "导入供应商数据不能为空");
72 74 ErrorCode MD_VENDOR_HAS_REFERENCE = new ErrorCode(1_040_104_005, "该供应商已被其他业务引用,无法删除");
  75 + ErrorCode MD_VENDOR_IS_DISABLE = new ErrorCode(1_040_104_006, "供应商已禁用");
73 76  
74 77 // ========== MES 基础数据-车间(1-040-105-000) ==========
75 78 ErrorCode MD_WORKSHOP_NOT_EXISTS = new ErrorCode(1_040_105_000, "车间不存在");
... ... @@ -81,6 +84,7 @@ public interface ErrorCodeConstants {
81 84 ErrorCode MD_WORKSTATION_NOT_EXISTS = new ErrorCode(1_040_106_000, "工作站不存在");
82 85 ErrorCode MD_WORKSTATION_CODE_DUPLICATE = new ErrorCode(1_040_106_001, "工作站编码已存在");
83 86 ErrorCode MD_WORKSTATION_NAME_DUPLICATE = new ErrorCode(1_040_106_002, "工作站名称已存在");
  87 + ErrorCode MD_WORKSTATION_IS_DISABLE = new ErrorCode(1_040_106_003, "工作站已禁用");
84 88 // ========== MES 基础数据-设备资源(1-040-106-100) ==========
85 89 ErrorCode MD_WORKSTATION_MACHINE_NOT_EXISTS = new ErrorCode(1_040_106_100, "设备资源记录不存在");
86 90 ErrorCode MD_WORKSTATION_MACHINE_EXISTS = new ErrorCode(1_040_106_101, "该设备已分配至工作站:{}");
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/client/MesMdClientService.java
... ... @@ -85,6 +85,13 @@ public interface MesMdClientService {
85 85 void validateClientExists(Long id);
86 86  
87 87 /**
  88 + * 校验客户存在且启用
  89 + *
  90 + * @param id 编号
  91 + */
  92 + void validateClientExistsAndEnable(Long id);
  93 +
  94 + /**
88 95 * 批量导入客户
89 96 *
90 97 * @param importClients 导入客户列表
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/client/MesMdClientServiceImpl.java
... ... @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.md.client.vo.MesMdClientImpo
10 10 import cn.iocoder.yudao.module.mes.controller.admin.md.client.vo.MesMdClientImportRespVO;
11 11 import cn.iocoder.yudao.module.mes.controller.admin.md.client.vo.MesMdClientPageReqVO;
12 12 import cn.iocoder.yudao.module.mes.controller.admin.md.client.vo.MesMdClientSaveReqVO;
  13 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
13 14 import cn.iocoder.yudao.module.mes.dal.dataobject.md.client.MesMdClientDO;
14 15 import cn.iocoder.yudao.module.mes.dal.mysql.md.client.MesMdClientMapper;
15 16 import cn.iocoder.yudao.module.mes.enums.wm.BarcodeBizTypeEnum;
... ... @@ -95,6 +96,17 @@ public class MesMdClientServiceImpl implements MesMdClientService {
95 96 }
96 97 }
97 98  
  99 + @Override
  100 + public void validateClientExistsAndEnable(Long id) {
  101 + MesMdClientDO client = clientMapper.selectById(id);
  102 + if (client == null) {
  103 + throw exception(MD_CLIENT_NOT_EXISTS);
  104 + }
  105 + if (ObjUtil.notEqual(CommonStatusEnum.ENABLE.getStatus(), client.getStatus())) {
  106 + throw exception(MD_CLIENT_IS_DISABLE);
  107 + }
  108 + }
  109 +
98 110 private void validateClientCodeUnique(Long id, String code) {
99 111 MesMdClientDO client = clientMapper.selectByCode(code);
100 112 if (client == null) {
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemService.java
... ... @@ -68,6 +68,14 @@ public interface MesMdItemService {
68 68 MesMdItemDO validateItemExists(Long id);
69 69  
70 70 /**
  71 + * 校验物料产品存在且启用
  72 + *
  73 + * @param id 编号
  74 + * @return 物料产品
  75 + */
  76 + MesMdItemDO validateItemExistsAndEnable(Long id);
  77 +
  78 + /**
71 79 * 获得物料产品分页
72 80 *
73 81 * @param pageReqVO 分页查询
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemServiceImpl.java
... ... @@ -150,6 +150,15 @@ public class MesMdItemServiceImpl implements MesMdItemService {
150 150 return item;
151 151 }
152 152  
  153 + @Override
  154 + public MesMdItemDO validateItemExistsAndEnable(Long id) {
  155 + MesMdItemDO item = validateItemExists(id);
  156 + if (ObjUtil.notEqual(CommonStatusEnum.ENABLE.getStatus(), item.getStatus())) {
  157 + throw exception(MD_ITEM_IS_DISABLE);
  158 + }
  159 + return item;
  160 + }
  161 +
153 162 private void validateItemCodeUnique(Long id, String code) {
154 163 MesMdItemDO item = itemMapper.selectByCode(code);
155 164 if (item == null) {
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/vendor/MesMdVendorService.java
... ... @@ -60,6 +60,14 @@ public interface MesMdVendorService {
60 60 MesMdVendorDO validateVendorExists(Long id);
61 61  
62 62 /**
  63 + * 校验供应商存在且启用
  64 + *
  65 + * @param id 供应商 ID
  66 + * @return 供应商
  67 + */
  68 + MesMdVendorDO validateVendorExistsAndEnable(Long id);
  69 +
  70 + /**
63 71 * 获得供应商分页
64 72 *
65 73 * @param pageReqVO 分页查询
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/vendor/MesMdVendorServiceImpl.java
... ... @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.md.vendor.vo.MesMdVendorImpo
10 10 import cn.iocoder.yudao.module.mes.controller.admin.md.vendor.vo.MesMdVendorImportRespVO;
11 11 import cn.iocoder.yudao.module.mes.controller.admin.md.vendor.vo.MesMdVendorPageReqVO;
12 12 import cn.iocoder.yudao.module.mes.controller.admin.md.vendor.vo.MesMdVendorSaveReqVO;
  13 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
13 14 import cn.iocoder.yudao.module.mes.dal.dataobject.md.vendor.MesMdVendorDO;
14 15 import cn.iocoder.yudao.module.mes.dal.mysql.md.vendor.MesMdVendorMapper;
15 16 import cn.iocoder.yudao.module.mes.enums.wm.BarcodeBizTypeEnum;
... ... @@ -103,6 +104,15 @@ public class MesMdVendorServiceImpl implements MesMdVendorService {
103 104 return vendor;
104 105 }
105 106  
  107 + @Override
  108 + public MesMdVendorDO validateVendorExistsAndEnable(Long id) {
  109 + MesMdVendorDO vendor = validateVendorExists(id);
  110 + if (ObjUtil.notEqual(CommonStatusEnum.ENABLE.getStatus(), vendor.getStatus())) {
  111 + throw exception(MD_VENDOR_IS_DISABLE);
  112 + }
  113 + return vendor;
  114 + }
  115 +
106 116 private void validateVendorSaveData(MesMdVendorSaveReqVO reqVO) {
107 117 // 校验编码唯一
108 118 validateVendorCodeUnique(reqVO.getId(), reqVO.getCode());
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/workstation/MesMdWorkstationService.java
... ... @@ -50,6 +50,14 @@ public interface MesMdWorkstationService {
50 50 MesMdWorkstationDO validateWorkstationExists(Long id);
51 51  
52 52 /**
  53 + * 校验工作站存在且启用
  54 + *
  55 + * @param id 编号
  56 + * @return 工作站
  57 + */
  58 + MesMdWorkstationDO validateWorkstationExistsAndEnable(Long id);
  59 +
  60 + /**
53 61 * 获得工作站
54 62 *
55 63 * @param id 编号
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/workstation/MesMdWorkstationServiceImpl.java
... ... @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.mes.service.md.workstation;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.ObjUtil;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
6 7 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
7 8 import cn.iocoder.yudao.module.mes.controller.admin.md.workstation.vo.MesMdWorkstationPageReqVO;
8 9 import cn.iocoder.yudao.module.mes.controller.admin.md.workstation.vo.MesMdWorkstationSaveReqVO;
... ... @@ -125,6 +126,15 @@ public class MesMdWorkstationServiceImpl implements MesMdWorkstationService {
125 126 return workstation;
126 127 }
127 128  
  129 + @Override
  130 + public MesMdWorkstationDO validateWorkstationExistsAndEnable(Long id) {
  131 + MesMdWorkstationDO workstation = validateWorkstationExists(id);
  132 + if (ObjUtil.notEqual(CommonStatusEnum.ENABLE.getStatus(), workstation.getStatus())) {
  133 + throw exception(MD_WORKSTATION_IS_DISABLE);
  134 + }
  135 + return workstation;
  136 + }
  137 +
128 138 private void validateWorkshopExists(Long workshopId) {
129 139 MesMdWorkshopDO workshop = workshopService.getWorkshop(workshopId);
130 140 if (workshop == null) {
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/arrivalnotice/MesWmArrivalNoticeLineServiceImpl.java
... ... @@ -66,7 +66,7 @@ public class MesWmArrivalNoticeLineServiceImpl implements MesWmArrivalNoticeLine
66 66 // 校验父单据存在且为草稿状态
67 67 arrivalNoticeService.validateArrivalNoticeExistsAndDraft(reqVO.getNoticeId());
68 68 // 校验物料存在
69   - itemService.validateItemExists(reqVO.getItemId());
  69 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
70 70 }
71 71  
72 72 /**
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/itemreceipt/MesWmItemReceiptServiceImpl.java
... ... @@ -89,7 +89,7 @@ public class MesWmItemReceiptServiceImpl implements MesWmItemReceiptService {
89 89 // 校验编码唯一
90 90 validateCodeUnique(reqVO.getId(), reqVO.getCode());
91 91 // 校验供应商存在
92   - vendorService.validateVendorExists(reqVO.getVendorId());
  92 + vendorService.validateVendorExistsAndEnable(reqVO.getVendorId());
93 93 // 校验到货通知单存在
94 94 if (reqVO.getNoticeId() != null) {
95 95 MesWmArrivalNoticeDO notice = arrivalNoticeService.validateArrivalNoticeExists(reqVO.getNoticeId());
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/miscissue/MesWmMiscIssueLineServiceImpl.java
... ... @@ -132,7 +132,7 @@ public class MesWmMiscIssueLineServiceImpl implements MesWmMiscIssueLineService
132 132 // 校验父单据存在且为可编辑状态
133 133 miscIssueService.validateMiscIssueEditable(issueId);
134 134 // 校验物料存在
135   - itemService.validateItemExists(reqVO.getItemId());
  135 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
136 136 // 校验仓库、库区、库位的父子关系
137 137 warehouseAreaService.validateWarehouseAreaExists(reqVO.getWarehouseId(),
138 138 reqVO.getLocationId(), reqVO.getAreaId());
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/miscreceipt/MesWmMiscReceiptLineServiceImpl.java
... ... @@ -125,7 +125,7 @@ public class MesWmMiscReceiptLineServiceImpl implements MesWmMiscReceiptLineServ
125 125 // 校验父单据存在且为可编辑状态
126 126 miscReceiptService.validateMiscReceiptEditable(reqVO.getReceiptId());
127 127 // 校验物料存在
128   - itemService.validateItemExists(reqVO.getItemId());
  128 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
129 129 // 校验仓库层级关系(仓库 - 库位 - 库区)
130 130 warehouseAreaService.validateWarehouseAreaExists(reqVO.getWarehouseId(),
131 131 reqVO.getLocationId(), reqVO.getAreaId());
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/outsourceissue/MesWmOutsourceIssueDetailServiceImpl.java
... ... @@ -112,7 +112,7 @@ public class MesWmOutsourceIssueDetailServiceImpl implements MesWmOutsourceIssue
112 112 throw exception(WM_OUTSOURCE_ISSUE_DETAIL_LINE_NOT_MATCH);
113 113 }
114 114 // 校验物料存在
115   - itemService.validateItemExists(saveReqVO.getItemId());
  115 + itemService.validateItemExistsAndEnable(saveReqVO.getItemId());
116 116 if (ObjUtil.notEqual(line.getItemId(), saveReqVO.getItemId())) {
117 117 throw exception(WM_OUTSOURCE_ISSUE_DETAIL_ITEM_MISMATCH);
118 118 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/outsourceissue/MesWmOutsourceIssueLineServiceImpl.java
... ... @@ -121,7 +121,7 @@ public class MesWmOutsourceIssueLineServiceImpl implements MesWmOutsourceIssueLi
121 121 throw exception(WM_OUTSOURCE_ISSUE_NOT_EXISTS);
122 122 }
123 123 // 校验关联的物料存在
124   - itemService.validateItemExists(saveReqVO.getItemId());
  124 + itemService.validateItemExistsAndEnable(saveReqVO.getItemId());
125 125 // 校验物料是否在工单 BOM 中
126 126 validateItemInWorkOrderBom(issue.getWorkOrderId(), saveReqVO.getItemId());
127 127 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/outsourceissue/MesWmOutsourceIssueServiceImpl.java
... ... @@ -259,7 +259,7 @@ public class MesWmOutsourceIssueServiceImpl implements MesWmOutsourceIssueServic
259 259 validateCodeUnique(saveReqVO.getId(), saveReqVO.getCode());
260 260 // 校验供应商存在
261 261 if (saveReqVO.getVendorId() != null) {
262   - vendorService.validateVendorExists(saveReqVO.getVendorId());
  262 + vendorService.validateVendorExistsAndEnable(saveReqVO.getVendorId());
263 263 }
264 264 // 校验工单存在且类型为外协(代工)
265 265 MesProWorkOrderDO workOrder = workOrderService.validateWorkOrderConfirmed(saveReqVO.getWorkOrderId());
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/outsourcereceipt/MesWmOutsourceReceiptDetailServiceImpl.java
... ... @@ -92,7 +92,7 @@ public class MesWmOutsourceReceiptDetailServiceImpl implements MesWmOutsourceRec
92 92 */
93 93 private void validateDetailSaveData(MesWmOutsourceReceiptDetailSaveReqVO reqVO) {
94 94 // 校验物料存在
95   - itemService.validateItemExists(reqVO.getItemId());
  95 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
96 96 // 校验仓库、库区、库位的层级关系
97 97 areaService.validateWarehouseAreaExists(reqVO.getWarehouseId(), reqVO.getLocationId(), reqVO.getAreaId());
98 98 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/outsourcereceipt/MesWmOutsourceReceiptLineServiceImpl.java
... ... @@ -56,7 +56,7 @@ public class MesWmOutsourceReceiptLineServiceImpl implements MesWmOutsourceRecei
56 56 @Override
57 57 public Long createOutsourceReceiptLine(MesWmOutsourceReceiptLineSaveReqVO createReqVO) {
58 58 // 校验物料存在
59   - itemService.validateItemExists(createReqVO.getItemId());
  59 + itemService.validateItemExistsAndEnable(createReqVO.getItemId());
60 60  
61 61 // 插入
62 62 MesWmOutsourceReceiptLineDO line = BeanUtils.toBean(createReqVO, MesWmOutsourceReceiptLineDO.class);
... ... @@ -76,7 +76,7 @@ public class MesWmOutsourceReceiptLineServiceImpl implements MesWmOutsourceRecei
76 76 // 校验存在
77 77 validateOutsourceReceiptLineExists(updateReqVO.getId());
78 78 // 校验物料存在
79   - itemService.validateItemExists(updateReqVO.getItemId());
  79 + itemService.validateItemExistsAndEnable(updateReqVO.getItemId());
80 80  
81 81 // 更新
82 82 MesWmOutsourceReceiptLineDO updateObj = BeanUtils.toBean(updateReqVO, MesWmOutsourceReceiptLineDO.class);
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/outsourcereceipt/MesWmOutsourceReceiptServiceImpl.java
... ... @@ -160,7 +160,7 @@ public class MesWmOutsourceReceiptServiceImpl implements MesWmOutsourceReceiptSe
160 160 MesWmOutsourceReceiptDetailDO::getQuantity, BigDecimal::add, BigDecimal.ZERO);
161 161 // 对比行数量与明细总数量,不满足直接抛出
162 162 if (line.getQuantity().compareTo(totalDetailQuantity) > 0) {
163   - MesMdItemDO item = itemService.validateItemExists(line.getItemId());
  163 + MesMdItemDO item = itemService.validateItemExistsAndEnable(line.getItemId());
164 164 throw exception(WM_OUTSOURCE_RECEIPT_DETAIL_QUANTITY_MISMATCH,
165 165 item.getCode() + " " + item.getName() + " 未完成上架");
166 166 }
... ... @@ -309,7 +309,7 @@ public class MesWmOutsourceReceiptServiceImpl implements MesWmOutsourceReceiptSe
309 309 // 校验编码唯一
310 310 validateCodeUnique(id, reqVO.getCode());
311 311 // 校验供应商存在
312   - vendorService.validateVendorExists(reqVO.getVendorId());
  312 + vendorService.validateVendorExistsAndEnable(reqVO.getVendorId());
313 313 // 校验外协工单存在
314 314 if (reqVO.getWorkOrderId() != null) {
315 315 workOrderService.validateWorkOrderConfirmed(reqVO.getWorkOrderId());
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/packages/MesWmPackageLineServiceImpl.java
... ... @@ -100,7 +100,7 @@ public class MesWmPackageLineServiceImpl implements MesWmPackageLineService {
100 100 // 校验装箱单状态为草稿
101 101 packageService.validatePackageStatusDraft(reqVO.getPackageId());
102 102 // 校验产品物料存在
103   - itemService.validateItemExists(reqVO.getItemId());
  103 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
104 104 // 校验工单已确认
105 105 workOrderService.validateWorkOrderConfirmed(reqVO.getWorkOrderId());
106 106 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productissue/MesWmProductIssueLineServiceImpl.java
... ... @@ -112,7 +112,7 @@ public class MesWmProductIssueLineServiceImpl implements MesWmProductIssueLineSe
112 112 // 校验父数据存在 + 校验物料在工单 BOM 中
113 113 validateItemInWorkOrderBom(reqVO.getIssueId(), reqVO.getItemId());
114 114 // 校验物料存在
115   - itemService.validateItemExists(reqVO.getItemId());
  115 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
116 116 }
117 117  
118 118 private void validateItemInWorkOrderBom(Long issueId, Long itemId) {
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productissue/MesWmProductIssueServiceImpl.java
... ... @@ -262,7 +262,7 @@ public class MesWmProductIssueServiceImpl implements MesWmProductIssueService {
262 262 validateCodeUnique(reqVO.getId(), reqVO.getCode());
263 263 workOrderService.validateWorkOrderConfirmed(reqVO.getWorkOrderId());
264 264 if (reqVO.getWorkstationId() != null) {
265   - workstationService.validateWorkstationExists(reqVO.getWorkstationId());
  265 + workstationService.validateWorkstationExistsAndEnable(reqVO.getWorkstationId());
266 266 }
267 267 }
268 268  
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productreceipt/MesWmProductReceiptLineServiceImpl.java
... ... @@ -111,7 +111,7 @@ public class MesWmProductReceiptLineServiceImpl implements MesWmProductReceiptLi
111 111 // 校验父单据存在且为可编辑状态
112 112 productReceiptService.validateProductReceiptEditable(reqVO.getReceiptId());
113 113 // 校验物料存在
114   - itemService.validateItemExists(reqVO.getItemId());
  114 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
115 115 }
116 116  
117 117 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesDetailServiceImpl.java
... ... @@ -115,7 +115,7 @@ public class MesWmProductSalesDetailServiceImpl implements MesWmProductSalesDeta
115 115 throw exception(WM_PRODUCT_SALES_DETAIL_LINE_NOT_MATCH);
116 116 }
117 117 // 校验物料存在
118   - itemService.validateItemExists(reqVO.getItemId());
  118 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
119 119 if (ObjUtil.notEqual(line.getItemId(), reqVO.getItemId())) {
120 120 throw exception(WM_PRODUCT_SALES_DETAIL_ITEM_MISMATCH);
121 121 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesLineServiceImpl.java
... ... @@ -52,10 +52,8 @@ public class MesWmProductSalesLineServiceImpl implements MesWmProductSalesLineSe
52 52  
53 53 @Override
54 54 public Long createProductSalesLine(MesWmProductSalesLineSaveReqVO createReqVO) {
55   - // 校验物料存在
56   - itemService.validateItemExists(createReqVO.getItemId());
57   - // 根据 batchCode 解析 batchId
58   - fillBatchId(createReqVO);
  55 + // 校验数据
  56 + validateLineSaveData(createReqVO);
59 57  
60 58 // 新增
61 59 MesWmProductSalesLineDO line = BeanUtils.toBean(createReqVO, MesWmProductSalesLineDO.class);
... ... @@ -66,11 +64,10 @@ public class MesWmProductSalesLineServiceImpl implements MesWmProductSalesLineSe
66 64 @Override
67 65 public void updateProductSalesLine(MesWmProductSalesLineSaveReqVO updateReqVO) {
68 66 // 校验存在
69   - validateProductSalesLineExists(updateReqVO.getId());
70   - // 校验物料存在
71   - itemService.validateItemExists(updateReqVO.getItemId());
72   - // 根据 batchCode 解析 batchId
73   - fillBatchId(updateReqVO);
  67 + MesWmProductSalesLineDO oldLine = validateProductSalesLineExists(updateReqVO.getId());
  68 + // 校验数据
  69 + updateReqVO.setSalesId(oldLine.getSalesId());
  70 + validateLineSaveData(updateReqVO);
74 71  
75 72 // 更新
76 73 MesWmProductSalesLineDO updateObj = BeanUtils.toBean(updateReqVO, MesWmProductSalesLineDO.class);
... ... @@ -81,7 +78,9 @@ public class MesWmProductSalesLineServiceImpl implements MesWmProductSalesLineSe
81 78 @Transactional(rollbackFor = Exception.class)
82 79 public void deleteProductSalesLine(Long id) {
83 80 // 校验存在
84   - validateProductSalesLineExists(id);
  81 + MesWmProductSalesLineDO line = validateProductSalesLineExists(id);
  82 + // 校验主单为草稿状态才允许删除行
  83 + productSalesService.validateProductSalesExistsAndDraft(line.getSalesId());
85 84  
86 85 // 级联删除明细
87 86 productSalesDetailService.deleteProductSalesDetailByLineId(id);
... ... @@ -139,6 +138,18 @@ public class MesWmProductSalesLineServiceImpl implements MesWmProductSalesLineSe
139 138 reqVO.setBatchId(batch != null ? batch.getId() : null);
140 139 }
141 140  
  141 + /**
  142 + * 校验保存时的关联数据
  143 + */
  144 + private void validateLineSaveData(MesWmProductSalesLineSaveReqVO reqVO) {
  145 + // 校验主单存在且为草稿状态
  146 + productSalesService.validateProductSalesExistsAndDraft(reqVO.getSalesId());
  147 + // 校验物料存在
  148 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
  149 + // 根据 batchCode 解析 batchId
  150 + fillBatchId(reqVO);
  151 + }
  152 +
142 153 @Override
143 154 @Transactional(rollbackFor = Exception.class)
144 155 public void updateProductSalesLineWhenOqcFinish(Long id, Long oqcId, Integer checkResult) {
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesService.java
... ... @@ -116,4 +116,13 @@ public interface MesWmProductSalesService {
116 116 */
117 117 List<MesWmProductSalesDO> getProductSalesListByClientId(Long clientId);
118 118  
  119 + /**
  120 + * 校验销售出库单存在且为草稿状态
  121 + *
  122 + * @param id 编号
  123 + * @return 销售出库单
  124 + */
  125 + MesWmProductSalesDO validateProductSalesExistsAndDraft(Long id);
  126 +
119 127 }
  128 +
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/productsales/MesWmProductSalesServiceImpl.java
... ... @@ -267,7 +267,7 @@ public class MesWmProductSalesServiceImpl implements MesWmProductSalesService {
267 267 // 校验编码唯一
268 268 validateCodeUnique(id, reqVO.getCode());
269 269 // 校验客户存在
270   - clientService.validateClientExists(reqVO.getClientId());
  270 + clientService.validateClientExistsAndEnable(reqVO.getClientId());
271 271 // 校验发货通知单
272 272 if (reqVO.getNoticeId() != null) {
273 273 MesWmSalesNoticeDO notice = salesNoticeService.validateSalesNoticeExists(reqVO.getNoticeId());
... ... @@ -291,7 +291,8 @@ public class MesWmProductSalesServiceImpl implements MesWmProductSalesService {
291 291 /**
292 292 * 校验销售出库单存在且为草稿状态
293 293 */
294   - private MesWmProductSalesDO validateProductSalesExistsAndDraft(Long id) {
  294 + @Override
  295 + public MesWmProductSalesDO validateProductSalesExistsAndDraft(Long id) {
295 296 MesWmProductSalesDO sales = validateProductSalesExists(id);
296 297 if (ObjUtil.notEqual(MesWmProductSalesStatusEnum.PREPARE.getStatus(), sales.getStatus())) {
297 298 throw exception(WM_PRODUCT_SALES_NOT_PREPARE);
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/returnissue/MesWmReturnIssueLineServiceImpl.java
... ... @@ -117,7 +117,7 @@ public class MesWmReturnIssueLineServiceImpl implements MesWmReturnIssueLineServ
117 117 // 校验父数据存在 + 草稿状态
118 118 MesWmReturnIssueDO issue = issueService.validateReturnIssueExistsAndPrepare(reqVO.getIssueId());
119 119 // 校验物料存在
120   - itemService.validateItemExists(reqVO.getItemId());
  120 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
121 121 return issue;
122 122 }
123 123  
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/returnissue/MesWmReturnIssueServiceImpl.java
... ... @@ -168,7 +168,7 @@ public class MesWmReturnIssueServiceImpl implements MesWmReturnIssueService {
168 168 MesWmReturnIssueDetailDO::getQuantity, BigDecimal::add, BigDecimal.ZERO);
169 169 // 对比行数量与明细总数量,不满足直接抛出
170 170 if (line.getQuantity().compareTo(totalDetailQuantity) > 0) {
171   - MesMdItemDO item = itemService.validateItemExists(line.getItemId());
  171 + MesMdItemDO item = itemService.validateItemExistsAndEnable(line.getItemId());
172 172 throw exception(WM_RETURN_ISSUE_DETAIL_QUANTITY_MISMATCH,
173 173 item.getCode() + " " + item.getName() + " 未完成上架");
174 174 }
... ... @@ -291,7 +291,7 @@ public class MesWmReturnIssueServiceImpl implements MesWmReturnIssueService {
291 291 validateCodeUnique(reqVO.getId(), reqVO.getCode());
292 292 workOrderService.validateWorkOrderConfirmed(reqVO.getWorkOrderId());
293 293 if (reqVO.getWorkstationId() != null) {
294   - workstationService.validateWorkstationExists(reqVO.getWorkstationId());
  294 + workstationService.validateWorkstationExistsAndEnable(reqVO.getWorkstationId());
295 295 }
296 296 }
297 297  
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/returnsales/MesWmReturnSalesLineServiceImpl.java
... ... @@ -65,7 +65,9 @@ public class MesWmReturnSalesLineServiceImpl implements MesWmReturnSalesLineServ
65 65 @Override
66 66 public void updateReturnSalesLine(MesWmReturnSalesLineSaveReqVO updateReqVO) {
67 67 // 校验存在
68   - validateReturnSalesLineExists(updateReqVO.getId());
  68 + MesWmReturnSalesLineDO oldLine = validateReturnSalesLineExists(updateReqVO.getId());
  69 + // 固定父单 ID,防止通过接口篡改
  70 + updateReqVO.setReturnId(oldLine.getReturnId());
69 71 validateLineSaveData(updateReqVO);
70 72  
71 73 // 更新
... ... @@ -153,7 +155,7 @@ public class MesWmReturnSalesLineServiceImpl implements MesWmReturnSalesLineServ
153 155 * @param batchId 批次ID
154 156 */
155 157 private void validateItemBatchManagement(Long returnId, Long itemId, Long batchId) {
156   - MesMdItemDO item = itemService.validateItemExists(itemId);
  158 + MesMdItemDO item = itemService.validateItemExistsAndEnable(itemId);
157 159 // 如果物料启用了批次管理,则必须选择批次
158 160 if (Boolean.TRUE.equals(item.getBatchFlag()) && batchId == null) {
159 161 throw exception(MD_ITEM_BATCH_REQUIRED);
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/returnsales/MesWmReturnSalesServiceImpl.java
... ... @@ -170,7 +170,7 @@ public class MesWmReturnSalesServiceImpl implements MesWmReturnSalesService {
170 170 MesWmReturnSalesDetailDO::getQuantity, BigDecimal::add, BigDecimal.ZERO);
171 171 // 对比行数量与明细总数量,不满足直接抛出
172 172 if (line.getQuantity().compareTo(totalDetailQuantity) > 0) {
173   - MesMdItemDO item = itemService.validateItemExists(line.getItemId());
  173 + MesMdItemDO item = itemService.validateItemExistsAndEnable(line.getItemId());
174 174 throw exception(WM_RETURN_SALES_DETAIL_QUANTITY_MISMATCH,
175 175 item.getCode() + " " + item.getName() + " 未完成上架");
176 176 }
... ... @@ -272,7 +272,7 @@ public class MesWmReturnSalesServiceImpl implements MesWmReturnSalesService {
272 272 */
273 273 private void validateSaveData(MesWmReturnSalesSaveReqVO reqVO) {
274 274 validateCodeUnique(reqVO.getId(), reqVO.getCode());
275   - clientService.validateClientExists(reqVO.getClientId());
  275 + clientService.validateClientExistsAndEnable(reqVO.getClientId());
276 276 }
277 277  
278 278 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/returnvendor/MesWmReturnVendorDetailServiceImpl.java
... ... @@ -72,7 +72,7 @@ public class MesWmReturnVendorDetailServiceImpl implements MesWmReturnVendorDeta
72 72 throw exception(WM_RETURN_VENDOR_DETAIL_LINE_NOT_MATCH);
73 73 }
74 74 // 校验物料存在
75   - itemService.validateItemExists(reqVO.getItemId());
  75 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
76 76 // 校验物料与行物料一致
77 77 validateItemConsistency(reqVO.getItemId(), line);
78 78 // 校验库位存在
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/returnvendor/MesWmReturnVendorLineServiceImpl.java
... ... @@ -55,7 +55,9 @@ public class MesWmReturnVendorLineServiceImpl implements MesWmReturnVendorLineSe
55 55 @Override
56 56 public void updateReturnVendorLine(MesWmReturnVendorLineSaveReqVO updateReqVO) {
57 57 // 校验存在
58   - validateReturnVendorLineExists(updateReqVO.getId());
  58 + MesWmReturnVendorLineDO oldLine = validateReturnVendorLineExists(updateReqVO.getId());
  59 + // 固定父单 ID,防止通过接口篡改
  60 + updateReqVO.setReturnId(oldLine.getReturnId());
59 61 // 校验数据
60 62 validateReturnVendorLineSaveData(updateReqVO);
61 63  
... ... @@ -111,7 +113,7 @@ public class MesWmReturnVendorLineServiceImpl implements MesWmReturnVendorLineSe
111 113 // 校验父数据存在且为草稿状态
112 114 MesWmReturnVendorDO returnVendor = returnVendorService.validateReturnVendorExistsAndPrepare(reqVO.getReturnId());
113 115 // 校验物料存在
114   - itemService.validateItemExists(reqVO.getItemId());
  116 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
115 117 // 校验批次存在且属于当前物料和供应商
116 118 if (reqVO.getBatchId() != null) {
117 119 batchService.validateBatchExists(reqVO.getBatchId(), reqVO.getItemId(), null, returnVendor.getVendorId());
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/returnvendor/MesWmReturnVendorServiceImpl.java
... ... @@ -217,7 +217,7 @@ public class MesWmReturnVendorServiceImpl implements MesWmReturnVendorService {
217 217 validateReturnVendorExistsAndPrepare(reqVO.getId());
218 218 }
219 219 // 校验供应商存在
220   - vendorService.validateVendorExists(reqVO.getVendorId());
  220 + vendorService.validateVendorExistsAndEnable(reqVO.getVendorId());
221 221 // 校验编码唯一
222 222 validateCodeUnique(reqVO.getId(), reqVO.getCode());
223 223 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/salesnotice/MesWmSalesNoticeLineServiceImpl.java
... ... @@ -113,7 +113,7 @@ public class MesWmSalesNoticeLineServiceImpl implements MesWmSalesNoticeLineServ
113 113 validateNoticeStatusDraft(reqVO.getNoticeId());
114 114 // 校验物料存在
115 115 if (reqVO.getItemId() != null) {
116   - itemService.validateItemExists(reqVO.getItemId());
  116 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
117 117 }
118 118 }
119 119  
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/salesnotice/MesWmSalesNoticeServiceImpl.java
... ... @@ -136,7 +136,7 @@ public class MesWmSalesNoticeServiceImpl implements MesWmSalesNoticeService {
136 136 validateNoticeCodeUnique(saveReqVO.getId(), saveReqVO.getNoticeCode());
137 137 // 校验客户存在
138 138 if (saveReqVO.getClientId() != null) {
139   - clientService.validateClientExists(saveReqVO.getClientId());
  139 + clientService.validateClientExistsAndEnable(saveReqVO.getClientId());
140 140 }
141 141 }
142 142  
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/transfer/MesWmTransferLineServiceImpl.java
... ... @@ -109,7 +109,7 @@ public class MesWmTransferLineServiceImpl implements MesWmTransferLineService {
109 109 // 校验父数据可编辑
110 110 transferService.validateTransferEditable(reqVO.getTransferId());
111 111 // 校验产品存在
112   - itemService.validateItemExists(reqVO.getItemId());
  112 + itemService.validateItemExistsAndEnable(reqVO.getItemId());
113 113 // 校验来源仓库、库区、库位的关联关系
114 114 warehouseAreaService.validateWarehouseAreaExists(reqVO.getFromWarehouseId(),
115 115 reqVO.getFromLocationId(), reqVO.getFromAreaId());
... ...
yudao-module-mes/src/test/java/cn/iocoder/yudao/module/mes/service/wm/returnsales/MesWmReturnSalesLineServiceImplTest.java
... ... @@ -11,6 +11,7 @@ import org.springframework.context.annotation.Import;
11 11 import org.springframework.test.context.bean.override.mockito.MockitoBean;
12 12  
13 13 import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
  14 +import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService;
14 15  
15 16 import java.math.BigDecimal;
16 17 import java.util.List;
... ... @@ -39,6 +40,12 @@ public class MesWmReturnSalesLineServiceImplTest extends BaseDbUnitTest {
39 40 @MockitoBean
40 41 private MesMdItemService itemService;
41 42  
  43 + @MockitoBean
  44 + private MesWmBatchService batchService;
  45 +
  46 + @MockitoBean
  47 + private MesWmReturnSalesDetailService returnSalesDetailService;
  48 +
42 49 @Test
43 50 public void testUpdateReturnSalesLineWhenRqcFinish_allPass() {
44 51 // 准备参数:全部合格
... ...