From 8dae7c6ef389ab85211a829dba7ea4196eb673b2 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Fri, 14 Jun 2024 15:10:29 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(all):=20=E5=A2=9E=E5=8A=A0=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2=E6=97=B6=E9=97=B4=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=92=8C=E4=BB=93=E5=BA=93=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReportBillLoadingController.java | 29 ------- .../impl/ReportBillLoadingAsyncService.java | 15 ++++ .../impl/ReportDeliverServiceImpl.java | 79 +++++++++++++------ .../service/impl/ReportStockServiceImpl.java | 13 +++ .../com/logpm/report/util/CheckDataUtil.java | 41 ---------- .../com/logpm/report/util/ReportUtil.java | 71 +++++++++++++++++ 6 files changed, 152 insertions(+), 96 deletions(-) delete mode 100644 blade-service/logpm-report/src/main/java/com/logpm/report/util/CheckDataUtil.java create mode 100644 blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportUtil.java diff --git a/blade-service/logpm-report/src/main/java/com/logpm/report/controller/ReportBillLoadingController.java b/blade-service/logpm-report/src/main/java/com/logpm/report/controller/ReportBillLoadingController.java index 2bdca6788..fc327e1b5 100644 --- a/blade-service/logpm-report/src/main/java/com/logpm/report/controller/ReportBillLoadingController.java +++ b/blade-service/logpm-report/src/main/java/com/logpm/report/controller/ReportBillLoadingController.java @@ -1,12 +1,7 @@ package com.logpm.report.controller; -import cn.hutool.core.util.EnumUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.logpm.factorydata.enums.BrandEnums; -import org.springblade.common.constant.WorkNodeEnums; -import com.logpm.factorydata.util.FactoryDataMessageSender; -import com.logpm.factorydata.vo.NodePushMsg; import com.logpm.report.query.BillDetailsQuery; import com.logpm.report.query.BillLoadingTasksQuery; import com.logpm.report.service.IReportBillLoadingAsyncService; @@ -17,15 +12,10 @@ import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; -import java.util.Date; -import java.util.List; -import java.util.Map; /** * 自提报表前端控制器 @@ -41,25 +31,6 @@ public class ReportBillLoadingController { private IReportBillLoadingAsyncService reportBillLoadingAsyncService; - private final FactoryDataMessageSender sender; - - @PostMapping("/sendMessage") - @ApiOperation(value = "发送消息测试", notes = "发送消息测试") - public R tasksPage(@RequestBody Map map) { - String node = (String) map.get("node"); - WorkNodeEnums workNodeEnums = EnumUtil.fromString(WorkNodeEnums.class, node); - NodePushMsg build = NodePushMsg.builder() - .node(workNodeEnums) - .brand(BrandEnums.ZB) - .operatorTime(new Date()) - .operator((String) map.get("operator")) - .address((String) map.get("address")) - .content((List) map.get("content")) - .build(); - sender.sendNodeDataByBrand(build); - return R.data("成功"); - } - @GetMapping("/tasks") @ApiOperationSupport(order = 1) @ApiOperation(value = "自提任务维度", notes = "自提任务维度") diff --git a/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportBillLoadingAsyncService.java b/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportBillLoadingAsyncService.java index 048211723..9f6c53fc4 100644 --- a/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportBillLoadingAsyncService.java +++ b/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportBillLoadingAsyncService.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.logpm.basicdata.feign.IBasicdataWarehouseClient; import com.logpm.report.constant.ReportConstants; import com.logpm.report.mapper.ReportBillLoadingMapper; import com.logpm.report.query.BillDetailsQuery; @@ -14,6 +15,7 @@ import com.logpm.report.reader.BillLoadingTasksReader; import com.logpm.report.service.IReportBillLoadingAsyncService; import com.logpm.report.util.QueryUtil; import com.logpm.report.util.ReportExcelUtil; +import com.logpm.report.util.ReportUtil; import com.logpm.report.vo.BillLoadingDetailsVO; import com.logpm.report.vo.BillLoadingTasksVO; import lombok.AllArgsConstructor; @@ -48,12 +50,16 @@ public class ReportBillLoadingAsyncService implements IReportBillLoadingAsyncSer private final BillLoadingDetailsReader billLoadingDetailsReader; private final BillLoadingTasksReader billLoadingTasksReader; private final IUserClient userClient; + private final IBasicdataWarehouseClient warehouseClient; @Override public IPage tasksPage(BillLoadingTasksVO vo, BillLoadingTasksQuery query) { + ReportUtil.dateIsWithinOneMonth(vo.getCreatedTime(), query.getStartCreatedTime(), query.getEndCreatedTime(), "提货时间"); IPage page = Condition.getPage(query); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, BillLoadingTasksVO.class); tasksCustomQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouse(), query.getWarehouseRange(), queryWrapper, warehouseClient); List detailsPage = reportBillLoadingMapper.getTasksPage(page, queryWrapper); return page.setRecords(detailsPage); } @@ -74,17 +80,23 @@ public class ReportBillLoadingAsyncService implements IReportBillLoadingAsyncSer @Override public void exportTasks(HttpServletResponse response, BillLoadingTasksVO vo, BillLoadingTasksQuery query) { + ReportUtil.dateIsWithinOneMonth(vo.getCreatedTime(), query.getStartCreatedTime(), query.getEndCreatedTime(), "提货时间"); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, BillLoadingTasksVO.class); tasksCustomQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouse(), query.getWarehouseRange(), queryWrapper, warehouseClient); new ReportExcelUtil().export(response, billLoadingTasksReader, BillLoadingTasksVO.class, queryWrapper, "自提任务维度报表"); } @Override public IPage detailsPage(BillLoadingDetailsVO vo, BillDetailsQuery query) { + ReportUtil.dateIsWithinOneMonth(vo.getScanTime(), query.getStartScanTime(), query.getEndScanTime(), "提货扫描时间"); IPage page = Condition.getPage(query); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, BillLoadingDetailsVO.class); // 自定义查询 detailsCustomQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouse(), query.getWarehouseRange(), queryWrapper, warehouseClient); List detailsPage = reportBillLoadingMapper.getDetailsPage(page, queryWrapper); if (CollUtil.isNotEmpty(detailsPage)) { // 组装数据批量去查询用户名称 @@ -128,8 +140,11 @@ public class ReportBillLoadingAsyncService implements IReportBillLoadingAsyncSer @Override public void exportDetails(HttpServletResponse response, BillLoadingDetailsVO vo, BillDetailsQuery query) { + ReportUtil.dateIsWithinOneMonth(vo.getScanTime(), query.getStartScanTime(), query.getEndScanTime(), "提货扫描时间"); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, BillLoadingDetailsVO.class); detailsCustomQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouse(), query.getWarehouseRange(), queryWrapper, warehouseClient); new ReportExcelUtil().export(response, billLoadingDetailsReader, BillLoadingDetailsVO.class, queryWrapper, "自提明细"); } } diff --git a/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportDeliverServiceImpl.java b/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportDeliverServiceImpl.java index 81e5b2b4f..7f73b9eef 100644 --- a/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportDeliverServiceImpl.java +++ b/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportDeliverServiceImpl.java @@ -6,7 +6,6 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.logpm.basicdata.entity.BasicdataWarehouseEntity; import com.logpm.basicdata.feign.IBasicdataWarehouseClient; import com.logpm.report.dto.DeliveryTrainLoadedScanDTO; import com.logpm.report.mapper.ReportDeliverMapeer; @@ -19,22 +18,23 @@ import com.logpm.report.reader.DeliveryDetailReader; import com.logpm.report.reader.DeliveryTrainReader; import com.logpm.report.reader.StockOrderReader; import com.logpm.report.service.ReportDeliverService; -import com.logpm.report.util.CheckDataUtil; import com.logpm.report.util.QueryUtil; import com.logpm.report.util.ReportExcelUtil; +import com.logpm.report.util.ReportUtil; import com.logpm.report.vo.ReportCustomerVO; import com.logpm.report.vo.ReportDetailVO; import com.logpm.report.vo.ReportDevilerVO; import com.logpm.report.vo.StockOrderVO; import lombok.AllArgsConstructor; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Condition; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,6 +49,7 @@ import java.util.stream.Collectors; @AllArgsConstructor public class ReportDeliverServiceImpl implements ReportDeliverService { + private static final Logger log = LoggerFactory.getLogger(ReportDeliverServiceImpl.class); private final ReportDeliverMapeer reportDeliverMapeer; private final DeliveryTrainReader deliveryTrainReader; private final DeliveryCustomerReader deliveryCustomerReader; @@ -59,7 +60,7 @@ public class ReportDeliverServiceImpl implements ReportDeliverService { @Override public IPage deliveryTrainPage(ReportDevilerVO vo, ReportDevilerQuery query) { // 校验时间 - dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime()); + ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); IPage page = Condition.getPage(query); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportDevilerVO.class); // 自定义 sql 查询条件 @@ -68,17 +69,15 @@ public class ReportDeliverServiceImpl implements ReportDeliverService { // 1 如果用户页面选择了仓库,按选择的仓库查询。 // 2 用户页面没有选择仓库,但是切换了仓库,按切换的仓库查 // 3 用户没有选择仓库,也没有切换仓库,按用户当前所有仓查询 - if (StrUtil.isEmpty(vo.getWarehouseName())) { - BasicdataWarehouseEntity myCurrentWarehouse = warehouseClient.getMyCurrentWarehouse(); - if (ObjectUtil.isNotEmpty(myCurrentWarehouse)) { - queryWrapper.eq("warehouse_id", myCurrentWarehouse.getId()); - } else { - List warehouseEntities = warehouseClient.getMyWarehouseList(); - queryWrapper.in("warehouse_id", warehouseEntities.stream().map(BasicdataWarehouseEntity::getId).collect(Collectors.toList())); - } - } - + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); + // 查询数据 List deliveryTrainPage = reportDeliverMapeer.getDeliveryTrainPage(page, queryWrapper); + // 异步组装统计数据 + asyncBuildDeliveryTrainPage(deliveryTrainPage); + return page.setRecords(deliveryTrainPage); + } + + private void asyncBuildDeliveryTrainPage(List deliveryTrainPage) { List ids = deliveryTrainPage.stream().map(ReportDevilerVO::getId).collect(Collectors.toList()); // 异步查询扫描装车和异常扫描装车数据 if (CollUtil.isNotEmpty(ids)) { @@ -93,12 +92,12 @@ public class ReportDeliverServiceImpl implements ReportDeliverService { CompletableFuture allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); allFutures.join(); } catch (Exception e) { - + log.error("系统异常:{}", e); } } - return page.setRecords(deliveryTrainPage); } + private @NotNull CompletableFuture> getTrainLoadedScanInvnFuture(List idBatch, List deliveryTrainPage) { CompletableFuture> future = CompletableFuture.supplyAsync(() -> reportDeliverMapeer.getDeliveryTrainLoadSacnInvnByIds(idBatch)); @@ -151,15 +150,6 @@ public class ReportDeliverServiceImpl implements ReportDeliverService { return future; } - private static void dateIsWithinOneMonth(String taskTime, Date startTaskTime, Date endTaskTime) { - if (ObjectUtil.isEmpty(taskTime)) { - boolean withinOneMonth = CheckDataUtil.isWithinOneMonth(startTaskTime, endTaskTime); - if (!withinOneMonth) { - throw new ServiceException("日期必选且日期只能选择一个月"); - } - } - } - private void trainCustomQuery(ReportDevilerQuery query, QueryWrapper queryWrapper) { // 配送时间开始 QueryUtil.timeGe("task_time", query.getStartTaskTime(), queryWrapper); @@ -179,19 +169,26 @@ public class ReportDeliverServiceImpl implements ReportDeliverService { @Override public void exportTrain(HttpServletResponse response, ReportDevilerVO vo, ReportDevilerQuery query) { - dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime()); + // 添加时间校验 + ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportDevilerVO.class); trainCustomQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); new ReportExcelUtil().export(response, deliveryTrainReader, ReportDevilerVO.class, queryWrapper, "配送车次维度报表"); } @Override public IPage customerPage(ReportCustomerVO vo, ReportCustomerQuery query) { + // 添加时间校验 + ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); // 构建前端查询参数 IPage page = Condition.getPage(query); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportCustomerVO.class); // 自定义查询 customerCustomQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); return page.setRecords(reportDeliverMapeer.getCustomerPage(page, queryWrapper)); } @@ -216,18 +213,26 @@ public class ReportDeliverServiceImpl implements ReportDeliverService { @Override public void exportCustomer(HttpServletResponse response, ReportCustomerVO vo, ReportCustomerQuery query) { + // 添加时间校验 + ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportCustomerVO.class); customerCustomQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); new ReportExcelUtil().export(response, deliveryCustomerReader, ReportCustomerVO.class, queryWrapper, "配送客户维度报表"); } @Override public IPage detailsPage(ReportDetailVO vo, DevilerDetailsQuery query) { + // 添加时间校验 + ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); Integer current = query.getCurrent(); Integer size = query.getSize(); IPage page = Condition.getPage(query); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportDetailVO.class); detailsCustomQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); List detailsPage = reportDeliverMapeer.getDetailsPage(page, queryWrapper); // 包件总数 long total = page.getTotal(); @@ -273,16 +278,29 @@ public class ReportDeliverServiceImpl implements ReportDeliverService { @Override public void exportDetails(HttpServletResponse response, ReportDetailVO vo, DevilerDetailsQuery query) { + // 添加时间校验 + ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportDetailVO.class); detailsCustomQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); new ReportExcelUtil().export(response, deliveryDetailReader, ReportDetailVO.class, queryWrapper, "配送明细报表"); } @Override public IPage stockOrderPage(StockOrderVO vo, StockOrderQuery query) { + // 添加时间校验 + if (ObjectUtil.isEmpty(vo.getWarehouseEntryTime())) { + boolean withinOneMonth = ReportUtil.isWithinOneMonth(query.getStartWarehouseEntryTime(), query.getEndWarehouseEntryTime()); + if (!withinOneMonth) { + throw new ServiceException("入库时间必选且时间不超过一个月"); + } + } IPage page = Condition.getPage(query); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, StockOrderVO.class); stockOrderQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouse(), query.getWarehouseRange(), queryWrapper, warehouseClient); return page.setRecords(reportDeliverMapeer.getStockOrderPage(page, queryWrapper)); } @@ -304,8 +322,17 @@ public class ReportDeliverServiceImpl implements ReportDeliverService { @Override public void exportStockOrder(HttpServletResponse response, StockOrderVO vo, StockOrderQuery query) { + // 添加时间校验 + if (ObjectUtil.isEmpty(vo.getWarehouseEntryTime())) { + boolean withinOneMonth = ReportUtil.isWithinOneMonth(query.getStartWarehouseEntryTime(), query.getEndWarehouseEntryTime()); + if (!withinOneMonth) { + throw new ServiceException("入库时间必选且时间不超过一个月"); + } + } QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, StockOrderVO.class); stockOrderQuery(query, queryWrapper); + // 仓库权限 + ReportUtil.buildReportWarehouseAuth(vo.getWarehouse(), query.getWarehouseRange(), queryWrapper, warehouseClient); new ReportExcelUtil().export(response, stockOrderReader, StockOrderVO.class, queryWrapper, "在库订单表"); } diff --git a/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportStockServiceImpl.java b/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportStockServiceImpl.java index f387b1a74..e0da39f0e 100644 --- a/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportStockServiceImpl.java +++ b/blade-service/logpm-report/src/main/java/com/logpm/report/service/impl/ReportStockServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.logpm.basicdata.feign.IBasicdataWarehouseClient; import com.logpm.report.mapper.ReportStockMapeer; import com.logpm.report.query.StockDetailsQuery; import com.logpm.report.query.StockInQuery; @@ -15,6 +16,7 @@ import com.logpm.report.reader.DeliveryStockReader; import com.logpm.report.service.ReportStockService; import com.logpm.report.util.QueryUtil; import com.logpm.report.util.ReportExcelUtil; +import com.logpm.report.util.ReportUtil; import com.logpm.report.vo.ReportInStockVO; import com.logpm.report.vo.ReportOutStockVO; import com.logpm.report.vo.StockDetailsVO; @@ -41,12 +43,14 @@ public class ReportStockServiceImpl implements ReportStockService { private final DeliveryInStocksReader inStocksReader; private final DeliveryOutStocksReader outStocksReader; private final IDictBizClient dictBizClient; + private final IBasicdataWarehouseClient warehouseClient; @Override public IPage detailsPage(StockDetailsVO vo, StockDetailsQuery query) { IPage page = Condition.getPage(query); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, StockDetailsVO.class); detailsCustomQuery(query, queryWrapper); + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); return page.setRecords(reportStockMapeer.getDetailPage(page, queryWrapper)); } @@ -67,14 +71,17 @@ public class ReportStockServiceImpl implements ReportStockService { public void exportDetails(HttpServletResponse response, StockDetailsVO vo, StockDetailsQuery query) { QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, StockDetailsVO.class); detailsCustomQuery(query, queryWrapper); + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); new ReportExcelUtil().export(response, deliveryStockReader, StockDetailsVO.class, queryWrapper, "库存品表"); } @Override public IPage inStocks(ReportInStockVO vo, StockInQuery query) { + ReportUtil.dateIsWithinOneMonth(vo.getWarehousingTime(), query.getStartWarehousingTime(), query.getEndWarehousingTime(), "入库时间"); IPage page = Condition.getPage(query); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportInStockVO.class); inStocksCustomQuery(query, queryWrapper); + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); List inStocks = reportStockMapeer.getInStocks(page, queryWrapper); if (CollUtil.isNotEmpty(inStocks)) { for (ReportInStockVO inStock : inStocks) { @@ -112,16 +119,20 @@ public class ReportStockServiceImpl implements ReportStockService { @Override public void exportInStocks(HttpServletResponse response, ReportInStockVO vo, StockInQuery query) { + ReportUtil.dateIsWithinOneMonth(vo.getWarehousingTime(), query.getStartWarehousingTime(), query.getEndWarehousingTime(), "入库时间"); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportInStockVO.class); inStocksCustomQuery(query, queryWrapper); + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); new ReportExcelUtil().export(response, inStocksReader, ReportInStockVO.class, queryWrapper, "库存入库表"); } @Override public IPage outStocks(ReportOutStockVO vo, StockOutQuery query) { + ReportUtil.dateIsWithinOneMonth(vo.getCreateTime(), query.getStartCreateTime(), query.getEndCreateTime(), "出库时间"); IPage page = Condition.getPage(query); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportOutStockVO.class); outStocksCustomQuery(query, queryWrapper); + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); return page.setRecords(reportStockMapeer.getOutStocks(page, queryWrapper)); } @@ -143,8 +154,10 @@ public class ReportStockServiceImpl implements ReportStockService { @Override public void exportOutStocks(HttpServletResponse response, ReportOutStockVO vo, StockOutQuery query) { + ReportUtil.dateIsWithinOneMonth(vo.getCreateTime(), query.getStartCreateTime(), query.getEndCreateTime(), "出库时间"); QueryWrapper queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportOutStockVO.class); outStocksCustomQuery(query, queryWrapper); + ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); new ReportExcelUtil().export(response, outStocksReader, ReportOutStockVO.class, queryWrapper, "库存出库表"); } diff --git a/blade-service/logpm-report/src/main/java/com/logpm/report/util/CheckDataUtil.java b/blade-service/logpm-report/src/main/java/com/logpm/report/util/CheckDataUtil.java deleted file mode 100644 index 7aaea6eb3..000000000 --- a/blade-service/logpm-report/src/main/java/com/logpm/report/util/CheckDataUtil.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.logpm.report.util; - -import cn.hutool.core.date.DateUnit; -import cn.hutool.core.date.DateUtil; - -import java.util.Date; - -/** - * 数据校验工具类 - * - * @Author zqb - * @Date 2024/6/13 - **/ -public class CheckDataUtil { - - /** - * 校验两个时间相差不超过 30 天 - * 如果不跨月则返回 true - * 如果跨月则不超过 30 天 - * - * @Param start 开始时间 - * @Param end 解释时间 - * @Return boolean - * @Author zqb 2024/6/13 - **/ - public static boolean isWithinOneMonth(Date start, Date end) { - // 检查输入是否为null - if (start == null || end == null) { - return false; - } - - // 是否跨月,不跨越则直接返回true - if (DateUtil.year(start) == DateUtil.year(end) && DateUtil.month(start) == DateUtil.month(end)) { - return true; - } - - // 跨越则判断两个日期是否相差超过30天 - return DateUtil.between(start, end, DateUnit.DAY) <= 30; - } - -} diff --git a/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportUtil.java b/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportUtil.java new file mode 100644 index 000000000..f70649cf9 --- /dev/null +++ b/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportUtil.java @@ -0,0 +1,71 @@ +package com.logpm.report.util; + +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.logpm.basicdata.entity.BasicdataWarehouseEntity; +import com.logpm.basicdata.feign.IBasicdataWarehouseClient; +import org.springblade.core.log.exception.ServiceException; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 报表工具类 + * + * @Author zqb + * @Date 2024/6/13 + **/ +public class ReportUtil { + + /** + * 校验两个时间相差不超过 30 天 + * 如果不跨月则返回 true + * 如果跨月则不超过 30 天 + * + * @Param start 开始时间 + * @Param end 解释时间 + * @Return boolean + * @Author zqb 2024/6/13 + **/ + public static boolean isWithinOneMonth(Date start, Date end) { + // 检查输入是否为null + if (start == null || end == null) { + return false; + } + + // 是否跨月,不跨越则直接返回true + if (DateUtil.year(start) == DateUtil.year(end) && DateUtil.month(start) == DateUtil.month(end)) { + return true; + } + + // 跨越则判断两个日期是否相差超过30天 + return DateUtil.between(start, end, DateUnit.DAY) <= 30; + } + + public static void buildReportWarehouseAuth(String warehouseName, String warehouseNameRange, + QueryWrapper queryWrapper, IBasicdataWarehouseClient warehouseClient) { + if (StrUtil.isEmpty(warehouseName) && StrUtil.isEmpty(warehouseNameRange)) { + BasicdataWarehouseEntity myCurrentWarehouse = warehouseClient.getMyCurrentWarehouse(); + if (ObjectUtil.isNotEmpty(myCurrentWarehouse)) { + queryWrapper.eq("warehouse_id", myCurrentWarehouse.getId()); + } else { + List warehouseEntities = warehouseClient.getMyWarehouseList(); + queryWrapper.in("warehouse_id", warehouseEntities.stream().map(BasicdataWarehouseEntity::getId).collect(Collectors.toList())); + } + } + } + + public static void dateIsWithinOneMonth(String taskTime, Date startTaskTime, Date endTaskTime, String title) { + if (ObjectUtil.isEmpty(taskTime)) { + boolean withinOneMonth = isWithinOneMonth(startTaskTime, endTaskTime); + if (!withinOneMonth) { + throw new ServiceException(title + "必选且时间不超过一个月"); + } + } + } + +} From 868460f6eac37b858d0698c9e57023b04fc87db2 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Fri, 14 Jun 2024 15:16:45 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat(all):=20=E5=A2=9E=E5=8A=A0=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E5=AF=BC=E5=87=BA=E6=95=B0=E9=87=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/logpm/report/util/ReportExcelUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportExcelUtil.java b/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportExcelUtil.java index 1b862b28a..625bddc6b 100644 --- a/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportExcelUtil.java +++ b/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportExcelUtil.java @@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.logpm.report.constant.ReportConstants; import com.logpm.report.service.ExportReader; import org.apache.poi.ss.formula.functions.T; +import org.springblade.core.log.exception.ServiceException; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -87,6 +88,9 @@ public class ReportExcelUtil { ReportExcelUtil.setExportHeader(response, fileName); // 获取需要导出的总条数 Long count = service.getCount(query); + if(count > 500000L){ + throw new ServiceException("导出数据不能大于50w,请增加检索条件"); + } // 每个 sheet 放多少条数据 Double sheetDataNum = onceSheetDataNum.doubleValue(); // 总共要几个 sheet From 02b833729efe8e3c1eed9955a13c9556c8e62a22 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Fri, 14 Jun 2024 15:24:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat(all):=20=E5=A2=9E=E5=8A=A0=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E5=AF=BC=E5=87=BA=E5=8D=95=E6=AC=A1=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/logpm/report/util/ReportExcelUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportExcelUtil.java b/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportExcelUtil.java index 625bddc6b..9b0677c81 100644 --- a/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportExcelUtil.java +++ b/blade-service/logpm-report/src/main/java/com/logpm/report/util/ReportExcelUtil.java @@ -39,7 +39,7 @@ public class ReportExcelUtil { /** * 每次查询几条数据 */ - public static final Long PAGESIZE = 50000L; + public static final Long PAGESIZE = 100000L; /** * 设置excel导出的返回头