| | |
| | | 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.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.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; |
| | | |
| | |
| | | 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: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(pageResult.getList(), MdmItemDO::getCategoryId)); |
| | | 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); |
| | |
| | | // 同步状态 |
| | | resp.setSyncedMes(syncedIds.contains(resp.getId())); |
| | | }); |
| | | return success(new PageResult<>(respList, pageResult.getTotal())); |
| | | return respList; |
| | | } |
| | | |
| | | @GetMapping("/list-by-ids") |
| | |
| | | } |
| | | } |
| | | |
| | | @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 = ExcelUtils.read(file, MdmItemImportExcelVO.class); |
| | | return success(itemService.importItemList(list, updateSupport)); |
| | | } |
| | | |
| | | } |