Commit fdaaa171 by 张富康

fix(attendance): 改进考勤数据插入逻辑,支持单条失败重试

- 优化考勤打卡日期与离职日期比较的代码格式
- 将原批量插入改为逐条插入,避免单条数据影响整体处理
- 捕获单条插入异常,记录详细失败信息及错误日志
- 移除批量插入事务控制,增强插入灵活性和稳定性
- 在每批次处理后清理内存,防止内存泄漏
1 parent 509da204
......@@ -311,7 +311,7 @@ public class AttendanceDataCleansingService {
// 2. 处理每条考勤记录
// 判断该打卡日期是否在离职直接之后,如果在离职日期之后则不计算
if (StrUtil.isNotBlank(employee.getLastWorkDate())) {
if(DateUtil.compare(DateUtil.parse(clockInfo.getClockInDate(), "yyyy-MM-dd"), DateUtil.parse(employee.getLastWorkDate(), "yyyy-MM-dd")) > 0){
if (DateUtil.compare(DateUtil.parse(clockInfo.getClockInDate(), "yyyy-MM-dd"), DateUtil.parse(employee.getLastWorkDate(), "yyyy-MM-dd")) > 0) {
log.info("{} 打卡日期:{},离职日期:{} 打卡日期在离职日期之后,不处理", employee.getStaffName(), clockInfo.getClockInDate(), employee.getLastWorkDate());
continue;
}
......@@ -416,24 +416,23 @@ public class AttendanceDataCleansingService {
// 处理每个批次
for (List<AttendanceSummary> batch : batches) {
try {
// 1. 开启事务
TransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
try {
// 2. 执行批量插入
attendanceSummaryMapper.insertOrUpdateBatch(batch);
transactionManager.commit(status);
log.info("成功插入 {} 条考勤数据", batch.size());
} catch (Exception e) {
// 3. 批量插入失败,回滚事务
transactionManager.rollback(status);
throw e;
for (AttendanceSummary summary : batch) {
try {
// 尝试单条插入
insertAttendanceData(summary);
} catch (Exception ex) {
// 记录详细失败信息
recordFailure(summary.getMobilePhone(), summary.getAttendanceMonth(),
"单条插入失败: " + ex.getMessage());
// 记录关键日志
log.error("单条插入失败 [phone: {}, month: {}] - {}",
summary.getMobilePhone(),
summary.getAttendanceMonth(),
ex.getMessage()
);
}
}
} catch (Exception e) {
// 4. 批量插入失败,重试单条插入
log.error("批量插入失败,开始单条重试 [batchSize: {}]", batch.size());
processSingleInsertBatch(batch);
} finally {
// 5. 释放内存
batch.clear();
......@@ -773,7 +772,6 @@ public class AttendanceDataCleansingService {
}
private ClockInResult processWithMerchant(StaffQwClockClean clockInfo, MerchantAttendanceList merchant, StaffBeisenBaseInfo employee) {
log.info("策略一:处理打卡时间:{}-{},经纬度:{},{}", clockInfo.getClockInTimeStart(), clockInfo.getClockOutTimeEnd(),
merchant.getAddressLng(), merchant.getAddressLat());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!