Commit aeec797c by 春觉晓

修改门店存量分析接口,商户号获取逻辑变更

1 parent c5f67c28
...@@ -59,6 +59,9 @@ public class SceneBaseReq implements Serializable { ...@@ -59,6 +59,9 @@ public class SceneBaseReq implements Serializable {
@ApiModelProperty(notes = "门店号列表") @ApiModelProperty(notes = "门店号列表")
private List<Integer> merchantIds; private List<Integer> merchantIds;
@ApiModelProperty(notes = "门店号列表")
private List<Integer> lkastmerchantIds;
@ApiModelProperty(notes = "门店号聚合") @ApiModelProperty(notes = "门店号聚合")
private Map<String, List<Integer>> merchantMap; private Map<String, List<Integer>> merchantMap;
...@@ -88,6 +91,18 @@ public class SceneBaseReq implements Serializable { ...@@ -88,6 +91,18 @@ public class SceneBaseReq implements Serializable {
private int queryType; private int queryType;
/** /**
* 权限角色
*/
private Integer role;
/**
* 大区ID
*/
private String regionId;
private List<Integer> excludeIds;
/**
* 转换指标参数 * 转换指标参数
*/ */
public DataBizQueryParamsDTO convertQueryParam() { public DataBizQueryParamsDTO convertQueryParam() {
......
...@@ -114,14 +114,16 @@ public interface BusinessIntelligenceMapper { ...@@ -114,14 +114,16 @@ public interface BusinessIntelligenceMapper {
/** /**
* 流失门店数统计-按业务类型 * 流失门店数统计-按业务类型
*/ */
Integer countLostMerchantByBizType(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate, @Param("bizType") Integer bizType); Integer countLostMerchantByBizType(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate, @Param("bizType") Integer bizType,
@Param("excludeIds") List<Integer> excludeIds);
/** /**
* 历史门店总数-二手车 * 历史门店总数-二手车
*/ */
Integer countHistoryMerchant(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate); Integer countHistoryMerchant(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate);
Integer countHistoryMerchantByBizType(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate, @Param("bizType") Integer bizType); Integer countHistoryMerchantByBizType(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate, @Param("bizType") Integer bizType,
@Param("excludeIds") List<Integer> excludeIds);
/** /**
* 查询二手车开店数量 * 查询二手车开店数量
......
...@@ -10,7 +10,9 @@ import cn.com.glsx.dj.peanalysis.dto.StoreSettingDTO; ...@@ -10,7 +10,9 @@ import cn.com.glsx.dj.peanalysis.dto.StoreSettingDTO;
import cn.com.glsx.dj.peanalysis.dto.job.BiRecord; import cn.com.glsx.dj.peanalysis.dto.job.BiRecord;
import cn.com.glsx.dj.peanalysis.dto.req.SalePotentialCustomersReq; import cn.com.glsx.dj.peanalysis.dto.req.SalePotentialCustomersReq;
import cn.com.glsx.dj.peanalysis.dto.req.output.SceneBaseReq; import cn.com.glsx.dj.peanalysis.dto.req.output.SceneBaseReq;
import cn.com.glsx.dj.peanalysis.dto.res.UserdCarDataStats.StockStoreAnalysisRes;
import cn.com.glsx.dj.peanalysis.dto.res.output.*; import cn.com.glsx.dj.peanalysis.dto.res.output.*;
import cn.com.glsx.dj.peanalysis.enums.LoginRoleEnum;
import cn.com.glsx.dj.peanalysis.mapper.*; import cn.com.glsx.dj.peanalysis.mapper.*;
import cn.com.glsx.dj.peanalysis.util.SortUtils; import cn.com.glsx.dj.peanalysis.util.SortUtils;
import cn.com.glsx.dj.peanalysis.utils.DateUtils; import cn.com.glsx.dj.peanalysis.utils.DateUtils;
...@@ -21,11 +23,13 @@ import cn.com.glsx.dj.smartcarlife.remote.MerchantOutputTargetConfigRemote; ...@@ -21,11 +23,13 @@ import cn.com.glsx.dj.smartcarlife.remote.MerchantOutputTargetConfigRemote;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination; import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.dto.merchant.CarBrandProvinceRequestDTO;
import cn.com.glsx.merchants.model.request.MerchantStaffRequest; import cn.com.glsx.merchants.model.request.MerchantStaffRequest;
import cn.com.glsx.merchants.model.response.MerchantProvinceDTO; import cn.com.glsx.merchants.model.response.MerchantProvinceDTO;
import cn.com.glsx.merchants.model.response.MerchantStaffResponse; import cn.com.glsx.merchants.model.response.MerchantStaffResponse;
import cn.com.glsx.merchants.remote.MerchantRemote; import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.com.glsx.merchants.remote.MerchantStaffRemote; import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
...@@ -40,6 +44,7 @@ import org.apache.commons.collections4.CollectionUtils; ...@@ -40,6 +44,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -101,7 +106,6 @@ public class BusinessSceneAnalysisService { ...@@ -101,7 +106,6 @@ public class BusinessSceneAnalysisService {
@Resource @Resource
private WarningMsgRemote warningMsgRemote; private WarningMsgRemote warningMsgRemote;
/** /**
* 总产值、目标产值、达成率 * 总产值、目标产值、达成率
*/ */
...@@ -308,6 +312,14 @@ public class BusinessSceneAnalysisService { ...@@ -308,6 +312,14 @@ public class BusinessSceneAnalysisService {
req.setPreEndDate(lastPeriodDates.getValue()); req.setPreEndDate(lastPeriodDates.getValue());
} }
public List<Integer> excludeWhite(List<Integer> allIds, List<Integer> excludeIds) {
if (CollectionUtils.isNotEmpty(excludeIds) && CollectionUtils.isNotEmpty(allIds)) {
return allIds.stream().filter(x -> !excludeIds.contains(x)).collect(Collectors.toList());
} else {
return allIds;
}
}
/** /**
* 存量门店分析 * 存量门店分析
*/ */
...@@ -323,11 +335,13 @@ public class BusinessSceneAnalysisService { ...@@ -323,11 +335,13 @@ public class BusinessSceneAnalysisService {
queryParams.setBrandIds(dataStatsConfig.defaultBrandId); queryParams.setBrandIds(dataStatsConfig.defaultBrandId);
queryParams.setItemCodes(DataStatsConstants.ITEM_CODE_A036); queryParams.setItemCodes(DataStatsConstants.ITEM_CODE_A036);
queryParams.setExts("merchantIds"); queryParams.setExts("merchantIds");
queryParams.setMerchantIds(StringUtils.join(req.getMerchantIds(), ",")); //queryParams.setMerchantIds(StringUtils.join(req.getMerchantIds(), ","));
List<DataBusinessDTO> trendOutputList = businessAnalysisService.getTotalOutputGroupByMerchant(queryParams); List<DataBusinessDTO> trendOutputList = businessAnalysisService.getTotalOutputGroupByMerchant(queryParams);
List<Integer> merchantIds = new ArrayList<>(); List<Integer> merchantIds = new ArrayList<>();
if (!CollectionUtils.isEmpty(trendOutputList)) { if (!CollectionUtils.isEmpty(trendOutputList)) {
merchantIds = trendOutputList.stream().map(DataBusinessDTO::getMerchantId).distinct().collect(Collectors.toList()); merchantIds = trendOutputList.stream().map(DataBusinessDTO::getMerchantId).distinct().collect(Collectors.toList());
merchantIds = excludeWhite(merchantIds, req.getExcludeIds());
//排除白名单
trendOutputList.clear(); trendOutputList.clear();
} }
//设置总开单门店数 //设置总开单门店数
...@@ -375,10 +389,10 @@ public class BusinessSceneAnalysisService { ...@@ -375,10 +389,10 @@ public class BusinessSceneAnalysisService {
BigDecimal oldStoreRatio = usedCarDataStatsService.calculateDiv(oldStoreCount, res.getTotalStores()); BigDecimal oldStoreRatio = usedCarDataStatsService.calculateDiv(oldStoreCount, res.getTotalStores());
res.setOldStoresRatio(oldStoreRatio); res.setOldStoresRatio(oldStoreRatio);
// 流失门店:以统计周期的开始日期为基准,近30天无产值且近60天存在产值的门店数 // 流失门店:以统计周期的开始日期为基准,近30天无产值且近60天存在产值的门店数
int lostStoreCount = businessIntelligenceMapper.countLostMerchantByBizType(req.getMerchantIds(), startDate, biBusinessType); int lostStoreCount = businessIntelligenceMapper.countLostMerchantByBizType(req.getMerchantIds(), startDate, biBusinessType, req.getExcludeIds());
res.setChurnedStores(lostStoreCount); res.setChurnedStores(lostStoreCount);
// 历史总门店数:以统计周期的开始日期为基准,近30-60天间存在产值的门店数; // 历史总门店数:以统计周期的开始日期为基准,近30-60天间存在产值的门店数;
int totalStoreCount = businessIntelligenceMapper.countHistoryMerchantByBizType(req.getMerchantIds(), startDate, biBusinessType); int totalStoreCount = businessIntelligenceMapper.countHistoryMerchantByBizType(req.getMerchantIds(), startDate, biBusinessType, req.getExcludeIds());
// 流失率:(流失门店/历史总门店数)*100%,保留百分比两位小数,其中历史总门店数:以统计周期的开始日期为基准,近30-60天间存在产值的门店数; // 流失率:(流失门店/历史总门店数)*100%,保留百分比两位小数,其中历史总门店数:以统计周期的开始日期为基准,近30-60天间存在产值的门店数;
if (totalStoreCount != 0) { if (totalStoreCount != 0) {
BigDecimal churnRate = usedCarDataStatsService.calculateDiv(lostStoreCount, totalStoreCount); BigDecimal churnRate = usedCarDataStatsService.calculateDiv(lostStoreCount, totalStoreCount);
...@@ -392,13 +406,14 @@ public class BusinessSceneAnalysisService { ...@@ -392,13 +406,14 @@ public class BusinessSceneAnalysisService {
List<DataBusinessDTO> preOutputList = getTotalOutputGroupByMerchant(queryParams); List<DataBusinessDTO> preOutputList = getTotalOutputGroupByMerchant(queryParams);
if (!CollectionUtils.isEmpty(preOutputList)) { if (!CollectionUtils.isEmpty(preOutputList)) {
List<Integer> preMerchantIds = preOutputList.stream().map(DataBusinessDTO::getMerchantId).distinct().collect(Collectors.toList()); List<Integer> preMerchantIds = preOutputList.stream().map(DataBusinessDTO::getMerchantId).distinct().collect(Collectors.toList());
preMerchantIds = excludeWhite(preMerchantIds, req.getExcludeIds());
preOutputList.clear(); preOutputList.clear();
//计算环比:((本周期开单门店数量-上周期开单门店数量)/上周期开单门店数量)*100% //计算环比:((本周期开单门店数量-上周期开单门店数量)/上周期开单门店数量)*100%
int preStoreCount = preMerchantIds.size(); int preStoreCount = preMerchantIds.size();
log.info("总开单门店:[{}], 上周期门店[{}]", res.getTotalStores(), preStoreCount); log.info("总开单门店:[{}], 上周期门店[{}]", res.getTotalStores(), preStoreCount);
BigDecimal countRatio = usedCarDataStatsService.calculateDiv(res.getTotalStores() - preStoreCount, preStoreCount); BigDecimal countRatio = usedCarDataStatsService.calculateDiv(res.getTotalStores() - preStoreCount, preStoreCount);
res.setTotalStoresMom(countRatio); res.setTotalStoresMom(countRatio);
log.info("计算上周期新店,开始日期[{}], 结束日期[{}], 有产值的门店[{}]", startDate, endDate, JSON.toJSONString(merchantIds)); log.info("计算上周期新店,开始日期[{}], 结束日期[{}], 有产值的门店[{}]", startDate, endDate, JSON.toJSONString(preMerchantIds));
List<BiRecord> biRecords = businessIntelligenceMapper.getBiRecords(null, preMerchantIds, req.getPreStartDate(), req.getPreEndDate()); List<BiRecord> biRecords = businessIntelligenceMapper.getBiRecords(null, preMerchantIds, req.getPreStartDate(), req.getPreEndDate());
if (!CollectionUtils.isEmpty(biRecords)) { if (!CollectionUtils.isEmpty(biRecords)) {
// 按门店分组 // 按门店分组
...@@ -433,6 +448,7 @@ public class BusinessSceneAnalysisService { ...@@ -433,6 +448,7 @@ public class BusinessSceneAnalysisService {
} }
// 兜底预警门店:触发兜底预警的门店数; // 兜底预警门店:触发兜底预警的门店数;
List<Integer> backUpStoreIds = businessIntelligenceMapper.findBackUpStores(req.getMerchantIds(), req.getBizs(), startDate, endDate); List<Integer> backUpStoreIds = businessIntelligenceMapper.findBackUpStores(req.getMerchantIds(), req.getBizs(), startDate, endDate);
backUpStoreIds = excludeWhite(backUpStoreIds, req.getExcludeIds());
res.setBottomLineWarningStoreIds(backUpStoreIds); res.setBottomLineWarningStoreIds(backUpStoreIds);
res.setBottomLineWarningStores(backUpStoreIds.size()); res.setBottomLineWarningStores(backUpStoreIds.size());
// 生态指标预警门店:触发生态指标预警的门店数,即生态指标低于1.0即属于生态指标预警; // 生态指标预警门店:触发生态指标预警的门店数,即生态指标低于1.0即属于生态指标预警;
...@@ -462,6 +478,7 @@ public class BusinessSceneAnalysisService { ...@@ -462,6 +478,7 @@ public class BusinessSceneAnalysisService {
if (CollectionUtils.isEmpty(storeIds)) { if (CollectionUtils.isEmpty(storeIds)) {
return; return;
} }
storeIds = excludeWhite(storeIds, req.getExcludeIds());
res.setEcosystemWarningStoreIds(storeIds); res.setEcosystemWarningStoreIds(storeIds);
res.setEcosystemWarningStores(storeIds.size()); res.setEcosystemWarningStores(storeIds.size());
} }
...@@ -595,6 +612,7 @@ public class BusinessSceneAnalysisService { ...@@ -595,6 +612,7 @@ public class BusinessSceneAnalysisService {
if (CollectionUtils.isEmpty(storeIds)) { if (CollectionUtils.isEmpty(storeIds)) {
return; return;
} }
storeIds = excludeWhite(storeIds, req.getExcludeIds());
res.setEcosystemWarningStoreIds(storeIds); res.setEcosystemWarningStoreIds(storeIds);
res.setEcosystemWarningStores(storeIds.size()); res.setEcosystemWarningStores(storeIds.size());
} }
......
...@@ -653,6 +653,12 @@ ...@@ -653,6 +653,12 @@
#{item} #{item}
</foreach> </foreach>
</if> </if>
<if test="excludeIds != null and excludeIds.size > 0">
and t1.merchant_id not in
<foreach item="item" index="index" collection="excludeIds" separator="," open="(" close=")">
#{item}
</foreach>
</if>
AND EXISTS ( AND EXISTS (
SELECT 1 SELECT 1
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t2 FROM dj_smartcarlife.dj_car_life_service_merchant_bi t2
...@@ -730,6 +736,12 @@ ...@@ -730,6 +736,12 @@
#{item} #{item}
</foreach> </foreach>
</if> </if>
<if test="excludeIds != null and excludeIds.size > 0">
and merchant_id not in
<foreach item="item" index="index" collection="excludeIds" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<![CDATA[ <![CDATA[
AND stat_date >= #{statDate} - INTERVAL 60 DAY AND stat_date >= #{statDate} - INTERVAL 60 DAY
AND stat_date <= #{statDate} - INTERVAL 30 DAY AND stat_date <= #{statDate} - INTERVAL 30 DAY
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 重复注释

      • 问题:SceneBaseReq.java 中新增的 lkastmerchantIds 字段的注释与 merchantIds 字段相同。
      • 影响:这可能导致混淆,不清楚两个字段的区别。
      • 建议:为 lkastmerchantIds 提供一个独特的注释,解释其用途和与其他字段的区别。
    2. 未使用的导入

      • 问题:BusinessSceneAnalysisService.java 中导入了 cn.com.glsx.dj.peanalysis.dto.res.UserdCarDataStats.StockStoreAnalysisRes; 和 cn.com.glsx.merchants.dto.merchant.CarBrandProvinceRequestDTO;,但这些类并未在代码中使用。
      • 影响:增加编译时间,潜在地引入不必要的依赖。
      • 建议:删除未使用的导入语句。
    3. 日志信息的准确性

      • 问题:在 BusinessSceneAnalysisService.java 的日志信息中,JSON.toJSONString(merchantIds) 应该改为 JSON.toJSONString(preMerchantIds)。
      • 影响:日志信息不准确,可能误导调试人员。
      • 建议:确保日志信息中的变量名称与实际使用的变量一致。
    4. 方法的可读性和可维护性

      • 问题:excludeWhite 方法虽然实现了排除功能,但是方法名不够直观。
      • 影响:其他开发者难以理解该方法的功能。
      • 建议:将方法名改为更具描述性的名称,例如 filterExcludedIds。

    评分明细

    1. 功能实现的正确性与健壮性(40分)

      • 得分:35分
      • 理由:新增字段和逻辑看起来合理,但是缺少对 excludeIds 参数的边界条件测试。
    2. 安全性与潜在风险(30分)

      • 得分:28分
      • 理由:没有明显的安全漏洞,但是缺少对 SQL 注入等潜在风险的预防措施(例如参数验证)。
    3. 是否符合最佳实践(20分)

      • 得分:16分
      • 理由:存在未使用的导入、重复注释和不够直观的方法名等问题,不符合最佳实践。
    4. 性能与资源利用效率(5分)

      • 得分:4分
      • 理由:代码逻辑合理,但是 excludeWhite 方法中使用 contains 可能导致性能问题,尤其是在 excludeIds 列表较大时。
    5. Commits信息的清晰性与准确性(5分)

      • 得分:3分
      • 理由:提交信息较为简单,未能详细描述更改的具体内容和原因。

    总分:86分

    通过以上审查,可以看出代码在功能实现方面基本正确,但在代码规范、安全性、可读性和提交信息等方面有待改进。希望开发人员能够根据建议进行相应的调整和优化。

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!