feat:报表

This commit is contained in:
dzc committed 2026-01-27 19:50:48 +08:00
1 parent df99986af6
commit 23c190b11e
9 files changed
+289 -25

No files matched your search

+22
View File
@@ -13,3 +13,25 @@ CREATE TABLE `hard_panel_setting`
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 COMMENT ='大屏配置表';
-- app版本控制表
CREATE TABLE `app_version`
(
`id` bigint NOT NULL COMMENT '主键ID',
`platform` varchar(32) NOT NULL COMMENT '平台类型(android、ios)',
`version_code` int NOT NULL COMMENT '内部版本号(用于比较大小)',
`version_name` varchar(32) NOT NULL COMMENT '展示版本号(字符串)',
`update_content` text COMMENT '更新内容/更新日志',
`download_url` varchar(512) NOT NULL COMMENT '安装包下载地址(wgt、apk)',
`is_force` varchar(32) NOT NULL COMMENT '是否强制更新',
`is_silent` varchar(32) NOT NULL COMMENT '是否静默更新(WGT用)',
`status` varchar(32) NOT NULL COMMENT '状态(已发布、未发布、已下架)',
`create_by` varchar(50) DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_by` varchar(50) DEFAULT NULL COMMENT '更新者',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`del_flag` char(1) DEFAULT '0' COMMENT '是否删除(0=正常 1=删除)',
`tenant_id` bigint(20) DEFAULT NULL COMMENT '租户编号',
PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 COMMENT ='app版本控制表';
@@ -38,6 +38,10 @@ public class HardOrderDto extends HardOrderEntity implements BaseIsIncludeTreeIn
private String createTimeYearStr;
private String payTimeYearStr;
private String auditTimeYearStr;
private LocalDateTime[] createTimeList;
private LocalDateTime[] payTimeList;
@@ -12,6 +12,8 @@ public class HardSelectOrderMerchIdsDto {
private List<String> merchTypes;
private String payTimeYearStr;
private LocalDateTime[] createTimeList;
}
@@ -67,4 +67,16 @@ public class HardOrderCsVo implements BaseMchInterface, BaseHardInterface {
@Schema(description = "列号")
private Long lineNumber;
@Data
static public class Month {
@Schema(description = "日期")
private String day;
@Schema(description = "总盈利金额(元)")
private double totalProfitPrice;
@Schema(description = "总盈利次数")
private long totalProfitCount;
}
}
@@ -423,6 +423,27 @@ public class HardOrderTotalController {
}
}
@Operation(summary = "商户交易记录导出(按月)", description = "商户交易记录导出(按月)")
@PostMapping("/export-cs-by-month")
@SysLog("商户交易记录导出(按月)")
@PreAuthorize("@pms.hasPermission('hard_hardTotal_export_cs')")
public void exportCsByMonth(HttpServletResponse response, @RequestBody HardOrderDto dto) {
dto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
// 查询商户和下面的子商户
List<Long> mchDtoIds = new ArrayList<>();
if (ObjectUtil.isNotEmpty(dto.getMerchantId())) {
List<MchManageVo> mchList = mchService.getByParentId(dto.getMerchantId()).getData();
if (ObjectUtil.isNotEmpty(mchList)) {
List<Long> mchIds = mchList.stream().map(MchManageVo::getId).toList();
mchDtoIds.add(dto.getMerchantId());
mchDtoIds.addAll(mchIds);
dto.setMerchantId(null);
dto.setMchIds(mchDtoIds);
}
}
hardOrderTotalService.exportCsByMonth(response, dto);
}
@Operation(summary = "支付方式交易记录", description = "支付方式交易记录")
@PostMapping("/export-payType")
@SysLog("支付方式交易记录")
@@ -6,6 +6,7 @@ import com.bsd.pjcloud.hard.api.dto.order.HardChartLatitudeVo;
import com.bsd.pjcloud.hard.api.dto.order.HardDeptTotalDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.hard.api.vo.order.*;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
@@ -55,4 +56,9 @@ public interface HardOrderTotalService {
* 统计每天、每周、每月、每年的交易人数和次数
*/
HardChartLatitudeVo chartLatitude(Long merchantId);
/**
* 商户交易记录导出(按月)
*/
void exportCsByMonth(HttpServletResponse response, HardOrderDto dto);
}
@@ -2,7 +2,17 @@ package com.bsd.pjcloud.hard.service.impl.order;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.enums.WriteDirectionEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.admin.api.dto.DeptAllListDto;
import com.bsd.pjcloud.admin.api.entity.SysDept;
@@ -13,6 +23,7 @@ import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.datascope.DataScopeFuncEnum;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleStatusEnum;
@@ -33,19 +44,22 @@ import com.bsd.pjcloud.wallet.api.feign.RemoteWalletTransactionService;
import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionSumAndCountVo;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import com.alibaba.excel.write.metadata.fill.FillWrapper;
import java.math.BigDecimal;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.math.RoundingMode;
import java.time.*;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@Validated
@@ -238,24 +252,10 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
} else {
dto.setMchTypeCodes(dto.getMchTypeCodes());
}
// // 查询总流水
// if (ObjectUtil.isEmpty(dto.getMchIds())) {
// HardSelectOrderMerchIdsDto merchQuery = new HardSelectOrderMerchIdsDto();
// if (ObjectUtil.isNotEmpty(dto.getMerchantId())) {
// merchQuery.setMerchIds(List.of(dto.getMerchantId()));
// }
// if (ObjectUtil.isNotEmpty(dto.getMchTypeCodes())) {
// merchQuery.setMerchTypes(dto.getMchTypeCodes());
// }
// if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) {
// merchQuery.setCreateTimeList(dto.getCreateTimeList());
// }
// List<Long> mechIds = hardOrderMapper.selectOrderMerchIds(merchQuery);
// dto.setMchIds(mechIds);
// }
// 查询总流水
HardOrderDto totalDto = BeanUtil.toBean(dto, HardOrderDto.class);
totalDto.setOrderStatusCodes(HardOrderStatusEnum.getPayPrice());
totalDto.setPayTimeYearStr(dto.getPayTimeYearStr());
DataScope totalDataScope = DataScope.of();
totalDataScope.setScopeDeptName("merchant_dept_id");
Page<HardOrderCsVo> totalPage = hardOrderMapper.pageCsByMonth(page, totalDto, totalDataScope);
@@ -264,8 +264,13 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
HardOrderDto refundDto = BeanUtil.toBean(dto, HardOrderDto.class);
refundDto.setPayTimeList(null);
refundDto.setRefundTimeList(dto.getPayTimeList());
refundDto.setAuditTimeYearStr(dto.getPayTimeYearStr());
refundDto.setPayTimeYearStr(null);
refundDto.setOrderStatusCodes(HardOrderStatusEnum.getPayErrorCodes());
refundDto.setRefundStatusCodes(List.of(HardSaleStatusEnum.COMPLETE.getStatus()));
if (ObjectUtil.isNotEmpty(dto.getMchIds())) {
refundDto.setMchIds(dto.getMchIds());
}
DataScope refundDataScope = DataScope.of();
refundDataScope.setScopeDeptName("merchant_dept_id");
List<HardOrderCsVo> refundList = hardOrderMapper.listRefundCsByMonth(refundDto, refundDataScope);
@@ -773,4 +778,180 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
result.setAllTotal(totalList);
return result;
}
/**
* 商户交易记录导出(按月)
*/
@Override
public void exportCsByMonth(HttpServletResponse response, HardOrderDto dto) {
// 查询所有有订单或者退款的店铺记录
List<Long> mchIds = new ArrayList<>();
if (ObjectUtil.isNotEmpty(mchIds)) {
mchIds = new ArrayList<>(dto.getMchIds());
}
// 查询总流水
if (ObjectUtil.isEmpty(mchIds)) {
HardSelectOrderMerchIdsDto merchQuery = new HardSelectOrderMerchIdsDto();
if (ObjectUtil.isNotEmpty(dto.getMerchantId())) {
merchQuery.setMerchIds(List.of(dto.getMerchantId()));
}
if (ObjectUtil.isNotEmpty(dto.getMchTypeCodes())) {
merchQuery.setMerchTypes(dto.getMchTypeCodes());
}
if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) {
merchQuery.setCreateTimeList(dto.getCreateTimeList());
}
if (ObjectUtil.isNotEmpty(dto.getPayTimeYearStr())) {
merchQuery.setPayTimeYearStr(dto.getPayTimeYearStr());
}
mchIds = hardOrderMapper.selectOrderMerchIds(merchQuery);
}
List<List<Long>> chuckMchIds = ListUtil.split(mchIds, 5);
List<MchManageVo> mchList = remoteMchService.getByIds(mchIds).getData();
Map<String, Object> map = new HashMap<String, Object>();
// 查询食堂
String mchName = "所有";
if (ObjectUtil.isNotEmpty(dto.getMerchantId())) {
MchManageVo mch = remoteMchService.getById(dto.getMerchantId()).getData();
if (ObjectUtil.isNotEmpty(mch)) {
mchName = mch.getName();
}
}
// 标题
// 格式-2025年浦江大饭店合作商家流水情况统计表
String title = dto.getPayTimeYearStr() + "年" + mchName + "合作商家流水情况统计表";
map.put("title", title);
// 年份
int payTimeYearint = Integer.parseInt(dto.getPayTimeYearStr());
ByteArrayOutputStream tempExcel = new ByteArrayOutputStream();
try {
ExcelWriter excelWriter = EasyExcel.write(tempExcel).withTemplate(ResourceUtil.getStream("file/商户交易金额汇总(按月).xlsx")).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
List<Map<String, Object>> excelTempMapList = new ArrayList<>();
for (int i = 0; i < mchIds.size(); i++) {
Long currentMchId = mchIds.get(i);
Map<String, Object> excelMap = new LinkedHashMap<>();
for (int j = 0; j <= 26; j++) {
String key = String.format("col%d", j);
String value = "";
if (j == 0) {
value = String.format("{col_%d.col}", currentMchId);
}
excelMap.put(key, value);
}
excelTempMapList.add(excelMap);
}
excelWriter.fill(Map.of("total", "{total.total}", "title", "{title}"), writeSheet);
excelWriter.fill(excelTempMapList, fillConfig, writeSheet);
excelWriter.finish();
} catch (Exception e) {
e.printStackTrace();
}
// 导出tempExcel用于调试
// FileUtil.writeBytes(tempExcel.toByteArray(), "/Users/dengzhangchen/Downloads/debug_hard_order_" + System.currentTimeMillis() + ".xlsx");
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(new ByteArrayInputStream(tempExcel.toByteArray())).build()) {
WriteSheet writeSheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).forceNewRow(Boolean.TRUE).build();
// 按月份总计
List<HardOrderCsVo.Month> monthTotalList = new LinkedList<>();
for (Month month : Month.values()) {
HardOrderCsVo.Month defaulMonthTotal = new HardOrderCsVo.Month();
LocalDate monthDate = LocalDate.of(payTimeYearint, month.getValue(), 1);
String monthStr = LocalDateTimeUtil.format(monthDate, DatePattern.NORM_MONTH_PATTERN);
defaulMonthTotal.setDay(monthStr);
defaulMonthTotal.setTotalProfitPrice(0);
defaulMonthTotal.setTotalProfitCount(0);
monthTotalList.add(defaulMonthTotal);
}
for (List<Long> ids : chuckMchIds) {
dto.setMchIds(ids);
Page<HardOrderCsVo> page = pageListCsByMonth(new Page(1L, 999L), dto);
List<HardOrderCsVo> records = page.getRecords();
if (ObjectUtil.isEmpty(records)) break;
for (Long id : ids) {
List<Map<String, Object>> excelMapList = new LinkedList<Map<String, Object>>();
// 先查询商户名
String currentMchName = "未知商户";
MchManageVo mchDetail = mchList.stream().filter(m -> ObjectUtil.equals(m.getId(), id)).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(mchDetail) && ObjectUtil.isNotEmpty(mchDetail.getName())) {
currentMchName = mchDetail.getName();
}
excelMapList.add(Map.of("col", currentMchName));
excelMapList.addAll(disposeCsByMonth(id, records, monthTotalList, payTimeYearint));
excelWriter.fill(new FillWrapper("col_" + id, excelMapList), fillConfig, writeSheet);
}
}
// 统计
double sumTotalPrice = 0;
long sumTimeCount = 0;
List<Map<String, Object>> excelTotalMapList = new LinkedList<Map<String, Object>>();
for (HardOrderCsVo.Month total : monthTotalList) {
excelTotalMapList.add(Map.of("total", total.getTotalProfitPrice()));
excelTotalMapList.add(Map.of("total", total.getTotalProfitCount()));
sumTotalPrice += total.getTotalProfitPrice();
sumTimeCount += total.getTotalProfitCount();
}
excelTotalMapList.add(Map.of("total", sumTotalPrice));
excelTotalMapList.add(Map.of("total", sumTimeCount));
excelWriter.fill(new FillWrapper("total", excelTotalMapList), fillConfig, writeSheet);
excelWriter.fill(map, writeSheet);
} catch (Exception e) {
e.printStackTrace();
log.error("|商户交易记录导出(按月)|以外的错误,error:{}", e.getMessage());
}
}
public List<Map<String, Object>> disposeCsByMonth(Long mchId, List<HardOrderCsVo> list, List<HardOrderCsVo.Month> monthTotalList, Integer yearStr) {
List<LocalDate> monthlyRanges = new LinkedList<>();
for (Month month : Month.values()) {
LocalDate localDate = LocalDate.of(yearStr, month.getValue(), 1);
monthlyRanges.add(localDate);
}
List<Map<String, Object>> listMap = new LinkedList<>();
List<HardOrderCsVo> sqlList = new LinkedList<>();
for (LocalDate i : monthlyRanges) {
String monthStr = LocalDateTimeUtil.format(i, DatePattern.NORM_MONTH_PATTERN);
HardOrderCsVo target = list.stream().filter(v -> ObjectUtil.equals(v.getDay(), monthStr) && ObjectUtil.equals(v.getMerchantId(), mchId)).findFirst().orElse(null);
if (ObjectUtil.isEmpty(target)) {
HardOrderCsVo defaultVo = new HardOrderCsVo();
defaultVo.setTotalProfitPrice(BigDecimal.ZERO);
defaultVo.setTotalProfitCount(BigDecimal.ZERO);
sqlList.add(defaultVo);
} else {
sqlList.add(target);
}
}
double sumTotalPrice = 0;
long sumTimeCount = 0;
for (HardOrderCsVo v : sqlList) {
BigDecimal totalProfitPrice = Optional.of(v.getTotalProfitPrice()).orElse(BigDecimal.ZERO);
BigDecimal totalProfitCount = Optional.of(v.getTotalProfitCount()).orElse(BigDecimal.ZERO);
totalProfitPrice = v.getTotalProfitPrice().divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
listMap.add(Map.of("col", totalProfitPrice.toString()));
listMap.add(Map.of("col", totalProfitCount.intValue()));
sumTotalPrice += totalProfitPrice.doubleValue();
sumTimeCount += totalProfitCount.longValue();
HardOrderCsVo.Month month = monthTotalList.stream().filter(item -> ObjectUtil.equals(item.getDay(), v.getDay())).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(month)) {
month.setTotalProfitPrice(month.getTotalProfitPrice() + totalProfitPrice.doubleValue());
month.setTotalProfitCount(month.getTotalProfitCount() + totalProfitCount.longValue());
}
}
listMap.add(Map.of("col", sumTotalPrice));
listMap.add(Map.of("col", sumTimeCount));
return listMap;
}
}
@@ -192,6 +192,9 @@
<if test="dto.payTimeList != null and dto.payTimeList.length == 2">
and a.pay_time between #{dto.payTimeList[0]} and #{dto.payTimeList[1]}
</if>
<if test="dto.payTimeYearStr != null and dto.payTimeYearStr != '' ">
and DATE_FORMAT(a.pay_time, '%Y') = #{dto.payTimeYearStr}
</if>
</sql>
<sql id="pageList">
@@ -230,13 +233,26 @@
where a.del_flag = '0'
and a.merchant_id is not null
and a.merchant_type is not null
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
<if test="dto.payTimeYearStr != null and dto.payTimeYearStr != '' ">
and DATE_FORMAT(a.pay_time, '%Y') = #{dto.payTimeYearStr}
</if>
union all
select o.merchant_id as merchantId, o.merchant_type as merchantType, a.create_time
from hard_after_sale a
left join hard_order o on o.id = a.order_id
where a.del_flag = '0'
and o.merchant_id is not null
and o.merchant_type is not null) total
and o.merchant_type is not null
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
<if test="dto.payTimeYearStr != null and dto.payTimeYearStr != '' ">
and DATE_FORMAT(a.refund_time, '%Y') = #{dto.payTimeYearStr}
</if>
) total
<where>
<if test="dto.merchIds != null and dto.merchIds.size() != 0">
and total.merchantId in
@@ -250,9 +266,6 @@
#{v}
</foreach>
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.createTime between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
</where>
</select>
@@ -414,6 +427,9 @@
<if test="dto.refundTimeList != null and dto.refundTimeList.length == 2">
and r.audit_time between #{dto.refundTimeList[0]} and #{dto.refundTimeList[1]}
</if>
<if test="dto.auditTimeYearStr != null and dto.auditTimeYearStr != '' ">
and DATE_FORMAT(r.audit_time, '%Y') = #{dto.auditTimeYearStr}
</if>
<if test="dto.refundStatusCodes != null and dto.refundStatusCodes.size() != 0">
and r.status in
<foreach collection="dto.refundStatusCodes" item="v" open="(" close=")" separator=",">