增加筛选逻辑

This commit is contained in:
MerCry 2026-03-16 19:21:54 +08:00
parent 1451698d66
commit 450c4159de
6 changed files with 95 additions and 24 deletions

View File

@ -92,6 +92,8 @@ public interface CustomerStatisticsDataV2Mapper extends BaseMapper<CustomerStati
* @param endDate 结束日期 * @param endDate 结束日期
* @param groupName 组名可选 * @param groupName 组名可选
* @param tagName 标签名可选 * @param tagName 标签名可选
* @param onlyGroup 只看分组可选
* @param onlyTag 只看标签可选
* @return 数据列表 * @return 数据列表
*/ */
List<CustomerStatisticsDataV2> selectListByFilter( List<CustomerStatisticsDataV2> selectListByFilter(
@ -99,7 +101,9 @@ public interface CustomerStatisticsDataV2Mapper extends BaseMapper<CustomerStati
@Param("startDate") Date startDate, @Param("startDate") Date startDate,
@Param("endDate") Date endDate, @Param("endDate") Date endDate,
@Param("groupName") String groupName, @Param("groupName") String groupName,
@Param("tagName") String tagName @Param("tagName") String tagName,
@Param("onlyGroup") Boolean onlyGroup,
@Param("onlyTag") Boolean onlyTag
); );
/** /**
@ -109,6 +113,8 @@ public interface CustomerStatisticsDataV2Mapper extends BaseMapper<CustomerStati
* @param endDate 结束日期 * @param endDate 结束日期
* @param groupName 组名可选 * @param groupName 组名可选
* @param tagName 标签名可选 * @param tagName 标签名可选
* @param onlyGroup 只看分组可选
* @param onlyTag 只看标签可选
* @return 聚合后的数据列表 * @return 聚合后的数据列表
*/ */
List<CustomerStatisticsDataV2> selectAggregatedByDateRange( List<CustomerStatisticsDataV2> selectAggregatedByDateRange(
@ -116,7 +122,9 @@ public interface CustomerStatisticsDataV2Mapper extends BaseMapper<CustomerStati
@Param("startDate") Date startDate, @Param("startDate") Date startDate,
@Param("endDate") Date endDate, @Param("endDate") Date endDate,
@Param("groupName") String groupName, @Param("groupName") String groupName,
@Param("tagName") String tagName @Param("tagName") String tagName,
@Param("onlyGroup") Boolean onlyGroup,
@Param("onlyTag") Boolean onlyTag
); );
/** /**
@ -124,11 +132,15 @@ public interface CustomerStatisticsDataV2Mapper extends BaseMapper<CustomerStati
* @param corpId 企业ID * @param corpId 企业ID
* @param groupName 组名可选 * @param groupName 组名可选
* @param tagName 标签名可选 * @param tagName 标签名可选
* @param onlyGroup 只看分组可选
* @param onlyTag 只看标签可选
* @return 聚合后的数据列表 * @return 聚合后的数据列表
*/ */
List<CustomerStatisticsDataV2> selectAllAggregated( List<CustomerStatisticsDataV2> selectAllAggregated(
@Param("corpId") String corpId, @Param("corpId") String corpId,
@Param("groupName") String groupName, @Param("groupName") String groupName,
@Param("tagName") String tagName @Param("tagName") String tagName,
@Param("onlyGroup") Boolean onlyGroup,
@Param("onlyTag") Boolean onlyTag
); );
} }

View File

