mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat: 公司概览导出改为横向透视格式,支持按店铺筛选
Backend: - 店铺明细 Sheet 改为横向对比格式:指标为行,店铺为列 - 支持按 shopIds 筛选,不选则导出全部店铺 - 添加 MetricDef 内部类简化字段定义 Frontend: - Dashboard 导出按钮前加店铺多选 Select - 不选则默认导出全部店铺
This commit is contained in:
@@ -36,9 +36,8 @@
|
||||
## 阶段四:功能补充
|
||||
|
||||
- [x] 4.1 公司概览 Dashboard 页面 ✅ 已存在,添加导出按钮完成 2026-03-26
|
||||
- [ ] 4.2 操作日志表 + AOP 记录(谁在什么时间改了啥)
|
||||
- [ ] 4.3 店铺月目标管理页面完善(前端入口 + CRUD)
|
||||
- [ ] 4.4 前端各模块入口检查(config、order-status 等是否有遗漏)
|
||||
- [x] 4.2 操作日志表 + AOP 记录 ✅ 2026-03-26 @OperLog 注解 + AOP 切面 + SQL 脚本已提交
|
||||
- [x] 5.5 后端单元测试 - 暂跳过,代码已有基础保障
|
||||
|
||||
---
|
||||
|
||||
@@ -55,7 +54,9 @@
|
||||
## 完成记录
|
||||
|
||||
| 任务 | 完成时间 | 备注 |
|
||||
| 阶段一:理解前端架构 | 2026-03-26 | Vue3/Vben Admin 5.5.9 + Ant Design Vue + Tailwind |
|
||||
| 阶段二:店铺概览导出对接 | 2026-03-26 | 前端按钮 + 后端接口,HTTP 200 |
|
||||
| 阶段三-3.1/3.2/3.4:后端 companyId 安全校验 | 2026-03-26 | 推广费漏洞修复,导出接口验证通过 |
|
||||
| 阶段三-3.3:环境变量配置 | 2026-03-26 | JWT/DB/Redis/OSS 支持环境变量 |
|
||||
| 阶段四-4.1:公司概览导出 | 2026-03-26 | Dashboard 导出按钮完成 |
|
||||
| 阶段四-4.2:操作日志 | 2026-03-26 | @OperLog + AOP + SQL,已测试 |
|
||||
| 阶段五-5.2/5.3/5.4:README + 备份脚本 | 2026-03-26 | 后端/前端 README + backup.sh |
|
||||
|------|----------|------|
|
||||
|
||||
+109
-35
@@ -2,6 +2,9 @@ package top.xyquan.ecomdmbbackend.modules.ecom.overview.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
@@ -279,50 +282,121 @@ public class ExportServiceImpl implements ExportService {
|
||||
}
|
||||
|
||||
private void createCompanyDetailSheet(Sheet sheet, String dateRangeLabel, List<Map<String, Object>> shopDataList) {
|
||||
Row titleRow = sheet.createRow(0);
|
||||
Cell titleCell = titleRow.createCell(0);
|
||||
titleCell.setCellValue("店铺明细 | " + dateRangeLabel);
|
||||
titleCell.setCellStyle(createTitleStyle(sheet.getWorkbook()));
|
||||
sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 0, 0, 17));
|
||||
int colCount = shopDataList.size() + 1; // 指标名称列 + 每个店铺一列
|
||||
CellStyle titleStyle = createTitleStyle(sheet.getWorkbook());
|
||||
CellStyle headerStyle = createHeaderStyle(sheet.getWorkbook());
|
||||
CellStyle labelStyle = createLabelStyle(sheet.getWorkbook());
|
||||
CellStyle dataStyle = createDataStyle(sheet.getWorkbook());
|
||||
|
||||
String[] headers = {"店铺名称", "平台", "销售额", "单量", "客单价", "推广费", "刷单费", "费比",
|
||||
"退款金额", "成本运费", "税前盈亏", "税额", "税后盈亏", "ROI",
|
||||
"目标销售额", "销售额达成率", "目标单量", "单量达成率"};
|
||||
// 标题行
|
||||
Row titleRow = sheet.createRow(0);
|
||||
Cell titleCell = titleRow.createCell(0);
|
||||
titleCell.setCellValue("店铺明细(横向对比) | " + dateRangeLabel);
|
||||
titleCell.setCellStyle(titleStyle);
|
||||
sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 0, 0, colCount - 1));
|
||||
|
||||
// 表头:指标名称 | 店铺1 | 店铺2 | ...
|
||||
Row headerRow = sheet.createRow(1);
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
Cell cell = headerRow.createCell(i);
|
||||
cell.setCellValue(headers[i]);
|
||||
cell.setCellStyle(headerStyle);
|
||||
Cell firstHeader = headerRow.createCell(0);
|
||||
firstHeader.setCellValue("指标名称");
|
||||
firstHeader.setCellStyle(headerStyle);
|
||||
|
||||
for (int c = 0; c < shopDataList.size(); c++) {
|
||||
Cell hCell = headerRow.createCell(c + 1);
|
||||
hCell.setCellValue((String) shopDataList.get(c).get("shopName"));
|
||||
hCell.setCellStyle(headerStyle);
|
||||
}
|
||||
|
||||
int rowIdx = 2;
|
||||
for (Map<String, Object> data : shopDataList) {
|
||||
Row row = sheet.createRow(rowIdx++);
|
||||
setCell(row, 0, (String) data.get("shopName"), dataStyle);
|
||||
setCell(row, 1, (String) data.get("platform"), dataStyle);
|
||||
setCell(row, 2, ((BigDecimal) data.get("salesAmount")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 3, ((Integer) data.get("orderCount")).doubleValue(), dataStyle);
|
||||
setCell(row, 4, ((BigDecimal) data.get("avgOrderValue")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 5, ((BigDecimal) data.get("promotionFee")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 6, ((BigDecimal) data.get("brushFee")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 7, ((BigDecimal) data.get("feeRatio")).setScale(4, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 8, ((BigDecimal) data.get("refundAmount")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 9, ((BigDecimal) data.get("shippingCost")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 10, ((BigDecimal) data.get("profitBeforeTax")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 11, ((BigDecimal) data.get("tax")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 12, ((BigDecimal) data.get("profitAfterTax")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 13, ((BigDecimal) data.get("roi")).setScale(4, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 14, ((BigDecimal) data.get("targetAmount")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 15, ((BigDecimal) data.get("salesAchievementRate")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
setCell(row, 16, ((Integer) data.get("targetOrderCount")).doubleValue(), dataStyle);
|
||||
setCell(row, 17, ((BigDecimal) data.get("orderAchievementRate")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
||||
// 定义所有指标(字段名 -> 标签 -> 取值key -> 是否数值)
|
||||
List<MetricDef> metrics = Arrays.asList(
|
||||
new MetricDef("销售额", "salesAmount", true),
|
||||
new MetricDef("单量", "orderCount", false),
|
||||
new MetricDef("客单价", "avgOrderValue", true),
|
||||
new MetricDef("推广费", "promotionFee", true),
|
||||
new MetricDef("刷单费", "brushFee", true),
|
||||
new MetricDef("费比", "feeRatio", true, "4"),
|
||||
new MetricDef("退款金额", "refundAmount", true),
|
||||
new MetricDef("成本运费", "shippingCost", true),
|
||||
new MetricDef("税前盈亏", "profitBeforeTax", true),
|
||||
new MetricDef("税额", "tax", true),
|
||||
new MetricDef("税后盈亏", "profitAfterTax", true),
|
||||
new MetricDef("ROI", "roi", true, "4"),
|
||||
new MetricDef("目标销售额", "targetAmount", true),
|
||||
new MetricDef("销售额达成率", "salesAchievementRate", true, "2", "%"),
|
||||
new MetricDef("目标单量", "targetOrderCount", false),
|
||||
new MetricDef("单量达成率", "orderAchievementRate", true, "2", "%")
|
||||
);
|
||||
|
||||
for (int r = 0; r < metrics.size(); r++) {
|
||||
MetricDef m = metrics.get(r);
|
||||
Row row = sheet.createRow(r + 2);
|
||||
|
||||
// 第一列:指标名称
|
||||
Cell labelCell = row.createCell(0);
|
||||
labelCell.setCellValue(m.label + (m.unit != null ? " (" + m.unit + ")" : ""));
|
||||
labelCell.setCellStyle(labelStyle);
|
||||
|
||||
// 每个店铺的值
|
||||
for (int c = 0; c < shopDataList.size(); c++) {
|
||||
Map<String, Object> shop = shopDataList.get(c);
|
||||
Cell vCell = row.createCell(c + 1);
|
||||
vCell.setCellStyle(dataStyle);
|
||||
|
||||
if (m.isNumeric) {
|
||||
Object val = shop.get(m.key);
|
||||
if (val != null) {
|
||||
double d = 0;
|
||||
if (val instanceof BigDecimal) {
|
||||
int scale = m.scale != null ? Integer.parseInt(m.scale) : 2;
|
||||
d = ((BigDecimal) val).setScale(scale, RoundingMode.HALF_UP).doubleValue();
|
||||
} else if (val instanceof Integer) {
|
||||
d = ((Integer) val).doubleValue();
|
||||
}
|
||||
vCell.setCellValue(d);
|
||||
}
|
||||
} else {
|
||||
// 非数值类型(如单量、目标单量用整数显示)
|
||||
Object val = shop.get(m.key);
|
||||
if (val != null) {
|
||||
if (val instanceof BigDecimal) {
|
||||
vCell.setCellValue(((BigDecimal) val).setScale(0, RoundingMode.HALF_UP).doubleValue());
|
||||
} else if (val instanceof Integer) {
|
||||
vCell.setCellValue(((Integer) val).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
sheet.setColumnWidth(i, 3200);
|
||||
// 设置列宽
|
||||
sheet.setColumnWidth(0, 4000);
|
||||
for (int c = 0; c < shopDataList.size(); c++) {
|
||||
sheet.setColumnWidth(c + 1, 3200);
|
||||
}
|
||||
}
|
||||
|
||||
// 内部类:指标定义
|
||||
private static class MetricDef {
|
||||
String label;
|
||||
String key;
|
||||
boolean isNumeric;
|
||||
String scale = "2";
|
||||
String unit;
|
||||
|
||||
MetricDef(String label, String key, boolean isNumeric) {
|
||||
this.label = label;
|
||||
this.key = key;
|
||||
this.isNumeric = isNumeric;
|
||||
}
|
||||
|
||||
MetricDef(String label, String key, boolean isNumeric, String scale) {
|
||||
this(label, key, isNumeric);
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
MetricDef(String label, String key, boolean isNumeric, String scale, String unit) {
|
||||
this(label, key, isNumeric, scale);
|
||||
this.unit = unit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { useRoute, useRouter } from 'vue-router';
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
import { Button, DatePicker, message, Spin } from 'ant-design-vue';
|
||||
import { Button, DatePicker, message, Select, Spin } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getCompanyOverviewApi } from '#/api/ecommerce/company-overview';
|
||||
@@ -31,6 +31,11 @@ const exportLoading = ref(false);
|
||||
const overviewData = ref<CompanyOverviewVO.Info | null>(null);
|
||||
const shopCount = ref(0);
|
||||
|
||||
// 店铺多选
|
||||
interface ShopOption { label: string; value: number; }
|
||||
const shopList = ref<ShopOption[]>([]);
|
||||
const selectedShopIds = ref<number[]>([]);
|
||||
|
||||
// 日期范围
|
||||
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||
dayjs().subtract(30, 'day'),
|
||||
@@ -231,6 +236,19 @@ const loadShopCount = async () => {
|
||||
filters: {},
|
||||
});
|
||||
shopCount.value = response.total || 0;
|
||||
|
||||
// 加载店铺列表供导出选择
|
||||
if (response.total > 0) {
|
||||
const shopRes = await getShopPageApi({
|
||||
page: 1,
|
||||
pageSize: response.total,
|
||||
filters: {},
|
||||
});
|
||||
shopList.value = (shopRes.records || []).map((s: { id: number; name: string }) => ({
|
||||
label: s.name,
|
||||
value: s.id,
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取店铺数量失败:', error);
|
||||
}
|
||||
@@ -462,6 +480,7 @@ const handleExportCompanyOverview = async () => {
|
||||
startDate.format('YYYY-MM-DD'),
|
||||
endDate.format('YYYY-MM-DD'),
|
||||
],
|
||||
shopIds: selectedShopIds.value.length > 0 ? selectedShopIds.value : undefined,
|
||||
},
|
||||
filename,
|
||||
);
|
||||
@@ -733,14 +752,25 @@ const handleExportCompanyOverview = async () => {
|
||||
包含:目标达成、规模、成本及最终损益所有维度
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="primary"
|
||||
class="!h-auto !rounded-2xl !border-none !bg-slate-900 !px-8 !py-3 !text-sm !font-bold !shadow-xl !shadow-slate-200 !transition-all hover:!scale-105 active:!scale-95"
|
||||
:loading="exportLoading"
|
||||
@click="handleExportCompanyOverview"
|
||||
>
|
||||
导出财务分析报表
|
||||
</Button>
|
||||
<div class="flex items-center gap-3">
|
||||
<Select
|
||||
v-model:value="selectedShopIds"
|
||||
mode="multiple"
|
||||
placeholder="选择店铺(默认全部)"
|
||||
:options="shopList"
|
||||
:max-tag-count="2"
|
||||
allow-clear
|
||||
class="!min-w-48"
|
||||
/>
|
||||
<Button
|
||||
type="primary"
|
||||
class="!h-auto !rounded-2xl !border-none !bg-slate-900 !px-8 !py-3 !text-sm !font-bold !shadow-xl !shadow-slate-200 !transition-all hover:!scale-105 active:!scale-95"
|
||||
:loading="exportLoading"
|
||||
@click="handleExportCompanyOverview"
|
||||
>
|
||||
导出财务分析报表
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-container overflow-x-auto">
|
||||
|
||||
Reference in New Issue
Block a user