feat:食堂菜品购买统计(按天)
This commit is contained in:
1 parent
26b60f81d4
commit
7cec1477cd
6 files changed
+142
-4
No files matched your search
+6
@@ -62,6 +62,12 @@ public class HardOrderDto extends HardOrderEntity implements BaseIsIncludeTreeIn
|
||||
*/
|
||||
private String afterSaleNo;
|
||||
|
||||
/**
|
||||
* 0 yyyy-MM-dd
|
||||
* 1 yyyy-MM
|
||||
*/
|
||||
private String createTimeType = "0";
|
||||
|
||||
private String createTimeStr;
|
||||
|
||||
/**
|
||||
|
||||
+10
@@ -28,6 +28,8 @@ import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -116,6 +118,14 @@ public class HardCanteenTotalController {
|
||||
@PostMapping("/proudct-total-export-by-day")
|
||||
@SysLog("食堂菜品购买统计导出(按天统计)")
|
||||
public void productTotalExportByDay(HttpServletResponse response, @RequestBody HardOrderDto dto) {
|
||||
if (ObjectUtil.isEmpty(dto.getCreateTimeList())) {
|
||||
throw new RuntimeException("请选择创建时间(天)");
|
||||
}
|
||||
// 导出最多只能导出一年
|
||||
long days = Math.abs(ChronoUnit.DAYS.between(dto.getCreateTimeList()[0].toLocalDate(), dto.getCreateTimeList()[1].toLocalDate()));
|
||||
if (days > 366) {
|
||||
throw new RuntimeException("最多只能导出一年的数据");
|
||||
}
|
||||
canteenTotalService.productTotalExportByDay(response, dto);
|
||||
}
|
||||
|
||||
|
||||
+126
-1
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.service.impl.order;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@@ -29,6 +30,7 @@ import com.bsd.pjcloud.hard.api.dto.order.app.HardAppProductLikeTopDto;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardCanteenProductTotalVo;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderSbVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.app.HardAppProductByCanteenVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.app.HardAppProductByClassifyVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.app.HardAppProductLikeTopVo;
|
||||
@@ -269,8 +271,121 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService {
|
||||
@Override
|
||||
public void productTotalExportByDay(HttpServletResponse response, HardOrderDto dto) {
|
||||
dto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
|
||||
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(ResourceUtil.getStream("file/设备交易金额汇总.xlsx")).build()) {
|
||||
// 查询食堂
|
||||
String mchName = "所有";
|
||||
if (ObjectUtil.isNotEmpty(dto.getMerchantId())) {
|
||||
MchManageVo mch = remoteMchService.getById(dto.getMerchantId()).getData();
|
||||
if (ObjectUtil.isNotEmpty(mch)) {
|
||||
mchName = mch.getName();
|
||||
}
|
||||
}
|
||||
// 标题
|
||||
// 格式-2025年县府一楼食堂就餐情况统计表
|
||||
String title = LocalDateTimeUtil.format(dto.getCreateTimeList()[0].toLocalDate(), DatePattern.CHINESE_DATE_PATTERN) + "至" + LocalDateTimeUtil.format(dto.getCreateTimeList()[1].toLocalDate(), DatePattern.CHINESE_DATE_PATTERN) + mchName + "就餐情况统计表";
|
||||
// 选择的天数
|
||||
List<LocalDate> dateRangeList = getDateRangeList(dto.getCreateTimeList()[0].toLocalDate(), dto.getCreateTimeList()[1].toLocalDate());
|
||||
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(ResourceUtil.getStream("file/食堂菜品购买统计(按天).xlsx")).inMemory(true).build()) {
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
map.put("title", title);
|
||||
|
||||
// 总金额
|
||||
double sumMorningPrice = 0;
|
||||
long sumMorningTimeCount = 0;
|
||||
double sumNoonPrice = 0;
|
||||
long sumNoonTimeCount = 0;
|
||||
double sumEveningPrice = 0;
|
||||
long sumEveningTimeCount = 0;
|
||||
|
||||
Page<HardCanteenProductTotalVo> page = productTotal(new Page(1, 2000), dto, null);
|
||||
List<HardCanteenProductTotalVo> records = page.getRecords();
|
||||
// 开始处理excel
|
||||
List<Map<String, Object>> excelList = new LinkedList<>();
|
||||
for (LocalDate v : dateRangeList) {
|
||||
Map<String, Object> excelMap = new HashMap<String, Object>();
|
||||
String timeStr = "";
|
||||
double morningPrice = 0;
|
||||
long morningTimeCount = 0;
|
||||
double noonPrice = 0;
|
||||
long noonTimeCount = 0;
|
||||
double eveningPrice = 0;
|
||||
long eveningTimeCount = 0;
|
||||
double colPrice = 0;
|
||||
long colTimeCount = 0;
|
||||
// 早
|
||||
HardCanteenProductTotalVo morning = records.stream().filter(item -> ObjectUtil.equals(item.getHourType(), HardHourTypeEnum.MORNING.getType()) && ObjectUtil.equals(item.getCreateTime().toLocalDate(), v)).findFirst().orElse(null);
|
||||
// 中
|
||||
HardCanteenProductTotalVo noon = records.stream().filter(item -> ObjectUtil.equals(item.getHourType(), HardHourTypeEnum.NOONING.getType()) && ObjectUtil.equals(item.getCreateTime().toLocalDate(), v)).findFirst().orElse(null);
|
||||
// 晚
|
||||
HardCanteenProductTotalVo evening = records.stream().filter(item -> ObjectUtil.equals(item.getHourType(), HardHourTypeEnum.NIGHT.getType()) && ObjectUtil.equals(item.getCreateTime().toLocalDate(), v)).findFirst().orElse(null);
|
||||
if (ObjectUtil.isNotEmpty(v)) {
|
||||
timeStr = LocalDateTimeUtil.format(v, DatePattern.NORM_DATE_PATTERN);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(morning)) {
|
||||
if (ObjectUtil.isNotEmpty(morning.getTotalPrice())) {
|
||||
morningPrice = BigDecimal.valueOf(morning.getTotalPrice()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(morning.getTimeCount())) {
|
||||
morningTimeCount = morning.getTimeCount();
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(noon)) {
|
||||
if (ObjectUtil.isNotEmpty(noon.getTotalPrice())) {
|
||||
noonPrice = BigDecimal.valueOf(noon.getTotalPrice()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(noon.getTimeCount())) {
|
||||
noonTimeCount = noon.getTimeCount();
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(evening)) {
|
||||
if (ObjectUtil.isNotEmpty(evening.getTotalPrice())) {
|
||||
eveningPrice = BigDecimal.valueOf(evening.getTotalPrice()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(evening.getTimeCount())) {
|
||||
eveningTimeCount = evening.getTimeCount();
|
||||
}
|
||||
}
|
||||
|
||||
sumMorningPrice += morningPrice;
|
||||
sumMorningTimeCount += morningTimeCount;
|
||||
sumNoonPrice += noonPrice;
|
||||
sumNoonTimeCount += noonTimeCount;
|
||||
sumEveningPrice += eveningPrice;
|
||||
sumEveningTimeCount += eveningTimeCount;
|
||||
colPrice = morningPrice + noonPrice + eveningPrice;
|
||||
colTimeCount = morningTimeCount + noonTimeCount + eveningTimeCount;
|
||||
|
||||
excelMap.put("timeStr", timeStr);
|
||||
excelMap.put("morningPrice", morningPrice);
|
||||
excelMap.put("morningTimeCount", morningTimeCount);
|
||||
excelMap.put("noonPrice", noonPrice);
|
||||
excelMap.put("noonTimeCount", noonTimeCount);
|
||||
excelMap.put("eveningPrice", eveningPrice);
|
||||
excelMap.put("eveningTimeCount", eveningTimeCount);
|
||||
excelMap.put("colPrice", colPrice);
|
||||
excelMap.put("colTimeCount", colTimeCount);
|
||||
excelList.add(excelMap);
|
||||
}
|
||||
map.put("sumMorningPrice", sumMorningPrice);
|
||||
map.put("sumMorningTimeCount", sumMorningTimeCount);
|
||||
map.put("sumNoonPrice", sumNoonPrice);
|
||||
map.put("sumNoonTimeCount", sumNoonTimeCount);
|
||||
map.put("sumEveningPrice", sumEveningPrice);
|
||||
map.put("sumEveningTimeCount", sumEveningTimeCount);
|
||||
map.put("colPrice", sumMorningPrice + sumNoonPrice + sumEveningPrice);
|
||||
map.put("colTimeCount", sumMorningTimeCount + sumNoonTimeCount + sumEveningTimeCount);
|
||||
|
||||
excelWriter.fill(map, writeSheet);
|
||||
excelWriter.fill(excelList, fillConfig, writeSheet);
|
||||
|
||||
Workbook workbook = excelWriter.writeContext().writeWorkbookHolder().getWorkbook();
|
||||
if (ObjectUtil.isNotEmpty(workbook)) {
|
||||
// 计算公式
|
||||
workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
|
||||
}
|
||||
excelWriter.finish();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|食堂菜品购买统计导出(按天统计)|导出数据异常error:{}", e.getMessage());
|
||||
@@ -511,4 +626,14 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<LocalDate> getDateRangeList(LocalDate startDate, LocalDate endDate) {
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
LocalDate currentDate = startDate;
|
||||
while (!currentDate.isAfter(endDate)) {
|
||||
dateList.add(currentDate);
|
||||
currentDate = currentDate.plusDays(1);
|
||||
}
|
||||
return dateList;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
-3
@@ -61,9 +61,6 @@
|
||||
<if test="dto.createTimeYearStr != null and dto.createTimeYearStr != '' ">
|
||||
and DATE_FORMAT(a.create_time, '%Y') = #{dto.createTimeYearStr}
|
||||
</if>
|
||||
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
|
||||
and o.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="productTotalByDept" resultType="com.bsd.pjcloud.hard.api.vo.order.HardCanteenProductTotalVo">
|
||||
|
||||
Reference in new issue
Block a user