| | |
| | | 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.controller.admin.unit.vo.MdmUnitMeasurePageReqVO; |
| | | import cn.iocoder.yudao.module.mdm.dal.dataobject.unit.MdmUnitMeasureDO; |
| | | import cn.iocoder.yudao.module.mdm.enums.MdmItemTypeEnum; |
| | | import cn.iocoder.yudao.module.mdm.service.brand.MdmBrandService; |
| | |
| | | @Operation(summary = "获得导入物料模板") |
| | | @PreAuthorize("@ss.hasPermission('mdm:item:import')") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // 分类编码、计量单位编码为必填项,示例取当前系统真实编码,避免照模板导入直接失败 |
| | | String sampleCategoryCode = ""; |
| | | try { |
| | | List<MdmItemCategoryDO> cats = itemCategoryService.getSimpleItemList(); |
| | | if (cats != null && !cats.isEmpty()) { |
| | | sampleCategoryCode = cats.get(0).getCode(); |
| | | } |
| | | } catch (Exception ignored) { |
| | | // 取不到留空,不影响模板下载 |
| | | } |
| | | String sampleUnitCode = ""; |
| | | try { |
| | | MdmUnitMeasurePageReqVO unitReq = new MdmUnitMeasurePageReqVO(); |
| | | unitReq.setPageNo(1); |
| | | unitReq.setPageSize(1); |
| | | List<MdmUnitMeasureDO> units = unitMeasureService.getUnitMeasurePage(unitReq).getList(); |
| | | if (units != null && !units.isEmpty()) { |
| | | sampleUnitCode = units.get(0).getCode(); |
| | | } |
| | | } catch (Exception ignored) { |
| | | // 同上 |
| | | } |
| | | |
| | | List<MdmItemImportExcelVO> list = Arrays.asList( |
| | | MdmItemImportExcelVO.builder().code("ITEM001").name("示例物料").specification("规格").status(0).isBatchManaged(false).build() |
| | | MdmItemImportExcelVO.builder() |
| | | .code("ITEM-EXAMPLE").name("示例物料(请替换)").specification("规格") |
| | | .categoryCode(sampleCategoryCode).unitMeasureCode(sampleUnitCode) |
| | | .status(0).isBatchManaged(false) |
| | | .remark("示例数据,导入前请替换;分类编码/单位编码请填写系统中已存在的编码") |
| | | .build() |
| | | ); |
| | | ExcelUtils.write(response, "物料导入模板.xls", "物料", MdmItemImportExcelVO.class, list); |
| | | ExcelUtils.writeTemplate(response, "物料导入模板.xls", "物料", MdmItemImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |