Commit 5eb9c71b by 谢海旭

v5.7.0版本 飞行督导

1 parent 109cddb1
...@@ -5,10 +5,13 @@ import cn.com.glsk.omni.ai.remote.AgiRemote; ...@@ -5,10 +5,13 @@ import cn.com.glsk.omni.ai.remote.AgiRemote;
import cn.com.glsx.dj.supervisor.model.SupervisorAiAnalysisRecord; import cn.com.glsx.dj.supervisor.model.SupervisorAiAnalysisRecord;
import cn.com.glsx.dj.supervisor.service.SupervisorAiAnalysisRecordService; import cn.com.glsx.dj.supervisor.service.SupervisorAiAnalysisRecordService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dangdang.ddframe.job.api.ShardingContext; import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob; import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf; import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -64,7 +67,7 @@ public class SupervisorAiAnalysisQueryJob implements SimpleJob { ...@@ -64,7 +67,7 @@ public class SupervisorAiAnalysisQueryJob implements SimpleJob {
* *
* @param record 待查询的 AI 分析记录 * @param record 待查询的 AI 分析记录
*/ */
private void queryAndUpdateRecord(SupervisorAiAnalysisRecord record) { public void queryAndUpdateRecord(SupervisorAiAnalysisRecord record) {
Long recordId = record.getId(); Long recordId = record.getId();
String aiTaskId = record.getAiTaskId(); String aiTaskId = record.getAiTaskId();
try { try {
...@@ -98,6 +101,22 @@ public class SupervisorAiAnalysisQueryJob implements SimpleJob { ...@@ -98,6 +101,22 @@ public class SupervisorAiAnalysisQueryJob implements SimpleJob {
// 任务成功,更新结果 // 任务成功,更新结果
String result = businessResponse.getMessage(); String result = businessResponse.getMessage();
// 类型为 4-人员 时,从返回的 JSON 中取 content 字段作为保存内容
if (Integer.valueOf(4).equals(record.getType())) {
if (StringUtils.isNotBlank(result)) {
try {
JSONObject jsonObject = JSON.parseObject(result);
String content = jsonObject.getString("content");
if (StringUtils.isNotBlank(content)) {
result = content;
} else {
log.warn("AI 分析结果 JSON 中 content 字段为空,recordId={},aiTaskId={},rawResult={}", recordId, aiTaskId, result);
}
} catch (Exception e) {
log.warn("解析 AI 分析结果 JSON 失败,recordId={},aiTaskId={},rawResult={}", recordId, aiTaskId, result, e);
}
}
}
log.info("AI 分析任务成功,recordId={},aiTaskId={},resultLength={}", recordId, aiTaskId, result != null ? result.length() : 0); log.info("AI 分析任务成功,recordId={},aiTaskId={},resultLength={}", recordId, aiTaskId, result != null ? result.length() : 0);
supervisorAiAnalysisRecordService.updateAiTaskResult(recordId, AI_TASK_STATUS_SUCCESS, result); supervisorAiAnalysisRecordService.updateAiTaskResult(recordId, AI_TASK_STATUS_SUCCESS, result);
......
...@@ -30,9 +30,12 @@ public class PersonCourseRecommendationService { ...@@ -30,9 +30,12 @@ public class PersonCourseRecommendationService {
*/ */
public Page<MyselfCourseRecommendDTO> getPersonCourseRecommendPage(RpcPagination<MyselfCourseRecommendDTO> pagination) { public Page<MyselfCourseRecommendDTO> getPersonCourseRecommendPage(RpcPagination<MyselfCourseRecommendDTO> pagination) {
Page<MyselfCourseRecommendDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize()); Page<MyselfCourseRecommendDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
personCourseRecommendationMapper.getPersonCourseRecommendPage(pagination.getCondition()); MyselfCourseRecommendDTO condition = pagination.getCondition();
if (condition == null) {
condition = new MyselfCourseRecommendDTO();
}
personCourseRecommendationMapper.getPersonCourseRecommendPage(condition);
log.info("分页查询人员课程推荐数据,pagination={}", pagination); log.info("分页查询人员课程推荐数据,pagination={}", pagination);
return page; return page;
} }
} }
...@@ -78,7 +78,7 @@ public class SupervisorLearningCenterService { ...@@ -78,7 +78,7 @@ public class SupervisorLearningCenterService {
.collect(Collectors.toList()); .collect(Collectors.toList());
List<BeiSenEmployeeListResonseDTO> employeeList = org.apache.commons.collections4.CollectionUtils.isEmpty(phoneList) List<BeiSenEmployeeListResonseDTO> employeeList = org.apache.commons.collections4.CollectionUtils.isEmpty(phoneList)
? null : listEmployeeInfoByStaffPhone(phoneList); ? null : listEmployeeInfoByStaffPhone(phoneList);
Map<String, Integer> phoneUserIdMap = Collections.EMPTY_MAP; Map<String, Integer> phoneUserIdMap = new HashMap<>();
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(employeeList)) { if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(employeeList)) {
//构建map //构建map
phoneUserIdMap = employeeList.stream().collect(Collectors.toMap(BeiSenEmployeeListResonseDTO::getMobilePhone, BeiSenEmployeeListResonseDTO::getUserID)); phoneUserIdMap = employeeList.stream().collect(Collectors.toMap(BeiSenEmployeeListResonseDTO::getMobilePhone, BeiSenEmployeeListResonseDTO::getUserID));
......
...@@ -521,18 +521,20 @@ public class SupervisorTaskInfoService { ...@@ -521,18 +521,20 @@ public class SupervisorTaskInfoService {
//根据员工手机号,查询北森员工信息 //根据员工手机号,查询北森员工信息
String phoneNumber = taskInfo.getStoreManagerPhone(); String phoneNumber = taskInfo.getStoreManagerPhone();
log.info("调用北森接口获取人员基本信息,手机号:{}", phoneNumber); log.info("调用北森接口获取人员基本信息,手机号:{}", phoneNumber);
List<String> phoneNumbers = new ArrayList<>(); if (StringUtils.isNotBlank(phoneNumber)) {
phoneNumbers.add(phoneNumber); List<String> phoneNumbers = new ArrayList<>();
RpcResponse<List<BeisenEmployeeInfoDTO>> beisenResponse = merchantUserRemote.selectByPhones(phoneNumbers); phoneNumbers.add(phoneNumber);
if (beisenResponse.isSuccess() && beisenResponse.getResult() != null && !beisenResponse.getResult().isEmpty()) { RpcResponse<List<BeisenEmployeeInfoDTO>> beisenResponse = merchantUserRemote.selectByPhones(phoneNumbers);
BeisenEmployeeInfoDTO beisenInfo = beisenResponse.getResult().get(0); if (beisenResponse.isSuccess() && beisenResponse.getResult() != null && !beisenResponse.getResult().isEmpty()) {
if (beisenInfo.getEntryDate() != null) { BeisenEmployeeInfoDTO beisenInfo = beisenResponse.getResult().get(0);
taskInfo.setEntryDate( if (beisenInfo.getEntryDate() != null) {
DateUtils.formatDate(beisenInfo.getEntryDate())); // 北森-人员-入职日期 taskInfo.setEntryDate(
} DateUtils.formatDate(beisenInfo.getEntryDate())); // 北森-人员-入职日期
// 性别:0男、1女 }
if (beisenInfo.getGender() != null) { // 性别:0男、1女
taskInfo.setGender(beisenInfo.getGender() == 0 ? "男" : "女"); if (beisenInfo.getGender() != null) {
taskInfo.setGender(beisenInfo.getGender() == 0 ? "男" : "女");
}
} }
} }
String businessScene = businessSceneMapper.getBusinessSceneByPhoneNumber(phoneNumber); String businessScene = businessSceneMapper.getBusinessSceneByPhoneNumber(phoneNumber);
......
package cn.com.glsx.dj.supervisor.job;
import cn.com.glsx.dj.supervisor.model.SupervisorAiAnalysisRecord;
import cn.com.glsx.dj.supervisor.service.BaseServiceTest;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @Title:
* @Description:
* @Author xiehx
* @Date 2026/3/24
**/
public class SupervisorAiAnalysisQueryJobTest extends BaseServiceTest {
@Autowired
private SupervisorAiAnalysisQueryJob supervisorAiAnalysisQueryJob;
@Test
public void testQueryAndUpdateRecord() {
SupervisorAiAnalysisRecord record = new SupervisorAiAnalysisRecord();
record.setId(10000L);
record.setType(4);
record.setAiTaskId("Task-2036284815216476160");
supervisorAiAnalysisQueryJob.queryAndUpdateRecord(record);
}
}
\ No newline at end of file \ No newline at end of file
  • @wangxw1
    commented
    Master

    你好,我是资深 Java 开发工程师。针对你提供的代码变更,我进行了详细的审查。

    本次代码变更主要涉及业务逻辑的空指针防御、JSON 解析逻辑增强以及单元测试的补充。整体来看,代码增强了健壮性,但在代码规范(Magic Number)、单元测试质量及封装性方面存在改进空间。

    以下是审查结果:

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

    1. 代码可维护性问题:存在“魔法值” (Magic Number)

      • 位置: SupervisorAiAnalysisQueryJob.java 第 105 行
      • 问题: 代码中直接使用了数字 4 (Integer.valueOf(4).equals(record.getType())) 来判断记录类型。这违反了《阿里巴巴 Java 开发手册》中“禁止在代码中直接使用魔法值”的规定。
      • 建议: 应在常量类或枚举类(如 AiAnalysisRecordTypeEnum)中定义该常量,例如 public static final int TYPE_PERSONNEL = 4;,以提高代码的可读性和可维护性。
    2. 单元测试质量与规范:依赖环境且数据硬编码

      • 位置: SupervisorAiAnalysisQueryJobTest.java
      • 问题:
        • 硬编码: 测试用例中硬编码了数据库 ID (10000L) 和 TaskId。这通常是本地调试遗留代码,在 CI/CD 流水线或其他开发者的环境中极易运行失败。
        • 依赖外部环境: 继承了 BaseServiceTest,意味着这是一个集成测试而非单元测试,依赖真实的数据库和 RPC 服务,导致测试脆弱且运行缓慢。
      • 建议:
        • 如果是单元测试,应使用 Mockito 等框架 Mock 掉 DAO 和 RPC 调用,验证逻辑而非数据。
        • 如果是集成测试,应使用 H2 内存数据库或在测试开始前自动初始化数据(Setup),测试结束后清理数据(Teardown),确保测试的可重复性。
    3. 封装性破坏:为测试修改方法可见性

      • 位置: SupervisorAiAnalysisQueryJob.java 第 67 行
      • 问题: 将核心业务方法 queryAndUpdateRecord 的修饰符从 private 修改为 public,且仅为了配合新增的测试类调用。这破坏了类的封装性,使得该方法可能被其他业务服务误调用。
      • 建议:
        • 保持 private,通过反射进行测试(不推荐)。
        • 推荐做法:将该方法逻辑抽取到独立的 Service 或 Manager 类中作为 public 方法,或者如果必须在当前类测试,可以使用 Guava 的 @VisibleForTesting 注解标记(仅起提示作用),或将修饰符改为 protected/默认包权限(package-private),尽量避免直接暴露为 public。

    二、评分明细

    维度 评分项 权重 得分 扣分/得分理由
    1. 功能正确性 逻辑正确与健壮性 40 38 (+): 修复了 PersonCourseRecommendationService 和 SupervisorTaskInfoService 中的潜在空指针异常(NPE),增加了防御性编程。
    (+): SupervisorLearningCenterService 中将不可变 Map 替换为 HashMap,避免了潜在的修改异常。
    (-): JSON 解析逻辑中 Integer.valueOf(4) 虽然安全但略显冗余。
    2. 安全性 漏洞与风险 30 27 (-): 使用了 com.alibaba.fastjson。FastJSON 1.x 版本历史漏洞较多,建议检查版本是否升级到安全版本,或迁移至 FastJSON2 / Jackson。解析外部传入的 JSON 字符串时需警惕。
    3. 可维护性 规范与设计 20 12 (-5): 存在魔法值 4。
    (-3): 随意修改方法可见性 (private -> public)。
    (-): 测试代码质量较低(硬编码)。
    4. 性能 资源利用 5 5 (+): SupervisorTaskInfoService 中增加了手机号非空判断,避免了无效的 RPC 远程调用,节省了网络资源。
    5. 提交信息 清晰度 5 4 提交信息基本清晰,但可以更详细地描述“飞行督导”具体修改了什么逻辑(如:增加AI分析结果解析)。

    总分:86分

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