|
|
@@ -0,0 +1,236 @@
|
|
|
+package com.yr.warehouse.admin.web.product.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.yr.bluecat.common.entity.bo.BaseBo;
|
|
|
+import com.yr.bluecat.common.entity.exception.MessageException;
|
|
|
+import com.yr.bluecat.common.entity.response.PageResult;
|
|
|
+import com.yr.bluecat.common.entity.response.Result;
|
|
|
+import com.yr.bluecat.common.entity.utils.StringUtils;
|
|
|
+import com.yr.bluecat.common.utils.excel.ExportClient;
|
|
|
+import com.yr.prism.auth.core.user.AdminUserInfo;
|
|
|
+import com.yr.warehouse.admin.service.warehouse.service.WarehouseProductDemandAnalysisService;
|
|
|
+import com.yr.warehouse.admin.service.warehouse.service.WarehouseProductService;
|
|
|
+import com.yr.warehouse.admin.warehouse.bo.*;
|
|
|
+import com.yr.warehouse.admin.warehouse.vo.WarehouseProductDemandAnalysisHistoryVo;
|
|
|
+import com.yr.warehouse.admin.warehouse.vo.WarehouseProductDemandAnalysisVo;
|
|
|
+import com.yr.warehouse.admin.warehouse.vo.WarehouseProductVo;
|
|
|
+import com.yr.warehouse.admin.web.common.BaseController;
|
|
|
+import com.yr.warehouse.admin.web.product.excel.WarehouseProductDemandAnalysisExcel;
|
|
|
+import com.yr.warehouse.admin.web.product.export.WarehouseProductDemandAnalysisExport;
|
|
|
+import com.yr.warehouse.admin.web.product.mapstruct.WarehouseProductMapStruct;
|
|
|
+import com.yr.warehouse.admin.web.product.request.*;
|
|
|
+import com.yr.warehouse.admin.web.product.response.WarehouseProductDemandAnalysisHistoryResponse;
|
|
|
+import com.yr.warehouse.admin.web.product.response.WarehouseProductDemandAnalysisResponse;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 仓库商品需求分析控制器
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/warehouse/product/demandAnalysis")
|
|
|
+public class WarehouseProductDemandAnalysisController extends BaseController {
|
|
|
+ @Resource
|
|
|
+ private WarehouseProductDemandAnalysisService warehouseProductDemandAnalysisService;
|
|
|
+ @Resource
|
|
|
+ private WarehouseProductService warehouseProductService;
|
|
|
+ @Resource
|
|
|
+ private ExportClient exportClient;
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private static WarehouseProductDemandAnalysisEditorBo generatorEditorBo(WarehouseProductDemandAnalysisExcel excel, WarehouseProductVo warehouseProduct) {
|
|
|
+ WarehouseProductDemandAnalysisEditorBo warehouseProductDemandAnalysisEditorBo = new WarehouseProductDemandAnalysisEditorBo();
|
|
|
+ warehouseProductDemandAnalysisEditorBo.setId(warehouseProduct.getId());
|
|
|
+ warehouseProductDemandAnalysisEditorBo.setProcurementCycle(excel.getProcurementCycle());
|
|
|
+ warehouseProductDemandAnalysisEditorBo.setMoq(excel.getMoq());
|
|
|
+ warehouseProductDemandAnalysisEditorBo.setInventoryWarningQuantity(excel.getInventoryWarningQuantity());
|
|
|
+ warehouseProductDemandAnalysisEditorBo.setWarningCoefficient(excel.getWarningCoefficient());
|
|
|
+ warehouseProductDemandAnalysisEditorBo.build();
|
|
|
+ return warehouseProductDemandAnalysisEditorBo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询仓库商品需求分析列表
|
|
|
+ * @return 仓库商品分页结果
|
|
|
+ */
|
|
|
+ @PostMapping("/page")
|
|
|
+ @ResponseBody
|
|
|
+ public PageResult<WarehouseProductDemandAnalysisResponse> page(@RequestBody WarehouseProductDemandAnalysisPageRequest request, AdminUserInfo adminUserInfo) {
|
|
|
+ PageResult<WarehouseProductDemandAnalysisResponse> result = PageResult.newPageResult(request.getPageNum(), request.getPageSize());
|
|
|
+ if (Objects.isNull(request.getWarehouseId())) {
|
|
|
+ return result.success(new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ WarehouseProductDemandAnalysisPageBo bo = WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisPageRequestToBo(request);
|
|
|
+ buildUserInfo(bo, adminUserInfo);
|
|
|
+
|
|
|
+ Page<WarehouseProductDemandAnalysisVo> page = warehouseProductDemandAnalysisService.page(bo);
|
|
|
+ return result.success(page.getTotal(), WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisVoToResponse(page.getRecords()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓库商品编辑
|
|
|
+ * @return 仓库商品编辑结果
|
|
|
+ */
|
|
|
+ @PostMapping("/editor")
|
|
|
+ @ResponseBody
|
|
|
+ public Result<String> editor(@Validated @RequestBody WarehouseProductDemandAnalysisEditorRequest request, AdminUserInfo adminUserInfo) {
|
|
|
+ WarehouseProductDemandAnalysisEditorBo bo = WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisEditorRequestToBo(request);
|
|
|
+ buildUserInfo(bo, adminUserInfo);
|
|
|
+ warehouseProductDemandAnalysisService.editor(bo);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓库商品参数批量导入
|
|
|
+ * excel 文件中数据格式要求如下:
|
|
|
+ * 商品编号, 商品名称, 采购周期, 起订量, 安全库存数, 预警系数
|
|
|
+ *
|
|
|
+ * @return 仓库商品参数批量导入结果
|
|
|
+ */
|
|
|
+ @PostMapping("/batchImport")
|
|
|
+ @ResponseBody
|
|
|
+ public Result<String> batchImport(@Validated @RequestBody WarehouseProductDemandAnalysisBatchImportRequest request, AdminUserInfo adminUserInfo) {
|
|
|
+ List<WarehouseProductDemandAnalysisExcel> excels = exportClient.parseExcelData(request.getExcelPath(), WarehouseProductDemandAnalysisExcel.class);
|
|
|
+ if (excels.isEmpty()) {
|
|
|
+ throw new MessageException("导入文件数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> exceptionMessages = new ArrayList<>();
|
|
|
+ List<String> goodsCodes = new ArrayList<>();
|
|
|
+ for (WarehouseProductDemandAnalysisExcel excel : excels) {
|
|
|
+ if (StringUtils.isNotBlank(excel.getGoodsName()) && StringUtils.isBlank(excel.getGoodsCode())) {
|
|
|
+ exceptionMessages.add(String.format("商品名称【%s】的商品编号为空, 该商品不予导入", excel.getGoodsName()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(excel.getGoodsCode())) {
|
|
|
+ goodsCodes.add(excel.getGoodsCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<WarehouseProductVo> warehouseProducts = warehouseProductService.searchWarehouseProductByGoodsCodes(goodsCodes, request.getWarehouseId());
|
|
|
+ Map<String, WarehouseProductVo> warehouseProductMap = warehouseProducts.stream().collect(Collectors.toMap(WarehouseProductVo::getGoodsCode, v -> v));
|
|
|
+
|
|
|
+ BaseBo bo = new BaseBo();
|
|
|
+ buildUserInfo(bo, adminUserInfo);
|
|
|
+ List<WarehouseProductDemandAnalysisEditorBo> batchBos = new ArrayList<>();
|
|
|
+ for (WarehouseProductDemandAnalysisExcel excel : excels) {
|
|
|
+ WarehouseProductVo warehouseProduct = warehouseProductMap.get(excel.getGoodsCode());
|
|
|
+ if (null == warehouseProduct) {
|
|
|
+ exceptionMessages.add(String.format("商品编号【%s】的商品不存在, 该商品不予导入", excel.getGoodsCode()));
|
|
|
+ } else {
|
|
|
+ WarehouseProductDemandAnalysisEditorBo warehouseProductDemandAnalysisEditorBo = generatorEditorBo(excel, warehouseProduct);
|
|
|
+ batchBos.add(warehouseProductDemandAnalysisEditorBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!exceptionMessages.isEmpty()) {
|
|
|
+ throw new MessageException(String.join("\n", exceptionMessages));
|
|
|
+ }
|
|
|
+
|
|
|
+ warehouseProductDemandAnalysisService.batchEditor(batchBos, bo);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓库商品需求分析导出
|
|
|
+ * @return 仓库商品需求分析导出结果
|
|
|
+ */
|
|
|
+ @PostMapping("/export")
|
|
|
+ @ResponseBody
|
|
|
+ public Result<String> export(@Validated @RequestBody WarehouseProductDemandAnalysisExportRequest request, AdminUserInfo adminUserInfo) {
|
|
|
+ WarehouseProductDemandAnalysisPageBo bo = WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisExportRequestToBo(request);
|
|
|
+ buildUserInfo(bo, adminUserInfo);
|
|
|
+
|
|
|
+ bo.setPageNum(1);
|
|
|
+ bo.setPageSize(1000);
|
|
|
+ List<WarehouseProductDemandAnalysisVo> all = new ArrayList<>();
|
|
|
+ while (true) {
|
|
|
+ Page<WarehouseProductDemandAnalysisVo> page = warehouseProductDemandAnalysisService.page(bo);
|
|
|
+ List<WarehouseProductDemandAnalysisVo> records = page.getRecords();
|
|
|
+ if (null == records || records.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ all.addAll(records);
|
|
|
+ bo.setPageNum(bo.getPageNum() + 1);
|
|
|
+ }
|
|
|
+ List<WarehouseProductDemandAnalysisExport> exportList = WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisVoListToExportList(all);
|
|
|
+ String uri = exportClient.export(exportList, "export/warehouseProductDemandAnalysis", "仓库商品需求分析" + System.currentTimeMillis());
|
|
|
+ return Result.success(uri);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓库商品需求分析生成记录
|
|
|
+ * @return 仓库商品需求分析生成记录结果
|
|
|
+ */
|
|
|
+ @PostMapping("/generator")
|
|
|
+ @ResponseBody
|
|
|
+ public Result<String> generator(@Validated @RequestBody WarehouseProductDemandAnalysisGeneratorRequest request, AdminUserInfo adminUserInfo) {
|
|
|
+ WarehouseProductDemandAnalysisGeneratorBo bo = WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisGeneratorRequestToBo(request);
|
|
|
+ buildUserInfo(bo, adminUserInfo);
|
|
|
+ warehouseProductDemandAnalysisService.generator(bo);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓库商品需求分析生成记录主表列表
|
|
|
+ * @return 仓库商品需求分析生成记录主表列表结果
|
|
|
+ */
|
|
|
+ @PostMapping("/history")
|
|
|
+ @ResponseBody
|
|
|
+ public PageResult<WarehouseProductDemandAnalysisHistoryResponse> history(@Validated @RequestBody WarehouseProductDemandAnalysisHistoryRequest request, AdminUserInfo adminUserInfo) {
|
|
|
+ WarehouseProductDemandAnalysisHistoryBo bo = WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisHistoryRequestToBo(request);
|
|
|
+ buildUserInfo(bo, adminUserInfo);
|
|
|
+ Page<WarehouseProductDemandAnalysisHistoryVo> page = warehouseProductDemandAnalysisService.history(bo);
|
|
|
+ PageResult<WarehouseProductDemandAnalysisHistoryResponse> result = PageResult.newPageResult(request.getPageNum(), request.getPageSize());
|
|
|
+ return result.success(page.getTotal(), WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisHistoryVoListToResponseList(page.getRecords()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓库商品需求分析生成记录子表列表
|
|
|
+ * @return 仓库商品需求分析生成记录子表列表结果
|
|
|
+ */
|
|
|
+ @PostMapping("/historyPage")
|
|
|
+ @ResponseBody
|
|
|
+ public PageResult<WarehouseProductDemandAnalysisResponse> historyPage(@Validated @RequestBody WarehouseProductDemandAnalysisHistoryPageRequest request, AdminUserInfo adminUserInfo) {
|
|
|
+ WarehouseProductDemandAnalysisHistoryPageBo bo = WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisHistoryPageRequestToBo(request);
|
|
|
+ buildUserInfo(bo, adminUserInfo);
|
|
|
+ Page<WarehouseProductDemandAnalysisVo> page = warehouseProductDemandAnalysisService.historyPage(bo);
|
|
|
+ PageResult<WarehouseProductDemandAnalysisResponse> result = PageResult.newPageResult(request.getPageNum(), request.getPageSize());
|
|
|
+ return result.success(page.getTotal(), WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisVoToResponse(page.getRecords()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓库商品需求分析生成记录导出
|
|
|
+ * @return 仓库商品需求分析生成记录导出结果
|
|
|
+ */
|
|
|
+ @PostMapping("/historyExport")
|
|
|
+ @ResponseBody
|
|
|
+ public Result<String> historyExport(@Validated @RequestBody WarehouseProductDemandAnalysisHistoryExportRequest request, AdminUserInfo adminUserInfo) {
|
|
|
+ WarehouseProductDemandAnalysisHistoryPageBo bo = WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisHistoryExportRequestToBo(request);
|
|
|
+ buildUserInfo(bo, adminUserInfo);
|
|
|
+ bo.setPageNum(1);
|
|
|
+ bo.setPageSize(1000);
|
|
|
+ List<WarehouseProductDemandAnalysisVo> all = new ArrayList<>();
|
|
|
+ while (true) {
|
|
|
+ Page<WarehouseProductDemandAnalysisVo> page = warehouseProductDemandAnalysisService.historyPage(bo);
|
|
|
+ List<WarehouseProductDemandAnalysisVo> records = page.getRecords();
|
|
|
+ if (null == records || records.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ all.addAll(records);
|
|
|
+ bo.setPageNum(bo.getPageNum() + 1);
|
|
|
+ }
|
|
|
+ List<WarehouseProductDemandAnalysisExport> exportList = WarehouseProductMapStruct.MAPSTRUCT.demandAnalysisVoListToExportList(all);
|
|
|
+ String uri = exportClient.export(exportList, "export/warehouseProductDemandAnalysis", "仓库商品需求分析生成记录" + System.currentTimeMillis());
|
|
|
+ return Result.success(uri);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|