From 9ca97fd558700e7054c5f54192a9db7a1e6b8230 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期三, 11 九月 2024 16:31:47 +0800 Subject: [PATCH] 完善导出等接口 --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDataStatisticsController.java | 177 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 141 insertions(+), 36 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDataStatisticsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDataStatisticsController.java index 2f9c3ec..6abf2f8 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDataStatisticsController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TDataStatisticsController.java @@ -1,22 +1,33 @@ package com.ruoyi.web.controller.api; +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.WebUtils; import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.system.export.SaleGeneratorListExport; +import com.ruoyi.system.query.ProfitDetailsQuery; +import com.ruoyi.system.query.TDataGeneratorQuery; import com.ruoyi.system.query.TDataStatisticsQuery; import com.ruoyi.system.service.TOrderMealService; import com.ruoyi.system.service.TOrderSaleService; -import com.ruoyi.system.vo.OrderTrendsVO; -import com.ruoyi.system.vo.PersonnelStatisticsVO; -import com.ruoyi.system.vo.SalesRankingVO; -import com.ruoyi.system.vo.SalesVolumeVO; +import com.ruoyi.system.vo.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -58,23 +69,23 @@ switch (query.getTimeType()){ case 1: // 今日 - startTime = LocalDateTime.MIN; - endTime = LocalDateTime.MAX; + startTime = DateUtils.getDayStart(LocalDateTime.now()); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 2: // 昨日 - startTime = LocalDateTime.now().minusDays(1); - endTime = LocalDateTime.now().minusDays(1); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); + endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); break; case 3: // 近7天 - startTime = LocalDateTime.now().minusDays(7); - endTime = LocalDateTime.now(); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 4: // 近30天 - startTime = LocalDateTime.now().minusDays(30); - endTime = LocalDateTime.now(); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); @@ -86,6 +97,100 @@ salesVolumeVO = orderSaleService.salesVolume(query); } return AjaxResult.success(salesVolumeVO); + } + + @ApiOperation( value = "盈利明细") + @PostMapping(value = "/profitDetails") + public AjaxResult<ProfitDetailsVO> profitDetails(@RequestBody ProfitDetailsQuery query) { + Long objectId = tokenService.getLoginUser().getObjectId(); + query.setShopId(objectId); + if(Objects.nonNull(query.getTimeType())){ + LocalDateTime startTime = null; + LocalDateTime endTime = null; + switch (query.getTimeType()){ + case 1: + // 今日 + startTime = DateUtils.getDayStart(LocalDateTime.now()); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); + break; + case 2: + // 昨日 + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); + endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); + break; + case 3: + // 近7天 + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); + break; + case 4: + // 近30天 + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); + break; + } + query.setStartTime(DateUtils.localDateTimeToDate(startTime)); + query.setEndTime(DateUtils.localDateTimeToDate(endTime)); + } + return AjaxResult.success(orderMealService.profitDetails(query)); + } + + @ApiOperation( value = "盈利明细导出") + @PostMapping(value = "/profitDetailsExport") + public void profitDetailsExport(@RequestBody ProfitDetailsQuery query) { + Long objectId = tokenService.getLoginUser().getObjectId(); + query.setShopId(objectId); + if(Objects.nonNull(query.getTimeType())){ + LocalDateTime startTime = null; + LocalDateTime endTime = null; + switch (query.getTimeType()){ + case 1: + // 今日 + startTime = DateUtils.getDayStart(LocalDateTime.now()); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); + break; + case 2: + // 昨日 + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); + endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); + break; + case 3: + // 近7天 + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); + break; + case 4: + // 近30天 + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); + break; + } + query.setStartTime(DateUtils.localDateTimeToDate(startTime)); + query.setEndTime(DateUtils.localDateTimeToDate(endTime)); + } + List<GoodsProfitVO> list = orderMealService.profitDetailsExport(query); + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), GoodsProfitVO.class, list); + HttpServletResponse response = WebUtils.response(); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("utf-8"); + ServletOutputStream outputStream = null; + try { + String fileName = URLEncoder.encode("盈利明细.xls", "utf-8"); + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); + response.setHeader("Pragma", "no-cache"); + response.setHeader("Cache-Control", "no-cache"); + outputStream = response.getOutputStream(); + workbook.write(outputStream); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } @ApiOperation( value = "商品分类销售排行") @@ -102,23 +207,23 @@ switch (query.getTimeType()){ case 1: // 今日 - startTime = LocalDateTime.MIN; - endTime = LocalDateTime.MAX; + startTime = DateUtils.getDayStart(LocalDateTime.now()); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 2: // 昨日 - startTime = LocalDateTime.now().minusDays(1); - endTime = LocalDateTime.now().minusDays(1); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); + endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); break; case 3: // 近7天 - startTime = LocalDateTime.now().minusDays(7); - endTime = LocalDateTime.now(); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 4: // 近30天 - startTime = LocalDateTime.now().minusDays(30); - endTime = LocalDateTime.now(); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); @@ -146,23 +251,23 @@ switch (query.getTimeType()){ case 1: // 今日 - startTime = LocalDateTime.MIN; - endTime = LocalDateTime.MAX; + startTime = DateUtils.getDayStart(LocalDateTime.now()); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 2: // 昨日 - startTime = LocalDateTime.now().minusDays(1); - endTime = LocalDateTime.now().minusDays(1); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); + endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); break; case 3: // 近7天 - startTime = LocalDateTime.now().minusDays(7); - endTime = LocalDateTime.now(); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 4: // 近30天 - startTime = LocalDateTime.now().minusDays(30); - endTime = LocalDateTime.now(); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); @@ -189,23 +294,23 @@ switch (query.getTimeType()){ case 1: // 今日 - startTime = LocalDateTime.MIN; - endTime = LocalDateTime.MAX; + startTime = DateUtils.getDayStart(LocalDateTime.now()); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 2: // 昨日 - startTime = LocalDateTime.now().minusDays(1); - endTime = LocalDateTime.now().minusDays(1); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(1)); + endTime = DateUtils.getDayEnd(LocalDateTime.now().minusDays(1)); break; case 3: // 近7天 - startTime = LocalDateTime.now().minusDays(7); - endTime = LocalDateTime.now(); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(7)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; case 4: // 近30天 - startTime = LocalDateTime.now().minusDays(30); - endTime = LocalDateTime.now(); + startTime = DateUtils.getDayStart(LocalDateTime.now().minusDays(30)); + endTime = DateUtils.getDayEnd(LocalDateTime.now()); break; } query.setStartTime(DateUtils.localDateTimeToDate(startTime)); -- Gitblit v1.7.1