Commit b8da9f5c by zhouhaibao

[+]bi报表,全业务

1 parent 24b73cce
package cn.com.glsx.dj.peanalysis.dto; package cn.com.glsx.dj.peanalysis.dto;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.ToString; import lombok.ToString;
...@@ -14,6 +15,7 @@ import java.math.BigDecimal; ...@@ -14,6 +15,7 @@ import java.math.BigDecimal;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@ToString @ToString
@Builder
public class DataBusinessDTO { public class DataBusinessDTO {
// 主要使用字段 // 主要使用字段
......
...@@ -7,10 +7,13 @@ import javax.validation.constraints.NotNull; ...@@ -7,10 +7,13 @@ import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
@Data @Data
public class RegionalOutputReq implements Serializable { public class RegionalOutputReq extends BaseReq implements Serializable {
private static final long serialVersionUID = -1; private static final long serialVersionUID = -1;
@ApiModelProperty(notes = "区域-省份名称")
private String provinceName;
@ApiModelProperty(notes = "区域-省份编码") @ApiModelProperty(notes = "区域-省份编码")
private String provinceId; private String provinceId;
...@@ -35,14 +38,4 @@ public class RegionalOutputReq implements Serializable { ...@@ -35,14 +38,4 @@ public class RegionalOutputReq implements Serializable {
@NotNull @NotNull
private String endTime; private String endTime;
/**
* 角色
*/
private Integer loginRole;
/**
* 省份code
*/
private String regionId;
} }
...@@ -2,12 +2,19 @@ package cn.com.glsx.dj.peanalysis.dto.req.output; ...@@ -2,12 +2,19 @@ package cn.com.glsx.dj.peanalysis.dto.req.output;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.util.List; import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Data @Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TotalOutputReq extends BaseReq implements Serializable { public class TotalOutputReq extends BaseReq implements Serializable {
private static final long serialVersionUID = -1; private static final long serialVersionUID = -1;
...@@ -33,4 +40,6 @@ public class TotalOutputReq extends BaseReq implements Serializable { ...@@ -33,4 +40,6 @@ public class TotalOutputReq extends BaseReq implements Serializable {
@NotNull @NotNull
private String endTime; private String endTime;
private Integer merchantId;
} }
...@@ -17,8 +17,16 @@ public class DirectStaffSummaryResponse implements Serializable { ...@@ -17,8 +17,16 @@ public class DirectStaffSummaryResponse implements Serializable {
private Integer technicianCount; private Integer technicianCount;
@ApiModelProperty(notes = "人均产值") @ApiModelProperty(notes = "人均产值")
private BigDecimal avgOutputPerPerson; private BigDecimal avgOutputPerPerson;
@ApiModelProperty(notes = "豪华门店人数")
private BigDecimal perPersonLuxuryStoreCount;
@ApiModelProperty(notes = "豪华车门店人均产值") @ApiModelProperty(notes = "豪华车门店人均产值")
private BigDecimal avgOutputPerPersonInLuxuryStore; private BigDecimal avgOutputPerPersonInLuxuryStore;
@ApiModelProperty(notes = "豪华车门店数量")
private BigDecimal perPersonInNonLuxuryStoreCount;
@ApiModelProperty(notes = "非豪华车门店人均产值") @ApiModelProperty(notes = "非豪华车门店人均产值")
private BigDecimal avgOutputPerPersonInNonLuxuryStore; private BigDecimal avgOutputPerPersonInNonLuxuryStore;
} }
\ No newline at end of file \ No newline at end of file
...@@ -14,13 +14,13 @@ public class OutputDistributionResponse implements Serializable { ...@@ -14,13 +14,13 @@ public class OutputDistributionResponse implements Serializable {
private static final long serialVersionUID = -1; private static final long serialVersionUID = -1;
@ApiModelProperty(notes = "业务类型:1-延保,2-权益,3-轻改,4-二手车", example = "1") @ApiModelProperty(notes = "业务类型:1-延保,2-轻改,3-权益,4-二手车", example = "1")
private Integer sceneType; private Integer sceneType;
@ApiModelProperty(notes = "该业务产值及占比") @ApiModelProperty(notes = "该业务产值")
private BigDecimal outputAndRatio; private BigDecimal outputAndRatio;
@ApiModelProperty(notes = "该业务毛利率") @ApiModelProperty(notes = "该业务产值占比")
private BigDecimal profitMargin; private BigDecimal profitMargin;
@ApiModelProperty(notes = "全国排名") @ApiModelProperty(notes = "全国排名")
......
...@@ -12,7 +12,7 @@ import java.math.BigDecimal; ...@@ -12,7 +12,7 @@ import java.math.BigDecimal;
public class StoreSummaryResponse implements Serializable { public class StoreSummaryResponse implements Serializable {
private static final long serialVersionUID = -1; private static final long serialVersionUID = -1;
@ApiModelProperty(notes = "门店总数") @ApiModelProperty(notes = "门店总数")
private Integer totalStoreCount; private Long totalStoreCount;
@ApiModelProperty(notes = "门店占比", example = "8.99%") @ApiModelProperty(notes = "门店占比", example = "8.99%")
private BigDecimal storeRatio; private BigDecimal storeRatio;
@ApiModelProperty(notes = "多品类门店占比", example = "8.99%") @ApiModelProperty(notes = "多品类门店占比", example = "8.99%")
...@@ -25,8 +25,16 @@ public class StoreSummaryResponse implements Serializable { ...@@ -25,8 +25,16 @@ public class StoreSummaryResponse implements Serializable {
private Integer directStoreCount; private Integer directStoreCount;
@ApiModelProperty(notes = "直营门店产值", example = "21,265,600") @ApiModelProperty(notes = "直营门店产值", example = "21,265,600")
private BigDecimal directStoreOutput; private BigDecimal directStoreOutput;
@ApiModelProperty(notes = "豪华门店数")
private Integer luxuryStoreCount;
@ApiModelProperty(notes = "豪华车门店产值", example = "612,656") @ApiModelProperty(notes = "豪华车门店产值", example = "612,656")
private BigDecimal luxuryStoreOutput; private BigDecimal luxuryStoreOutput;
@ApiModelProperty(notes = "非豪华门店数")
private Integer nonLuxuryStoreCount;
@ApiModelProperty(notes = "非豪华门店产值", example = "612,656") @ApiModelProperty(notes = "非豪华门店产值", example = "612,656")
private BigDecimal nonLuxuryStoreOutput; private BigDecimal nonLuxuryStoreOutput;
} }
\ No newline at end of file \ No newline at end of file
...@@ -24,13 +24,16 @@ public interface BusinessAnalysisRemote { ...@@ -24,13 +24,16 @@ public interface BusinessAnalysisRemote {
RpcResponse<TotalOutputResponse> totalOutput(TotalOutputReq request); RpcResponse<TotalOutputResponse> totalOutput(TotalOutputReq request);
RpcResponse<List<RegionOutputResponse>> regionalOutput(RegionalOutputReq req);
RpcResponse<TotalOutputResponse> provinceOutput(TotalOutputReq request);
RpcResponse<RegionOutputResponse> regionalOutput(RegionalOutputReq req);
RpcResponse<List<OutputDistributionResponse>> outputDistribution(RegionalOutputReq req); RpcResponse<List<OutputDistributionResponse>> outputDistribution(RegionalOutputReq req);
RpcResponse<List<StoreSummaryResponse>> storeSummary(RegionalOutputReq req); RpcResponse<StoreSummaryResponse> storeSummary(RegionalOutputReq req);
RpcResponse<List<DirectStaffSummaryResponse>> directStaffSummary(RegionalOutputReq req); RpcResponse<DirectStaffSummaryResponse> directStaffSummary(RegionalOutputReq req);
RpcResponse<List<StoreDetailResponse>> listStoreDetails(RegionalOutputReq req); RpcResponse<List<StoreDetailResponse>> listStoreDetails(RegionalOutputReq req);
......
package cn.com.glsx.dj.peanalysis.config;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.*;
@Configuration
public class ExecutorConfiguration {
/**
* 自定义线程池:用于数据查询类异步任务
* - 核心线程数:4
* - 最大线程数:8
* - 队列容量:100(有界队列,防 OOM)
* - 线程空闲回收时间:60 秒
* - 拒绝策略:CallerRunsPolicy(主线程执行,避免丢任务)
*/
@Bean("dataQueryExecutor")
public ExecutorService dataQueryExecutor() {
ThreadFactory threadFactory = new ThreadFactory() {
private final AtomicInteger threadNumber = new AtomicInteger(1);
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, "data-query-pool-thread-" + threadNumber.getAndIncrement());
t.setDaemon(false); // 非守护线程,确保应用关闭前完成任务
return t;
}
};
return new ThreadPoolExecutor(
4, // corePoolSize
8, // maximumPoolSize
60L, TimeUnit.SECONDS, // keepAliveTime
new LinkedBlockingQueue<>(100), // 有界工作队列
threadFactory,
new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
);
}
}
\ No newline at end of file \ No newline at end of file
...@@ -61,7 +61,17 @@ public class BusinessAnalysisRemoteImpl implements BusinessAnalysisRemote{ ...@@ -61,7 +61,17 @@ public class BusinessAnalysisRemoteImpl implements BusinessAnalysisRemote{
} }
@Override @Override
public RpcResponse<List<RegionOutputResponse>> regionalOutput(RegionalOutputReq req) { public RpcResponse<TotalOutputResponse> provinceOutput(TotalOutputReq request) {
try {
return RpcResponse.success(businessAnalysisService.provinceOutput(request));
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
return RpcResponse.error(e);
}
}
@Override
public RpcResponse<RegionOutputResponse> regionalOutput(RegionalOutputReq req) {
try { try {
return RpcResponse.success(businessAnalysisService.regionalOutput(req)); return RpcResponse.success(businessAnalysisService.regionalOutput(req));
} catch (RpcServiceException e) { } catch (RpcServiceException e) {
...@@ -81,7 +91,7 @@ public class BusinessAnalysisRemoteImpl implements BusinessAnalysisRemote{ ...@@ -81,7 +91,7 @@ public class BusinessAnalysisRemoteImpl implements BusinessAnalysisRemote{
} }
@Override @Override
public RpcResponse<List<StoreSummaryResponse>> storeSummary(RegionalOutputReq req) { public RpcResponse<StoreSummaryResponse> storeSummary(RegionalOutputReq req) {
try { try {
return RpcResponse.success(businessAnalysisService.storeSummary(req)); return RpcResponse.success(businessAnalysisService.storeSummary(req));
} catch (RpcServiceException e) { } catch (RpcServiceException e) {
...@@ -91,7 +101,7 @@ public class BusinessAnalysisRemoteImpl implements BusinessAnalysisRemote{ ...@@ -91,7 +101,7 @@ public class BusinessAnalysisRemoteImpl implements BusinessAnalysisRemote{
} }
@Override @Override
public RpcResponse<List<DirectStaffSummaryResponse>> directStaffSummary(RegionalOutputReq req) { public RpcResponse<DirectStaffSummaryResponse> directStaffSummary(RegionalOutputReq req) {
try { try {
return RpcResponse.success(businessAnalysisService.directStaffSummary(req)); return RpcResponse.success(businessAnalysisService.directStaffSummary(req));
} catch (RpcServiceException e) { } catch (RpcServiceException e) {
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 功能实现的正确性与健壮性
      • 问题:BusinessAnalysisService.provinceOutput 方法中计算 avgOutput 时,如果 storeNumber 为零会导致除零错误。 java BigDecimal avgOutput = totalOutput.multiply(BigDecimal.valueOf(100)).divide(BigDecimal.valueOf(storeNumber), 2, RoundingMode.HALF_UP); 建议:增加对 storeNumber 的非零检查。 java BigDecimal avgOutput = storeNumber > 0 ? totalOutput.multiply(BigDecimal.valueOf(100)).divide(BigDecimal.valueOf(storeNumber), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
    • 问题:BusinessAnalysisService.regionalOutput 方法中存在重复代码,如 totalOutputReq 的初始化和赋值。 建议:将重复的代码提取到一个单独的方法中,以提高代码复用性和可读性。 java private TotalOutputReq initializeTotalOutputReq(RegionalOutputReq req) { TotalOutputReq totalOutputReq = new TotalOutputReq(); BeanUtils.copyProperties(req, totalOutputReq); return totalOutputReq; }
    1. 安全性与潜在风险

      • 问题:代码中没有明显的安全漏洞,但需要注意的是,provinceName 和其他字符串参数应该进行适当的验证,防止注入攻击或其他恶意输入。 建议:使用 @Valid 和 @Pattern 注解来验证字符串参数。 java @Pattern(regexp = "^[a-zA-Z\\u4e00-\\u9fa5]{1,20}$", message = "Invalid province name") private String provinceName;
    2. 是否符合最佳实践

      • 问题:BusinessAnalysisService.provinceOutput 方法中的 FIXED_PROVINCE_NAMES 常量未见定义,这可能会导致编译错误。 建议:定义 FIXED_PROVINCE_NAMES 常量。 java private static final List<String> FIXED_PROVINCE_NAMES = Arrays.asList( "北京市", "天津市", "上海市", "重庆市", "河北省", "山西省", "辽宁省", "吉林省", "黑龙江省", "江苏省", "浙江省", "安徽省", "福建省", "江西省", "山东省", "河南省", "湖北省", "湖南省", "广东省", "海南省", "四川省", "贵州省", "云南省", "陕西省", "甘肃省", "青海省", "台湾省", "内蒙古自治区", "广西壮族自治区", "西藏自治区", "宁夏回族自治区", "新疆维吾尔自治区", "香港特别行政区", "澳门特别行政区" );
    • 问题:BusinessAnalysisService.provinceOutput 方法中存在硬编码的数字 2,表示小数位数。 建议:将数字 2 提取为常量,以便于修改和维护。 java private static final int DECIMAL_SCALE = 2;
    1. 性能与资源利用效率

      • 问题:BusinessAnalysisService.provinceOutput 方法中使用了 FIXED_PROVINCE_NAMES.stream() 来创建 metricMap,这可能导致不必要的遍历。 建议:可以考虑使用 Collectors.toMap 直接创建 metricMap,减少中间步骤。 java Map<String, BigDecimal> metricMap = groupedData.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, entry -> entry.getValue().stream() .map(DataBusinessDTO::getItemValue) .filter(Objects::nonNull) .reduce(BigDecimal.ZERO, BigDecimal::add) ));
    2. Commits信息的清晰性与准确性

      • 问题:提交信息仅为 "bi报表,全业务",不够具体。 建议:提供更详细的提交信息,说明具体的更改内容和目的。 plaintext feat(BusinessAnalysisService): 添加 provinceOutput 方法实现 fix(BusinessAnalysisService): 修复 regionalOutput 方法中的重复代码 refactor(BusinessAnalysisService): 提取重复代码到单独的方法

    评分明细

    1. 功能实现的正确性与健壮性:35/40

      • 减分原因:存在潜在的除零错误,缺少对某些参数的验证。
    2. 安全性与潜在风险:25/30

      • 减分原因:缺少对字符串参数的验证。
    3. 是否符合最佳实践:15/20

      • 减分原因:存在硬编码的数字,缺少常量定义。
    4. 性能与资源利用效率:3/5

      • 减分原因:存在不必要的遍历,可以优化。
    5. Commits信息的清晰性与准确性:2/5

      • 减分原因:提交信息过于简单,缺乏细节。

    总分: 80分


    希望以上反馈能够帮助您改进代码质量,提高代码的健壮性和可维护性。

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