Commit f0b66379 by 章家宝

feat:专项任务调用策略中心接口改成单个接口

1 parent 75cf00d4
......@@ -8,6 +8,7 @@ import lombok.ToString;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* 发起专项任务请求DTO(新)
......@@ -61,28 +62,16 @@ public class SubmitSpecialTaskDTO implements Serializable {
private String description;
/**
* 问题驻店销售手机号(多个逗号分隔)
* 问题驻店销售列表
*/
@ApiModelProperty(value = "问题驻店销售手机号(多个逗号分隔)")
private String problemStaffPhones;
@ApiModelProperty(value = "问题驻店销售列表")
private List<StaffInfo> problemStaffList;
/**
* 问题驻店销售名称(多个逗号分隔)
* 指定区域运营列表
*/
@ApiModelProperty(value = "问题驻店销售名称(多个逗号分隔)")
private String problemStaffName;
/**
* 指定区域运营手机号
*/
@ApiModelProperty(value = "指定区域运营手机号")
private String regionOperatorPhone;
/**
* 指定区域运营姓名
*/
@ApiModelProperty(value = "指定区域运营姓名")
private String regionOperatorName;
@ApiModelProperty(value = "指定区域运营列表")
private List<StaffInfo> regionOperatorList;
/**
* 督导手机号
......@@ -110,4 +99,12 @@ public class SubmitSpecialTaskDTO implements Serializable {
@ApiModelProperty(value = "创建人")
private String createdBy;
@Data
public static class StaffInfo {
@ApiModelProperty(value = "手机号")
private String phone;
@ApiModelProperty(value = "名称")
private String name;
}
}
package cn.com.glsx.dj.supervisor.service;
import cn.com.glsx.dj.supervisor.dto.*;
import cn.com.glsx.dj.supervisor.enums.BusinessTypeEnum;
import cn.com.glsx.dj.supervisor.mapper.SupervisorSpecialTaskMapper;
import cn.com.glsx.dj.supervisor.model.SupervisorSpecialTask;
import cn.com.glsx.dj.strategy.dto.BatchInsertStrategyInfo;
import cn.com.glsx.dj.strategy.dto.MerchantInfo;
import cn.com.glsx.dj.strategy.enums.StrategyPushFlagEnum;
import cn.com.glsx.dj.strategy.enums.StrategyTypeEnum;
import cn.com.glsx.dj.strategy.model.StrategyInfo;
import cn.com.glsx.dj.strategy.model.StrategyStaffRel;
import cn.com.glsx.dj.strategy.remote.StrategyInfoRemote;
import cn.com.glsx.dj.supervisor.dto.*;
import cn.com.glsx.dj.supervisor.enums.BusinessTypeEnum;
import cn.com.glsx.dj.supervisor.mapper.SupervisorSpecialTaskMapper;
import cn.com.glsx.dj.supervisor.model.SupervisorSpecialTask;
import cn.com.glsx.framework.core.beans.BaseModel;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
......@@ -20,7 +19,6 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -29,9 +27,9 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 专项任务服务类
......@@ -66,6 +64,26 @@ public class SupervisorSpecialTaskService {
Date now = new Date();
SupervisorSpecialTask task = new SupervisorSpecialTask();
BeanUtils.copyProperties(request, task);
String regionOperatorName = "";
String regionOperatorPhone = "";
if (CollectionUtils.isNotEmpty(request.getRegionOperatorList())) {
List<String> nameList = request.getRegionOperatorList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getName).collect(Collectors.toList());
List<String> phoneList = request.getRegionOperatorList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getPhone).collect(Collectors.toList());
regionOperatorName = String.join(";", nameList);
regionOperatorPhone = String.join(";", phoneList);
}
String problemStaffName = "";
String problemStaffPhones = "";
if (CollectionUtils.isNotEmpty(request.getProblemStaffList())) {
List<String> nameList = request.getProblemStaffList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getName).collect(Collectors.toList());
List<String> phoneList = request.getProblemStaffList().stream().map(SubmitSpecialTaskDTO.StaffInfo::getPhone).collect(Collectors.toList());
problemStaffName = String.join(";", nameList);
problemStaffPhones = String.join(";", phoneList);
}
task.setRegionOperatorName(regionOperatorName);
task.setRegionOperatorPhone(regionOperatorPhone);
task.setProblemStaffName(problemStaffName);
task.setProblemStaffPhones(problemStaffPhones);
task.setCreateTime(now);
task.setCreatedBy(request.getSupervisorPhone());
task.setUpdateTime(now);
......@@ -242,11 +260,6 @@ public class SupervisorSpecialTaskService {
return;
}
// 2. 构建商户列表
MerchantInfo merchantInfo = new MerchantInfo();
merchantInfo.setMerchantId(request.getMerchantId());
merchantInfo.setMerchantName(request.getMerchantName());
// 3. 构建策略信息
StrategyInfo strategyInfo = new StrategyInfo();
strategyInfo.setStrategyType(strategyType);
......@@ -255,45 +268,45 @@ public class SupervisorSpecialTaskService {
strategyInfo.setDescription(request.getDescription());
strategyInfo.setMerchantId(request.getMerchantId());
strategyInfo.setMerchantName(request.getMerchantName());
// 状态设为未完成
strategyInfo.setPushFlag(2); // StrategyPushFlagEnum.UNFINISHED
strategyInfo.setStartDate(new Date());
strategyInfo.setPushType(0);
strategyInfo.setPushFlag(StrategyPushFlagEnum.NOT_PUSHED.getValue());
strategyInfo.setHandlerType("0");
strategyInfo.setCreatedUUid(request.getSupervisorUuid());
strategyInfo.setDataSource(2);
strategyInfo.setDataSourceId(taskId);
// 4. 构建人员列表(问题人员 + 区域运营)
List<StrategyStaffRel> staffList = new ArrayList<>();
// 4.1 添加问题驻店销售
if (StringUtils.isNotBlank(request.getProblemStaffPhones())) {
String[] phones = request.getProblemStaffPhones().split(",");
String[] names = StringUtils.isNotBlank(request.getProblemStaffName())
? request.getProblemStaffName().split(",") : new String[0];
for (int i = 0; i < phones.length; i++) {
if (CollectionUtils.isNotEmpty(request.getProblemStaffList())) {
for (SubmitSpecialTaskDTO.StaffInfo staffInfo : request.getProblemStaffList()) {
StrategyStaffRel staff = new StrategyStaffRel();
staff.setUserPhone(phones[i].trim());
staff.setUserName(i < names.length ? names[i].trim() : "");
staff.setUserPosition(0); // 驻店
staff.setUserPhone(staffInfo.getPhone());
staff.setUserName(staffInfo.getName());
staff.setUserPosition(0);
staffList.add(staff);
}
}
// 4.2 添加区域运营
if (StringUtils.isNotBlank(request.getRegionOperatorPhone())) {
StrategyStaffRel operator = new StrategyStaffRel();
operator.setUserPhone(request.getRegionOperatorPhone());
operator.setUserName(request.getRegionOperatorName());
operator.setUserPosition(9); // 区域运营
staffList.add(operator);
Integer userPosition = null;
if (request.getBusinessType() == 2) {
userPosition = 8;
} else {
userPosition = 9;
}
// 5. 构建请求对象
BatchInsertStrategyInfo batchInfo = new BatchInsertStrategyInfo();
batchInfo.setMerchantList(Collections.singletonList(merchantInfo));
batchInfo.setStrategyInfo(strategyInfo);
batchInfo.setStaffList(staffList);
batchInfo.setCreatedBy(request.getSupervisorPhone());
batchInfo.setCreatedUUid(request.getSupervisorUuid());
if (CollectionUtils.isNotEmpty(request.getRegionOperatorList())) {
for (SubmitSpecialTaskDTO.StaffInfo staffInfo : request.getRegionOperatorList()) {
StrategyStaffRel staff = new StrategyStaffRel();
staff.setUserPhone(staffInfo.getPhone());
staff.setUserName(staffInfo.getName());
staff.setUserPosition(userPosition);
staffList.add(staff);
}
}
strategyInfo.setStaffList(staffList);
// 6. 调用远程接口
RpcResponse<Boolean> response = strategyInfoRemote.batchCreate(batchInfo);
RpcResponse<Integer> response = strategyInfoRemote.create(strategyInfo);
if (response == null || !response.isSuccess()) {
log.error("创建协同任务策略失败,taskId={}, response={}", taskId, response);
} else {
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议(Top 3)

    1. 严重:Dubbo RPC 接口 DTO 发生破坏性变更(违反重要规则)

    • 问题描述:SubmitSpecialTaskDTO 位于 rpc-dj-supervisor-api 模块中,属于提供给外部调用的 RPC 接口参数。本次提交直接删除了原有的 problemStaffPhones、problemStaffName 等 String 类型字段,替换为了 List 类型的对象。
    • 影响分析:直接触犯“dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”的规则。这属于破坏性(非向后兼容)更新,现有调用方如果未同步更新 API jar 包,在进行序列化/反序列化时会导致请求失败或核心参数丢失,引发线上生产故障。
    • 优化建议:RPC 接口的参数变更必须向下兼容。应保留原有字段并标记 @Deprecated,同时新增 List 字段。在 Service 层兼容处理新老字段的数据。 ```java // 建议的 DTO 修改方式 @Deprecated @ApiModelProperty(value = "问题驻店销售手机号(多个逗号分隔)- 已废弃") private String problemStaffPhones;

    @ApiModelProperty(value = "问题驻店销售列表(新)") private List problemStaffList;

    
    **2. 缺陷:数据拼接符变更及潜在的 "null" 字符串污染**
    - **问题描述**:在 `SupervisorSpecialTaskService` 中,将 `List<StaffInfo>` 转换为字符串落库时,使用了分号 `;`(`String.join(";", nameList)`)。而原 DTO 注释明确说明历史数据是“多个逗号分隔”。此外,未对 `StaffInfo` 中的 `name` 或 `phone` 进行判空处理。
    - **影响分析**:
      1. 改变分隔符可能导致下游依赖该字段的业务(如按逗号 `split` 的逻辑)发生数组越界或解析错误。
      2. 如果前端传入的 `StaffInfo` 中存在 `name` 为 `null` 的情况,`String.join` 会将其转换为 `"null"` 字符串存入数据库(如 `张三;null;李四`),造成脏数据。
    - **优化建议**:保持与历史逻辑一致的逗号分隔符,并在拼接前过滤掉空值。
      ```java
      // 优化示例
      List<String> nameList = request.getRegionOperatorList().stream()
          .map(SubmitSpecialTaskDTO.StaffInfo::getName)
          .filter(StringUtils::isNotBlank) // 过滤空值
          .collect(Collectors.toList());
      regionOperatorName = String.join(",", nameList); // 改回逗号分隔
    

    3. 规范:硬编码与魔法值泛滥

    • 问题描述:在构建 StrategyInfo 和 StrategyStaffRel 时,引入了大量魔法值,例如 pushType(0)、handlerType("0")、dataSource(2),以及判断 request.getBusinessType() == 2 时设定 userPosition = 8,否则为 9。
    • 影响分析:代码可读性极差,后续维护人员无法理解 2、8、9 代表的具体业务含义,极易在后续迭代中引发逻辑错误。
    • 优化建议:将这些魔法值替换为已有的枚举类(如 StrategyPushFlagEnum)或在相关类中定义常量。 java // 建议替换为常量或枚举 if (BusinessTypeEnum.SOME_TYPE.getValue().equals(request.getBusinessType())) { userPosition = UserPositionEnum.ROLE_A.getValue(); // 替代 8 } else { userPosition = UserPositionEnum.ROLE_B.getValue(); // 替代 9 }

    二、评分明细

    • 功能实现的正确性与健壮性(28 / 40分): 扣分原因:对象属性拼接字符串时未考虑 Null 安全,可能产生 "null" 脏数据;擅自更改了数据落库的分隔符(逗号变分号),可能引发隐蔽的兼容性 bug。
    • 安全性与潜在风险(20 / 30分): 扣分原因:触发了 RPC 接口参数非兼容性变更的红线风险。直接删除 API 包中原有字段会导致线上调用方序列化异常,属于高危操作。
    • 最佳实践与可维护性(12 / 20分): 扣分原因:业务逻辑中充斥着未解释的魔法数字(8, 9, 2, 0等);新增的内部类 StaffInfo 的属性缺少基础的 @NotBlank 等参数校验注解。
    • 性能与资源利用(5 / 5分): 得分原因:使用 Stream API 处理少量集合数据,性能在合理范围内,无明显资源浪费。
    • 提交信息质量(2 / 5分): 扣分原因:Commit 信息(feat:专项任务调用策略中心接口改成单个接口)仅描述了 Service 层的调用变更,完全未提及 DTO 结构的重大重构,信息不完整,不利于追溯。

    总分:67分

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