|
@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.security.SecureRandom;
|
|
import java.security.SecureRandom;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
@@ -72,13 +73,14 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Result<Map<String, Object>> issueCode(Boolean isAdmin, Long operatorId, String sessionId,
|
|
|
|
|
|
|
+ public Result<Map<String, Object>> issueCode(Boolean isAdmin, Long userId, String sessionId,
|
|
|
Integer sessionHours, String category, String note) {
|
|
Integer sessionHours, String category, String note) {
|
|
|
- String noAuth = roleGuard.requireAdminRole(isAdmin);
|
|
|
|
|
|
|
+ // 权限三重校验:isAdmin | 任一 active 机构 org_admin/dispatcher | 该批次主讲讲师本人
|
|
|
|
|
+ String noAuth = checkIssueAuth(isAdmin, userId, sessionId);
|
|
|
if (noAuth != null) {
|
|
if (noAuth != null) {
|
|
|
return Result.error(noAuth);
|
|
return Result.error(noAuth);
|
|
|
}
|
|
}
|
|
|
- if (operatorId == null || sessionId == null || sessionId.trim().isEmpty()) {
|
|
|
|
|
|
|
+ if (userId == null || sessionId == null || sessionId.trim().isEmpty()) {
|
|
|
return Result.error("参数不完整");
|
|
return Result.error("参数不完整");
|
|
|
}
|
|
}
|
|
|
// cohort_id 为 NOT NULL:sessionId 必须含可解析的 cohortId 前缀
|
|
// cohort_id 为 NOT NULL:sessionId 必须含可解析的 cohortId 前缀
|
|
@@ -99,18 +101,18 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
if (active != null && active.getValidTo() != null && !active.getValidTo().before(now)) {
|
|
if (active != null && active.getValidTo() != null && !active.getValidTo().before(now)) {
|
|
|
return Result.success(codeVO(active));
|
|
return Result.success(codeVO(active));
|
|
|
}
|
|
}
|
|
|
- return doIssue(operatorId, sessionId, sessionHours, category, now);
|
|
|
|
|
|
|
+ return doIssue(userId, sessionId, sessionHours, category, now);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Result<Map<String, Object>> rotateCode(Boolean isAdmin, Long operatorId, String sessionId,
|
|
|
|
|
|
|
+ public Result<Map<String, Object>> rotateCode(Boolean isAdmin, Long userId, String sessionId,
|
|
|
Integer sessionHours, String category, String note) {
|
|
Integer sessionHours, String category, String note) {
|
|
|
- String noAuth = roleGuard.requireAdminRole(isAdmin);
|
|
|
|
|
|
|
+ String noAuth = checkIssueAuth(isAdmin, userId, sessionId);
|
|
|
if (noAuth != null) {
|
|
if (noAuth != null) {
|
|
|
return Result.error(noAuth);
|
|
return Result.error(noAuth);
|
|
|
}
|
|
}
|
|
|
- if (operatorId == null || sessionId == null || sessionId.trim().isEmpty()) {
|
|
|
|
|
|
|
+ if (userId == null || sessionId == null || sessionId.trim().isEmpty()) {
|
|
|
return Result.error("参数不完整");
|
|
return Result.error("参数不完整");
|
|
|
}
|
|
}
|
|
|
Long cohortId = parseCohortId(sessionId);
|
|
Long cohortId = parseCohortId(sessionId);
|
|
@@ -121,7 +123,36 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
return Result.error("批次不存在");
|
|
return Result.error("批次不存在");
|
|
|
}
|
|
}
|
|
|
Date now = new Date();
|
|
Date now = new Date();
|
|
|
- return doIssue(operatorId, sessionId, sessionHours, category, now);
|
|
|
|
|
|
|
+ return doIssue(userId, sessionId, sessionHours, category, now);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发码权限校验(Service 方法内,非注解):
|
|
|
|
|
+ * ① isAdmin=true 直接放行;
|
|
|
|
|
+ * ② userId 是任一 active 机构成员(角色∈{org_admin,dispatcher},复用 RoleGuard.requireOrgManager);
|
|
|
|
|
+ * ③ 或该 session 所属 batch 的 lecturer_id == userId(主讲讲师本人)。
|
|
|
|
|
+ * 合法返回 null,越权返回中文 message。
|
|
|
|
|
+ */
|
|
|
|
|
+ private String checkIssueAuth(Boolean isAdmin, Long userId, String sessionId) {
|
|
|
|
|
+ if (Boolean.TRUE.equals(isAdmin)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (userId == null) {
|
|
|
|
|
+ return "需要登录";
|
|
|
|
|
+ }
|
|
|
|
|
+ Long cohortId = parseCohortId(sessionId);
|
|
|
|
|
+ String orgErr = roleGuard.requireOrgManager(userId);
|
|
|
|
|
+ if (orgErr == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 兜底:主讲讲师本人
|
|
|
|
|
+ if (cohortId != null) {
|
|
|
|
|
+ TrainCohort cohort = trainCohortMapper.selectById(cohortId);
|
|
|
|
|
+ if (cohort != null && cohort.getLecturerId() != null && cohort.getLecturerId().equals(userId)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return orgErr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 实际发码:轮换本 session 所有 active 旧码 + 新建 active 码 */
|
|
/** 实际发码:轮换本 session 所有 active 旧码 + 新建 active 码 */
|
|
@@ -307,6 +338,9 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
m.put("hours", a.getSessionHours() == null ? 0 : a.getSessionHours()); // 分钟
|
|
m.put("hours", a.getSessionHours() == null ? 0 : a.getSessionHours()); // 分钟
|
|
|
m.put("category", a.getSessionCategory());
|
|
m.put("category", a.getSessionCategory());
|
|
|
m.put("attendedAt", a.getAttendedAt());
|
|
m.put("attendedAt", a.getAttendedAt());
|
|
|
|
|
+ // 修复2:前端契约键 attended(bool) / time('yyyy-MM-dd HH:mm'),保留 attendedAt
|
|
|
|
|
+ m.put("attended", !ST_REJECTED.equals(a.getStatus())); // 非 rejected 视为已出勤
|
|
|
|
|
+ m.put("time", formatTime(a.getAttendedAt()));
|
|
|
m.put("status", a.getStatus());
|
|
m.put("status", a.getStatus());
|
|
|
m.put("source", a.getSource());
|
|
m.put("source", a.getSource());
|
|
|
m.put("effectiveAt", a.getEffectiveAt());
|
|
m.put("effectiveAt", a.getEffectiveAt());
|
|
@@ -324,10 +358,49 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
m.put("category", c.getSessionCategory());
|
|
m.put("category", c.getSessionCategory());
|
|
|
m.put("validFrom", c.getValidFrom());
|
|
m.put("validFrom", c.getValidFrom());
|
|
|
m.put("validTo", c.getValidTo());
|
|
m.put("validTo", c.getValidTo());
|
|
|
|
|
+ m.put("expireAt", c.getValidTo());
|
|
|
m.put("status", c.getStatus());
|
|
m.put("status", c.getStatus());
|
|
|
|
|
+ // 修复3:展示辅助键(前端 qr.vue 绑定 name/cohortName/startAt/endAt)
|
|
|
|
|
+ TrainCohort cohort = c.getCohortId() == null ? null : trainCohortMapper.selectById(c.getCohortId());
|
|
|
|
|
+ if (cohort != null) {
|
|
|
|
|
+ m.put("cohortName", cohort.getName() == null ? "" : cohort.getName());
|
|
|
|
|
+ m.put("startAt", cohort.getStartAt());
|
|
|
|
|
+ m.put("endAt", cohort.getEndAt());
|
|
|
|
|
+ String seq = parseSeq(c.getSessionId());
|
|
|
|
|
+ m.put("sessionName", cohort.getName() + (seq == null ? " 现场签到" : " 第" + seq + "次课"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ m.put("cohortName", "");
|
|
|
|
|
+ m.put("startAt", null);
|
|
|
|
|
+ m.put("endAt", null);
|
|
|
|
|
+ m.put("sessionName", "现场签到");
|
|
|
|
|
+ }
|
|
|
return m;
|
|
return m;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 时间格式化为 'yyyy-MM-dd HH:mm'(可空) */
|
|
|
|
|
+ private String formatTime(Date d) {
|
|
|
|
|
+ if (d == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(d);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 从 sessionId({cohortId}:{seq} 或 {cohortId}-{seq})取场次序号,解析失败返回 null */
|
|
|
|
|
+ private String parseSeq(String sessionId) {
|
|
|
|
|
+ if (sessionId == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ int idx = sessionId.indexOf(':');
|
|
|
|
|
+ if (idx < 0) {
|
|
|
|
|
+ idx = sessionId.indexOf('-');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (idx < 0 || idx + 1 >= sessionId.length()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ String tail = sessionId.substring(idx + 1).trim();
|
|
|
|
|
+ return tail.isEmpty() ? null : tail;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private Long parseCohortId(String sessionId) {
|
|
private Long parseCohortId(String sessionId) {
|
|
|
if (sessionId == null) {
|
|
if (sessionId == null) {
|
|
|
return null;
|
|
return null;
|