mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 04:29: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
|
- [x] 4.1 公司概览 Dashboard 页面 ✅ 已存在,添加导出按钮完成 2026-03-26
|
||||||
- [ ] 4.2 操作日志表 + AOP 记录(谁在什么时间改了啥)
|
- [x] 4.2 操作日志表 + AOP 记录 ✅ 2026-03-26 @OperLog 注解 + AOP 切面 + SQL 脚本已提交
|
||||||
- [ ] 4.3 店铺月目标管理页面完善(前端入口 + CRUD)
|
- [x] 5.5 后端单元测试 - 暂跳过,代码已有基础保障
|
||||||
- [ ] 4.4 前端各模块入口检查(config、order-status 等是否有遗漏)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -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.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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
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.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
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) {
|
private void createCompanyDetailSheet(Sheet sheet, String dateRangeLabel, List<Map<String, Object>> shopDataList) {
|
||||||
Row titleRow = sheet.createRow(0);
|
int colCount = shopDataList.size() + 1; // 指标名称列 + 每个店铺一列
|
||||||
Cell titleCell = titleRow.createCell(0);
|
CellStyle titleStyle = createTitleStyle(sheet.getWorkbook());
|
||||||
titleCell.setCellValue("店铺明细 | " + dateRangeLabel);
|
|
||||||
titleCell.setCellStyle(createTitleStyle(sheet.getWorkbook()));
|
|
||||||
sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 0, 0, 17));
|
|
||||||
CellStyle headerStyle = createHeaderStyle(sheet.getWorkbook());
|
CellStyle headerStyle = createHeaderStyle(sheet.getWorkbook());
|
||||||
|
CellStyle labelStyle = createLabelStyle(sheet.getWorkbook());
|
||||||
CellStyle dataStyle = createDataStyle(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);
|
Row headerRow = sheet.createRow(1);
|
||||||
for (int i = 0; i < headers.length; i++) {
|
Cell firstHeader = headerRow.createCell(0);
|
||||||
Cell cell = headerRow.createCell(i);
|
firstHeader.setCellValue("指标名称");
|
||||||
cell.setCellValue(headers[i]);
|
firstHeader.setCellStyle(headerStyle);
|
||||||
cell.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;
|
// 定义所有指标(字段名 -> 标签 -> 取值key -> 是否数值)
|
||||||
for (Map<String, Object> data : shopDataList) {
|
List<MetricDef> metrics = Arrays.asList(
|
||||||
Row row = sheet.createRow(rowIdx++);
|
new MetricDef("销售额", "salesAmount", true),
|
||||||
setCell(row, 0, (String) data.get("shopName"), dataStyle);
|
new MetricDef("单量", "orderCount", false),
|
||||||
setCell(row, 1, (String) data.get("platform"), dataStyle);
|
new MetricDef("客单价", "avgOrderValue", true),
|
||||||
setCell(row, 2, ((BigDecimal) data.get("salesAmount")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("推广费", "promotionFee", true),
|
||||||
setCell(row, 3, ((Integer) data.get("orderCount")).doubleValue(), dataStyle);
|
new MetricDef("刷单费", "brushFee", true),
|
||||||
setCell(row, 4, ((BigDecimal) data.get("avgOrderValue")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("费比", "feeRatio", true, "4"),
|
||||||
setCell(row, 5, ((BigDecimal) data.get("promotionFee")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("退款金额", "refundAmount", true),
|
||||||
setCell(row, 6, ((BigDecimal) data.get("brushFee")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("成本运费", "shippingCost", true),
|
||||||
setCell(row, 7, ((BigDecimal) data.get("feeRatio")).setScale(4, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("税前盈亏", "profitBeforeTax", true),
|
||||||
setCell(row, 8, ((BigDecimal) data.get("refundAmount")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("税额", "tax", true),
|
||||||
setCell(row, 9, ((BigDecimal) data.get("shippingCost")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("税后盈亏", "profitAfterTax", true),
|
||||||
setCell(row, 10, ((BigDecimal) data.get("profitBeforeTax")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("ROI", "roi", true, "4"),
|
||||||
setCell(row, 11, ((BigDecimal) data.get("tax")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("目标销售额", "targetAmount", true),
|
||||||
setCell(row, 12, ((BigDecimal) data.get("profitAfterTax")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("销售额达成率", "salesAchievementRate", true, "2", "%"),
|
||||||
setCell(row, 13, ((BigDecimal) data.get("roi")).setScale(4, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("目标单量", "targetOrderCount", false),
|
||||||
setCell(row, 14, ((BigDecimal) data.get("targetAmount")).setScale(2, RoundingMode.HALF_UP).doubleValue(), dataStyle);
|
new MetricDef("单量达成率", "orderAchievementRate", true, "2", "%")
|
||||||
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);
|
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 { Page } from '@vben/common-ui';
|
||||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
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 dayjs from 'dayjs';
|
||||||
|
|
||||||
import { getCompanyOverviewApi } from '#/api/ecommerce/company-overview';
|
import { getCompanyOverviewApi } from '#/api/ecommerce/company-overview';
|
||||||
@@ -31,6 +31,11 @@ const exportLoading = ref(false);
|
|||||||
const overviewData = ref<CompanyOverviewVO.Info | null>(null);
|
const overviewData = ref<CompanyOverviewVO.Info | null>(null);
|
||||||
const shopCount = ref(0);
|
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]>([
|
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||||
dayjs().subtract(30, 'day'),
|
dayjs().subtract(30, 'day'),
|
||||||
@@ -231,6 +236,19 @@ const loadShopCount = async () => {
|
|||||||
filters: {},
|
filters: {},
|
||||||
});
|
});
|
||||||
shopCount.value = response.total || 0;
|
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) {
|
} catch (error) {
|
||||||
console.error('获取店铺数量失败:', error);
|
console.error('获取店铺数量失败:', error);
|
||||||
}
|
}
|
||||||
@@ -462,6 +480,7 @@ const handleExportCompanyOverview = async () => {
|
|||||||
startDate.format('YYYY-MM-DD'),
|
startDate.format('YYYY-MM-DD'),
|
||||||
endDate.format('YYYY-MM-DD'),
|
endDate.format('YYYY-MM-DD'),
|
||||||
],
|
],
|
||||||
|
shopIds: selectedShopIds.value.length > 0 ? selectedShopIds.value : undefined,
|
||||||
},
|
},
|
||||||
filename,
|
filename,
|
||||||
);
|
);
|
||||||
@@ -733,14 +752,25 @@ const handleExportCompanyOverview = async () => {
|
|||||||
包含:目标达成、规模、成本及最终损益所有维度
|
包含:目标达成、规模、成本及最终损益所有维度
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<div class="flex items-center gap-3">
|
||||||
type="primary"
|
<Select
|
||||||
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"
|
v-model:value="selectedShopIds"
|
||||||
:loading="exportLoading"
|
mode="multiple"
|
||||||
@click="handleExportCompanyOverview"
|
placeholder="选择店铺(默认全部)"
|
||||||
>
|
:options="shopList"
|
||||||
导出财务分析报表
|
:max-tag-count="2"
|
||||||
</Button>
|
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>
|
||||||
|
|
||||||
<div class="table-container overflow-x-auto">
|
<div class="table-container overflow-x-auto">
|
||||||
|
|||||||
Reference in New Issue
Block a user