Commit 592981d4 by zhouhaibao

Merge branch 'v5.5.1' of http://192.168.3.233:8090/dj/rop-dj-pe-analysis into v5.5.1

2 parents 3933f0fc ad242713
......@@ -9,6 +9,8 @@ import cn.com.glsx.dj.request.output.SceneBaseRequest;
import cn.com.glsx.dj.util.CommonUtil;
import cn.com.glsx.dj.util.DateUtils;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.hutool.core.util.StrUtil;
import com.rop.annotation.NeedInSessionType;
......@@ -35,22 +37,15 @@ public class BusinessSceneAnalysisController {
* 转换指标参数
*/
private void convertQueryParam(SceneBaseRequest request, SceneBaseReq req) {
if (req == null || request == null || request.getMerchantFilter() == null) {
return;
if (req == null || request == null) {
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "异常参数处理");
}
MerchantIdPermissionRequest permissionRequest = request.getMerchantFilter();
DataBizQueryParamsDTO queryParams = req.getQueryParams() == null ? new DataBizQueryParamsDTO() : req.getQueryParams();
queryParams.setStartDate(permissionRequest.getCycleTime());
queryParams.setEndDate(permissionRequest.getCycleTimeEnd());
queryParams.setBizs(permissionRequest.getBizs());
queryParams.setDateType(request.convertQueryParamCycleType(permissionRequest.getCycleType()));
if (CollectionUtils.isNotEmpty(req.getMerchantIds())) {
queryParams.setMerchantIds(StrUtil.join(",", req.getMerchantIds()));
}
if (CollectionUtils.isNotEmpty(req.getStaffUuids())) {
queryParams.setStaffIds(StrUtil.join(",", req.getStaffUuids()));
}
queryParams.setStartDate(request.getStartTime());
queryParams.setEndDate(request.getEndTime());
queryParams.setBizs(request.getBizs());
queryParams.setDateType(request.convertQueryParamCycleType());
req.setQueryParams(queryParams);
req.setCycleType(request.getMerchantFilter().getCycleType());
}
......
package cn.com.glsx.dj.controller;
import cn.com.glsx.dj.request.QueryCarBrandRequest;
import cn.com.glsx.dj.response.CarBrandResponse;
import cn.com.glsx.dj.util.CommonUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.scrm.proxy.enums.ProxyRequestSourceEnum;
import cn.com.glsx.scrm.proxy.model.CommonProxyRequest;
import cn.com.glsx.scrm.proxy.model.ProxyBaseResponse;
import cn.com.glsx.scrm.proxy.remote.CommonProxyRemote;
import cn.hutool.extra.pinyin.PinyinUtil;
import com.rop.AbstractRopRequest;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
......@@ -18,12 +15,10 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
@Slf4j
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.NO)
......@@ -37,31 +32,28 @@ public class CarBrandController {
*/
@ServiceMethod(method = "dj.api.sale.getCarBrandTree", needInSession = NeedInSessionType.NO)
@ApiOperation("获取车型品牌")
public RopResponse<List<CarBrandResponse>> getCarBrandTree(AbstractRopRequest request) {
try {
final String requestMethod = "merchants.api.merchantCommon.getCarbrandTree";
CommonProxyRequest proxyRequest = new CommonProxyRequest();
proxyRequest.setRequestMethod(requestMethod);
proxyRequest.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
proxyRequest.setParams(params);
RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest2(proxyRequest);
if (!response.hasResult()) {
log.error("获取车型品牌:{}", response.getMessage());
return RopResponse.error("获取车型品牌失败");
public RopResponse<List<CarBrandResponse>> getCarBrandTree(QueryCarBrandRequest queryCarBrandRequest){
final String requestMethod = "merchants.api.merchantCommon.getCarbrandTree";
CommonProxyRequest proxyRequest = new CommonProxyRequest();
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
proxyRequest.setRequestMethod(requestMethod);
proxyRequest.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
proxyRequest.setParams(params);
RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest(proxyRequest);
if (log.isDebugEnabled()) {
log.debug("查询车品牌返回:{}", response);
}
if (response.isFailed()) {
log.error("查询车品牌失败, message:{}", response.getMessage());
return RopResponse.error("查询车品牌失败");
}
List<CarBrandResponse> carBrandResponseList = response.getResult().getList(CarBrandResponse.class);
//是否展示子品牌
if (!Objects.equals(queryCarBrandRequest.getContainsChildren(), true)) {
for (CarBrandResponse carBrandResponse : carBrandResponseList) {
carBrandResponse.setChildren(null);
}
RopResponse<List<CarBrandResponse>> ropResponse = CommonUtil.convertRopResponseList(response, CarBrandResponse.class);
ropResponse.getData().forEach(v -> {
if (!StringUtils.isEmpty(v.getLabel())) {
String firstLetter = PinyinUtil.getFirstLetter(v.getLabel().charAt(0)) + "";
v.setLetter(firstLetter.toUpperCase());
}
});
ropResponse.getData().sort(Comparator.comparing(CarBrandResponse::getLetter));
return ropResponse;
} catch (RpcServiceException e) {
log.info("=======MerchantCommonController__invoke__getCarbrandTree__exception:{}", e.getMessage());
return RopResponse.error(e.getErrId(), e.getMessage());
}
return RopResponse.success(carBrandResponseList);
}
}
\ No newline at end of file
......@@ -81,4 +81,10 @@ public class MerchantIdPermissionRequest implements Serializable{
@ApiModelProperty(notes = "业务性质列表(1:直营渠道,2:直营4S店,3:合资收购(已废弃),4:投资收购-利丰,5:投资收购-内蒙古,6:服务商投资,7:投资收购-龙南,8:投资收购-湖北正旺,9:系统实施-新疆东捷,10:系统实施-捷通达),与businessType不可同时使用")
private List<Byte> businessTypeList;
@ApiModelProperty(notes = "门店类型 1新店 2老店")
private Byte storeType;
@ApiModelProperty(notes = "经营品类 1单品类 2多品类")
private Byte businessCategory;
}
package cn.com.glsx.dj.request;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* @Author: chenx
* @Description: 车品牌信息查询request
* @Date: 2024/3/7 14:09
* @Version: 1.0
*/
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
@Data
public class QueryCarBrandRequest extends AbstractRopRequest {
@ApiModelProperty(notes = "是否包含子品牌信息,默认false")
private Boolean containsChildren;
}
\ No newline at end of file
package cn.com.glsx.dj.request.output;
import cn.com.glsx.dj.request.MerchantIdPermissionRequest;
import cn.com.glsx.dj.smartcarlife.enums.SceneTypeEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.Lists;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.beans.BeanUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@Data
@ToString(callSuper = true)
......@@ -19,18 +23,48 @@ public class SceneBaseRequest extends AbstractRopRequest implements Serializable
private static final long serialVersionUID = -1;
@ApiModelProperty(notes = "门店过滤条件")
private MerchantIdPermissionRequest merchantFilter;
@ApiModelProperty(notes = "业务场景(0.会员权益,1.精品升级),必须,默认会员权益")
private Byte sceneType = SceneTypeEnum.SCENE1_0.getValue();
@ApiModelProperty(notes = "排序:1-产值(默认),2-客单价,3-转化率")
private Integer sortType;
@ApiModelProperty(notes = "业务类型(1.延保 2.轻改 3.权益)")
private Integer bizs;
@ApiModelProperty(notes = "排序:1-降序(默认),2-升序")
@ApiModelProperty(notes = "周期类型(1.按天,2.按周,3.按月,4.自定义,5.按年),必须", required = true)
private Integer cycleType;
@ApiModelProperty(notes = "开始时间", required = true)
private String startTime;
@ApiModelProperty(notes = "结束时间")
private String endTime;
@ApiModelProperty(notes = "车品牌ID")
private Integer carBrandId;
@ApiModelProperty(notes = "省份编码")
private String provinceId;
@ApiModelProperty(notes = "门店类型 1新店 2老店")
private Byte storeType;
@ApiModelProperty(notes = "经营品类 1单品类 2多品类")
private Byte businessCategory;
@ApiModelProperty(notes = "业务性质(1:直营4S店,2:合资收公司,3:服务商")
private Byte businessType;
@ApiModelProperty(notes = "排序")
private Integer orderBy;
@ApiModelProperty(notes = "排序方式 1.Desc 2.asc")
private Integer orderType;
@ApiModelProperty(notes = "门店号列表")
private List<Integer> merchantIds;
@ApiModelProperty(notes = "门店号聚合")
private Map<String, List<Integer>> merchantMap;
@ApiModelProperty(notes = "员工编号列表")
private List<String> staffUuids;
......@@ -38,6 +72,27 @@ public class SceneBaseRequest extends AbstractRopRequest implements Serializable
private String search;
/**
* 构建门店过滤条件
*/
public MerchantIdPermissionRequest getMerchantFilter(){
MerchantIdPermissionRequest request = new MerchantIdPermissionRequest();
BeanUtils.copyProperties(this, request);
request.setCycleTime(startTime);
request.setCycleTimeEnd(endTime);
request.setProvinceCode(provinceId);
if (businessType == 1) {
request.setBusinessTypeList(Lists.newArrayList((byte) 2));
}
if (businessType == 2) {
request.setBusinessTypeList(Lists.newArrayList((byte) 4, (byte) 5, (byte) 7, (byte) 7));
}
if (businessType == 3) {
request.setBusinessTypeList(Lists.newArrayList((byte) 6));
}
return request;
}
/**
* 转换周期传参,适配指标传参
......@@ -46,7 +101,7 @@ public class SceneBaseRequest extends AbstractRopRequest implements Serializable
* queryParams.dataType:指标参数:0,按指定时段;1,按周;2,按月;3,按年;4,全部
*/
@JsonIgnoreProperties
public Integer convertQueryParamCycleType(Integer cycleType) {
public Integer convertQueryParamCycleType() {
switch (cycleType) {
case 1:
case 4:
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 功能实现的正确性与健壮性
      • 问题: 在 totalOutput 方法中,请求对象类型从 TotalOutputReq 改为 ProviceOutputReq,但远程调用的方法 businessAnalysisRemote.provinceOutput(req) 预期参数类型为 TotalOutputReq,这可能导致类型不匹配错误。
        • 优化建议: 确保请求对象类型与远程调用方法的参数类型一致。如果需要使用 ProviceOutputReq,则应确认 businessAnalysisRemote.provinceOutput 方法是否支持该类型,或者修改方法调用以匹配 TotalOutputReq。
    • 问题: 在 listStoreDetails 方法中,请求对象类型从 RegionalOutputRequest 改为 RegionalOutputMerchantDetailRequest,但 CommonUtil.convertRequest 方法可能无法正确转换为 RegionalOutputDetailReq 类型。

      • 优化建议: 确认 CommonUtil.convertRequest 方法是否支持将 RegionalOutputMerchantDetailRequest 转换为 RegionalOutputDetailReq 类型。如果不支持,则需要修改 convertRequest 方法或调整请求对象类型。
    • 问题: 在 listStoreDetails 方法中,仅在 response.isSuccess() 时才对结果进行过滤,这可能导致在响应失败的情况下,前端仍然接收到未过滤的数据。

      • 优化建议: 在任何情况下都应对结果进行过滤,以确保数据的一致性和安全性。可以在 if (response.isSuccess()) 块外执行过滤逻辑,或者在响应失败时返回一个空列表或错误信息。
    1. 安全性与潜在风险

      • 问题: 在 totalOutput 和 listStoreDetails 方法中,直接使用用户输入的 provinceName 和 merchantName 进行字符串包含过滤,这可能会导致潜在的安全问题,如SQL注入或XSS攻击,尽管此处没有直接拼接SQL或HTML,但仍需谨慎处理用户输入。
        • 优化建议: 对用户输入进行适当的验证和清理,确保其符合预期格式。可以使用白名单验证或正则表达式来限制输入内容。
    2. 是否符合最佳实践

      • 问题: 请求对象类 TotalOutputDetailRequest 中新增的 provinceName 字段缺少相应的 getter 和 setter 方法。
        • 优化建议: 添加 provinceName 字段的 getter 和 setter 方法,以符合 JavaBean 规范。
    • 问题: 日志记录信息中包含了请求对象 request,这可能会泄露敏感信息。
      • 优化建议: 只记录必要的日志信息,避免记录包含敏感信息的对象。可以考虑只记录请求的关键字段而不是整个对象。
    1. 性能与资源利用效率

      • 问题: 在 totalOutput 和 listStoreDetails 方法中,对响应结果进行过滤的操作可能会导致性能下降,特别是在数据量较大的情况下。
        • 优化建议: 考虑在服务端进行更高效的过滤操作,或者在客户端进行过滤,以减轻服务器负担。此外,可以使用流式处理或分页技术来优化大数据集的处理。
    2. Commits信息的清晰性与准确性

      • 问题: 提交信息 "bi报表,全业务;Merge branch 'v5.5.1' of http://192.168.3.233:8090/dj/rop-dj-pe-analysis into v5.5.1" 不够清晰,难以理解具体的变更内容。
        • 优化建议: 提交信息应简洁明了,明确描述所做的更改。例如:"Refactor totalOutput and listStoreDetails methods to use new request types and add filtering logic"。

    评分明细

    1. 功能实现的正确性与健壮性:25/40 分
    2. 安全性与潜在风险:25/30 分
    3. 是否符合最佳实践:15/20 分
    4. 性能与资源利用效率:3/5 分
    5. Commits信息的清晰性与准确性:2/5 分

    总分: 70分


    建议:

    • 修正类型不匹配的问题,确保远程调用的参数类型正确。
    • 对用户输入进行适当的验证和清理,防止潜在的安全问题。
    • 添加缺失的 getter 和 setter 方法,遵循 JavaBean 规范。
    • 优化日志记录,避免记录敏感信息。
    • 在服务端进行高效的过滤操作,优化大数据集的处理。
    • 提高提交信息的清晰度,便于后续维护和协作。
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!