feat:食堂菜品购买统计(按月)导出
This commit is contained in:
1 parent
e1527c5bd0
commit
26b60f81d4
8 files changed
+98
-35
No files matched your search
@@ -33,7 +33,7 @@
|
||||
<description>pjcloud excel 操作</description>
|
||||
|
||||
<properties>
|
||||
<easyexcel.version>4.0.2</easyexcel.version>
|
||||
<easyexcel.version>4.0.3</easyexcel.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
+2
@@ -19,6 +19,8 @@ public class HardCarDto extends HardCarEntity {
|
||||
|
||||
private String createTimeStr;
|
||||
|
||||
private String createTimeYearStr;
|
||||
|
||||
private LocalDate[] createTimeList;
|
||||
|
||||
private List<String> orderStatusCodes;
|
||||
|
||||
+2
@@ -36,6 +36,8 @@ public class HardOrderDto extends HardOrderEntity implements BaseIsIncludeTreeIn
|
||||
|
||||
private List<String> orderStatusCodes;
|
||||
|
||||
private String createTimeYearStr;
|
||||
|
||||
private LocalDateTime[] createTimeList;
|
||||
|
||||
private LocalDateTime[] payTimeList;
|
||||
|
||||
+3
@@ -123,6 +123,9 @@ public class HardCanteenTotalController {
|
||||
@PostMapping("/proudct-total-export-by-month")
|
||||
@SysLog("食堂菜品购买统计导出(按月统计)")
|
||||
public void productTotalExportByMonth(HttpServletResponse response, @RequestBody HardOrderDto dto) {
|
||||
if (ObjectUtil.isEmpty(dto.getCreateTimeYearStr())) {
|
||||
throw new RuntimeException("请选择创建时间(年)");
|
||||
}
|
||||
canteenTotalService.productTotalExportByMonth(response, dto);
|
||||
}
|
||||
}
|
||||
+84
-34
@@ -40,6 +40,7 @@ import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -48,6 +49,7 @@ import java.math.RoundingMode;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -281,52 +283,100 @@ public class HardCanteenTotalServiceImpl implements HardCanteenTotalService {
|
||||
@Override
|
||||
public void productTotalExportByMonth(HttpServletResponse response, HardOrderDto dto) {
|
||||
dto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
|
||||
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(ResourceUtil.getStream("file/食堂菜品购买统计(按月).xlsx")).build()) {
|
||||
String createTimeYearStr = dto.getCreateTimeYearStr();
|
||||
Integer createTimeYear = Integer.valueOf(createTimeYearStr);
|
||||
|
||||
// 查询食堂
|
||||
String mchName = "所有";
|
||||
if (ObjectUtil.isNotEmpty(dto.getMerchantId())) {
|
||||
MchManageVo mch = remoteMchService.getById(dto.getMerchantId()).getData();
|
||||
if (ObjectUtil.isNotEmpty(mch)) {
|
||||
mchName = mch.getName();
|
||||
}
|
||||
}
|
||||
|
||||
// 标题
|
||||
// 格式-2025年县府一楼食堂就餐情况统计表
|
||||
String title = createTimeYear + "年" + mchName + "就餐情况统计表";
|
||||
|
||||
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(ResourceUtil.getStream("file/食堂菜品购买统计(按月).xlsx")).inMemory(true).build()) {
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
||||
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build();
|
||||
|
||||
long currentPage = 1L;
|
||||
long pageSize = 200L;
|
||||
while (true) {
|
||||
Page<HardCanteenProductTotalVo> page = productTotalByMonth(new Page(currentPage, pageSize), dto, null);
|
||||
if (ObjectUtil.isEmpty(page) || ObjectUtil.isEmpty(page.getRecords())) break;
|
||||
// 填充数据
|
||||
List<HardCanteenProductTotalVo> records = page.getRecords();
|
||||
// 月份
|
||||
List<Map<String, String>> mounthList = records.stream().map(v -> {
|
||||
LocalDateTime createTime = v.getCreateTime();
|
||||
String createTimeStr = LocalDateTimeUtil.format(createTime, DatePattern.NORM_MONTH_PATTERN);
|
||||
return Map.of("createTimeStr", createTimeStr);
|
||||
}).toList();
|
||||
excelWriter.fill(mounthList, fillConfig, writeSheet);
|
||||
// 早
|
||||
List<HardCanteenProductTotalVo> morningList = records.stream().filter(v -> ObjectUtil.equals(v.getHourType(), HardHourTypeEnum.MORNING.getType())).toList();
|
||||
excelWriter.fill(productTotalExportByMonthToDefaulColExcelMap(morningList), fillConfig, writeSheet);
|
||||
// 中
|
||||
List<HardCanteenProductTotalVo> noonList = records.stream().filter(v -> ObjectUtil.equals(v.getHourType(), HardHourTypeEnum.NOONING.getType())).toList();
|
||||
excelWriter.fill(productTotalExportByMonthToDefaulColExcelMap(noonList), fillConfig, writeSheet);
|
||||
// 晚
|
||||
List<HardCanteenProductTotalVo> nightList = records.stream().filter(v -> ObjectUtil.equals(v.getHourType(), HardHourTypeEnum.NIGHT.getType())).toList();
|
||||
excelWriter.fill(productTotalExportByMonthToDefaulColExcelMap(nightList), fillConfig, writeSheet);
|
||||
if (ObjectUtil.isEmpty(page.getPages()) || page.getCurrent() > page.getPages()) break;
|
||||
currentPage++;
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("title", title);
|
||||
|
||||
Page<HardCanteenProductTotalVo> page = productTotalByMonth(new Page(1L, 999L), dto, null);
|
||||
List<HardCanteenProductTotalVo> records = page.getRecords();
|
||||
// 填充数据
|
||||
// 早
|
||||
List<HardCanteenProductTotalVo> morningList = records.stream().filter(v -> ObjectUtil.equals(v.getHourType(), HardHourTypeEnum.MORNING.getType())).toList();
|
||||
excelWriter.fill(productTotalExportByMonthToDefaulColExcelMap(morningList, createTimeYear, "morning"), fillConfig, writeSheet);
|
||||
// 中
|
||||
List<HardCanteenProductTotalVo> noonList = records.stream().filter(v -> ObjectUtil.equals(v.getHourType(), HardHourTypeEnum.NOONING.getType())).toList();
|
||||
excelWriter.fill(productTotalExportByMonthToDefaulColExcelMap(noonList, createTimeYear, "noon"), fillConfig, writeSheet);
|
||||
// 晚
|
||||
List<HardCanteenProductTotalVo> nightList = records.stream().filter(v -> ObjectUtil.equals(v.getHourType(), HardHourTypeEnum.NIGHT.getType())).toList();
|
||||
excelWriter.fill(productTotalExportByMonthToDefaulColExcelMap(nightList, createTimeYear, "night"), fillConfig, writeSheet);
|
||||
|
||||
excelWriter.fill(map, writeSheet);
|
||||
|
||||
Workbook workbook = excelWriter.writeContext().writeWorkbookHolder().getWorkbook();
|
||||
if (ObjectUtil.isNotEmpty(workbook)) {
|
||||
// 计算公式
|
||||
workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
|
||||
}
|
||||
excelWriter.fill(new HashMap<>(), writeSheet);
|
||||
excelWriter.finish();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|食堂菜品购买统计导出(按月统计)|导出数据异常error:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private List<Map<String, String>> productTotalExportByMonthToDefaulColExcelMap(List<HardCanteenProductTotalVo> records) {
|
||||
List<Map<String, String>> list = new LinkedList<>();
|
||||
private List<Map<String, Object>> productTotalExportByMonthToDefaulColExcelMap(List<HardCanteenProductTotalVo> records, int year, String prefix) {
|
||||
List<Map<String, Object>> list = new LinkedList<>();
|
||||
if (ObjectUtil.isEmpty(records)) return list;
|
||||
for (HardCanteenProductTotalVo i : records) {
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
map.put("totalPrice", BigDecimal.valueOf(i.getTotalPrice()).divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP).toString());
|
||||
map.put("timeCount", String.valueOf(i.getTimeCount()));
|
||||
list.add(map);
|
||||
List<HardCanteenProductTotalVo> sqlList = new LinkedList<>();
|
||||
|
||||
List<LocalDate> monthlyRanges = new LinkedList<>();
|
||||
for (Month month : Month.values()) {
|
||||
LocalDate localDate = LocalDate.of(year, month.getValue(), 1);
|
||||
monthlyRanges.add(localDate);
|
||||
}
|
||||
|
||||
for (LocalDate i : monthlyRanges) {
|
||||
HardCanteenProductTotalVo target = records.stream().filter(v -> ObjectUtil.equals(v.getCreateTime().toLocalDate(), i)).findFirst().orElse(null);
|
||||
if (ObjectUtil.isEmpty(target)) {
|
||||
HardCanteenProductTotalVo defaultVo = new HardCanteenProductTotalVo();
|
||||
defaultVo.setCreateTime(i.atStartOfDay());
|
||||
defaultVo.setCreateTimeStr(LocalDateTimeUtil.format(i, DatePattern.NORM_MONTH_PATTERN));
|
||||
sqlList.add(defaultVo);
|
||||
} else {
|
||||
sqlList.add(target);
|
||||
}
|
||||
}
|
||||
|
||||
double sumTotalPrice = 0;
|
||||
long sumTimeCount = 0;
|
||||
|
||||
String mapKey = prefix + "Col";
|
||||
for (HardCanteenProductTotalVo i : sqlList) {
|
||||
double totalPrice = 0;
|
||||
if (ObjectUtil.isNotEmpty(i.getTotalPrice())) {
|
||||
totalPrice = BigDecimal.valueOf(i.getTotalPrice()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
list.add(Map.of(mapKey, totalPrice));
|
||||
sumTotalPrice += totalPrice;
|
||||
|
||||
long timeCount = 0;
|
||||
if (ObjectUtil.isNotEmpty(i.getTimeCount())) {
|
||||
timeCount = i.getTimeCount();
|
||||
}
|
||||
list.add(Map.of(mapKey, timeCount));
|
||||
sumTimeCount += timeCount;
|
||||
}
|
||||
list.add(Map.of(mapKey, sumTotalPrice));
|
||||
list.add(Map.of(mapKey, sumTimeCount));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
+3
@@ -58,6 +58,9 @@
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<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>
|
||||
|
||||
+3
@@ -32,6 +32,9 @@
|
||||
|
||||
<sql id="whereA">
|
||||
a.del_flag = '0'
|
||||
<if test="dto.code != null ">
|
||||
and a.code like concat('%', #{dto.code}, '%')
|
||||
</if>
|
||||
<if test="dto.status != null and dto.status != '' ">
|
||||
and a.status = #{dto.status}
|
||||
</if>
|
||||
|
||||
Reference in new issue
Block a user