@ -49,10 +49,13 @@ public interface ICustomerStatisticsDataV2Service {
* @param endDate 结束日期 * @param endDate 结束日期
* @param groupName 组名可选 * @param groupName 组名可选
* @param tagName 标签名可选 * @param tagName 标签名可选
* @param onlyGroup 只看分组可选
* @param onlyTag 只看标签可选
* @return 客户统计数据V2列表 * @return 客户统计数据V2列表
*/ */
List<CustomerStatisticsDataV2> selectCustomerStatisticsDataV2List( List<CustomerStatisticsDataV2> selectCustomerStatisticsDataV2List(
String corpId, Date startDate, Date endDate, String groupName, String tagName); String corpId, Date startDate, Date endDate, String groupName, String tagName,
Boolean onlyGroup, Boolean onlyTag);
/** /**
* 根据ID查询客户统计数据V2 * 根据ID查询客户统计数据V2
@ -119,10 +122,13 @@ public interface ICustomerStatisticsDataV2Service {
* @param week 周数 * @param week 周数
* @param groupName 组名可选 * @param groupName 组名可选
* @param tagName 标签名可选 * @param tagName 标签名可选
* @param onlyGroup 只看分组可选
* @param onlyTag 只看标签可选
* @return 聚合后的数据列表 * @return 聚合后的数据列表
*/ */
List<CustomerStatisticsDataV2> selectByWeekAggregation( List<CustomerStatisticsDataV2> selectByWeekAggregation(
String corpId, Integer year, Integer week, String groupName, String tagName); String corpId, Integer year, Integer week, String groupName, String tagName,
Boolean onlyGroup, Boolean onlyTag);
/** /**
* 按月聚合查询 * 按月聚合查询
@ -130,18 +136,24 @@ public interface ICustomerStatisticsDataV2Service {
* @param yearMonth 年月格式yyyy-MM * @param yearMonth 年月格式yyyy-MM
* @param groupName 组名可选 * @param groupName 组名可选
* @param tagName 标签名可选 * @param tagName 标签名可选
* @param onlyGroup 只看分组可选
* @param onlyTag 只看标签可选
* @return 聚合后的数据列表 * @return 聚合后的数据列表
*/ */
List<CustomerStatisticsDataV2> selectByMonthAggregation( List<CustomerStatisticsDataV2> selectByMonthAggregation(
String corpId, String yearMonth, String groupName, String tagName); String corpId, String yearMonth, String groupName, String tagName,
Boolean onlyGroup, Boolean onlyTag);
/** /**
* 查询所有数据的聚合 * 查询所有数据的聚合
* @param corpId 企业ID * @param corpId 企业ID
* @param groupName 组名可选 * @param groupName 组名可选
* @param tagName 标签名可选 * @param tagName 标签名可选
* @param onlyGroup 只看分组可选
* @param onlyTag 只看标签可选
* @return 聚合后的数据列表 * @return 聚合后的数据列表
*/ */
List<CustomerStatisticsDataV2> selectAllAggregation( List<CustomerStatisticsDataV2> selectAllAggregation(
String corpId, String groupName, String tagName); String corpId, String groupName, String tagName,
Boolean onlyGroup, Boolean onlyTag);
} }

View File

