From 10158625f1096c54664a5f87b3f32d33794e4eee Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期五, 11 九月 2026 12:13:59 +0800
Subject: [PATCH] fix(mdm): 物料导入“状态”列兼容中文,读表异常改为友好提示
---
yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java | 204 ++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 187 insertions(+), 17 deletions(-)
diff --git a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java
index fee0f83..b570ded 100644
--- a/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java
+++ b/yudao-module-mdm/src/main/java/cn/iocoder/yudao/module/mdm/controller/admin/item/MdmItemController.java
@@ -1,30 +1,49 @@
package cn.iocoder.yudao.module.mdm.controller.admin.item;
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemExcelVO;
+import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemImportExcelVO;
+import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemImportRespVO;
import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemPageReqVO;
import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemRespVO;
import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSaveReqVO;
import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemStatusUpdateReqVO;
+import cn.iocoder.yudao.module.mdm.controller.admin.item.vo.MdmItemSyncUpdateReqVO;
+import cn.iocoder.yudao.module.mdm.dal.dataobject.category.MdmItemCategoryDO;
+import cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO;
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.dataobject.warehouse.MdmWarehouseDO;
+import cn.iocoder.yudao.module.mdm.enums.MdmItemTypeEnum;
+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.item.MdmItemBatchConfigService;
import cn.iocoder.yudao.module.mdm.service.item.MdmItemService;
import cn.iocoder.yudao.module.mdm.service.unit.MdmUnitMeasureService;
-import cn.iocoder.yudao.module.mdm.service.warehouse.MdmWarehouseService;
+import cn.iocoder.yudao.module.mes.api.item.MesMdItemApi;
+import cn.iocoder.yudao.module.mes.api.wm.warehouse.MesWmWarehouseApi;
+import cn.iocoder.yudao.module.mes.api.wm.warehouse.dto.MesWmWarehouseRespDTO;
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;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@@ -38,10 +57,18 @@
private MdmItemService itemService;
@Resource
- private MdmUnitMeasureService unitMeasureService;
+ private MesMdItemApi mesMdItemApi;
@Resource
- private MdmWarehouseService warehouseService;
+ private MdmItemCategoryService itemCategoryService;
+ @Resource
+ private MdmUnitMeasureService unitMeasureService;
+ @Resource
+ private MesWmWarehouseApi mesWmWarehouseApi;
+ @Resource
+ private MdmBrandService brandService;
+ @Resource
+ private MdmItemBatchConfigService itemBatchConfigService;
@PostMapping("/create")
@Operation(summary = "鍒涘缓鐗╂枡")
@@ -66,12 +93,29 @@
return success(true);
}
+ @PutMapping("/update-sync")
+ @Operation(summary = "鏇存柊鐗╂枡鍚屾鐘舵��")
+ @PreAuthorize("@ss.hasPermission('mdm:item:update')")
+ public CommonResult<Boolean> updateItemSync(@Valid @RequestBody MdmItemSyncUpdateReqVO reqVO) {
+ itemService.updateItemSync(reqVO.getId(), reqVO.getSync());
+ return success(true);
+ }
+
@DeleteMapping("/delete")
@Operation(summary = "鍒犻櫎鐗╂枡")
@Parameter(name = "id", description = "缂栧彿", required = true, example = "1")
@PreAuthorize("@ss.hasPermission('mdm:item:delete')")
public CommonResult<Boolean> deleteItem(@RequestParam("id") Long id) {
itemService.deleteItem(id);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete-list")
+ @Operation(summary = "鎵归噺鍒犻櫎鐗╂枡")
+ @Parameter(name = "ids", description = "缂栧彿鍒楄〃", required = true, example = "1,2,3")
+ @PreAuthorize("@ss.hasPermission('mdm:item:delete')")
+ public CommonResult<Boolean> deleteItemList(@RequestParam("ids") List<Long> ids) {
+ itemService.deleteItemList(ids);
return success(true);
}
@@ -84,6 +128,10 @@
MdmItemRespVO resp = BeanUtils.toBean(item, MdmItemRespVO.class);
if (resp != null) {
enrichItemRespVO(resp);
+ // 濉厖鎵规灞炴�ч厤缃�
+ enrichItemBatchConfig(resp);
+ // 濉厖鍚屾鐘舵��
+ resp.setSyncedMes(mesMdItemApi.getSyncedMdmItemIds(Set.of(id)).contains(id));
}
return success(resp);
}
@@ -93,11 +141,51 @@
@PreAuthorize("@ss.hasPermission('mdm:item:query')")
public CommonResult<PageResult<MdmItemRespVO>> getItemPage(@Valid MdmItemPageReqVO pageReqVO) {
PageResult<MdmItemDO> pageResult = itemService.getItemPage(pageReqVO);
+ // 杞崲骞惰ˉ榻愬叧鑱斿悕绉�
+ List<MdmItemRespVO> respList = convertAndEnrichItemList(pageResult.getList());
+ return success(new PageResult<>(respList, pageResult.getTotal()));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "瀵煎嚭鐗╂枡 Excel")
+ @PreAuthorize("@ss.hasPermission('mdm:item:export')")
+ @ApiAccessLog(operateType = EXPORT)
+ public void exportItemExcel(@Valid MdmItemPageReqVO pageReqVO,
+ HttpServletResponse response) throws IOException {
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+ // 澶嶇敤鍒嗛〉鏌ヨ鐨勮繃婊や笌鍏宠仈濉厖閫昏緫锛屼繚璇佸鍑烘暟鎹笌鍒楄〃涓�鑷�
+ List<MdmItemRespVO> respList = convertAndEnrichItemList(itemService.getItemPage(pageReqVO).getList());
+ List<MdmItemExcelVO> excelList = new ArrayList<>();
+ for (MdmItemRespVO resp : respList) {
+ MdmItemExcelVO excelVO = BeanUtils.toBean(resp, MdmItemExcelVO.class);
+ MdmItemTypeEnum itemType = MdmItemTypeEnum.fromType(resp.getItemType());
+ excelVO.setItemTypeName(itemType != null ? itemType.getName() : null);
+ excelList.add(excelVO);
+ }
+ // 瀵煎嚭 Excel
+ ExcelUtils.write(response, "鐗╂枡鏁版嵁.xls", "鐗╂枡", MdmItemExcelVO.class, excelList);
+ }
+
+ /**
+ * 灏嗙墿鏂� DO 鍒楄〃杞崲涓哄凡琛ラ綈鍏宠仈鍚嶇О锛堝垎绫汇�佷富/杈呰閲忓崟浣嶃�侀粯璁や粨搴擄級鍙婂悓姝ョ姸鎬佺殑 RespVO 鍒楄〃
+ *
+ * 鍒嗛〉鏌ヨ涓� Excel 瀵煎嚭鍏辩敤锛屼繚璇佸鍑哄唴瀹逛笌鍒楄〃灞曠ず涓�鑷�
+ */
+ private List<MdmItemRespVO> convertAndEnrichItemList(List<MdmItemDO> itemList) {
+ if (itemList == null || itemList.isEmpty()) {
+ return Collections.emptyList();
+ }
+ // 鍏宠仈鏌ヨ鍒嗙被鍚嶇О
+ Map<Long, MdmItemCategoryDO> categoryMap = itemCategoryService.getItemCategoryMap(
+ convertSet(itemList, MdmItemDO::getCategoryId));
// 鍏宠仈鏌ヨ璁¢噺鍗曚綅鍚嶇О
Map<Long, MdmUnitMeasureDO> unitMap = unitMeasureService.getUnitMeasureMap(
- convertSet(pageResult.getList(), MdmItemDO::getUnitMeasureId));
+ convertSet(itemList, MdmItemDO::getUnitMeasureId));
// 杞崲
- List<MdmItemRespVO> respList = BeanUtils.toBean(pageResult.getList(), MdmItemRespVO.class);
+ List<MdmItemRespVO> respList = BeanUtils.toBean(itemList, MdmItemRespVO.class);
+ // 鎵归噺鏌ヨ鍚屾鐘舵��
+ Set<Long> allIds = convertSet(respList, MdmItemRespVO::getId);
+ Set<Long> syncedIds = mesMdItemApi.getSyncedMdmItemIds(allIds);
// 鎵归噺鍏宠仈鏌ヨ杈呭崟浣嶅悕绉�
Set<Long> unitIds = new HashSet<>();
respList.forEach(resp -> {
@@ -106,16 +194,21 @@
});
Map<Long, MdmUnitMeasureDO> auxUnitMap = unitIds.isEmpty() ?
Collections.emptyMap() : unitMeasureService.getUnitMeasureMap(unitIds);
- // 鎵归噺鍏宠仈鏌ヨ浠撳簱鍚嶇О
+ // 鎵归噺鍏宠仈鏌ヨ浠撳簱鍚嶇О锛堜娇鐢� MES 浠撳簱锛�
Set<Long> warehouseIds = new HashSet<>();
respList.forEach(resp -> {
if (resp.getWarehouseId() != null) warehouseIds.add(resp.getWarehouseId());
});
- Map<Long, MdmWarehouseDO> warehouseMap = warehouseIds.isEmpty() ?
- Collections.emptyMap() : warehouseService.getWarehouseList(warehouseIds).stream()
- .collect(Collectors.toMap(MdmWarehouseDO::getId, w -> w));
+ Map<Long, MesWmWarehouseRespDTO> warehouseMap = warehouseIds.isEmpty() ?
+ Collections.emptyMap() : mesWmWarehouseApi.getWarehouseList(warehouseIds).stream()
+ .collect(Collectors.toMap(MesWmWarehouseRespDTO::getId, w -> w));
// 璧嬪��
respList.forEach(resp -> {
+ // 鍒嗙被鍚嶇О
+ MdmItemCategoryDO category = categoryMap.get(resp.getCategoryId());
+ if (category != null) {
+ resp.setCategoryName(category.getName());
+ }
MdmUnitMeasureDO unit = unitMap.get(resp.getUnitMeasureId());
if (unit != null) {
resp.setUnitMeasureName(unit.getName());
@@ -128,12 +221,14 @@
if (auxUnit2 != null) {
resp.setUnitMeasureName3(auxUnit2.getName());
}
- MdmWarehouseDO warehouse = warehouseMap.get(resp.getWarehouseId());
+ MesWmWarehouseRespDTO warehouse = warehouseMap.get(resp.getWarehouseId());
if (warehouse != null) {
resp.setWarehouseName(warehouse.getName());
}
+ // 鍚屾鐘舵��
+ resp.setSyncedMes(syncedIds.contains(resp.getId()));
});
- return success(new PageResult<>(respList, pageResult.getTotal()));
+ return respList;
}
@GetMapping("/list-by-ids")
@@ -145,10 +240,34 @@
return success(BeanUtils.toBean(list, MdmItemRespVO.class));
}
+ @GetMapping("/simple-list")
+ @Operation(summary = "鑾峰彇鐗╂枡绮剧畝鍒楄〃锛堝惎鐢ㄧ姸鎬侊紝鐢ㄤ簬涓嬫媺閫夋嫨锛�")
+ public CommonResult<List<MdmItemRespVO>> getItemSimpleList() {
+ List<MdmItemDO> list = itemService.getItemSimpleList();
+ List<MdmItemRespVO> respList = BeanUtils.toBean(list, MdmItemRespVO.class);
+ // 濉厖鍗曚綅鍚嶇О绛夊叧鑱斿瓧娈碉紝纭繚涓嬫媺閫夋嫨鍚庡彲甯﹀嚭鍗曚綅绛変俊鎭�
+ Map<Long, MdmUnitMeasureDO> unitMap = unitMeasureService.getUnitMeasureMap(
+ convertSet(respList, MdmItemRespVO::getUnitMeasureId));
+ respList.forEach(resp -> {
+ MdmUnitMeasureDO unit = unitMap.get(resp.getUnitMeasureId());
+ if (unit != null) {
+ resp.setUnitMeasureName(unit.getName());
+ }
+ });
+ return success(respList);
+ }
+
/**
- * 濉厖鐗╂枡鍝嶅簲 VO 鐨勫叧鑱斿悕绉帮紙涓诲崟浣嶃�佽緟鍗曚綅銆佷粨搴撳悕绉帮級
+ * 濉厖鐗╂枡鍝嶅簲 VO 鐨勫叧鑱斿悕绉帮紙鍒嗙被銆佷富鍗曚綅銆佽緟鍗曚綅銆佷粨搴撳悕绉帮級
*/
private void enrichItemRespVO(MdmItemRespVO resp) {
+ // 鍒嗙被鍚嶇О
+ if (resp.getCategoryId() != null) {
+ MdmItemCategoryDO category = itemCategoryService.getItemCategory(resp.getCategoryId());
+ if (category != null) {
+ resp.setCategoryName(category.getName());
+ }
+ }
// 涓诲崟浣嶅悕绉�
if (resp.getUnitMeasureId() != null) {
MdmUnitMeasureDO unit = unitMeasureService.getUnitMeasure(resp.getUnitMeasureId());
@@ -170,13 +289,64 @@
resp.setUnitMeasureName3(unit3.getName());
}
}
- // 榛樿浠撳簱鍚嶇О
+ // 榛樿浠撳簱鍚嶇О锛堜娇鐢� MES 浠撳簱锛�
if (resp.getWarehouseId() != null) {
- MdmWarehouseDO warehouse = warehouseService.getWarehouse(resp.getWarehouseId());
- if (warehouse != null) {
- resp.setWarehouseName(warehouse.getName());
+ List<MesWmWarehouseRespDTO> warehouses = mesWmWarehouseApi.getWarehouseList(List.of(resp.getWarehouseId()));
+ if (!warehouses.isEmpty()) {
+ resp.setWarehouseName(warehouses.get(0).getName());
}
}
}
+ /**
+ * 濉厖鐗╂枡鎵规灞炴�ч厤缃�
+ */
+ private void enrichItemBatchConfig(MdmItemRespVO resp) {
+ MdmItemBatchConfigDO config = itemBatchConfigService.getItemBatchConfigByItemId(resp.getId());
+ if (config != null) {
+ resp.setProduceDateFlag(config.getProduceDateFlag());
+ resp.setExpireDateFlag(config.getExpireDateFlag());
+ resp.setReceiptDateFlag(config.getReceiptDateFlag());
+ resp.setVendorFlag(config.getVendorFlag());
+ resp.setPurchaseOrderCodeFlag(config.getPurchaseOrderCodeFlag());
+ resp.setLotNumberFlag(config.getLotNumberFlag());
+ resp.setQualityStatusFlag(config.getQualityStatusFlag());
+ }
+ }
+
+ @GetMapping("/get-import-template")
+ @Operation(summary = "鑾峰緱瀵煎叆鐗╂枡妯℃澘")
+ @PreAuthorize("@ss.hasPermission('mdm:item:import')")
+ public void importTemplate(HttpServletResponse response) throws IOException {
+ List<MdmItemImportExcelVO> list = Arrays.asList(
+ MdmItemImportExcelVO.builder().code("ITEM001").name("绀轰緥鐗╂枡").specification("瑙勬牸").status(0).isBatchManaged(false).build()
+ );
+ ExcelUtils.write(response, "鐗╂枡瀵煎叆妯℃澘.xls", "鐗╂枡", MdmItemImportExcelVO.class, list);
+ }
+
+ @PostMapping("/import")
+ @Operation(summary = "瀵煎叆鐗╂枡")
+ @Parameters({
+ @Parameter(name = "file", description = "Excel 鏂囦欢", required = true),
+ @Parameter(name = "updateSupport", description = "鏄惁鏀寔鏇存柊锛岄粯璁や负 false", example = "true")
+ })
+ @PreAuthorize("@ss.hasPermission('mdm:item:import')")
+ public CommonResult<MdmItemImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
+ @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
+ List<MdmItemImportExcelVO> list;
+ try {
+ list = ExcelUtils.read(file, MdmItemImportExcelVO.class);
+ } catch (cn.idev.excel.exception.ExcelDataConvertException e) {
+ int row = e.getRowIndex() == null ? 0 : e.getRowIndex() + 1;
+ int col = e.getColumnIndex() == null ? 0 : e.getColumnIndex() + 1;
+ String cellVal = e.getCellData() == null ? "" : String.valueOf(e.getCellData().getStringValue());
+ throw new cn.iocoder.yudao.framework.common.exception.ServiceException(400,
+ "Excel 绗� " + row + " 琛岀 " + col + " 鍒楁暟鎹��" + cellVal + "銆忔牸寮忎笉姝g‘锛岃妫�鏌ヨ鍒楀唴瀹癸紙渚嬪鈥滅姸鎬佲�濊濉� 0/1 鎴� 鍚敤/鍋滅敤锛�");
+ } catch (Exception e) {
+ throw new cn.iocoder.yudao.framework.common.exception.ServiceException(400,
+ "Excel 瑙f瀽澶辫触锛�" + e.getMessage() + "锛岃浣跨敤绯荤粺鈥滀笅杞藉鍏ユā鏉库�濆苟鎸夋ā鏉垮~鍐欍��");
+ }
+ return success(itemService.importItemList(list, updateSupport));
+ }
+
}
\ No newline at end of file
--
Gitblit v1.9.3