Commit b69aad268715c9de88b30f7dec9f1a3050751c0f

Authored by YunaiV
1 parent 3d1896e0

✨ feat(mes): 添加物料产品状态更新功能,优化物料分类选择器

yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/MesMdItemController.java
@@ -72,6 +72,19 @@ public class MesMdItemController { @@ -72,6 +72,19 @@ public class MesMdItemController {
72 return success(true); 72 return success(true);
73 } 73 }
74 74
  75 + @PutMapping("/update-status")
  76 + @Operation(summary = "更新物料产品状态")
  77 + @Parameters({
  78 + @Parameter(name = "id", description = "编号", required = true),
  79 + @Parameter(name = "status", description = "状态", required = true)
  80 + })
  81 + @PreAuthorize("@ss.hasPermission('mes:md-item:update')")
  82 + public CommonResult<Boolean> updateItemStatus(@RequestParam("id") Long id,
  83 + @RequestParam("status") Integer status) {
  84 + itemService.updateItemStatus(id, status);
  85 + return success(true);
  86 + }
  87 +
75 @DeleteMapping("/delete") 88 @DeleteMapping("/delete")
76 @Operation(summary = "删除物料产品") 89 @Operation(summary = "删除物料产品")
77 @Parameter(name = "id", description = "编号", required = true) 90 @Parameter(name = "id", description = "编号", required = true)
@@ -87,7 +100,7 @@ public class MesMdItemController { @@ -87,7 +100,7 @@ public class MesMdItemController {
87 @PreAuthorize("@ss.hasPermission('mes:md-item:query')") 100 @PreAuthorize("@ss.hasPermission('mes:md-item:query')")
88 public CommonResult<MesMdItemRespVO> getItem(@RequestParam("id") Long id) { 101 public CommonResult<MesMdItemRespVO> getItem(@RequestParam("id") Long id) {
89 MesMdItemDO item = itemService.getItem(id); 102 MesMdItemDO item = itemService.getItem(id);
90 - return success(BeanUtils.toBean(item, MesMdItemRespVO.class)); 103 + return success(buildItemVO(item));
91 } 104 }
92 105
93 @GetMapping("/page") 106 @GetMapping("/page")
@@ -168,4 +181,11 @@ public class MesMdItemController { @@ -168,4 +181,11 @@ public class MesMdItemController {
168 }); 181 });
169 } 182 }
170 183
  184 + private MesMdItemRespVO buildItemVO(MesMdItemDO item) {
  185 + if (item == null) {
  186 + return null;
  187 + }
  188 + return CollUtil.getFirst(buildItemVOList(Collections.singletonList(item)));
  189 + }
  190 +
