Commit 886724e7 by 谢海旭

策略中心:协同任务,推送群消息实现

1 parent 59e8fca5
package cn.com.glsx.dj.strategy.enums; package cn.com.glsx.dj.strategy.enums;
/** /**
* 岗位类型:0-驻店、6-飞行督导、8-1.1区域运营、9-2.1区域运营 * 岗位类型:0-驻店、6-1.1飞行督导、8-1.1区域运营、9-2.1区域运营、13-2.1飞行督导
*/ */
public enum UserPositionEnum { public enum UserPositionEnum {
/** /**
...@@ -9,9 +9,9 @@ public enum UserPositionEnum { ...@@ -9,9 +9,9 @@ public enum UserPositionEnum {
*/ */
RESIDENT(0, "驻店"), RESIDENT(0, "驻店"),
/** /**
* 飞行督导 * 1.1飞行督导
*/ */
FLIGHT_SUPERVISION(6, "飞行督导"), FLIGHT_SUPERVISION_1_1(6, "1.1飞行督导"),
/** /**
* 1.1区域运营 * 1.1区域运营
*/ */
...@@ -20,6 +20,10 @@ public enum UserPositionEnum { ...@@ -20,6 +20,10 @@ public enum UserPositionEnum {
* 2.1区域运营 * 2.1区域运营
*/ */
REGIONAL_OPERATION_2_1(9, "2.1区域运营"), REGIONAL_OPERATION_2_1(9, "2.1区域运营"),
/**
* 2.1飞行督导
*/
FLIGHT_SUPERVISION_2_1(13, "2.1飞行督导"),
; ;
private Integer value; private Integer value;
......
...@@ -36,24 +36,24 @@ public class StrategyStaffRel implements Serializable { ...@@ -36,24 +36,24 @@ public class StrategyStaffRel implements Serializable {
private String userName; private String userName;
/** /**
* 人员手机号 * 手机号
*/ */
@ApiModelProperty(notes = "人员手机号") @ApiModelProperty(notes = "手机号")
@Column(name = "user_phone") @Column(name = "user_phone")
private String userPhone; private String userPhone;
/** /**
* 岗位类型:0:驻店,6:飞行督导,8:1.1区域运营,9:2.1区域运营 * 岗位类型:0:驻店,6:1.1飞行督导,8:1.1区域运营,9:2.1区域运营,13:2.1飞行督导
* @see UserPositionEnum * @see UserPositionEnum
*/ */
@ApiModelProperty(notes = "岗位类型:0:驻店,6:飞行督导,8:1.1区域运营,9:2.1区域运营。轻改=8,延保与权益=9") @ApiModelProperty(notes = "岗位类型:0:驻店,6:1.1飞行督导,8:1.1区域运营,9:2.1区域运营,13:2.1飞行督导")
@Column(name = "user_position") @Column(name = "user_position")
private Integer userPosition; private Integer userPosition;
/** /**
* 北森人员id * 北森员工id
*/ */
@ApiModelProperty(notes = "北森人员id") @ApiModelProperty(notes = "北森员工id")
@Column(name = "beisen_userid") @Column(name = "beisen_userid")
private Integer beisenUserId; private Integer beisenUserId;
......
...@@ -317,6 +317,13 @@ public class StrategyCreatedConsumer extends KafkaConsumer { ...@@ -317,6 +317,13 @@ public class StrategyCreatedConsumer extends KafkaConsumer {
strategyInfo.getId(), strategyInfo.getId(),
result != null ? result.getTaskId() : null, result != null ? result.getTaskId() : null,
result != null ? result.getTaskNo() : null); result != null ? result.getTaskNo() : null);
// 5. 推送群消息(独立try-catch,不影响任务中心创建结果)
try {
strategyInfoService.processWorktoolStrategy(strategyInfo);
} catch (Exception e) {
log.error("推送协同任务群消息异常,strategyId:{}", strategyInfo.getId(), e);
}
} else { } else {
String errorMsg = response != null ? response.getMessage() : "response is null"; String errorMsg = response != null ? response.getMessage() : "response is null";
log.error("推送任务中心失败,strategyId:{}, errorMsg:{}", log.error("推送任务中心失败,strategyId:{}, errorMsg:{}",
......
...@@ -2,8 +2,6 @@ package cn.com.glsx.dj.strategy.mqlistener; ...@@ -2,8 +2,6 @@ package cn.com.glsx.dj.strategy.mqlistener;
import cn.com.glsx.dj.mindworkplate.enums.messagebox.ReminderTypeEnums; import cn.com.glsx.dj.mindworkplate.enums.messagebox.ReminderTypeEnums;
import cn.com.glsx.dj.strategy.config.KafkaTopicConfig; import cn.com.glsx.dj.strategy.config.KafkaTopicConfig;
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.model.StrategyStaffRel;
import cn.com.glsx.dj.strategy.service.StrategyInfoService; import cn.com.glsx.dj.strategy.service.StrategyInfoService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -11,7 +9,6 @@ import org.oreframework.jms.kafka.consumer.KafkaConsumer; ...@@ -11,7 +9,6 @@ import org.oreframework.jms.kafka.consumer.KafkaConsumer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
...@@ -22,14 +19,6 @@ import java.util.List; ...@@ -22,14 +19,6 @@ import java.util.List;
@Component @Component
public class StrategyPushConsumer extends KafkaConsumer { public class StrategyPushConsumer extends KafkaConsumer {
/** 新推送逻辑覆盖的策略类型(排除带教申请,已迁移至 StrategyCreatedConsumer) */
private static final List<Integer> NEW_PUSH_STRATEGY_TYPES = Arrays.asList(
StrategyTypeEnum.PERSONNEL_CHANGE_EVAL.getValue(),
StrategyTypeEnum.BUSINESS_POLICY_UPDATE_EVAL.getValue(),
StrategyTypeEnum.MULTI_CATEGORY_EXPANSION.getValue(),
StrategyTypeEnum.TRAFFIC_IMPROVEMENT.getValue()
);
@Autowired @Autowired
private StrategyInfoService strategyInfoService; private StrategyInfoService strategyInfoService;
...@@ -51,14 +40,7 @@ public class StrategyPushConsumer extends KafkaConsumer { ...@@ -51,14 +40,7 @@ public class StrategyPushConsumer extends KafkaConsumer {
} }
try { try {
StrategyInfo strategyInfo = strategyInfoService.queryStrategyInfoById(strategyId); processOriginalStrategyPush(strategyId);
Integer strategyType = strategyInfo.getStrategyType();
if (NEW_PUSH_STRATEGY_TYPES.contains(strategyType)) {
processNewStrategyPush(strategyInfo);
} else {
processOriginalStrategyPush(strategyId);
}
} catch (Exception e) { } catch (Exception e) {
log.error("策略推送处理失败 strategyId:{}", strategyId, e); log.error("策略推送处理失败 strategyId:{}", strategyId, e);
} }
...@@ -84,32 +66,4 @@ public class StrategyPushConsumer extends KafkaConsumer { ...@@ -84,32 +66,4 @@ public class StrategyPushConsumer extends KafkaConsumer {
} }
} }
} }
/**
* 新推送逻辑:根据策略类型分发到不同的推送处理
*
* @param strategyInfo 策略详情(已包含人员列表)
*/
private void processNewStrategyPush(StrategyInfo strategyInfo) {
Integer strategyType = strategyInfo.getStrategyType();
log.info("进入新推送逻辑,strategyId:{}, strategyType:{}", strategyInfo.getId(), strategyType);
if (Arrays.asList(
StrategyTypeEnum.PERSONNEL_CHANGE_EVAL.getValue(),
StrategyTypeEnum.BUSINESS_POLICY_UPDATE_EVAL.getValue(),
StrategyTypeEnum.MULTI_CATEGORY_EXPANSION.getValue(),
StrategyTypeEnum.TRAFFIC_IMPROVEMENT.getValue()).contains(strategyType)) {
// 9-人员更换评估、10-商务政策更新评估、11-多品类拓张、12-流量问题改善
processWorktoolStrategy(strategyInfo);
}
}
/**
* 9-人员更换评估、10-商务政策更新评估、11-多品类拓张、12-流量问题改善 推送处理
*/
private void processWorktoolStrategy(StrategyInfo strategyInfo) {
// TODO 组装推送信息并发送 rpc-dj-smartcarlife-job项目下的cn.com.glsx.dj.smartcarlife.manager.BatchMessagingManager#sendNewReportGroupPush
strategyInfoService.processWorktoolStrategy(strategyInfo);
log.info("worktool策略推送处理,strategyId:{}, strategyType:{}", strategyInfo.getId(), strategyInfo.getStrategyType());
}
} }
\ No newline at end of file \ No newline at end of file
  • @wangxw1
    commented
    Master

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

    1. Kafka 消费线程中执行同步 HTTP 请求(性能与稳定性风险)

    • 问题描述:在 StrategyCreatedConsumer 中直接调用了 strategyInfoService.processWorktoolStrategy,该方法内部最终通过 HttpRequestUtils.postJson 发起同步 HTTP 网络请求。
    • 影响分析:Kafka Consumer 的消费是单线程或绑定特定线程池的。如果企微/Worktool 推送接口出现网络波动、响应缓慢或超时,将直接阻塞 Kafka 消费线程,导致消息积压严重;极端情况下可能引发 Kafka 消费者心跳超时,触发频繁的 Rebalance,影响整个集群的稳定性。
    • 优化建议:将 HTTP 推送动作异步化处理。可以使用 @Async 注解,或者将推送任务提交到自定义的线程池中执行,同时必须为 HTTP 请求设置合理的连接超时和读取超时时间。 java // 建议在 Service 层或使用专门的异步组件处理 @Async("pushExecutor") public void processWorktoolStrategy(StrategyInfo strategyInfo) { // 原有逻辑... }

    2. API 包中修改已有的 Enum 枚举常量名称(破坏性变更风险)

    • 问题描述:在 rpc-dj-strategy-api 包下的 UserPositionEnum 中,将原有的 FLIGHT_SUPERVISION(6, "飞行督导") 修改为了 FLIGHT_SUPERVISION_1_1(6, "1.1飞行督导")。
    • 影响分析:API 包通常被多个微服务或模块依赖。直接修改枚举常量的名称属于不兼容的破坏性变更(Breaking Change)。如果其他依赖方代码中使用了 UserPositionEnum.FLIGHT_SUPERVISION 进行判断,更新 API 包后会导致编译报错;如果未重新编译直接部署,会在运行时抛出 NoSuchFieldError 异常。
    • 优化建议:为了保证向后兼容性,建议保留原有枚举名称,标记为 @Deprecated,并新增需要的枚举常量。 java /** * @deprecated 建议使用 FLIGHT_SUPERVISION_1_1 */ @Deprecated FLIGHT_SUPERVISION(6, "飞行督导"), FLIGHT_SUPERVISION_1_1(6, "1.1飞行督导"),

    3. HTTP 推送结果未校验业务响应状态(功能健壮性)

    • 问题描述:在 StrategyInfoService#sendGroupPush 方法中,调用 HttpRequestUtils.postJson 获取到 response 字符串后,仅进行了日志打印,随即直接 return true;,未对响应内容进行任何解析和校验。
    • 影响分析:第三方 HTTP 接口通常在业务失败时也会返回 HTTP 200 状态码,但在 JSON body 中包含错误码(如 {"code": 500, "msg": "群名不存在"})。当前代码会将这类业务失败统统视为“推送成功”,导致日志记录失真,掩盖线上真实的推送失败问题,增加排查难度。
    • 优化建议:解析 HTTP 响应的 JSON 字符串,判断第三方接口约定的业务成功状态码后再返回 true/false。 java String response = HttpRequestUtils.postJson(pushUrl, requestBody.toString()); log.info("协同任务群推送响应:{}", response); // 假设第三方接口成功时返回包含 "code": 200 或 "errcode": 0 JSONObject respJson = JSONUtil.parseObj(response); if (respJson.getInt("code", -1) == 200) { return true; } else { log.error("协同任务群推送业务失败,响应内容: {}", response); return false; }

    二、评分明细

    • 功能实现的正确性与健壮性(36/40分): 核心业务逻辑(DB查询、模板替换、组装发送)实现清晰,对各种空指针场景做了较好的防御性编程(如 strategyInfo == null,executor == null 等)。扣分点在于对 HTTP 请求的响应结果缺乏业务层面的断言,存在“假成功”的隐患。

    • 安全性与潜在风险(30/30分): 未见明显的 SQL 注入、越权或敏感信息泄露等安全漏洞,日志打印适度,无敏感数据明文暴露。

    • 最佳实践与可维护性(15/20分): 代码结构清晰,注释较为详尽,方法拆分合理(如 queryWorktoolRobotInfo 等独立方法增强了可读性)。扣分点在于在公共 API 包中直接重命名枚举常量,违背了接口/契约向后兼容的最佳实践。

    • 性能与资源利用(3/5分): 在 Kafka 消费主流程中串行执行多次 DB 查询和同步 HTTP 请求,存在拖慢消费速率和阻塞线程的性能隐患。

    • 提交信息质量(4/5分): Commit 信息(策略中心:协同任务,推送群消息实现)简明扼要地说明了业务目的,但未提及 API 包中枚举的破坏性修改,若有更详细的变更影响说明会更好。

    总分:88分

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