| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package com.train.controller.admin;
- import com.train.common.Result;
- import com.train.service.AttendanceService;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestAttribute;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- import java.util.Map;
- /**
- * 管理端-培训签到 Controller(发码 / 轮换 / 待生效列表)。
- *
- * 权限(Service 层经 RoleGuard 校验 isAdmin):全部端点仅 admin 可访问。
- * - issueCode 幂等返回:同 session active 码未过期则复用
- * - rotateCode 强制轮换
- * - 学时字段一律「分钟」整数;code 有效期可配 app.attendance.code-valid-minutes(默认 5 分钟)
- */
- @Tag(name = "管理端-培训签到", description = "发码 / 轮换 / 待生效签到列表")
- @RestController
- @RequestMapping("/api/admin/attendance")
- public class AdminAttendanceController {
- @Resource
- private AttendanceService attendanceService;
- /**
- * 发码(幂等返回)
- * body: {sessionId, sessionHours?(分钟), category?(theory/practice/other)}
- */
- @Operation(summary = "发签到码(幂等)")
- @PostMapping("/issueCode")
- public Result<Map<String, Object>> issueCode(
- @RequestAttribute(value = "adminId", required = false) Long adminId,
- @RequestAttribute(value = "isAdmin", required = false) Boolean isAdmin,
- @RequestBody(required = false) Map<String, Object> body) {
- String sessionId = body == null || body.get("sessionId") == null ? null : body.get("sessionId").toString().trim();
- Integer hours = toInt(body == null ? null : body.get("sessionHours"));
- String category = body == null || body.get("category") == null ? null : body.get("category").toString().trim();
- String note = body == null || body.get("note") == null ? null : body.get("note").toString().trim();
- return attendanceService.issueCode(isAdmin, adminId, sessionId, hours, category, note);
- }
- /**
- * 轮换码
- * body: {sessionId, sessionHours?(分钟), category?(theory/practice/other)}
- */
- @Operation(summary = "轮换签到码")
- @PostMapping("/rotateCode")
- public Result<Map<String, Object>> rotateCode(
- @RequestAttribute(value = "adminId", required = false) Long adminId,
- @RequestAttribute(value = "isAdmin", required = false) Boolean isAdmin,
- @RequestBody(required = false) Map<String, Object> body) {
- String sessionId = body == null || body.get("sessionId") == null ? null : body.get("sessionId").toString().trim();
- Integer hours = toInt(body == null ? null : body.get("sessionHours"));
- String category = body == null || body.get("category") == null ? null : body.get("category").toString().trim();
- String note = body == null || body.get("note") == null ? null : body.get("note").toString().trim();
- return attendanceService.rotateCode(isAdmin, adminId, sessionId, hours, category, note);
- }
- /**
- * 待生效签到列表(真分页)
- * body: {cohortId?, page?, size?}
- */
- @Operation(summary = "待生效签到列表(分页)")
- @PostMapping("/pending")
- public Result<Map<String, Object>> pending(
- @RequestAttribute(value = "isAdmin", required = false) Boolean isAdmin,
- @RequestBody(required = false) Map<String, Object> body) {
- Long cohortId = toLong(body == null ? null : body.get("cohortId"));
- Integer page = toInt(body == null ? null : body.get("page"));
- Integer size = toInt(body == null ? null : body.get("size"));
- return attendanceService.pendingAttendance(isAdmin, cohortId, page, size);
- }
- private Long toLong(Object v) {
- if (v == null) {
- return null;
- }
- try {
- return Long.valueOf(v.toString().trim());
- } catch (NumberFormatException e) {
- return null;
- }
- }
- private Integer toInt(Object v) {
- if (v == null) {
- return null;
- }
- try {
- return Integer.valueOf(v.toString().trim());
- } catch (NumberFormatException e) {
- return null;
- }
- }
- }
|