171 } 191 }
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/md/item/vo/MesMdItemSaveReqVO.java
@@ -33,10 +33,6 @@ public class MesMdItemSaveReqVO { @@ -33,10 +33,6 @@ public class MesMdItemSaveReqVO {
33 @NotNull(message = "物料分类编号不能为空") 33 @NotNull(message = "物料分类编号不能为空")
34 private Long itemTypeId; 34 private Long itemTypeId;
35 35
36 - @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")  
37 - @NotNull(message = "状态不能为空")  
38 - private Integer status;  
39 -  
40 @Schema(description = "是否启用安全库存", example = "false") 36 @Schema(description = "是否启用安全库存", example = "false")
41 private Boolean safeStockFlag; 37 private Boolean safeStockFlag;
42 38
@@ -55,4 +51,4 @@ public class MesMdItemSaveReqVO { @@ -55,4 +51,4 @@ public class MesMdItemSaveReqVO {
55 @Schema(description = "备注", example = "备注") 51 @Schema(description = "备注", example = "备注")
56 private String remark; 52 private String remark;
57 53
58 - } 54 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemService.java
@@ -37,6 +37,14 @@ public interface MesMdItemService { @@ -37,6 +37,14 @@ public interface MesMdItemService {
37 void updateItem(@Valid MesMdItemSaveReqVO updateReqVO); 37 void updateItem(@Valid MesMdItemSaveReqVO updateReqVO);
38 38
39 /** 39 /**
  40 + * 更新物料产品状态
  41 + *
  42 + * @param id 编号
  43 + * @param status 状态
  44 + */
  45 + void updateItemStatus(Long id, Integer status);
  46 +
  47 + /**
40 * 删除物料产品 48 * 删除物料产品
41 * 49 *
42 * @param id 编号 50 * @param id 编号
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/item/MesMdItemServiceImpl.java
1 package cn.iocoder.yudao.module.mes.service.md.item; 1 package cn.iocoder.yudao.module.mes.service.md.item;
2 2
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjUtil;
4 import cn.hutool.core.util.StrUtil; 5 import cn.hutool.core.util.StrUtil;
5 import cn.iocoder.yudao.framework.common.exception.ServiceException; 6 import cn.iocoder.yudao.framework.common.exception.ServiceException;
6 import cn.iocoder.yudao.framework.common.pojo.PageResult; 7 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -71,6 +72,7 @@ public class MesMdItemServiceImpl implements MesMdItemService { @@ -71,6 +72,7 @@ public class MesMdItemServiceImpl implements MesMdItemService {
71 72
72 // 插入 73 // 插入
73 MesMdItemDO item = BeanUtils.toBean(createReqVO, MesMdItemDO.class); 74 MesMdItemDO item = BeanUtils.toBean(createReqVO, MesMdItemDO.class);
  75 + item.setStatus(CommonStatusEnum.DISABLE.getStatus()); // 默认禁用。信息完成后,再启用
74 clearStockIfNotSafe(item); // 如果未启用安全库存,清零库存上下限 76 clearStockIfNotSafe(item); // 如果未启用安全库存,清零库存上下限
75 itemMapper.insert(item); 77 itemMapper.insert(item);
76 78
@@ -93,9 +95,6 @@ public class MesMdItemServiceImpl implements MesMdItemService { @@ -93,9 +95,6 @@ public class MesMdItemServiceImpl implements MesMdItemService {
93 // 校验计量单位存在 95 // 校验计量单位存在
94 validateUnitMeasureExists(updateReqVO.getUnitMeasureId()); 96 validateUnitMeasureExists(updateReqVO.getUnitMeasureId());
95 97
96 - // 如果启用了批次管理且状态为开启,校验批次属性配置  
97 - validateBatchConfigIfNeeded(updateReqVO);  
98 -  
99 // 更新 98 // 更新
100 MesMdItemDO updateObj = BeanUtils.toBean(updateReqVO, MesMdItemDO.class); 99 MesMdItemDO updateObj = BeanUtils.toBean(updateReqVO, MesMdItemDO.class);
101 clearStockIfNotSafe(updateObj); // 如果未启用安全库存,清零库存上下限 100 clearStockIfNotSafe(updateObj); // 如果未启用安全库存,清零库存上下限
@@ -103,6 +102,19 @@ public class MesMdItemServiceImpl implements MesMdItemService { @@ -103,6 +102,19 @@ public class MesMdItemServiceImpl implements MesMdItemService {
103 } 102 }
104 103
105 @Override 104 @Override
  105 + public void updateItemStatus(Long id, Integer status) {
  106 + // 校验存在
  107 + MesMdItemDO item = validateItemExists(id);
  108 + // 如果启用,校验批次属性配置
  109 + if (CommonStatusEnum.isEnable(status) && Boolean.TRUE.equals(item.getBatchFlag())) {
  110 + validateBatchConfigExists(id);
  111 + }
  112 +
  113 + // 更新状态
  114 + itemMapper.updateById(new MesMdItemDO().setId(id).setStatus(status));
  115 + }
  116 +
  117 + @Override
106 @Transactional(rollbackFor = Exception.class) 118 @Transactional(rollbackFor = Exception.class)
107 public void deleteItem(Long id) { 119 public void deleteItem(Long id) {
108 // 校验存在 120 // 校验存在
@@ -134,10 +146,7 @@ public class MesMdItemServiceImpl implements MesMdItemService { @@ -134,10 +146,7 @@ public class MesMdItemServiceImpl implements MesMdItemService {
134 if (item == null) { 146 if (item == null) {
135 return; 147 return;
136 } 148 }
137 - if (id == null) {  
138 - throw exception(MD_ITEM_CODE_DUPLICATE);  
139 - }  
140 - if (!Objects.equals(item.getId(), id)) { 149 + if (ObjUtil.notEqual(item.getId(), id)) {
141 throw exception(MD_ITEM_CODE_DUPLICATE); 150 throw exception(MD_ITEM_CODE_DUPLICATE);
142 } 151 }
143 } 152 }
@@ -147,10 +156,7 @@ public class MesMdItemServiceImpl implements MesMdItemService { @@ -147,10 +156,7 @@ public class MesMdItemServiceImpl implements MesMdItemService {
147 if (item == null) { 156 if (item == null) {
148 return; 157 return;
149 } 158 }
150 - if (id == null) {  
151 - throw exception(MD_ITEM_NAME_DUPLICATE);  
152 - }  
153 - if (!Objects.equals(item.getId(), id)) { 159 + if (ObjUtil.notEqual(item.getId(), id)) {
154 throw exception(MD_ITEM_NAME_DUPLICATE); 160 throw exception(MD_ITEM_NAME_DUPLICATE);
155 } 161 }
156 } 162 }
@@ -180,14 +186,8 @@ public class MesMdItemServiceImpl implements MesMdItemService { @@ -180,14 +186,8 @@ public class MesMdItemServiceImpl implements MesMdItemService {
180 /** 186 /**
181 * 如果启用了批次管理且状态为开启,校验批次属性配置是否存在且至少一个属性为 true 187 * 如果启用了批次管理且状态为开启,校验批次属性配置是否存在且至少一个属性为 true
182 */ 188 */
183 - private void validateBatchConfigIfNeeded(MesMdItemSaveReqVO reqVO) {  
184 - if (!Boolean.TRUE.equals(reqVO.getBatchFlag())) {  
185 - return;  
186 - }  
187 - if (!CommonStatusEnum.ENABLE.getStatus().equals(reqVO.getStatus())) {  
188 - return;  
189 - }  
190 - MesMdItemBatchConfigDO config = itemBatchConfigService.getItemBatchConfigByItemId(reqVO.getId()); 189 + private void validateBatchConfigExists(Long itemId) {
  190 + MesMdItemBatchConfigDO config = itemBatchConfigService.getItemBatchConfigByItemId(itemId);
191 if (config == null) { 191 if (config == null) {
192 throw exception(MD_ITEM_BATCH_CONFIG_NOT_EXISTS); 192 throw exception(MD_ITEM_BATCH_CONFIG_NOT_EXISTS);
193 } 193 }
@@ -306,6 +306,7 @@ public class MesMdItemServiceImpl implements MesMdItemService { @@ -306,6 +306,7 @@ public class MesMdItemServiceImpl implements MesMdItemService {
306 } 306 }
307 MesMdItemDO item = BeanUtils.toBean(importItem, MesMdItemDO.class); 307 MesMdItemDO item = BeanUtils.toBean(importItem, MesMdItemDO.class);
308 item.setUnitMeasureId(unitMeasure.getId()); 308 item.setUnitMeasureId(unitMeasure.getId());
  309 + item.setStatus(CommonStatusEnum.DISABLE.getStatus()); // 默认禁用。信息完成后,再启用
309 clearStockIfNotSafe(item); 310 clearStockIfNotSafe(item);
310 itemMapper.insert(item); 311 itemMapper.insert(item);
311 // 自动生成条码 312 // 自动生成条码