|
@@ -277,10 +277,10 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
.eq(TrainAttendanceCode::getStatus, ST_ACTIVE)
|
|
.eq(TrainAttendanceCode::getStatus, ST_ACTIVE)
|
|
|
.last("LIMIT 1"));
|
|
.last("LIMIT 1"));
|
|
|
if (c == null) {
|
|
if (c == null) {
|
|
|
- return Result.error("签到码无效");
|
|
|
|
|
|
|
+ return Result.error(CODE_NOT_FOUND, "签到码无效");
|
|
|
}
|
|
}
|
|
|
if (c.getValidTo() != null && c.getValidTo().before(now)) {
|
|
if (c.getValidTo() != null && c.getValidTo().before(now)) {
|
|
|
- return Result.error("签到码已过期,请重新发码");
|
|
|
|
|
|
|
+ return Result.error(CODE_NOT_FOUND, "签到码已过期,请重新发码");
|
|
|
}
|
|
}
|
|
|
// 2. 校验报名:该用户须为所扫批次 approved 报名人
|
|
// 2. 校验报名:该用户须为所扫批次 approved 报名人
|
|
|
TrainCohortSignup sig = trainCohortSignupMapper.selectOne(
|
|
TrainCohortSignup sig = trainCohortSignupMapper.selectOne(
|
|
@@ -290,8 +290,11 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
.eq(TrainCohortSignup::getStatus, SIG_APPROVED)
|
|
.eq(TrainCohortSignup::getStatus, SIG_APPROVED)
|
|
|
.last("LIMIT 1"));
|
|
.last("LIMIT 1"));
|
|
|
if (sig == null) {
|
|
if (sig == null) {
|
|
|
- return Result.error("未通过该批次报名审核,无法签到");
|
|
|
|
|
|
|
+ return Result.error(CODE_FORBIDDEN, "未通过该批次报名审核,无法签到");
|
|
|
}
|
|
}
|
|
|
|
|
+ // 归一化本次扫码载荷(学时/分类),供幂等一致性校验与台账入账复用
|
|
|
|
|
+ int hours = c.getSessionHours() == null || c.getSessionHours() <= 0 ? 480 : c.getSessionHours();
|
|
|
|
|
+ String category = c.getSessionCategory() == null ? "other" : c.getSessionCategory();
|
|
|
// 3. 反扫幂等:attendance uk(user_id,session_id)
|
|
// 3. 反扫幂等:attendance uk(user_id,session_id)
|
|
|
TrainAttendance exist = trainAttendanceMapper.selectOne(
|
|
TrainAttendance exist = trainAttendanceMapper.selectOne(
|
|
|
new LambdaQueryWrapper<TrainAttendance>()
|
|
new LambdaQueryWrapper<TrainAttendance>()
|
|
@@ -300,18 +303,23 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
.eq(TrainAttendance::getDeleted, 0)
|
|
.eq(TrainAttendance::getDeleted, 0)
|
|
|
.last("LIMIT 1"));
|
|
.last("LIMIT 1"));
|
|
|
if (exist != null) {
|
|
if (exist != null) {
|
|
|
- // 已签到,返回已存在视图(幂等,不重复入账)
|
|
|
|
|
|
|
+ // 幂等键命中:载荷须一致,否则 C4092(禁止静默复用旧签到记录)
|
|
|
|
|
+ int existHours = exist.getSessionHours() == null || exist.getSessionHours() <= 0 ? 480 : exist.getSessionHours();
|
|
|
|
|
+ String existCategory = exist.getSessionCategory() == null ? "other" : exist.getSessionCategory();
|
|
|
|
|
+ if (existHours != hours || !category.equals(existCategory)) {
|
|
|
|
|
+ return Result.error(CODE_PAYLOAD_CONFLICT, "同场次签到学时/分类与本次扫码不一致");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 已签到且载荷一致,返回已存在视图(幂等,不重复入账)
|
|
|
return Result.success(attVO(exist, true));
|
|
return Result.success(attVO(exist, true));
|
|
|
}
|
|
}
|
|
|
// 4. 写 attendance(pending)
|
|
// 4. 写 attendance(pending)
|
|
|
- int hours = c.getSessionHours() == null || c.getSessionHours() <= 0 ? 480 : c.getSessionHours();
|
|
|
|
|
TrainAttendance att = new TrainAttendance();
|
|
TrainAttendance att = new TrainAttendance();
|
|
|
att.setUserId(userId);
|
|
att.setUserId(userId);
|
|
|
att.setCohortId(c.getCohortId());
|
|
att.setCohortId(c.getCohortId());
|
|
|
att.setSessionId(c.getSessionId());
|
|
att.setSessionId(c.getSessionId());
|
|
|
att.setCode(c.getCode());
|
|
att.setCode(c.getCode());
|
|
|
att.setSessionHours(hours);
|
|
att.setSessionHours(hours);
|
|
|
- att.setSessionCategory(c.getSessionCategory() == null ? "other" : c.getSessionCategory());
|
|
|
|
|
|
|
+ att.setSessionCategory(category);
|
|
|
att.setAttendedAt(now);
|
|
att.setAttendedAt(now);
|
|
|
att.setSource("scan");
|
|
att.setSource("scan");
|
|
|
att.setStatus(ST_PENDING);
|
|
att.setStatus(ST_PENDING);
|
|
@@ -319,7 +327,7 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
try {
|
|
try {
|
|
|
trainAttendanceMapper.insert(att);
|
|
trainAttendanceMapper.insert(att);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- // uk 冲突(并发扫码)→ 幂等返回已存在
|
|
|
|
|
|
|
+ // uk 冲突(并发扫码)→ 幂等返回已存在;未查到重复记录则 C422(并发丢失更新)
|
|
|
TrainAttendance dup = trainAttendanceMapper.selectOne(
|
|
TrainAttendance dup = trainAttendanceMapper.selectOne(
|
|
|
new LambdaQueryWrapper<TrainAttendance>()
|
|
new LambdaQueryWrapper<TrainAttendance>()
|
|
|
.eq(TrainAttendance::getUserId, userId)
|
|
.eq(TrainAttendance::getUserId, userId)
|
|
@@ -328,7 +336,7 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
if (dup != null) {
|
|
if (dup != null) {
|
|
|
return Result.success(attVO(dup, true));
|
|
return Result.success(attVO(dup, true));
|
|
|
}
|
|
}
|
|
|
- return Result.error("签到失败,请重试");
|
|
|
|
|
|
|
+ return Result.error(CODE_VERSION_CONFLICT, "签到失败,请重试");
|
|
|
}
|
|
}
|
|
|
// 5. 台账入账(pending,T+3 生效)—— 同事务
|
|
// 5. 台账入账(pending,T+3 生效)—— 同事务
|
|
|
creditService.ledgerPending(userId, SRC_ATTENDANCE, String.valueOf(att.getId()),
|
|
creditService.ledgerPending(userId, SRC_ATTENDANCE, String.valueOf(att.getId()),
|