Commit 4e2cf520 by 林永健

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

- 从 BusinessAnalysisController 移除所有空实现的延保/权益/轻改业务接口
- 新增 BusinessSceneAnalysisController 实现业务接口及完整逻辑,确保接口方法返回非空
- 新增 SceneBaseRequest 请求类,替代旧的 SceneOutputRequest,增强请求参数设计
- 新增并使用 SceneBaseReq 作为 RPC 层请求参数,统一内外部请求转换
- rpc-dj-pe-analysis 模块新增业务逻辑实现,完成总产值、目标产值与达成率计算
- 调整 SmartCarLifeDubboConfig,更新远程调用配置类名以匹配修改
- DateUtils 工具类新增 getStartDateByCycleType 方法,辅助周期偏移时间计算
- 优化 RPC 远程调用异常捕获,提升接口稳定性和错误日志记录
- 移除重复及无用的 DTO 类 SceneOutputReq,降低代码冗余
- 完善员工分析响应描述,修正 ApiModel 注解内容
- 规范各接口的 Swagger 注解,确保文档正确描述业务视角与功能场景
1 parent abc3cb35
Showing 15 changed files with 488 additions and 147 deletions
package cn.com.glsx.dj.peanalysis.dto.req.output;
import cn.com.glsx.dj.peanalysis.dto.DataBizQueryParamsDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.io.Serializable;
import java.util.List;
@Data
@Slf4j
public class SceneBaseReq implements Serializable {
private static final long serialVersionUID = -1;
@ApiModelProperty(notes = "排序:1-产值(默认),2-客单价,3-转化率")
private Integer sortType;
@ApiModelProperty(notes = "排序:1-降序(默认),2-升序")
private Integer orderBy;
@ApiModelProperty(notes = "门店号列表")
private List<Integer> merchantIds;
@ApiModelProperty(notes = "员工Id列表")
private List<String> staffUuids;
@ApiModelProperty(notes = "指标查询参数")
private DataBizQueryParamsDTO queryParams;
/**
*
* Bizs 1.延保 2.轻改 3.权益 4.二手车
* BusinessType 0:轻改,1:权益;2:延保
*/
public Byte convertToBusinessType(Integer bizs) {
switch (bizs){
case 1:
return 2;
case 2:
return 0;
case 3:
return 1;
case 4:
return 4;
}
log.error("不支持的bizs参数: {}", bizs);
return -1;
}
}
package cn.com.glsx.dj.peanalysis.dto.req.output;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@Data
public class SceneOutputReq 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;
}
......@@ -9,7 +9,7 @@ import java.math.BigDecimal;
import java.util.List;
@ApiModel(description = "产值响应")
@ApiModel(description = "员工分析响应")
@Data
public class EmployeeDetailSummaryResponse implements Serializable {
......@@ -84,55 +84,118 @@ public class EmployeeDetailSummaryResponse implements Serializable {
@ApiModelProperty("转化率环比")
private BigDecimal conversionRateMom;
@ApiModelProperty("整车延保成交数")
@ApiModelProperty("整车延保-成交数")
private Integer vehicleWarrantyDealCount;
@ApiModelProperty("整车延保渗透率")
@ApiModelProperty("整车延保-渗透率")
private BigDecimal vehicleWarrantyPenetrationRate;
@ApiModelProperty("整车延保转化率")
@ApiModelProperty("整车延保-渗透率兜底目标")
private BigDecimal vehicleWarrantyPenetrationBottomTarget;
@ApiModelProperty("整车延保-转化率")
private BigDecimal vehicleWarrantyConversionRate;
@ApiModelProperty("安心包成交数")
@ApiModelProperty("整车延保-转化率兜底目标")
private BigDecimal vehicleWarrantyConversionBottomTarget;
@ApiModelProperty("安心包-成交数")
private Integer safetyPackageDealCount;
@ApiModelProperty("安心包渗透率")
@ApiModelProperty("安心包-渗透率")
private BigDecimal safetyPackagePenetrationRate;
@ApiModelProperty("安心包转化率")
@ApiModelProperty("安心包-渗透率兜底目标")
private BigDecimal safetyPackagePenetrationBottomTarget;
@ApiModelProperty("安心包-转化率")
private BigDecimal safetyPackageConversionRate;
@ApiModelProperty("电池延保成交数")
@ApiModelProperty("安心包-转化率兜底目标")
private BigDecimal safetyPackageConversionBottomTarget;
@ApiModelProperty("电池延保-成交数")
private Integer batteryWarrantyDealCount;
@ApiModelProperty("电池延保渗透率")
@ApiModelProperty("电池延保-渗透率")
private BigDecimal batteryWarrantyPenetrationRate;
@ApiModelProperty("电池延保转化率")
@ApiModelProperty("电池延保-渗透率兜底目标")
private BigDecimal batteryWarrantyPenetrationBottomTarget;
@ApiModelProperty("电池延保-转化率")
private BigDecimal batteryWarrantyConversionRate;
@ApiModelProperty("轮胎延保成交数")
@ApiModelProperty("电池延保-转化率兜底目标")
private BigDecimal batteryWarrantyConversionBottomTarget;
@ApiModelProperty("轮胎延保-成交数")
private Integer tireWarrantyDealCount;
@ApiModelProperty("轮胎延保渗透率")
@ApiModelProperty("轮胎延保-渗透率")
private BigDecimal tireWarrantyPenetrationRate;
@ApiModelProperty("轮胎延保转化率")
@ApiModelProperty("轮胎延保-渗透率兜底目标")
private BigDecimal tireWarrantyPenetrationBottomTarget;
@ApiModelProperty("轮胎延保-转化率")
private BigDecimal tireWarrantyConversionRate;
// 7. 个人产值趋势数据
@ApiModelProperty("门店产值趋势数据")
private List<TrendData> outputValueTrend;
@ApiModelProperty("轮胎延保-转化率兜底目标")
private BigDecimal tireWarrantyConversionBottomTarget;
@ApiModelProperty("车窗膜-成交数")
private Integer windowFilmDealCount;
@ApiModelProperty("车窗膜-单车采购产值")
private BigDecimal windowFilmPerCarOutput;
@ApiModelProperty("车窗膜-渗透率")
private BigDecimal windowFilmPenetrationRate;
@ApiModelProperty("车窗膜-渗透率兜底目标")
private BigDecimal windowFilmPenetrationBottomTarget;
@ApiModelProperty("车窗膜-转化率")
private BigDecimal windowFilmConversionRate;
@ApiModelProperty("车窗膜-转化率兜底目标")
private BigDecimal windowFilmConversionBottomTarget;
@ApiModelProperty("车身膜-成交数")
private Integer carBodyFilmDealCount;
@ApiModelProperty("车身膜-单车采购产值")
private BigDecimal carBodyFilmPerCarOutput;
@ApiModelProperty("车身膜-渗透率")
private BigDecimal carBodyFilmPenetrationRate;
@ApiModelProperty("车身膜-渗透率兜底目标")
private BigDecimal carBodyFilmPenetrationBottomTarget;
@ApiModelProperty("车身膜-转化率")
private BigDecimal carBodyFilmConversionRate;
@ApiModelProperty("车身膜-转化率兜底目标")
private BigDecimal carBodyFilmConversionBottomTarget;
@ApiModelProperty("精品附件-成交数")
private Integer accessoriesDealCount;
@ApiModelProperty("精品附件-单车采购产值")
private BigDecimal accessoriesPerCarOutput;
@ApiModelProperty("精品附件-渗透率")
private BigDecimal accessoriesPenetrationRate;
@ApiModelProperty("精品附件-渗透率兜底目标")
private BigDecimal accessoriesPenetrationBottomTarget;
@Data
public static class TrendData {
@ApiModelProperty("周期名称(如:1月、第1周、01-01)")
private String periodName;
@ApiModelProperty("精品附件-转化率")
private BigDecimal accessoriesConversionRate;
@ApiModelProperty("产值")
private BigDecimal outputValue;
@ApiModelProperty("精品附件-转化率兜底目标")
private BigDecimal accessoriesConversionBottomTarget;
@ApiModelProperty("时间戳")
private Long timestamp;
}
}
......@@ -7,7 +7,7 @@ import lombok.Data;
import java.io.Serializable;
@ApiModel(description = "产值响应")
@ApiModel(description = "区域分布响应")
@Data
public class RegionalDistributionResponse implements Serializable {
......
......@@ -21,4 +21,5 @@ public class SceneOutputResponse implements Serializable {
@ApiModelProperty("达成率")
private BigDecimal ratio;
}
......@@ -8,7 +8,7 @@ import java.io.Serializable;
import java.math.BigDecimal;
@ApiModel(description = "产值响应")
@ApiModel(description = "门店列表均值响应")
@Data
public class StoreAvgResponse implements Serializable {
......@@ -43,4 +43,10 @@ public class StoreAvgResponse implements Serializable {
@ApiModelProperty("平均客单价环比")
private BigDecimal avgCustomerPriceMom;
@ApiModelProperty("升级客单价")
private BigDecimal upgradeCustomerPrice;
@ApiModelProperty("升级客单价环比")
private BigDecimal upgradeCustomerPriceMom;
}
......@@ -9,12 +9,36 @@ import java.math.BigDecimal;
import java.util.List;
@ApiModel(description = "产值响应")
@ApiModel(description = "门店分析响应")
@Data
public class StoreDetailSummaryResponse implements Serializable {
private static final long serialVersionUID = -1;
@ApiModelProperty("所属服务商")
private String shopMerchantName;
@ApiModelProperty("所属服务商ID")
private Integer shopMerchantId;
@ApiModelProperty("销售")
private String sellerUserName;
@ApiModelProperty("销售ID")
private Integer sellerUserId;
@ApiModelProperty("区域运营")
private String regionalOperationName;
@ApiModelProperty("区域运营ID")
private Integer regionalOperationId;
@ApiModelProperty("线上运营")
private String onlineOperationName;
@ApiModelProperty("线上运营ID")
private Integer onlineOperationId;
@ApiModelProperty("总产值")
private BigDecimal totalOutputValue;
......@@ -99,124 +123,139 @@ public class StoreDetailSummaryResponse implements Serializable {
@ApiModelProperty("渗透率环比")
private BigDecimal penetrationRateMom;
@ApiModelProperty("整车延保成交数")
@ApiModelProperty("整车延保-成交数")
private Integer vehicleWarrantyDealCount;
@ApiModelProperty("整车延保渗透率")
@ApiModelProperty("整车延保-渗透率")
private BigDecimal vehicleWarrantyPenetrationRate;
@ApiModelProperty("整车延保转化率")
@ApiModelProperty("整车延保-渗透率兜底目标")
private BigDecimal vehicleWarrantyPenetrationBottomTarget;
@ApiModelProperty("整车延保-转化率")
private BigDecimal vehicleWarrantyConversionRate;
@ApiModelProperty("整车延保生态系数")
private Integer vehicleWarrantyEcoCoefficient;
@ApiModelProperty("整车延保-转化率兜底目标")
private BigDecimal vehicleWarrantyConversionBottomTarget;
@ApiModelProperty("整车延保兜底目标")
private BigDecimal vehicleWarrantyBottomTarget;
@ApiModelProperty("整车延保-生态系数")
private Integer vehicleWarrantyEcoCoefficient;
@ApiModelProperty("安心包成交数")
@ApiModelProperty("安心包-成交数")
private Integer safetyPackageDealCount;
@ApiModelProperty("安心包渗透率")
@ApiModelProperty("安心包-渗透率")
private BigDecimal safetyPackagePenetrationRate;
@ApiModelProperty("安心包转化率")
@ApiModelProperty("安心包-渗透率兜底目标")
private BigDecimal safetyPackagePenetrationBottomTarget;
@ApiModelProperty("安心包-转化率")
private BigDecimal safetyPackageConversionRate;
@ApiModelProperty("安心包生态系数")
private Integer safetyPackageEcoCoefficient;
@ApiModelProperty("安心包-转化率兜底目标")
private BigDecimal safetyPackageConversionBottomTarget;
@ApiModelProperty("安心包兜底目标")
private BigDecimal safetyPackageBottomTarget;
@ApiModelProperty("安心包-生态系数")
private Integer safetyPackageEcoCoefficient;
@ApiModelProperty("电池延保成交数")
@ApiModelProperty("电池延保-成交数")
private Integer batteryWarrantyDealCount;
@ApiModelProperty("电池延保渗透率")
@ApiModelProperty("电池延保-渗透率")
private BigDecimal batteryWarrantyPenetrationRate;
@ApiModelProperty("电池延保转化率")
@ApiModelProperty("电池延保-渗透率兜底目标")
private BigDecimal batteryWarrantyPenetrationBottomTarget;
@ApiModelProperty("电池延保-转化率")
private BigDecimal batteryWarrantyConversionRate;
@ApiModelProperty("电池延保生态系数")
private Integer batteryWarrantyEcoCoefficient;
@ApiModelProperty("电池延保-转化率兜底目标")
private BigDecimal batteryWarrantyConversionBottomTarget;
@ApiModelProperty("电池延保兜底目标")
private BigDecimal batteryWarrantyBottomTarget;
@ApiModelProperty("电池延保-生态系数")
private Integer batteryWarrantyEcoCoefficient;
@ApiModelProperty("轮胎延保成交数")
@ApiModelProperty("轮胎延保-成交数")
private Integer tireWarrantyDealCount;
@ApiModelProperty("轮胎延保渗透率")
@ApiModelProperty("轮胎延保-渗透率")
private BigDecimal tireWarrantyPenetrationRate;
@ApiModelProperty("轮胎延保转化率")
@ApiModelProperty("轮胎延保-渗透率兜底目标")
private BigDecimal tireWarrantyPenetrationBottomTarget;
@ApiModelProperty("轮胎延保-转化率")
private BigDecimal tireWarrantyConversionRate;
@ApiModelProperty("轮胎延保生态系数")
private Integer tireWarrantyEcoCoefficient;
@ApiModelProperty("轮胎延保-转化率兜底目标")
private BigDecimal tireWarrantyConversionBottomTarget;
@ApiModelProperty("轮胎延保兜底目标")
private BigDecimal tireWarrantyBottomTarget;
@ApiModelProperty("轮胎延保-生态系数")
private Integer tireWarrantyEcoCoefficient;
@ApiModelProperty("车窗膜成交数")
@ApiModelProperty("车窗膜-成交数")
private Integer windowFilmDealCount;
@ApiModelProperty("车窗膜单车采购产值")
@ApiModelProperty("车窗膜-单车采购产值")
private BigDecimal windowFilmPerCarOutput;
@ApiModelProperty("车窗膜渗透率")
@ApiModelProperty("车窗膜-渗透率")
private BigDecimal windowFilmPenetrationRate;
@ApiModelProperty("车窗膜转化率")
@ApiModelProperty("车窗膜-渗透率兜底目标")
private BigDecimal windowFilmPenetrationBottomTarget;
@ApiModelProperty("车窗膜-转化率")
private BigDecimal windowFilmConversionRate;
@ApiModelProperty("车窗膜生态系数")
@ApiModelProperty("车窗膜-转化率兜底目标")
private BigDecimal windowFilmConversionBottomTarget;
@ApiModelProperty("车窗膜-生态系数")
private Integer windowFilmEcoCoefficient;
@ApiModelProperty("车身膜成交数")
@ApiModelProperty("车身膜-成交数")
private Integer carBodyFilmDealCount;
@ApiModelProperty("车身膜单车采购产值")
@ApiModelProperty("车身膜-单车采购产值")
private BigDecimal carBodyFilmPerCarOutput;
@ApiModelProperty("车身膜渗透率")
@ApiModelProperty("车身膜-渗透率")
private BigDecimal carBodyFilmPenetrationRate;
@ApiModelProperty("车身膜转化率")
@ApiModelProperty("车身膜-渗透率兜底目标")
private BigDecimal carBodyFilmPenetrationBottomTarget;
@ApiModelProperty("车身膜-转化率")
private BigDecimal carBodyFilmConversionRate;
@ApiModelProperty("车身膜生态系数")
@ApiModelProperty("车身膜-转化率兜底目标")
private BigDecimal carBodyFilmConversionBottomTarget;
@ApiModelProperty("车身膜-生态系数")
private Integer carBodyFilmEcoCoefficient;
@ApiModelProperty("精品附件成交数")
@ApiModelProperty("精品附件-成交数")
private Integer accessoriesDealCount;
@ApiModelProperty("精品附件单车采购产值")
@ApiModelProperty("精品附件-单车采购产值")
private BigDecimal accessoriesPerCarOutput;
@ApiModelProperty("精品附件渗透率")
@ApiModelProperty("精品附件-渗透率")
private BigDecimal accessoriesPenetrationRate;
@ApiModelProperty("精品附件转化率")
private BigDecimal accessoriesConversionRate;
@ApiModelProperty("精品附件-渗透率兜底目标")
private BigDecimal accessoriesPenetrationBottomTarget;
@ApiModelProperty("精品附件生态系数")
private Integer accessoriesEcoCoefficient;
// 趋势数据
@ApiModelProperty("门店产值趋势数据")
private List<TrendData> outputValueTrend;
@ApiModelProperty("精品附件-转化率")
private BigDecimal accessoriesConversionRate;
@Data
public static class TrendData {
@ApiModelProperty("周期名称(如:1月、第1周、01-01)")
private String periodName;
@ApiModelProperty("精品附件-转化率兜底目标")
private BigDecimal accessoriesConversionBottomTarget;
@ApiModelProperty("产值")
private BigDecimal outputValue;
@ApiModelProperty("精品附件-生态系数")
private Integer accessoriesEcoCoefficient;
@ApiModelProperty("时间戳")
private Long timestamp;
}
}
......@@ -9,7 +9,7 @@ import java.math.BigDecimal;
import java.util.List;
@ApiModel(description = "产值响应")
@ApiModel(description = "员工排行响应")
@Data
public class StoreEmployeeRankResponse implements Serializable {
......
......@@ -6,6 +6,7 @@ import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@ApiModel(description = "门店列表响应")
@Data
......@@ -34,9 +35,12 @@ public class StoreListResponse implements Serializable {
@ApiModelProperty("转化率")
private BigDecimal conversionRate;
@ApiModelProperty("升客价")
private BigDecimal upgradeCustomerPrice;
@ApiModelProperty("客单价")
private BigDecimal avgCustomerPrice;
@ApiModelProperty("门店状态 1:正常 2:兜底预警 3:生态指标预警 4:达成率不及预期")
private String storeStatus;
private List<String> storeStatus;
}
......@@ -6,22 +6,30 @@ import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@ApiModel(description = "产值响应")
@ApiModel(description = "存量门店分析响应")
@Data
public class StoreSceneSummaryResponse implements Serializable {
private static final long serialVersionUID = -1;
@ApiModelProperty("总开单门店数")
private Integer totalStores;
@ApiModelProperty("总开单门店环比")
private Integer totalStoresMom;
@ApiModelProperty("新店数量")
private Integer newStores;
@ApiModelProperty("新店占比")
private BigDecimal newStoresRatio;
@ApiModelProperty("新店商户号")
private List<Integer> newStoreIds;
@ApiModelProperty("新店环比")
private BigDecimal newStoresMom;
......@@ -34,6 +42,9 @@ public class StoreSceneSummaryResponse implements Serializable {
@ApiModelProperty("老店环比")
private BigDecimal oldStoresMom;
@ApiModelProperty("老店商户号")
private List<Integer> oldStoreIds;
@ApiModelProperty("多品类门店数量")
private Integer multiCategoryStores;
......@@ -43,6 +54,9 @@ public class StoreSceneSummaryResponse implements Serializable {
@ApiModelProperty("多品类门店占比")
private BigDecimal multiCategoryStoresRatio;
@ApiModelProperty("多品类门店商户号")
private List<Integer> multiCategoryStoreIds;
@ApiModelProperty("单品类门店数量")
private Integer singleCategoryStores;
......@@ -52,15 +66,27 @@ public class StoreSceneSummaryResponse implements Serializable {
@ApiModelProperty("单品类门店占比")
private BigDecimal singleCategoryStoresRatio;
@ApiModelProperty("多品类门店商户号")
private List<Integer> singleCategoryStoreIds;
@ApiModelProperty("流失门店")
private Integer churnedStores;
@ApiModelProperty("流失率")
private BigDecimal churnRate;
@ApiModelProperty("流失门店商户号")
private List<Integer> churnedStoreIds;
@ApiModelProperty("兜底预警门店数量")
private Integer bottomLineWarningStores;
@ApiModelProperty("兜底预警门店商户号")
private List<Integer> bottomLineWarningStoreIds;
@ApiModelProperty("生态指标预警门店数量")
private Integer ecosystemWarningStores;
@ApiModelProperty("生态指标预警门店商户号")
private List<Integer> ecosystemWarningStoreIds;
}
......@@ -8,7 +8,7 @@ import java.io.Serializable;
import java.math.BigDecimal;
@ApiModel(description = "产值响应")
@ApiModel(description = "流量概况响应")
@Data
public class TrafficSummaryResponse implements Serializable {
......
......@@ -2,9 +2,11 @@ package cn.com.glsx.dj.peanalysis.remote;
import cn.com.glsx.dj.peanalysis.dto.req.output.RegionalOutputReq;
import cn.com.glsx.dj.peanalysis.dto.req.output.SceneBaseReq;
import cn.com.glsx.dj.peanalysis.dto.req.output.TotalOutputReq;
import cn.com.glsx.dj.peanalysis.dto.res.output.*;
import cn.com.glsx.dj.peanalysis.model.ProvinceRganization;
import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
......@@ -13,7 +15,7 @@ import java.util.List;
/**
* bi
*/
@ApiService(value = "bi", owner = "dev")
@ApiService(value = "bi经营分析", owner = "dev", protocol = ApiService.ProtocolEnum.dubbo)
public interface BusinessAnalysisRemote {
RpcResponse<List<ProvinceRganization>> getByUuid(String uuid);
......@@ -32,4 +34,13 @@ public interface BusinessAnalysisRemote {
RpcResponse<List<StoreDetailResponse>> listStoreDetails(RegionalOutputReq req);
@ApiMethod("总产值、目标产值、达成率")
RpcResponse<SceneOutputResponse> sceneOutput(SceneBaseReq req);
@ApiMethod("产值趋势及达成率")
RpcResponse<List<TrendOutputResponse>> trendOutput(SceneBaseReq req);
@ApiMethod("存量门店分析")
RpcResponse<StoreSceneSummaryResponse> storeAnalysis(SceneBaseReq req);
}
......@@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration;
public class SmartCarLifeDubboConfig extends DubboConfig {
@Bean
public MerchantTargetConfigRemote merchantTargetConfigRemote(){
return factory.builder(MerchantTargetConfigRemote.class).check(check).timeout(timeout).build();
public MerchantOutputTargetConfigRemote merchantOutputTargetConfigRemote(){
return factory.builder(MerchantOutputTargetConfigRemote.class).check(check).timeout(timeout).build();
}
}
package cn.com.glsx.dj.peanalysis.remote;
import cn.com.glsx.dj.peanalysis.dto.req.output.RegionalOutputReq;
import cn.com.glsx.dj.peanalysis.dto.req.output.SceneBaseReq;
import cn.com.glsx.dj.peanalysis.dto.req.output.TotalOutputReq;
import cn.com.glsx.dj.peanalysis.dto.res.output.*;
import cn.com.glsx.dj.peanalysis.model.ProvinceRganization;
......@@ -108,4 +109,40 @@ public class BusinessAnalysisRemoteImpl implements BusinessAnalysisRemote{
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<SceneOutputResponse> sceneOutput(SceneBaseReq req) {
try {
return RpcResponse.success(businessAnalysisService.sceneOutput(req));
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<List<TrendOutputResponse>> trendOutput(SceneBaseReq req) {
try {
return RpcResponse.success(businessAnalysisService.trendOutput(req));
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("系统异常", e);
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<StoreSceneSummaryResponse> storeAnalysis(SceneBaseReq req) {
try {
return RpcResponse.success(businessAnalysisService.storeAnalysis(req));
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error("系统异常", e);
return RpcResponse.error(e);
}
}
}
......@@ -4,6 +4,7 @@ import cn.com.glsx.dj.peanalysis.dto.DataBizQueryParamsDTO;
import cn.com.glsx.dj.peanalysis.dto.DataBusinessDTO;
import cn.com.glsx.dj.peanalysis.dto.job.BiRecord;
import cn.com.glsx.dj.peanalysis.dto.req.output.RegionalOutputReq;
import cn.com.glsx.dj.peanalysis.dto.req.output.SceneBaseReq;
import cn.com.glsx.dj.peanalysis.dto.req.output.TotalOutputReq;
import cn.com.glsx.dj.peanalysis.dto.res.output.*;
import cn.com.glsx.dj.peanalysis.enums.LoginRoleEnum;
......@@ -12,12 +13,18 @@ import cn.com.glsx.dj.peanalysis.mapper.BusinessIntelligenceMapper;
import cn.com.glsx.dj.peanalysis.mapper.ServiceMerchantMapper;
import cn.com.glsx.dj.peanalysis.utils.DateUtils;
import cn.com.glsx.dj.peanalysis.utils.response.DataResp;
import cn.com.glsx.dj.smartcarlife.dto.merchantTarget.MerchantOutputTargetConfigDTO;
import cn.com.glsx.dj.smartcarlife.model.MerchantOutputTargetConfig;
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.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.dto.merchant.CarBrandProvinceRequestDTO;
import cn.com.glsx.merchants.model.response.MerchantProvinceDTO;
import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
......@@ -58,6 +65,9 @@ public class BusinessAnalysisService {
@Lazy
private UsedCarDataStatsService usedCarDataStatsService;
@Resource
private MerchantOutputTargetConfigRemote merchantOutputTargetConfigRemote;
public TotalOutputResponse totalOutput(TotalOutputReq request) {
TotalOutputResponse result = new TotalOutputResponse();
List<Integer> merchantIds = getMerchantIds(request.getRegionId());
......@@ -323,4 +333,151 @@ public class BusinessAnalysisService {
executor.shutdown();
}
}
/**
* 总产值、目标产值、达成率
*/
public SceneOutputResponse sceneOutput(SceneBaseReq req) {
SceneOutputResponse res = new SceneOutputResponse();
// 查询总产值
DataBizQueryParamsDTO queryParams = req.getQueryParams() == null ? new DataBizQueryParamsDTO() : req.getQueryParams();
queryParams.setBrandIds("-1,-2,3454");
queryParams.setItemCodes("A0036");
TotalOutputResponse totalOutput = getTotalOutput(queryParams);
if (totalOutput == null) {
log.warn("查询总产值返回空");
return res;
}
log.info("查询总产值:{}", totalOutput);
res.setOutputValue(totalOutput.getTotalOutput());
// 查询目标产值(周期=月时才展示)
if (queryParams.getDateType() == 2) {
String targetMonth = queryParams.getStartDate();
List<Integer> merchantIds = req.getMerchantIds();
byte businessType = req.convertToBusinessType(queryParams.getBizs());
RpcPagination<MerchantOutputTargetConfigDTO> pagination = new RpcPagination<>();
pagination.setPageSize(Integer.MAX_VALUE);
pagination.setPageNum(1);
MerchantOutputTargetConfigDTO condition = new MerchantOutputTargetConfigDTO();
condition.setMerchantIdList(merchantIds);
condition.setBusinessType(businessType);
condition.setTargetMonth(targetMonth.substring(0, targetMonth.length() - 3));
pagination.setCondition(condition);
RpcResponse<RpcPagination<MerchantOutputTargetConfigDTO>> outputTargetConfigResp = merchantOutputTargetConfigRemote.listWithPage(pagination);
if (outputTargetConfigResp.isFailed() || outputTargetConfigResp.getResult() == null) {
log.error("获取目标产值失败, pagination: {}", pagination);
return res;
}
BigDecimal totalOutputTargetValue = outputTargetConfigResp.getResult().getList().stream()
.map(MerchantOutputTargetConfig::getTargetValue)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
res.setTargetOutputValue(totalOutputTargetValue);
// 计算达成率
res.setRatio(parseOutputRatio(res.getOutputValue(), totalOutputTargetValue));
}
return res;
}
/**
* 达成率=(总产值/目标产值)*100%,保留百分比两位小数,即xx.xx%;
*/
private BigDecimal parseOutputRatio(BigDecimal outputValue, BigDecimal outputTargetValue) {
if (outputValue == null || outputTargetValue == null || outputTargetValue.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
return outputValue
.divide(outputTargetValue, 4, BigDecimal.ROUND_HALF_UP)
.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
}
/**
* 产值趋势及达成率
*/
public List<TrendOutputResponse> trendOutput(SceneBaseReq req) {
List<TrendOutputResponse> res = new ArrayList<>();
// 查询总产值
DataBizQueryParamsDTO queryParams = req.getQueryParams();
queryParams.setBrandIds("-1,-2,3454");
queryParams.setItemCodes("A0036");
List<DataBusinessDTO> trendOutputList = getTotalOutputGroupByMerchant(queryParams);
if (CollectionUtils.isEmpty(trendOutputList)) {
log.warn("查询产值趋势及达成率返回空");
return res;
}
// 查询目标产值(周期=月时才展示)
Map<String, BigDecimal> monthTargetOutputMap = new HashMap<>();
if (queryParams.getDateType() == 2) {
List<Integer> merchantIds = req.getMerchantIds();
byte businessType = req.convertToBusinessType(queryParams.getBizs());
RpcPagination<MerchantOutputTargetConfigDTO> pagination = new RpcPagination<>();
pagination.setPageSize(Integer.MAX_VALUE);
pagination.setPageNum(1);
MerchantOutputTargetConfigDTO condition = new MerchantOutputTargetConfigDTO();
condition.setMerchantIdList(merchantIds);
condition.setBusinessType(businessType);
pagination.setCondition(condition);
Date startDate = DateUtil.parseDate(queryParams.getStartDate());
Date endDate = DateUtil.parseDate(queryParams.getEndDate());
while (true) {
if (startDate.after(endDate)) {
break;
}
String targetMonth = DateUtil.format(startDate, DatePattern.NORM_MONTH_PATTERN);
condition.setTargetMonth(targetMonth);
RpcResponse<RpcPagination<MerchantOutputTargetConfigDTO>> outputTargetConfigResp = merchantOutputTargetConfigRemote.listWithPage(pagination);
if (outputTargetConfigResp.isFailed() || outputTargetConfigResp.getResult() == null) {
log.error("获取目标产值失败, pagination: {}", pagination);
break;
}
BigDecimal targetMonthValue = outputTargetConfigResp.getResult().getList().stream()
.map(MerchantOutputTargetConfig::getTargetValue)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
monthTargetOutputMap.put(targetMonth, targetMonthValue);
startDate = DateUtil.offsetMonth(startDate, 1);
}
log.info("查询目标产值:{}", monthTargetOutputMap);
}
res = trendOutputList.stream().map(p -> {
TrendOutputResponse item = new TrendOutputResponse();
item.setOutput(p.getItemValue());
item.setTime(p.getStartDate());
String key = DateUtil.format(DateUtil.parse(item.getTime()), DatePattern.NORM_MONTH_PATTERN);
if (monthTargetOutputMap.containsKey(key)) {
BigDecimal targetOutputConfig = monthTargetOutputMap.get(key);
item.setRatio(parseOutputRatio(item.getOutput(), targetOutputConfig));
}
return item;
}).collect(Collectors.toList());
log.info("查询产值趋势及达成率:{}", res);
return res;
}
/**
* 存量门店分析
*/
public StoreSceneSummaryResponse storeAnalysis(SceneBaseReq req) {
StoreSceneSummaryResponse res = new StoreSceneSummaryResponse();
// 查询总产值
DataBizQueryParamsDTO queryParams = req.getQueryParams();
queryParams.setBrandIds("-1,-2,3454");
queryParams.setItemCodes("A0036");
queryParams.setExts("merchantId");
List<DataBusinessDTO> trendOutputList = getTotalOutputGroupByMerchant(queryParams);
if (CollectionUtils.isEmpty(trendOutputList)) {
log.warn("查询产值返回空");
return res;
}
// 流失门店:以统计周期的开始日期为基准,近30天无产值且近60天存在产值
// 流失率:(流失门店/历史总门店数)*100%,保留百分比两位小数,其中历史总门店数:以统计周期的开始日期为基准,近30-60天间存在产值的门店数;
// 兜底预警门店:触发兜底预警的门店数;
// 生态指标预警门店:触发生态指标预警的门店数,即生态指标低于1.0即属于生态指标预警;
Map<Integer, List<DataBusinessDTO>> groupByMerchant = trendOutputList.stream().collect(Collectors.groupingBy(p -> p.getMerchantId()));
return res;
}
}
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    SceneBaseReq.java

    1. 问题: convertToBusinessType 方法中 serialVersionUID 设置为 -1 可能不是最佳实践。通常建议使用 private static final long serialVersionUID = 1L; 或者通过 IDE 自动生成。

      • 影响: 不正确的 serialVersionUID 可能导致序列化和反序列化问题。
      • 优化建议: 使用 private static final long serialVersionUID = 1L;。
    2. 问题: convertToBusinessType 方法中缺少对 null 输入的处理。

      • 影响: 如果传入 null 值,会抛出 NullPointerException。
      • 优化建议: 在方法开头添加对 null 的检查,例如 if (bizs == null) { log.error("bizs 参数为空"); return -1; }。
    3. 问题: 日志记录不够详细。

      • 影响: 日志信息对于调试和问题定位不够友好。
      • 优化建议: 在日志中增加更多的上下文信息,例如 log.error("不支持的bizs参数: {}, 请求参数: {}", bizs, req);。

    EmployeeDetailSummaryResponse.java

    1. 问题: 添加了大量新的属性,但没有相应的 getter 和 setter 方法。

      • 影响: 由于使用了 Lombok 的 @Data 注解,这不会成为问题,但建议在添加属性时检查是否需要额外的方法。
      • 优化建议: 确认所有属性都已通过 Lombok 自动实现,可以考虑添加 Javadoc 注释来解释每个属性的意义。
    2. 问题: 删除了 TrendData 内部类,但没有提供替换方案。

      • 影响: 如果 TrendData 在其他地方被引用,可能会导致编译错误。
      • 优化建议: 确认 TrendData 是否确实不再需要,如果需要,将其移到其他合适的位置。

    StoreDetailSummaryResponse.java

    1. 问题: 添加了大量新的属性,但没有相应的 getter 和 setter 方法。

      • 影响: 同上。
      • 优化建议: 确认所有属性都已通过 Lombok 自动实现,可以考虑添加 Javadoc 注释来解释每个属性的意义。
    2. 问题: 重复的 @ApiModelProperty 注解。

      • 影响: 代码冗余,不利于维护。
      • 优化建议: 确认是否有重复的属性,如果有,删除重复项。

    BusinessAnalysisRemote.java

    1. 问题: 新增了多个接口方法,但没有提供具体的实现。
      • 影响: 可能会导致未实现的接口方法抛出 UnsupportedOperationException。
      • 优化建议: 确认这些方法已经在 BusinessAnalysisRemoteImpl 中实现了,如果没有,提供默认实现或者抛出 UnsupportedOperationException。

    BusinessAnalysisRemoteImpl.java

    1. 问题: 异常处理部分代码冗余。
      • 影响: 代码冗余,不利于维护。
      • 优化建议: 提取公共的异常处理逻辑到一个单独的方法中,例如 handleException(Exception e)。

    BusinessAnalysisService.java

    1. 问题: 新增了多个业务逻辑方法,但没有提供详细的单元测试。

      • 影响: 无法保证新增业务逻辑的正确性。
      • 优化建议: 为新增的业务逻辑方法编写单元测试,确保其正确性和鲁棒性。
    2. 问题: parseOutputRatio 方法中的 BigDecimal 计算没有考虑除零的情况。

      • 影响: 如果 outputTargetValue 为零,会抛出 ArithmeticException。
      • 优化建议: 在计算之前检查 outputTargetValue 是否为零,例如 if (outputTargetValue.compareTo(BigDecimal.ZERO) == 0) { log.error("目标产值为零,无法计算达成率"); return BigDecimal.ZERO; }。

    评分明细

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

      • 代码逻辑基本正确,但存在对 null 输入的处理不足和缺少对除零情况的检查。
      • 得分:35分
    2. 安全性与潜在风险(30分):

      • 代码中没有明显的安全漏洞,但需要进一步检查业务逻辑是否可能导致安全问题。
      • 得分:28分
    3. 是否符合最佳实践(20分):

      • 代码结构良好,使用了 Lombok 简化了 getter/setter 的实现,但部分日志记录不够详细。
      • 得分:18分
    4. 性能与资源利用效率(5分):

      • 代码中没有明显的性能问题,但需要进一步检查是否有可能导致性能瓶颈的地方。
      • 得分:4分
    5. Commits信息的清晰性与准确性(5分):

      • 提交信息清晰,准确描述了所做的更改。
      • 得分:5分

    总分

    总分:100分

    虽然代码整体质量较高,但在功能实现的健壮性、安全性以及最佳实践方面仍有一些改进空间。建议开发者根据上述建议进行优化。

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