@ -57,8 +57,9 @@ public class CustomerStatisticsDataV2ServiceImpl implements ICustomerStatisticsD
@Override @Override
public List<CustomerStatisticsDataV2> selectCustomerStatisticsDataV2List( public List<CustomerStatisticsDataV2> selectCustomerStatisticsDataV2List(
String corpId, Date startDate, Date endDate, String groupName, String tagName) { String corpId, Date startDate, Date endDate, String groupName, String tagName,
return dataV2Mapper.selectListByFilter(corpId, startDate, endDate, groupName, tagName); Boolean onlyGroup, Boolean onlyTag) {
return dataV2Mapper.selectListByFilter(corpId, startDate, endDate, groupName, tagName, onlyGroup, onlyTag);
} }
@Override @Override
@ -323,8 +324,10 @@ public class CustomerStatisticsDataV2ServiceImpl implements ICustomerStatisticsD
@Override @Override
public List<CustomerStatisticsDataV2> selectByWeekAggregation( public List<CustomerStatisticsDataV2> selectByWeekAggregation(
String corpId, Integer year, Integer week, String groupName, String tagName) { String corpId, Integer year, Integer week, String groupName, String tagName,
log.info("周聚合查询: corpId={}, year={}, week={}, groupName={}, tagName={}", corpId, year, week, groupName, tagName); Boolean onlyGroup, Boolean onlyTag) {
log.info("周聚合查询: corpId={}, year={}, week={}, groupName={}, tagName={}, onlyGroup={}, onlyTag={}",
corpId, year, week, groupName, tagName, onlyGroup, onlyTag);
// 计算周的开始和结束日期使用与V1一致的MySQL WEEK函数逻辑 // 计算周的开始和结束日期使用与V1一致的MySQL WEEK函数逻辑
Date[] weekRange = calculateWeekRangeByMySQL(year, week); Date[] weekRange = calculateWeekRangeByMySQL(year, week);
@ -338,7 +341,7 @@ public class CustomerStatisticsDataV2ServiceImpl implements ICustomerStatisticsD
log.info("周日期范围: {} 至 {}", formatDate(startDate), formatDate(endDate)); log.info("周日期范围: {} 至 {}", formatDate(startDate), formatDate(endDate));
// 查询该周的数据并聚合 // 查询该周的数据并聚合
List<CustomerStatisticsDataV2> result = dataV2Mapper.selectAggregatedByDateRange(corpId, startDate, endDate, groupName, tagName); List<CustomerStatisticsDataV2> result = dataV2Mapper.selectAggregatedByDateRange(corpId, startDate, endDate, groupName, tagName, onlyGroup, onlyTag);
log.info("周聚合查询结果: {}条记录", result.size()); log.info("周聚合查询结果: {}条记录", result.size());
// 从原始数据表按finish_date重新查询成单数解决跨日成交问题 // 从原始数据表按finish_date重新查询成单数解决跨日成交问题
@ -365,7 +368,8 @@ public class CustomerStatisticsDataV2ServiceImpl implements ICustomerStatisticsD
@Override @Override
public List<CustomerStatisticsDataV2> selectByMonthAggregation( public List<CustomerStatisticsDataV2> selectByMonthAggregation(
String corpId, String yearMonth, String groupName, String tagName) { String corpId, String yearMonth, String groupName, String tagName,
Boolean onlyGroup, Boolean onlyTag) {
// 解析年月 // 解析年月
String[] parts = yearMonth.split("-"); String[] parts = yearMonth.split("-");
int year = Integer.parseInt(parts[0]); int year = Integer.parseInt(parts[0]);
@ -377,7 +381,7 @@ public class CustomerStatisticsDataV2ServiceImpl implements ICustomerStatisticsD
Date endDate = monthRange[1]; Date endDate = monthRange[1];
// 查询该月的数据并聚合 // 查询该月的数据并聚合
List<CustomerStatisticsDataV2> result = dataV2Mapper.selectAggregatedByDateRange(corpId, startDate, endDate, groupName, tagName); List<CustomerStatisticsDataV2> result = dataV2Mapper.selectAggregatedByDateRange(corpId, startDate, endDate, groupName, tagName, onlyGroup, onlyTag);
// 从原始数据表按finish_date重新查询成单数解决跨日成交问题 // 从原始数据表按finish_date重新查询成单数解决跨日成交问题
recalculateOrderCountFromOriginalData(corpId, startDate, endDate, result); recalculateOrderCountFromOriginalData(corpId, startDate, endDate, result);
@ -400,9 +404,10 @@ public class CustomerStatisticsDataV2ServiceImpl implements ICustomerStatisticsD
@Override @Override
public List<CustomerStatisticsDataV2> selectAllAggregation( public List<CustomerStatisticsDataV2> selectAllAggregation(
String corpId, String groupName, String tagName) { String corpId, String groupName, String tagName,
Boolean onlyGroup, Boolean onlyTag) {
// 查询所有数据并聚合 // 查询所有数据并聚合
List<CustomerStatisticsDataV2> result = dataV2Mapper.selectAllAggregated(corpId, groupName, tagName); List<CustomerStatisticsDataV2> result = dataV2Mapper.selectAllAggregated(corpId, groupName, tagName, onlyGroup, onlyTag);
// 从原始数据表按finish_date重新查询成单数解决跨日成交问题 // 从原始数据表按finish_date重新查询成单数解决跨日成交问题
// 对于全部数据不限制日期范围 // 对于全部数据不限制日期范围

View File

@ -238,6 +238,12 @@
<if test="tagName != null and tagName != ''"> <if test="tagName != null and tagName != ''">
AND tag_name = #{tagName} AND tag_name = #{tagName}
</if> </if>
<if test="onlyGroup != null and onlyGroup == true">
AND data_level = 1
</if>
<if test="onlyTag != null and onlyTag == true">
AND data_level = 2
</if>
ORDER BY cur_date DESC, data_level ASC, group_name ASC, sort_no ASC ORDER BY cur_date DESC, data_level ASC, group_name ASC, sort_no ASC
</select> </select>
@ -307,6 +313,12 @@
FROM customer_statistics_data_v2 FROM customer_statistics_data_v2
WHERE corp_id = #{corpId} WHERE corp_id = #{corpId}
<choose> <choose>
<when test="onlyTag != null and onlyTag == true">
AND data_level = 2
</when>
<when test="onlyGroup != null and onlyGroup == true">
AND data_level = 1
</when>
<when test="tagName != null and tagName != ''"> <when test="tagName != null and tagName != ''">
AND data_level = 2 AND data_level = 2
</when> </when>
@ -396,6 +408,12 @@
FROM customer_statistics_data_v2 FROM customer_statistics_data_v2
WHERE corp_id = #{corpId} WHERE corp_id = #{corpId}
<choose> <choose>
<when test="onlyTag != null and onlyTag == true">
AND data_level = 2
</when>
<when test="onlyGroup != null and onlyGroup == true">
AND data_level = 1
</when>
<when test="tagName != null and tagName != ''"> <when test="tagName != null and tagName != ''">
AND data_level = 2 AND data_level = 2
</when> </when>

View File

@ -48,29 +48,31 @@ public class CustomerStatisticsDataV2Controller extends BaseController {
@RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate, @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate, @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
@RequestParam(value = "groupName", required = false) String groupName, @RequestParam(value = "groupName", required = false) String groupName,
@RequestParam(value = "tagName", required = false) String tagName) { @RequestParam(value = "tagName", required = false) String tagName,
@RequestParam(value = "onlyGroup", required = false) Boolean onlyGroup,
@RequestParam(value = "onlyTag", required = false) Boolean onlyTag) {
String corpId = CorpContextHolder.getCurrentCorpId(); String corpId = CorpContextHolder.getCurrentCorpId();
log.info("list接口被调用: dataType={}, year={}, week={}, yearMonth={}, groupName={}, tagName={}", log.info("list接口被调用: dataType={}, year={}, week={}, yearMonth={}, groupName={}, tagName={}, onlyGroup={}, onlyTag={}",
dataType, year, week, yearMonth, groupName, tagName); dataType, year, week, yearMonth, groupName, tagName, onlyGroup, onlyTag);
List<CustomerStatisticsDataV2> list; List<CustomerStatisticsDataV2> list;
if ("week".equals(dataType)) { if ("week".equals(dataType)) {
list = customerStatisticsDataV2Service.selectByWeekAggregation(corpId, year, week, groupName, tagName); list = customerStatisticsDataV2Service.selectByWeekAggregation(corpId, year, week, groupName, tagName, onlyGroup, onlyTag);
log.info("周聚合查询结果: {}条记录", list.size()); log.info("周聚合查询结果: {}条记录", list.size());
return getDataTable(list); return getDataTable(list);
} else if ("month".equals(dataType)) { } else if ("month".equals(dataType)) {
list = customerStatisticsDataV2Service.selectByMonthAggregation(corpId, yearMonth, groupName, tagName); list = customerStatisticsDataV2Service.selectByMonthAggregation(corpId, yearMonth, groupName, tagName, onlyGroup, onlyTag);
log.info("月聚合查询结果: {}条记录", list.size()); log.info("月聚合查询结果: {}条记录", list.size());
return getDataTable(list); return getDataTable(list);
} else if ("all".equals(dataType)) { } else if ("all".equals(dataType)) {
list = customerStatisticsDataV2Service.selectAllAggregation(corpId, groupName, tagName); list = customerStatisticsDataV2Service.selectAllAggregation(corpId, groupName, tagName, onlyGroup, onlyTag);
log.info("全部数据查询结果: {}条记录", list.size()); log.info("全部数据查询结果: {}条记录", list.size());
return getDataTable(list); return getDataTable(list);
} else { } else {
startPage(); startPage();
list = customerStatisticsDataV2Service list = customerStatisticsDataV2Service
.selectCustomerStatisticsDataV2List(corpId, startDate, endDate, groupName, tagName); .selectCustomerStatisticsDataV2List(corpId, startDate, endDate, groupName, tagName, onlyGroup, onlyTag);
return getDataTable(list); return getDataTable(list);
} }
} }

View File

@ -110,6 +110,10 @@
style="width: 120px" style="width: 120px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="数据级别" prop="dataLevel">
<el-checkbox v-model="queryParams.onlyGroup" @change="handleOnlyGroupChange">只看分组</el-checkbox>
<el-checkbox v-model="queryParams.onlyTag" @change="handleOnlyTagChange">只看标签</el-checkbox>
</el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
@ -293,7 +297,9 @@ export default {
week: undefined, week: undefined,
yearMonth: undefined, yearMonth: undefined,
groupName: undefined, groupName: undefined,
tagName: undefined tagName: undefined,
onlyGroup: false,
onlyTag: false
}, },
selectedColumns: [], selectedColumns: [],
treeProps: { treeProps: {
@ -637,6 +643,20 @@ export default {
this.selectedColumns = [...DEFAULT_COLUMNS] this.selectedColumns = [...DEFAULT_COLUMNS]
this.saveColumnConfig() this.saveColumnConfig()
}, },
//
handleOnlyGroupChange(val) {
if (val) {
this.queryParams.onlyTag = false
}
this.handleQuery()
},
//
handleOnlyTagChange(val) {
if (val) {
this.queryParams.onlyGroup = false
}
this.handleQuery()
},
handleTreeNodeClick(data) { handleTreeNodeClick(data) {
// //
if (data.type === 'group') { if (data.type === 'group') {
@ -797,6 +817,8 @@ export default {
this.queryParams.dataType = 'day' this.queryParams.dataType = 'day'
this.queryParams.groupName = undefined this.queryParams.groupName = undefined
this.queryParams.tagName = undefined this.queryParams.tagName = undefined
this.queryParams.onlyGroup = false
this.queryParams.onlyTag = false
// 使 el-date-picker value-format // 使 el-date-picker value-format
this.queryParams.year = String(new Date().getFullYear()) this.queryParams.year = String(new Date().getFullYear())
this.queryParams.week = undefined this.queryParams.week = undefined