Commit bf3a9c0c by 林冲

fix(staff): 修复考勤申诉周期判断并添加日志输出

- 增加未配置T3时间周期的日志提示
- 添加是否驻店、是否上个月、是否在T3周期内的日志记录
- 优化考勤申诉和平板申诉条件复用,避免重复判断
- 添加缺失日报状态的日志输出
- 保持补日报逻辑不变,确保条件完整判定
1 parent 5b586fb0
...@@ -518,17 +518,22 @@ public class StaffSalaryAppealApplyRecordService { ...@@ -518,17 +518,22 @@ public class StaffSalaryAppealApplyRecordService {
if (t3Cycle != null && t3Cycle.getStartDate() != null && t3Cycle.getEndDate() != null) { if (t3Cycle != null && t3Cycle.getStartDate() != null && t3Cycle.getEndDate() != null) {
Date now = new Date(); Date now = new Date();
inT3Period = !now.before(t3Cycle.getStartDate()) && !now.after(t3Cycle.getEndDate()); inT3Period = !now.before(t3Cycle.getStartDate()) && !now.after(t3Cycle.getEndDate());
} else {
log.info("未配置T3时间周期");
} }
// 考勤申诉:只允许驻店人员在T3周期内申诉上个月的 // 考勤申诉:只允许驻店人员在T3周期内申诉上个月的
result.setAttendanceAppealable(isStoreStaff && isLastMonth && inT3Period); log.info("isStoreStaff:{}, isLastMonth:{}, inT3Period:{}", isStoreStaff, isLastMonth, inT3Period);
boolean allowAppeal = isStoreStaff && isLastMonth && inT3Period;
result.setAttendanceAppealable(allowAppeal);
// 平板申诉:只允许驻店人员在T3周期内申诉上个月的 // 平板申诉:只允许驻店人员在T3周期内申诉上个月的
result.setPadAppealable(isStoreStaff && isLastMonth && inT3Period); result.setPadAppealable(allowAppeal);
SimpleDateFormat sdf = new SimpleDateFormat("d"); SimpleDateFormat sdf = new SimpleDateFormat("d");
if (t3Cycle != null) { if (t3Cycle != null) {
result.setAppealStartTime(sdf.format(t3Cycle.getStartDate())); result.setAppealStartTime(sdf.format(t3Cycle.getStartDate()));
result.setAppealEndTime(sdf.format(t3Cycle.getEndDate())); result.setAppealEndTime(sdf.format(t3Cycle.getEndDate()));
} }
boolean existMissingDailyReport = CollUtil.isNotEmpty(result.getMissingDailyReportDates()); boolean existMissingDailyReport = CollUtil.isNotEmpty(result.getMissingDailyReportDates());
log.info("existMissingDailyReport:{}", existMissingDailyReport);
// 补日报:只允许在T1-T5周期内补上个月的日报、驻店人员、日报缺失、选择上个月 // 补日报:只允许在T1-T5周期内补上个月的日报、驻店人员、日报缺失、选择上个月
result.setDailyReportable(isStoreStaff && isLastMonth && existMissingDailyReport && checkTodayInT1ToT5()); result.setDailyReportable(isStoreStaff && isLastMonth && existMissingDailyReport && checkTodayInT1ToT5());
......
  • @wangxw1
    commented
    Master

    你好,我是负责本次代码审查的资深软件开发工程师。

    你提交的代码主要涉及薪资申诉记录服务中关于申诉周期和权限判断的逻辑修复及日志增强。代码逻辑清晰,意图明确,但在工程最佳实践、日志管理以及日期处理的细节上仍有优化空间。

    以下是我的审查意见:

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

    1. 日志级别使用不当,可能导致生产环境日志“噪音” (最佳实践)

    • 问题描述:代码中新增了多处 log.info,用于打印 boolean 标志位(如 isStoreStaff, inT3Period 等)。
    • 影响分析:StaffSalaryAppealApplyRecordService 属于高频调用的业务服务。在生产环境中,将此类调试(Debug)性质的信息输出为 INFO 级别,会导致日志文件迅速膨胀,增加磁盘 I/O 压力,并掩盖真正的业务关键日志,不利于运维排查问题。
    • 优化建议:建议将此类用于追踪逻辑流和变量状态的日志级别降级为 DEBUG。 java // 建议修改为 if (log.isDebugEnabled()) { log.debug("isStoreStaff:{}, isLastMonth:{}, inT3Period:{}", isStoreStaff, isLastMonth, inT3Period); log.debug("existMissingDailyReport:{}", existMissingDailyReport); }

    2. java.util.Date 比较逻辑存在潜在的边界缺陷 (功能正确性)

    • 问题描述:代码使用了 !now.after(t3Cycle.getEndDate()) 来判断是否在周期内。
    • 影响分析:java.util.Date 包含时间(时分秒)信息。通常数据库配置的周期结束日期(endDate)默认为当天的 00:00:00。如果当前时间 now 是结束日当天的中午(例如 12:00:00),now.after(endDate) 会返回 true,导致 inT3Period 被误判为 false。这意味着用户在周期的最后一天无法进行申诉。
    • 优化建议:比较日期区间时,应忽略时间部分,或者确保 endDate 被设置为当天的 23:59:59。建议使用 DateUtil (如 Hutool) 或 Java 8 的 LocalDate 进行比较。 java // 示例优化(假设使用 Hutool DateUtil 或类似工具) // 检查当前时间是否在 [start, end] 闭区间,忽略时分秒差异 inT3Period = DateUtil.isIn(new Date(), t3Cycle.getStartDate(), t3Cycle.getEndDate()); // 或者手动处理 endDate 为当天的 23:59:59

    3. 使用过时的 SimpleDateFormat 且频繁实例化 (性能与最佳实践)

    • 问题描述:代码中在方法内部执行了 SimpleDateFormat sdf = new SimpleDateFormat("d");。
    • 影响分析:虽然在方法内部局部变量使用 SimpleDateFormat 避免了线程安全问题,但该类是重对象,频繁创建销毁会有一定的性能开销。且 SimpleDateFormat 是 Java 旧版 API,现代 Java 开发推荐使用 DateTimeFormatter。
    • 优化建议:建议将其替换为线程安全的 DateTimeFormatter 并提取为静态常量,或者使用项目内现有的日期工具类。

      // 建议提取为类的静态常量
      private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("d");
      
      // 方法内使用
      result.setAppealStartTime(DAY_FORMATTER.format(t3Cycle.getStartDate().toInstant().atZone(ZoneId.systemDefault())));
      

    二、评分明细

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

      • 逻辑复用(allowAppeal)做得很好,减少了代码冗余。
      • 扣分点在于 Date 比较逻辑可能存在的“最后一天失效”的边界Bug。
    2. 安全性与潜在风险(30/30分)

      • 未发现明显的 SQL 注入、XSS 或越权风险。
      • 日志输出仅包含布尔值,无敏感数据泄露风险。
    3. 最佳实践与可维护性(10/20分)

      • 扣分较多。主要因为在生产代码中留存了大量 INFO 级别的调试日志,以及使用了不推荐的 SimpleDateFormat。
      • 代码结构和命名(如 allowAppeal)是清晰的。
    4. 性能与资源利用(4/5分)

      • SimpleDateFormat 的局部实例化有轻微性能损耗,但在非超高并发下可接受。
    5. 提交信息质量(5/5分)

      • Commit Message 格式规范(type: subject),描述清晰,准确覆盖了修改内容。

    三、总分

    总分:84分

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