From 3aa3f9e730127147236c9e7627920dd8aacf3a36 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 15 七月 2026 15:49:59 +0800
Subject: [PATCH] 1.仓储物流-批次号优化覆盖数据 2.仓储物流-新增自定义出入库流水查询 3.采购管理-清理无用代码和表 4.销售管理-清理无用代码和表 5.销售流程状态字段数据回游
---
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java | 191 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 185 insertions(+), 6 deletions(-)
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
index 13e8dec..9b32fc6 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/service/item/MdmItemServiceImpl.java
@@ -6,16 +6,24 @@
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemPageReqVO;
import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSaveReqVO;
+import cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO;
import cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemDO;
+import cn.iocoder.yudao.module.mdm.dal.dataobject.unit.MdmUnitMeasureDO;
+import cn.iocoder.yudao.module.mdm.dal.mysql.item.MdmItemBatchConfigMapper;
import cn.iocoder.yudao.module.mdm.dal.mysql.item.MdmItemMapper;
+import cn.iocoder.yudao.module.mdm.service.brand.MdmBrandService;
import cn.iocoder.yudao.module.mdm.service.category.MdmItemCategoryService;
import cn.iocoder.yudao.module.mdm.service.unit.MdmUnitMeasureService;
-import cn.iocoder.yudao.module.mdm.service.brand.MdmBrandService;
+import cn.iocoder.yudao.module.mes.api.item.MesMdItemApi;
+import cn.iocoder.yudao.module.mes.api.item.dto.MesMdItemSyncReqDTO;
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;
import java.util.*;
+import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@@ -40,32 +48,121 @@
@Resource
private MdmBrandService brandService;
+ @Resource
+ @Lazy
+ private MesMdItemApi mesMdItemApi;
+ @Resource
+ private MdmItemBatchConfigMapper itemBatchConfigMapper;
+
@Override
+ @Transactional(rollbackFor = Exception.class)
public Long createItem(MdmItemSaveReqVO createReqVO) {
// 鏍¢獙鏁版嵁
validateItemSaveData(createReqVO);
- // 鎻掑叆
+ // 鎻掑叆 MDM 鐗╂枡
MdmItemDO item = BeanUtils.toBean(createReqVO, MdmItemDO.class);
itemMapper.insert(item);
+
+ // 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
+ saveBatchConfig(item.getId(), createReqVO);
+
+ // 鍚屾鍒� MES锛堝嬀閫� syncMes 鏃讹級
+ if (Boolean.TRUE.equals(createReqVO.getSyncMes())) {
+ syncItemToMes(createReqVO);
+ }
return item.getId();
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public void updateItem(MdmItemSaveReqVO updateReqVO) {
// 鏍¢獙瀛樺湪
validateItemExists(updateReqVO.getId());
// 鏍¢獙鏁版嵁
validateItemSaveData(updateReqVO);
- // 鏇存柊
+ // 鏇存柊 MDM 鐗╂枡
MdmItemDO updateObj = BeanUtils.toBean(updateReqVO, MdmItemDO.class);
itemMapper.updateById(updateObj);
+
+ // 淇濆瓨鎵规閰嶇疆锛堝鏋滄湁锛�
+ saveBatchConfig(updateReqVO.getId(), updateReqVO);
+
+ // 鍚屾鍒� MES锛堝嬀閫� syncMes 鏃讹級
+ if (Boolean.TRUE.equals(updateReqVO.getSyncMes())) {
+ syncItemToMes(updateReqVO);
+ }
}
private void validateItemSaveData(MdmItemSaveReqVO reqVO) {
// 鏍¢獙鐗╂枡缂栫爜鐨勫敮涓�鎬�
validateItemCodeUnique(reqVO.getId(), reqVO.getCode());
+ }
+
+ /**
+ * 鍚屾鐗╂枡鍒� MES锛堝崟浣�/鍒嗙被鎸� code 鏄犲皠锛�
+ *
+ * MDM 鐨� unitMeasureId/categoryId 涓� MES 鐨� unitMeasureId/itemTypeId 鍒嗗睘涓ゅ涓绘暟鎹紝
+ * 杩欓噷鍏堝湪 MDM 渚цВ鏋愬嚭 code锛屽啀浜ょ敱 MesMdItemApi 鍦� MES 渚цВ鏋愪负瀵瑰簲 id銆�
+ * 鍚屾澶辫触灏嗘姏鍑哄紓甯革紝瑙﹀彂澶栧眰 @Transactional 鏁翠綋鍥炴粴锛圡DM 鎿嶄綔涓�骞跺洖婊氾級銆�
+ */
+ private void syncItemToMes(MdmItemSaveReqVO reqVO) {
+ // 瑙f瀽璁¢噺鍗曚綅 id -> code
+ String unitCode = null;
+ if (reqVO.getUnitMeasureId() != null) {
+ MdmUnitMeasureDO unitMeasure = unitMeasureService.getUnitMeasure(reqVO.getUnitMeasureId());
+ if (unitMeasure == null) {
+ throw exception(MDM_UNIT_MEASURE_NOT_EXISTS);
+ }
+ unitCode = unitMeasure.getCode();
+ }
+ // 瑙f瀽鍒嗙被 id -> code锛堜娇鐢� MDM 鏈湴鍒嗙被鏈嶅姟锛�
+ String itemTypeCode = null;
+ if (reqVO.getCategoryId() != null) {
+ MdmItemCategoryDO category = itemCategoryService.getItemCategory(reqVO.getCategoryId());
+ if (category != null) {
+ itemTypeCode = category.getCode();
+ }
+ } else if (reqVO.getItemType() != null) {
+ // 鏍规嵁 itemType 鏌ユ壘瀵瑰簲鍒嗙被缂栫爜
+ // itemType: 1鍘熸枡, 2鍗婃垚鍝�, 3鎴愬搧, 4杈呮枡
+ String itemTypeName = convertItemTypeToName(reqVO.getItemType());
+ List<MdmItemCategoryDO> categories = itemCategoryService.getItemCategoryList(
+ itemCategoryService.getItemCategoryChildrenList(null).stream().map(MdmItemCategoryDO::getId).collect(Collectors.toSet()));
+ itemTypeCode = categories.stream()
+ .filter(c -> c.getName() != null && c.getName().equals(itemTypeName))
+ .findFirst()
+ .map(MdmItemCategoryDO::getCode)
+ .orElse(null);
+ }
+ // 缁勮鍚屾 DTO
+ MesMdItemSyncReqDTO syncReqDTO = new MesMdItemSyncReqDTO();
+ syncReqDTO.setCode(reqVO.getCode());
+ syncReqDTO.setName(reqVO.getName());
+ syncReqDTO.setSpecification(reqVO.getSpecification());
+ syncReqDTO.setUnitCode(unitCode);
+ syncReqDTO.setItemTypeCode(itemTypeCode);
+ syncReqDTO.setSafeStockFlag(Boolean.TRUE); // 淇濈暀 MDM 鐨� minStock/maxStock锛岄伩鍏嶈 MES 娓呴浂
+ syncReqDTO.setMinStock(reqVO.getMinStock());
+ syncReqDTO.setMaxStock(reqVO.getMaxStock());
+ syncReqDTO.setHighValue(reqVO.getIsHighValue());
+ syncReqDTO.setBatchFlag(reqVO.getIsBatchManaged());
+ syncReqDTO.setRemark(reqVO.getRemark());
+ // 鎵规閰嶇疆瀛楁
+ syncReqDTO.setProduceDateFlag(reqVO.getProduceDateFlag());
+ syncReqDTO.setExpireDateFlag(reqVO.getExpireDateFlag());
+ syncReqDTO.setReceiptDateFlag(reqVO.getReceiptDateFlag());
+ syncReqDTO.setVendorFlag(reqVO.getVendorFlag());
+ syncReqDTO.setPurchaseOrderCodeFlag(reqVO.getPurchaseOrderCodeFlag());
+ syncReqDTO.setLotNumberFlag(reqVO.getLotNumberFlag());
+ syncReqDTO.setQualityStatusFlag(reqVO.getQualityStatusFlag());
+ // create 璧� createItem锛寀pdate 璧� updateItem锛圡ES 渚ф寜 code upsert锛�
+ if (reqVO.getId() == null) {
+ mesMdItemApi.createItem(syncReqDTO);
+ } else {
+ mesMdItemApi.updateItem(syncReqDTO);
+ }
}
@Override
@@ -77,10 +174,16 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public void deleteItem(Long id) {
// 鏍¢獙瀛樺湪
- validateItemExists(id);
- // 鍒犻櫎
+ MdmItemDO item = validateItemExists(id);
+ // 瑙e喅杞垹闄ゅ敮涓�閿啿绐侊細濡傛灉宸插瓨鍦ㄧ浉鍚� code 涓斿凡杞垹闄ょ殑璁板綍锛屽厛鐗╃悊鍒犻櫎瀹�
+ MdmItemDO existingDeleted = itemMapper.selectByCodeAndDeleted(item.getCode(), true);
+ if (existingDeleted != null && !existingDeleted.getId().equals(id)) {
+ itemMapper.physicalDeleteById(existingDeleted.getId());
+ }
+ // 杞垹闄ゅ綋鍓嶈褰�
itemMapper.deleteById(id);
}
@@ -113,7 +216,12 @@
}
private void validateCategoryExists(Long categoryId) {
- if (itemCategoryService.getItemCategory(categoryId) == null) {
+ if (categoryId == null) {
+ return;
+ }
+ // 浣跨敤 MDM 鏈湴鍒嗙被鏈嶅姟鏍¢獙
+ MdmItemCategoryDO category = itemCategoryService.getItemCategory(categoryId);
+ if (category == null) {
throw exception(MDM_ITEM_CATEGORY_NOT_EXISTS);
}
}
@@ -127,6 +235,30 @@
private void validateBrandExists(Long brandId) {
if (brandService.getBrand(brandId) == null) {
throw exception(MDM_BRAND_NOT_EXISTS);
+ }
+ }
+
+ /**
+ * 灏� itemType 杞崲涓轰腑鏂囧悕绉�
+ *
+ * @param itemType 鐗╂枡绫诲瀷锛�1鍘熸枡, 2鍗婃垚鍝�, 3鎴愬搧, 4杈呮枡
+ * @return 涓枃鍚嶇О
+ */
+ private String convertItemTypeToName(Integer itemType) {
+ if (itemType == null) {
+ return null;
+ }
+ switch (itemType) {
+ case 1:
+ return "鍘熸枡";
+ case 2:
+ return "鍗婃垚鍝�";
+ case 3:
+ return "鎴愬搧";
+ case 4:
+ return "杈呮枡";
+ default:
+ return null;
}
}
@@ -178,4 +310,51 @@
return itemMapper.selectByCode(code);
}
+ /**
+ * 淇濆瓨鎵规閰嶇疆锛堝埌 MDM 鏈湴琛級
+ */
+ private void saveBatchConfig(Long itemId, MdmItemSaveReqVO reqVO) {
+ // 妫�鏌ユ槸鍚︽湁鎵规閰嶇疆鏁版嵁
+ if (reqVO.getProduceDateFlag() == null
+ && reqVO.getExpireDateFlag() == null
+ && reqVO.getReceiptDateFlag() == null
+ && reqVO.getVendorFlag() == null
+ && reqVO.getPurchaseOrderCodeFlag() == null
+ && reqVO.getLotNumberFlag() == null
+ && reqVO.getQualityStatusFlag() == null) {
+ return;
+ }
+
+ // 鏌ヨ宸叉湁閰嶇疆
+ cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO existing =
+ itemBatchConfigMapper.selectOne(
+ cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO::getItemId, itemId);
+
+ cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO config =
+ new cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO();
+ config.setItemId(itemId);
+ config.setProduceDateFlag(Boolean.TRUE.equals(reqVO.getProduceDateFlag()));
+ config.setExpireDateFlag(Boolean.TRUE.equals(reqVO.getExpireDateFlag()));
+ config.setReceiptDateFlag(Boolean.TRUE.equals(reqVO.getReceiptDateFlag()));
+ config.setVendorFlag(Boolean.TRUE.equals(reqVO.getVendorFlag()));
+ config.setPurchaseOrderCodeFlag(Boolean.TRUE.equals(reqVO.getPurchaseOrderCodeFlag()));
+ config.setLotNumberFlag(Boolean.TRUE.equals(reqVO.getLotNumberFlag()));
+ config.setQualityStatusFlag(Boolean.TRUE.equals(reqVO.getQualityStatusFlag()));
+ // 娓呯┖涓嶉渶瑕佺殑瀛楁
+ config.setClientFlag(false);
+ config.setSalesOrderCodeFlag(false);
+ config.setWorkOrderFlag(false);
+ config.setTaskFlag(false);
+ config.setWorkstationFlag(false);
+ config.setToolFlag(false);
+ config.setMoldFlag(false);
+
+ if (existing != null) {
+ config.setId(existing.getId());
+ itemBatchConfigMapper.updateById(config);
+ } else {
+ itemBatchConfigMapper.insert(config);
+ }
+ }
+
}
\ No newline at end of file
--
Gitblit v1.9.3