Commit 20091750 by 林永健

refactor(business-analysis): 重构经营分析相关接口并迁移业务逻辑

- 从 BusinessAnalysisController 移除所有空实现的延保/权益/轻改业务接口
- 新增 BusinessSceneAnalysisController 实现业务接口及完整逻辑,确保接口方法返回非空
- 新增 SceneBaseRequest 请求类,替代旧的 SceneOutputRequest,增强请求参数设计
- 新增并使用 SceneBaseReq 作为 RPC 层请求参数,统一内外部请求转换
- rpc-dj-pe-analysis 模块新增业务逻辑实现,完成总产值、目标产值与达成率计算
- 调整 SmartCarLifeDubboConfig,更新远程调用配置类名以匹配修改
- DateUtils 工具类新增 getStartDateByCycleType 方法,辅助周期偏移时间计算
- 优化 RPC 远程调用异常捕获,提升接口稳定性和错误日志记录
- 移除重复及无用的 DTO 类 SceneOutputReq,降低代码冗余
- 完善员工分析响应描述,修正 ApiModel 注解内容
- 规范各接口的 Swagger 注解,确保文档正确描述业务视角与功能场景
1 parent c939d86b
...@@ -146,85 +146,6 @@ public class BusinessAnalysisController { ...@@ -146,85 +146,6 @@ public class BusinessAnalysisController {
return RopResponse.success(null); return RopResponse.success(null);
} }
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-总产值、目标产值、达成率")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.output.scene", needInSession = NeedInSessionType.YES)
public RopResponse<SceneOutputResponse> sceneOutput(SceneOutputRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-产值趋势及达成率")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.output.trend.scene", needInSession = NeedInSessionType.YES)
public RopResponse<TrendOutputResponse> trendOutput(SceneOutputRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-存量门店分析")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.output.store.scene", needInSession = NeedInSessionType.YES)
public RopResponse<StoreSceneSummaryResponse> storeSummary(SceneOutputRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-流量概况")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.traffic.summary.scene", needInSession = NeedInSessionType.YES)
public RopResponse<TrafficSummaryResponse> trafficSummary(SceneOutputRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-区域分布")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.regional distribution", needInSession = NeedInSessionType.YES)
public RopResponse<List<RegionalDistributionResponse>> regionalDistribution(SceneOutputRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-新拓门店分析")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.store.new.summary.scene", needInSession = NeedInSessionType.YES)
public RopResponse<NewStoreAnalysisResponse> newStoreSummary(SceneOutputRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-触客率分析")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.touch.rate.scene", needInSession = NeedInSessionType.YES)
public RopResponse<List<ContactRateAnalysisResponse>> touchRateSummary(SceneOutputRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-门店列表均值")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.store.avg.list", needInSession = NeedInSessionType.YES)
public RopResponse<StoreAvgResponse> storeAvgList(SceneOutputRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-门店列表")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.store.list", needInSession = NeedInSessionType.YES)
public RopResponse<List<StoreListResponse>> storeList(SceneOutputRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-门店分析")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.store.detail.summary", needInSession = NeedInSessionType.YES)
public RopResponse<StoreDetailSummaryResponse> storeDetailSummary(SceneStoreRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-员工排行")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.store.employee.rank", needInSession = NeedInSessionType.YES)
public RopResponse<StoreEmployeeRankResponse> storeEmployeeRank(SceneStoreRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-流量贡献排行")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.store.traffic.rank", needInSession = NeedInSessionType.YES)
public RopResponse<TrafficContributionRankResponse> storeTrafficRank(SceneStoreRequest request) {
return RopResponse.success(null);
}
@ApiOperation("总部视角/区域运营、销售视角----延保/权益/轻改-员工分析")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.store.employee.summary", needInSession = NeedInSessionType.YES)
public RopResponse<EmployeeDetailSummaryResponse> storeEmployeeSummary(SceneStoreRequest request) {
return RopResponse.success(null);
}
@ApiOperation("区域运营/销售视角----全业务-个人总览-总产值、毛利率") @ApiOperation("区域运营/销售视角----全业务-个人总览-总产值、毛利率")
@ServiceMethod(method = "dj.api.smartcarlife.business.analysis.output.personal", needInSession = NeedInSessionType.YES) @ServiceMethod(method = "dj.api.smartcarlife.business.analysis.output.personal", needInSession = NeedInSessionType.YES)
public RopResponse<List<RegionOutputResponse>> personalOutput(RegionalOutputRequest request) { public RopResponse<List<RegionOutputResponse>> personalOutput(RegionalOutputRequest request) {
......
...@@ -36,11 +36,17 @@ public class MerchantIdPermissionRequest implements Serializable{ ...@@ -36,11 +36,17 @@ public class MerchantIdPermissionRequest implements Serializable{
//周期类型-- 4.自定义 //周期类型-- 4.自定义
@ApiModelProperty(hidden = true) @ApiModelProperty(hidden = true)
public static final int CYCLE_TYPE_CUSTOMIZE = 4; public static final int CYCLE_TYPE_CUSTOMIZE = 4;
//周期类型-- 5.按年
@ApiModelProperty(hidden = true)
public static final int CYCLE_TYPE_YEAR = 5;
@Builder.Default @Builder.Default
@ApiModelProperty(notes = "业务场景(0.会员权益,1.精品升级),必须,默认会员权益") @ApiModelProperty(notes = "业务场景(0.会员权益,1.精品升级),必须,默认会员权益")
private Byte sceneType = SceneTypeEnum.SCENE1_0.getValue(); private Byte sceneType = SceneTypeEnum.SCENE1_0.getValue();
@ApiModelProperty(notes = "周期类型(1.按天,2.按周,3.按月,4.自定义),必须", required = true) @ApiModelProperty(notes = "业务类型(1:全业务;2:延保;3:权益;4:轻改;5:二手车)")
private Integer bizs;
@ApiModelProperty(notes = "周期类型(1.按天,2.按周,3.按月,4.自定义,5.按年),必须", required = true)
private Integer cycleType; private Integer cycleType;
@ApiModelProperty(notes = "当前周期内的任一时间(格式 yyyy-MM-dd/yyyy-MM-dd HH:mm:ss均可),如果为自定义类型则为开始时间(格式yyyy-MM-dd HH:mm:ss)必须", required = true) @ApiModelProperty(notes = "当前周期内的任一时间(格式 yyyy-MM-dd/yyyy-MM-dd HH:mm:ss均可),如果为自定义类型则为开始时间(格式yyyy-MM-dd HH:mm:ss)必须", required = true)
......
package cn.com.glsx.dj.request.output;
import cn.com.glsx.dj.request.MerchantIdPermissionRequest;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class SceneBaseRequest extends AbstractRopRequest implements Serializable {
private static final long serialVersionUID = -1;
@ApiModelProperty(notes = "门店过滤条件")
private MerchantIdPermissionRequest merchantFilter;
@ApiModelProperty(notes = "排序:1-产值(默认),2-客单价,3-转化率")
private Integer sortType;
@ApiModelProperty(notes = "排序:1-降序(默认),2-升序")
private Integer orderBy;
@ApiModelProperty(notes = "门店号列表")
private List<Integer> merchantIds;
@ApiModelProperty(notes = "员工编号列表")
private List<String> staffUuids;
@ApiModelProperty(notes = "模糊搜索")
private String search;
/**
* 转换周期传参,适配指标传参
*
* permissionRequest.cycleType:request筛选参数:1.按天,2.按周,3.按月,4.自定义
* queryParams.dataType:指标参数:0,按指定时段;1,按周;2,按月;3,按年;4,全部
*/
@JsonIgnoreProperties
public Integer convertQueryParamCycleType(Integer cycleType) {
switch (cycleType) {
case 1:
case 4:
return 0;
case 2:
return 1;
case 3:
return 2;
case 5:
return 3;
default:
throw new RpcServiceException("不支持的周期类型");
}
}
}
package cn.com.glsx.dj.request.output;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@Data
public class SceneOutputRequest extends AbstractRopRequest implements Serializable {
private static final long serialVersionUID = -1;
/**
* 业务类型 「全业务」「延保」「权益」「轻改」「二手车」
*/
@ApiModelProperty(notes = "业务类型(1:全业务;2:延保;3:权益;4:轻改;5:二手车)")
@NotNull
private Integer businessType;
/**
* 1-天 2-周 3-月 4-自定义
*/
@ApiModelProperty(notes = "1-天 2-周 3-月 4-自定义")
@NotNull
private Integer cycleType;
/**
* 开始时间
*/
@ApiModelProperty(notes = "开始时间")
@NotNull
private String startTime;
/**
* 结束时间
*/
@ApiModelProperty(notes = "结束时间")
@NotNull
private String endTime;
/**
* 品牌筛选 选择一级主营品牌
*/
@ApiModelProperty(notes = "品牌筛选 选择一级主营品牌")
private Integer brandId;
/**
* 省份筛选
*/
@ApiModelProperty(notes = "省份筛选")
private String provinceId;
}
...@@ -621,4 +621,44 @@ public class DateUtils extends cn.com.glsx.framework.core.util.DateUtils { ...@@ -621,4 +621,44 @@ public class DateUtils extends cn.com.glsx.framework.core.util.DateUtils {
LocalDateTime localDateTime = date.atTime(23, 59, 59); LocalDateTime localDateTime = date.atTime(23, 59, 59);
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
} }
/**
* 根据cycleType偏移周期和endDate,计算出开始时间
* 如cycleType为按周统计时,开始时间应该是endDate的8周前
*
* @param cycleType 周期类型:1-天 2-周 3-月 4-自定义
* @param endDate 结束日期
* @param offset 偏移周期数
* @return 计算后的开始日期
*/
public static Date getStartDateByCycleType(Integer cycleType, Date endDate, int offset) {
if (cycleType == null || endDate == null || offset <= 0) {
throw new IllegalArgumentException("参数不能为空且偏移量必须大于0");
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(endDate);
switch (cycleType) {
case 1: // 按天
calendar.add(Calendar.DAY_OF_YEAR, offset);
break;
case 2: // 按周(一周7天)
calendar.add(Calendar.WEEK_OF_YEAR, offset);
break;
case 3: // 按月
calendar.add(Calendar.MONTH, offset);
break;
case 4: // 自定义,默认按天处理
calendar.add(Calendar.DAY_OF_YEAR, offset);
break;
case 5: // 按年
calendar.add(Calendar.YEAR, offset);
break;
default:
throw new IllegalArgumentException("不支持的周期类型: " + cycleType);
}
return calendar.getTime();
}
} }
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 未完全实现的方法

    问题描述: 在 BusinessSceneAnalysisController 中,许多方法仍然返回 null 或未实现具体逻辑,例如 trafficSummary, regionalDistribution, newStoreSummary, touchRateSummary, storeAvgList, storeList, storeDetailSummary, storeEmployeeRank, storeTrafficRank, 和 storeEmployeeSummary。 影响: 这些接口在实际调用时将无法提供预期的数据,导致客户端无法正常工作。 优化建议: 完成这些方法的具体逻辑实现,确保它们能够正确地调用相应的服务并返回数据。

    2. 硬编码的字符串

    问题描述: 在 convertQueryParamCycleType 方法中,存在硬编码的字符串映射,这可能导致难以维护和扩展。 影响: 如果需要增加新的周期类型,需要手动修改代码。 优化建议: 使用枚举类型来替代硬编码的字符串映射,这样可以提高代码的可读性和可维护性。

    3. 异常处理

    问题描述: 在 sceneOutput 和 trendOutput 方法中,捕获了所有异常并返回异常信息。虽然有日志记录,但如果抛出的是业务异常,可能会暴露敏感信息。 影响: 可能会泄露敏感信息给客户端。 优化建议: 区分业务异常和系统异常,对于业务异常返回友好的错误信息,而对于系统异常返回通用的错误信息,并记录详细的日志。

    4. 日志记录

    问题描述: 在 sceneOutput 和 trendOutput 方法中,日志记录仅使用了 log.error("接口异常", e);,没有包含更多的上下文信息。 影响: 日志信息不够详细,不利于排查问题。 优化建议: 增加更多的上下文信息到日志中,例如请求参数、用户信息等。

    5. API 文档

    问题描述: 在 BusinessSceneAnalysisController 中,一些接口的 API 文档描述不够详细。 影响: 客户端开发者可能不清楚接口的具体用途和参数要求。 优化建议: 详细描述每个接口的功能、参数、返回结果和可能的错误码。

    评分明细

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

      • 问题:多个方法未实现具体逻辑,返回 null。
      • 评分:10/40
    2. 安全性与潜在风险(30分)

      • 问题:异常处理不当,可能泄露敏感信息;日志记录不够详细。
      • 评分:15/30
    3. 是否符合最佳实践(20分)

      • 问题:硬编码的字符串映射;API 文档描述不够详细。
      • 评分:10/20
    4. 性能与资源利用效率(5分)

      • 问题:暂未发现明显性能问题。
      • 评分:5/5
    5. Commits信息的清晰性与准确性(5分)

      • 问题:提交信息清晰、准确。
      • 评分:5/5

    总分

    总分: 45分


    希望这些建议能够帮助改进代码的质量和稳定性。如有任何疑问或需要进一步讨论的地方,请随时联系我。

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