Browse Source

feat(backend): 补齐后台9视图契约端点6项

按 train-web 216e790 已消费的契约路径/字段补齐 6 个占位端点(路径逐字、字段名以 train-web 实际用法为最高约束):
- /api/admin/org/member/disable {orgId,userId}→Result<Boolean>,置 train_org_member.status=disabled,uk org_id+user_id,缺失报「成员不存在」,幂等
- /api/admin/cohort/list {keyword?,status?,page,size}→分页(id 倒序),复用 cohortVO + countApproved,新增 enrolledCount 别名
- /api/admin/attendance/list {cohortId?,sessionId?,status?,page,size}→分页(attended_at 倒序),复用 attVO + 补 id/userName/code/sessionHours/sessionCategory
- /api/admin/credit/account/list {year?,keyword?,page,size}→分页,按学员×年度聚合,返回 totalHours/theoryHours/practiceHours/effectiveHours/pendingHours/status + 短别名
- /api/admin/credit/ledger/detail {userId,year?}→List 台账流水(id 倒序,含 sourceId)
- /api/admin/credit/ledger/objected 双模:含 id 走异议处置 {id,approved,reason?}→Result<Boolean>;无 id 走异议列表(前端已消费)

学时账户物化收敛为唯一写回路径 accrueAccount:applyEffective(pending→effective,含 deductPending)与新增 restoreEffective(objected→effective 补救恢复,不再扣 pending,防重复扣减)共用;异议否决沿用既有 applyRollBack。
分页统一手写 LIMIT/OFFSET(项目无 PaginationInnerInterceptor)。禁 git add -A、未 push。mvn clean compile -DskipTests BUILD SUCCESS。
liaoxg 3 hours ago
parent
commit
dc6d14ed12

+ 12 - 0
train-backend/src/main/java/com/train/controller/admin/AdminAttendanceController.java

@@ -29,6 +29,18 @@ public class AdminAttendanceController {
     @Resource
     @Resource
     private AttendanceService attendanceService;
     private AttendanceService attendanceService;
 
 
+    /**
+     * 签到记录列表(管理端全量;真分页 attended_at 倒序)
+     * body: {cohortId?, sessionId?, status?, page?, size?}
+     */
+    @Operation(summary = "签到记录列表(分页,全量)")
+    @PostMapping("/list")
+    public Result<Map<String, Object>> list(
+            @RequestAttribute(value = "isAdmin", required = false) Boolean isAdmin,
+            @RequestBody(required = false) Map<String, Object> body) {
+        return attendanceService.adminList(isAdmin, body);
+    }
+
     /**
     /**
      * 发码(幂等返回)
      * 发码(幂等返回)
      * body: {sessionId, sessionHours?(分钟), category?(theory/practice/other)}
      * body: {sessionId, sessionHours?(分钟), category?(theory/practice/other)}

+ 13 - 0
train-backend/src/main/java/com/train/controller/admin/AdminCohortController.java

@@ -29,6 +29,19 @@ public class AdminCohortController {
     @Resource
     @Resource
     private CohortService cohortService;
     private CohortService cohortService;
 
 
+    /**
+     * 批次列表(管理端全量,含草稿/已关闭;真分页 id 倒序)
+     * body: {keyword?, status?, page?, size?}
+     */
+    @Operation(summary = "批次列表(分页,全量含草稿/已关闭)")
+    @PostMapping("/list")
+    public Result<Map<String, Object>> list(
+            @RequestAttribute(value = "adminId", required = false) Long adminId,
+            @RequestAttribute(value = "isAdmin", required = false) Boolean isAdmin,
+            @RequestBody(required = false) Map<String, Object> body) {
+        return cohortService.adminList(adminId, isAdmin, body);
+    }
+
     /**
     /**
      * 创建批次(草稿)
      * 创建批次(草稿)
      * body: {courseId, name, code?, startAt?, endAt?, signupDeadline?, capacity?, creditHours?, creditTheoryHours?, creditPracticeHours?, place?, lecturerId?}
      * body: {courseId, name, code?, startAt?, endAt?, signupDeadline?, capacity?, creditHours?, creditTheoryHours?, creditPracticeHours?, place?, lecturerId?}

+ 71 - 1
train-backend/src/main/java/com/train/controller/admin/AdminCreditController.java

@@ -12,12 +12,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
+import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
 /**
 /**
- * 管理端-学时 Controller(待生效台账 / 手动补跑到期扫描)。
+ * 管理端-学时 Controller(待生效台账 / 账户列表 / 明细下钻 / 异议处置 / 手动补跑到期扫描)。
  *
  *
  * 权限:仅 admin。
  * 权限:仅 admin。
+ * - accountList:学时账户列表(按学员×年度聚合,真分页)
+ * - ledgerDetail:单学员单年度明细下钻
+ * - objected:同路径双模——含 id 走异议处置,无 id 走异议列表(前端 216e790 已按列表消费)
  * - ledgerPending:待生效台账列表(真分页)
  * - ledgerPending:待生效台账列表(真分页)
  * - scan:手动补跑到期生效 + 异议回滚 + cfc 重推(与定时任务共用同一 Service 方法)
  * - scan:手动补跑到期生效 + 异议回滚 + cfc 重推(与定时任务共用同一 Service 方法)
  */
  */
@@ -59,6 +63,72 @@ public class AdminCreditController {
         return Result.success(creditEffectiveManager.manualScan());
         return Result.success(creditEffectiveManager.manualScan());
     }
     }
 
 
+    /**
+     * 学时账户列表(按学员×年度聚合,真分页)
+     * body: {year?, keyword?, page?, size?}
+     * 出参行: userId/year/totalHours/theoryHours/practiceHours/effectiveHours/pendingHours/effectiveAt/status
+     *        + 短别名 total/theory/practice/effective
+     */
+    @Operation(summary = "学时账户列表(分页)")
+    @PostMapping("/account/list")
+    public Result<Map<String, Object>> accountList(
+            @RequestAttribute(value = "isAdmin", required = false) Boolean isAdmin,
+            @RequestBody(required = false) Map<String, Object> body) {
+        Integer year = toInt(body == null ? null : body.get("year"));
+        String keyword = body == null || body.get("keyword") == null ? null : body.get("keyword").toString().trim();
+        Integer page = toInt(body == null ? null : body.get("page"));
+        Integer size = toInt(body == null ? null : body.get("size"));
+        return creditService.accountList(isAdmin, year, keyword, page, size);
+    }
+
+    /**
+     * 学时明细下钻(单学员单年度流水)
+     * body: {userId, year?}
+     * 出参: List<{ledgerId, sourceId, sourceType, sourceCategory, hours, status, effectiveAt, sourceDesc, createdAt}>,id 倒序
+     */
+    @Operation(summary = "学时明细下钻")
+    @PostMapping("/ledger/detail")
+    public Result<List<Map<String, Object>>> ledgerDetail(
+            @RequestAttribute(value = "isAdmin", required = false) Boolean isAdmin,
+            @RequestBody(required = false) Map<String, Object> body) {
+        Long userId = toLong(body == null ? null : body.get("userId"));
+        Integer year = toInt(body == null ? null : body.get("year"));
+        return creditService.ledgerDetail(isAdmin, userId, year);
+    }
+
+    /**
+     * 异议台账(双模,同一路径兼容前端 216e790 已消费的列表与契约处置):
+     * - 报文含 id → 处置模式:{id(ledger主键), approved(boolean), reason?} → Result<Boolean>
+     * - 报文不含 id → 列表模式:{page?, size?} → Result<{total,page,size,list}>
+     */
+    @Operation(summary = "异议台账(含 id 处置 / 无 id 列表)")
+    @PostMapping("/ledger/objected")
+    public Result<?> objected(
+            @RequestAttribute(value = "adminId", required = false) Long adminId,
+            @RequestAttribute(value = "isAdmin", required = false) Boolean isAdmin,
+            @RequestBody(required = false) Map<String, Object> body) {
+        if (body != null && body.get("id") != null) {
+            Long id = toLong(body.get("id"));
+            Boolean approved = body.get("approved") == null ? null : Boolean.valueOf(body.get("approved").toString());
+            String reason = body.get("reason") == null ? null : body.get("reason").toString().trim();
+            return creditService.disposeObjected(isAdmin, adminId, id, approved, reason);
+        }
+        Integer page = toInt(body == null ? null : body.get("page"));
+        Integer size = toInt(body == null ? null : body.get("size"));
+        return creditService.objectedList(isAdmin, 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) {
     private Integer toInt(Object v) {
         if (v == null) {
         if (v == null) {
             return null;
             return null;

+ 13 - 0
train-backend/src/main/java/com/train/controller/admin/AdminOrgController.java

@@ -83,4 +83,17 @@ public class AdminOrgController {
             @RequestBody(required = false) Map<String, Object> body) {
             @RequestBody(required = false) Map<String, Object> body) {
         return orgService.memberList(userId, isAdmin, body);
         return orgService.memberList(userId, isAdmin, body);
     }
     }
+
+    /**
+     * 禁用机构成员(置 status=disabled)
+     * body: {orgId, userId}
+     */
+    @Operation(summary = "禁用机构成员")
+    @PostMapping("/member/disable")
+    public Result<Boolean> memberDisable(
+            @RequestAttribute(value = "userId", required = false) Long userId,
+            @RequestAttribute(value = "isAdmin", required = false) Boolean isAdmin,
+            @RequestBody(required = false) Map<String, Object> body) {
+        return orgService.memberDisable(userId, isAdmin, body);
+    }
 }
 }

+ 8 - 0
train-backend/src/main/java/com/train/service/AttendanceService.java

@@ -47,4 +47,12 @@ public interface AttendanceService {
      * 管理后台:待生效签到记录列表(真分页;仅 admin)。
      * 管理后台:待生效签到记录列表(真分页;仅 admin)。
      */
      */
     Result<Map<String, Object>> pendingAttendance(Boolean isAdmin, Long cohortId, Integer page, Integer size);
     Result<Map<String, Object>> pendingAttendance(Boolean isAdmin, Long cohortId, Integer page, Integer size);
+
+    /**
+     * 管理后台:签到记录列表(全量;真分页 attended_at 倒序;仅 admin)。
+     * body: {cohortId?, sessionId?, status?, page?, size?}
+     * 行 = attVO(userId/cohortId/sessionId/hours/category/attended/attendedAt/status/source/effectiveAt)
+     *      + id/userName/code/sessionHours/sessionCategory(契约别名与联查字段)
+     */
+    Result<Map<String, Object>> adminList(Boolean isAdmin, Map<String, Object> body);
 }
 }

+ 8 - 0
train-backend/src/main/java/com/train/service/CohortService.java

@@ -61,4 +61,12 @@ public interface CohortService {
      * 管理:审核报名(pending→approved/rejected,置 enrollment 学籍;仅 admin)。
      * 管理:审核报名(pending→approved/rejected,置 enrollment 学籍;仅 admin)。
      */
      */
     Result<Map<String, Object>> auditSignup(Long operatorId, Boolean isAdmin, Long signupId, Boolean pass, String reason);
     Result<Map<String, Object>> auditSignup(Long operatorId, Boolean isAdmin, Long signupId, Boolean pass, String reason);
+
+    /**
+     * 管理:批次列表(全量含草稿/已关闭;真分页 id 倒序;仅 admin)。
+     * body: {keyword?(name/code 模糊), status?, page?, size?}
+     * 行 = cohortVO(含 id/code/name/status/startAt/endAt/signupDeadline/capacity/lecturerId/signedCount)
+     *      + enrolledCount(=status=approved 且未删除的报名人数,与 signedCount 同源)
+     */
+    Result<Map<String, Object>> adminList(Long operatorId, Boolean isAdmin, Map<String, Object> body);
 }
 }

+ 36 - 0
train-backend/src/main/java/com/train/service/CreditService.java

@@ -74,4 +74,40 @@ public interface CreditService {
      * 由 rollBackObjected 经代理自注入逐条调用。
      * 由 rollBackObjected 经代理自注入逐条调用。
      */
      */
     void applyRollBack(TrainCreditLedger l);
     void applyRollBack(TrainCreditLedger l);
+
+    /**
+     * 异议补救恢复(单事务,经代理自注入调用):ledger objected→effective + attendance 翻转 + 账户物化。
+     *
+     * 与 applyEffective 的差异:object() 时已扣减账户 pending_hours,故此处**不得**再扣 pending
+     * (否则重复扣减);账户 effective/theory/practice/total 的累加仍复用同一
+     * {@code accrueAccount} 写回路径,禁止另写一份账户物化逻辑。
+     */
+    void restoreEffective(TrainCreditLedger l);
+
+    /**
+     * 管理后台:学时账户列表(按学员×年度聚合;手写 LIMIT/OFFSET 真分页;仅 admin)。
+     * body: {year?, keyword?(userId), page?, size?}
+     */
+    Result<Map<String, Object>> accountList(Boolean isAdmin, Integer year, String keyword, Integer page, Integer size);
+
+    /**
+     * 管理后台:单学员单年度学时明细下钻(流水,id 倒序;仅 admin)。
+     * year 为空取当前年;返回 List(前端兼容 data 或 data.list)。
+     */
+    Result<List<Map<String, Object>>> ledgerDetail(Boolean isAdmin, Long userId, Integer year);
+
+    /**
+     * 管理后台:异议台账列表(status=objected,id 倒序;手写 LIMIT/OFFSET 真分页;仅 admin)。
+     * 与 disposeObjected 共用同一路径 /ledger/objected(前端 216e790 已按列表消费)。
+     */
+    Result<Map<String, Object>> objectedList(Boolean isAdmin, Integer page, Integer size);
+
+    /**
+     * 管理后台:责任人对 T+3 异议的处置(仅 admin)。
+     *
+     * approved=true  驳回异议 → 恢复生效(回填 account 分列;幂等:已 effective 直接成功)
+     * approved=false 否决撤销 → objected→rejected(账户不增加,沿用既有 applyRollBack 路径)
+     * 由 AdminCreditController /ledger/objected 依报文是否含 id 分流。
+     */
+    Result<Boolean> disposeObjected(Boolean isAdmin, Long operatorId, Long ledgerId, Boolean approved, String reason);
 }
 }

+ 6 - 0
train-backend/src/main/java/com/train/service/OrgService.java

@@ -37,4 +37,10 @@ public interface OrgService {
      * body: {orgId}
      * body: {orgId}
      */
      */
     Result<List<Map<String, Object>>> memberList(Long userId, Boolean isAdmin, Map<String, Object> body);
     Result<List<Map<String, Object>>> memberList(Long userId, Boolean isAdmin, Map<String, Object> body);
+
+    /**
+     * 禁用机构成员(admin 或该机构 org_admin):置 train_org_member.status='disabled'。
+     * body: {orgId, userId};uk org_id+user_id;缺失 → 业务错误「成员不存在」;幂等:已 disabled 直接成功。
+     */
+    Result<Boolean> memberDisable(Long userId, Boolean isAdmin, Map<String, Object> body);
 }
 }

+ 76 - 0
train-backend/src/main/java/com/train/service/impl/AttendanceServiceImpl.java

@@ -6,10 +6,12 @@ import com.train.entity.TrainAttendance;
 import com.train.entity.TrainAttendanceCode;
 import com.train.entity.TrainAttendanceCode;
 import com.train.entity.TrainCohort;
 import com.train.entity.TrainCohort;
 import com.train.entity.TrainCohortSignup;
 import com.train.entity.TrainCohortSignup;
+import com.train.entity.TrainUser;
 import com.train.mapper.TrainAttendanceCodeMapper;
 import com.train.mapper.TrainAttendanceCodeMapper;
 import com.train.mapper.TrainAttendanceMapper;
 import com.train.mapper.TrainAttendanceMapper;
 import com.train.mapper.TrainCohortMapper;
 import com.train.mapper.TrainCohortMapper;
 import com.train.mapper.TrainCohortSignupMapper;
 import com.train.mapper.TrainCohortSignupMapper;
+import com.train.mapper.TrainUserMapper;
 import com.train.service.AttendanceService;
 import com.train.service.AttendanceService;
 import com.train.service.RoleGuard;
 import com.train.service.RoleGuard;
 import com.train.service.CreditService;
 import com.train.service.CreditService;
@@ -63,6 +65,8 @@ public class AttendanceServiceImpl implements AttendanceService {
     @Resource
     @Resource
     private TrainCohortSignupMapper trainCohortSignupMapper;
     private TrainCohortSignupMapper trainCohortSignupMapper;
     @Resource
     @Resource
+    private TrainUserMapper trainUserMapper;
+    @Resource
     private CreditService creditService;
     private CreditService creditService;
     @Resource
     @Resource
     private RoleGuard roleGuard;
     private RoleGuard roleGuard;
@@ -327,6 +331,56 @@ public class AttendanceServiceImpl implements AttendanceService {
         return Result.success(data);
         return Result.success(data);
     }
     }
 
 
+    @Override
+    public Result<Map<String, Object>> adminList(Boolean isAdmin, Map<String, Object> body) {
+        String noAuth = roleGuard.requireAdminRole(isAdmin);
+        if (noAuth != null) {
+            return Result.error(noAuth);
+        }
+        int p = body == null || toInt(body.get("page")) == null || toInt(body.get("page")) < 1 ? 1 : toInt(body.get("page"));
+        int s = body == null || toInt(body.get("size")) == null || toInt(body.get("size")) < 1 ? 20 : Math.min(toInt(body.get("size")), 100);
+        int offset = (p - 1) * s;
+        Long cohortId = body == null ? null : toLong(body.get("cohortId"));
+        String sessionId = body == null ? null : (body.get("sessionId") == null ? null : body.get("sessionId").toString().trim());
+        String status = body == null ? null : (body.get("status") == null ? null : body.get("status").toString().trim());
+        LambdaQueryWrapper<TrainAttendance> q = new LambdaQueryWrapper<TrainAttendance>()
+                .eq(TrainAttendance::getDeleted, 0);
+        if (cohortId != null) {
+            q.eq(TrainAttendance::getCohortId, cohortId);
+        }
+        if (sessionId != null && !sessionId.isEmpty()) {
+            q.eq(TrainAttendance::getSessionId, sessionId);
+        }
+        if (status != null && !status.isEmpty()) {
+            q.eq(TrainAttendance::getStatus, status);
+        }
+        Long total = trainAttendanceMapper.selectCount(q);
+        List<TrainAttendance> list = trainAttendanceMapper.selectList(
+                q.orderByDesc(TrainAttendance::getAttendedAt).last("LIMIT " + offset + "," + s));
+        List<Map<String, Object>> rows = new ArrayList<>();
+        for (TrainAttendance a : list) {
+            rows.add(adminAttVO(a));
+        }
+        Map<String, Object> data = new HashMap<>();
+        data.put("total", total == null ? 0 : total);
+        data.put("page", p);
+        data.put("size", s);
+        data.put("list", rows);
+        return Result.success(data);
+    }
+
+    /** 管理端签到行 VO:复用 attVO(前端实际读取键)后补契约别名与联查字段 */
+    private Map<String, Object> adminAttVO(TrainAttendance a) {
+        Map<String, Object> m = attVO(a, false);
+        m.put("id", a.getId());
+        TrainUser u = a.getUserId() == null ? null : trainUserMapper.selectById(a.getUserId());
+        m.put("userName", u == null ? null : u.getName());
+        m.put("code", a.getCode());
+        m.put("sessionHours", m.get("hours"));        // 契约别名(=sessionHours)
+        m.put("sessionCategory", m.get("category"));   // 契约别名(=sessionCategory)
+        return m;
+    }
+
     // ============ helpers ============
     // ============ helpers ============
 
 
     private Map<String, Object> attVO(TrainAttendance a, boolean alreadyExists) {
     private Map<String, Object> attVO(TrainAttendance a, boolean alreadyExists) {
@@ -425,6 +479,28 @@ public class AttendanceServiceImpl implements AttendanceService {
         return sb.toString();
         return sb.toString();
     }
     }
 
 
+    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;
+        }
+    }
+
     private Date addMinutes(Date base, int minutes) {
     private Date addMinutes(Date base, int minutes) {
         Calendar cal = Calendar.getInstance();
         Calendar cal = Calendar.getInstance();
         cal.setTime(base);
         cal.setTime(base);

+ 36 - 0
train-backend/src/main/java/com/train/service/impl/CohortServiceImpl.java

@@ -388,6 +388,42 @@ public class CohortServiceImpl implements CohortService {
         return Result.success(signupVO(sig));
         return Result.success(signupVO(sig));
     }
     }
 
 
+    @Override
+    public Result<Map<String, Object>> adminList(Long operatorId, Boolean isAdmin, Map<String, Object> body) {
+        String noAuth = roleGuard.requireAdminRole(isAdmin);
+        if (noAuth != null) {
+            return Result.error(noAuth);
+        }
+        int p = body == null || toInt(body.get("page")) == null || toInt(body.get("page")) < 1 ? 1 : toInt(body.get("page"));
+        int s = body == null || toInt(body.get("size")) == null || toInt(body.get("size")) < 1 ? 20 : Math.min(toInt(body.get("size")), 100);
+        int offset = (p - 1) * s;
+        String keyword = body == null ? null : str(body.get("keyword"));
+        String status = body == null ? null : str(body.get("status"));
+        LambdaQueryWrapper<TrainCohort> q = new LambdaQueryWrapper<TrainCohort>().eq(TrainCohort::getDeleted, 0);
+        if (status != null && !status.trim().isEmpty()) {
+            q.eq(TrainCohort::getStatus, status.trim());
+        }
+        if (keyword != null && !keyword.trim().isEmpty()) {
+            String kw = keyword.trim();
+            q.and(w -> w.like(TrainCohort::getName, kw).or().like(TrainCohort::getCode, kw));
+        }
+        Long total = trainCohortMapper.selectCount(q);
+        List<TrainCohort> list = trainCohortMapper.selectList(
+                q.orderByDesc(TrainCohort::getId).last("LIMIT " + offset + "," + s));
+        List<Map<String, Object>> rows = new ArrayList<>();
+        for (TrainCohort c : list) {
+            Map<String, Object> vo = cohortVO(c); // 复用既有 cohortVO(含 signedCount=countApproved)
+            vo.put("enrolledCount", vo.get("signedCount")); // 契约别名,同源不重复计算
+            rows.add(vo);
+        }
+        Map<String, Object> data = new HashMap<>();
+        data.put("total", total == null ? 0 : total);
+        data.put("page", p);
+        data.put("size", s);
+        data.put("list", rows);
+        return Result.success(data);
+    }
+
     // ============ VO / helpers ============
     // ============ VO / helpers ============
 
 
     private Map<String, Object> cohortVO(TrainCohort c) {
     private Map<String, Object> cohortVO(TrainCohort c) {

+ 239 - 7
train-backend/src/main/java/com/train/service/impl/CreditServiceImpl.java

@@ -184,6 +184,7 @@ public class CreditServiceImpl implements CreditService {
     private Map<String, Object> toLedgerVO(TrainCreditLedger l) {
     private Map<String, Object> toLedgerVO(TrainCreditLedger l) {
         Map<String, Object> m = new HashMap<>();
         Map<String, Object> m = new HashMap<>();
         m.put("ledgerId", l.getId());
         m.put("ledgerId", l.getId());
+        m.put("sourceId", l.getSourceId());
         m.put("sourceType", l.getSourceType());
         m.put("sourceType", l.getSourceType());
         m.put("sourceCategory", l.getSourceCategory());
         m.put("sourceCategory", l.getSourceCategory());
         m.put("hours", l.getHours() == null ? 0 : l.getHours()); // 分钟
         m.put("hours", l.getHours() == null ? 0 : l.getHours()); // 分钟
@@ -371,26 +372,64 @@ public class CreditServiceImpl implements CreditService {
                 trainAttendanceMapper.updateById(att);
                 trainAttendanceMapper.updateById(att);
             }
             }
         }
         }
-        // 账户累加:effective + 分类 + total
-        TrainCreditAccount acc = ensureAccount(cur.getUserId(), Year.now().getValue());
+        // 账户物化:effective + 分类 + total
+        // ★唯一账户写回路径:applyEffective 与异议补救恢复(restoreEffective)共用 accrueAccount,
+        //   禁止另写一份账户物化逻辑。pending_hours 的增减由各调用方按语义显式处理,此处不触碰。
         int h = cur.getHours() == null ? 0 : cur.getHours();
         int h = cur.getHours() == null ? 0 : cur.getHours();
-        int pending = acc.getPendingHours() == null ? 0 : acc.getPendingHours();
+        deductPending(cur.getUserId(), h);
+        accrueAccount(cur.getUserId(), cur.getSourceCategory(), h);
+    }
+
+    /**
+     * 账户物化写回(唯一路径,见 applyEffective 注释):effective + 分类分列 + total 累加 h 分钟。
+     * 不触碰 pending_hours(pending 累加在 ledgerPending、扣减在 object 时已完成),避免重复扣减。
+     */
+    private void accrueAccount(Long userId, String category, int h) {
+        TrainCreditAccount acc = ensureAccount(userId, Year.now().getValue());
         int effective = acc.getEffectiveHours() == null ? 0 : acc.getEffectiveHours();
         int effective = acc.getEffectiveHours() == null ? 0 : acc.getEffectiveHours();
         int theory = acc.getTheoryHours() == null ? 0 : acc.getTheoryHours();
         int theory = acc.getTheoryHours() == null ? 0 : acc.getTheoryHours();
         int practice = acc.getPracticeHours() == null ? 0 : acc.getPracticeHours();
         int practice = acc.getPracticeHours() == null ? 0 : acc.getPracticeHours();
         int total = acc.getTotalHours() == null ? 0 : acc.getTotalHours();
         int total = acc.getTotalHours() == null ? 0 : acc.getTotalHours();
         acc.setEffectiveHours(effective + h);
         acc.setEffectiveHours(effective + h);
-        acc.setPendingHours(Math.max(0, pending - h));
-        if (CAT_THEORY.equals(cur.getSourceCategory())) {
+        if (CAT_THEORY.equals(category)) {
             acc.setTheoryHours(theory + h);
             acc.setTheoryHours(theory + h);
-        } else if (CAT_PRACTICE.equals(cur.getSourceCategory())) {
+        } else if (CAT_PRACTICE.equals(category)) {
             acc.setPracticeHours(practice + h);
             acc.setPracticeHours(practice + h);
         }
         }
         acc.setTotalHours(total + h);
         acc.setTotalHours(total + h);
-        acc.setUpdatedAt(now);
+        acc.setUpdatedAt(new Date());
         trainCreditAccountMapper.updateById(acc);
         trainCreditAccountMapper.updateById(acc);
     }
     }
 
 
+    /**
+     * 异议补救恢复(单事务,经代理自注入调用):ledger objected→effective + attendance 翻转 + 账户物化。
+     * 与 applyEffective 的差异:object() 时已扣减 pending_hours,此处不得再扣(否则重复扣减)。
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void restoreEffective(TrainCreditLedger l) {
+        TrainCreditLedger cur = trainCreditLedgerMapper.selectById(l.getId());
+        if (cur == null || !ST_OBJECTED.equals(cur.getStatus())) {
+            return;
+        }
+        Date now = new Date();
+        cur.setStatus(ST_EFFECTIVE);
+        cur.setEffectiveAt(now);
+        cur.setUpdatedAt(now);
+        trainCreditLedgerMapper.updateById(cur);
+        // attendance 双写翻转(objected→effective)
+        if (SRC_ATTENDANCE.equals(cur.getSourceType())) {
+            TrainAttendance att = trainAttendanceMapper.selectById(parseLong(cur.getSourceId()));
+            if (att != null && ST_OBJECTED.equals(att.getStatus())) {
+                att.setStatus(ST_EFFECTIVE);
+                att.setEffectiveAt(now);
+                att.setUpdatedAt(now);
+                trainAttendanceMapper.updateById(att);
+            }
+        }
+        accrueAccount(cur.getUserId(), cur.getSourceCategory(), cur.getHours() == null ? 0 : cur.getHours());
+    }
+
     @Override
     @Override
     public int rollBackObjected() {
     public int rollBackObjected() {
         List<TrainCreditLedger> list = trainCreditLedgerMapper.selectList(
         List<TrainCreditLedger> list = trainCreditLedgerMapper.selectList(
@@ -465,4 +504,197 @@ public class CreditServiceImpl implements CreditService {
         data.put("list", rows);
         data.put("list", rows);
         return Result.success(data);
         return Result.success(data);
     }
     }
+
+    @Override
+    public Result<Map<String, Object>> accountList(Boolean isAdmin, Integer year, String keyword, Integer page, Integer size) {
+        String noAuth = roleGuard.requireAdminRole(isAdmin);
+        if (noAuth != null) {
+            return Result.error(noAuth);
+        }
+        int p = page == null || page < 1 ? 1 : page;
+        int s = size == null || size < 1 ? 20 : Math.min(size, 100);
+        int offset = (p - 1) * s;
+        LambdaQueryWrapper<TrainCreditAccount> q = new LambdaQueryWrapper<>();
+        if (year != null) {
+            q.eq(TrainCreditAccount::getYear, year);
+        }
+        if (keyword != null && !keyword.trim().isEmpty()) {
+            q.like(TrainCreditAccount::getUserId, keyword.trim());
+        }
+        Long total = trainCreditAccountMapper.selectCount(q);
+        List<TrainCreditAccount> list = trainCreditAccountMapper.selectList(
+                q.orderByDesc(TrainCreditAccount::getId).last("LIMIT " + offset + "," + s));
+        // 一次性取本页 user 的最近生效时间(聚合无单一生效时间,取 max),避免 N+1
+        Map<String, Date> effMap = latestEffectiveAt(list);
+        List<Map<String, Object>> rows = new ArrayList<>();
+        for (TrainCreditAccount a : list) {
+            rows.add(accountVO(a, effMap.get(a.getUserId() + ":" + a.getYear())));
+        }
+        Map<String, Object> data = new HashMap<>();
+        data.put("total", total == null ? 0 : total);
+        data.put("page", p);
+        data.put("size", s);
+        data.put("list", rows);
+        return Result.success(data);
+    }
+
+    /** 一次查询取本页 user 的最近生效时间(键 userId:year) */
+    private Map<String, Date> latestEffectiveAt(List<TrainCreditAccount> page) {
+        Map<String, Date> out = new HashMap<>();
+        if (page == null || page.isEmpty()) {
+            return out;
+        }
+        List<Long> userIds = new ArrayList<>();
+        for (TrainCreditAccount a : page) {
+            if (a.getUserId() != null) {
+                userIds.add(a.getUserId());
+            }
+        }
+        if (userIds.isEmpty()) {
+            return out;
+        }
+        List<TrainCreditLedger> effs = trainCreditLedgerMapper.selectList(
+                new LambdaQueryWrapper<TrainCreditLedger>()
+                        .select(TrainCreditLedger::getUserId, TrainCreditLedger::getYear, TrainCreditLedger::getEffectiveAt)
+                        .eq(TrainCreditLedger::getStatus, ST_EFFECTIVE)
+                        .eq(TrainCreditLedger::getDeleted, 0)
+                        .in(TrainCreditLedger::getUserId, userIds)
+                        .last("LIMIT 5000"));
+        for (TrainCreditLedger l : effs) {
+            Date at = l.getEffectiveAt();
+            if (at == null) {
+                continue;
+            }
+            String k = l.getUserId() + ":" + l.getYear();
+            Date old = out.get(k);
+            if (old == null || at.after(old)) {
+                out.put(k, at);
+            }
+        }
+        return out;
+    }
+
+    /** 账户行 VO:前端实际读取 totalHours/theoryHours/practiceHours(Credits.vue),
+     *  同时保留短别名 total/theory/practice/effective(管理端契约命名),同值不重复计算。 */
+    private Map<String, Object> accountVO(TrainCreditAccount a, Date effectiveAt) {
+        int total = a.getTotalHours() == null ? 0 : a.getTotalHours();
+        int theory = a.getTheoryHours() == null ? 0 : a.getTheoryHours();
+        int practice = a.getPracticeHours() == null ? 0 : a.getPracticeHours();
+        int effective = a.getEffectiveHours() == null ? 0 : a.getEffectiveHours();
+        int pending = a.getPendingHours() == null ? 0 : a.getPendingHours();
+        Map<String, Object> m = new HashMap<>();
+        m.put("userId", a.getUserId());
+        m.put("year", a.getYear());
+        m.put("totalHours", total);
+        m.put("theoryHours", theory);
+        m.put("practiceHours", practice);
+        m.put("effectiveHours", effective);
+        m.put("pendingHours", pending);
+        m.put("effectiveAt", effectiveAt);
+        m.put("status", a.getStatus());
+        m.put("total", total);
+        m.put("theory", theory);
+        m.put("practice", practice);
+        m.put("effective", effective);
+        return m;
+    }
+
+    @Override
+    public Result<List<Map<String, Object>>> ledgerDetail(Boolean isAdmin, Long userId, Integer year) {
+        String noAuth = roleGuard.requireAdminRole(isAdmin);
+        if (noAuth != null) {
+            return Result.error(noAuth);
+        }
+        if (userId == null) {
+            return Result.error("userId 不能为空");
+        }
+        int y = year == null ? Year.now().getValue() : year;
+        List<TrainCreditLedger> list = trainCreditLedgerMapper.selectList(
+                new LambdaQueryWrapper<TrainCreditLedger>()
+                        .eq(TrainCreditLedger::getUserId, userId)
+                        .eq(TrainCreditLedger::getYear, y)
+                        .eq(TrainCreditLedger::getDeleted, 0)
+                        .orderByDesc(TrainCreditLedger::getId));
+        List<Map<String, Object>> rows = new ArrayList<>();
+        for (TrainCreditLedger l : list) {
+            rows.add(toLedgerVO(l));
+        }
+        return Result.success(rows);
+    }
+
+    @Override
+    public Result<Map<String, Object>> objectedList(Boolean isAdmin, Integer page, Integer size) {
+        String noAuth = roleGuard.requireAdminRole(isAdmin);
+        if (noAuth != null) {
+            return Result.error(noAuth);
+        }
+        int p = page == null || page < 1 ? 1 : page;
+        int s = size == null || size < 1 ? 20 : Math.min(size, 100);
+        int offset = (p - 1) * s;
+        Long total = trainCreditLedgerMapper.selectCount(
+                new LambdaQueryWrapper<TrainCreditLedger>()
+                        .eq(TrainCreditLedger::getStatus, ST_OBJECTED)
+                        .eq(TrainCreditLedger::getDeleted, 0));
+        List<TrainCreditLedger> list = trainCreditLedgerMapper.selectList(
+                new LambdaQueryWrapper<TrainCreditLedger>()
+                        .eq(TrainCreditLedger::getStatus, ST_OBJECTED)
+                        .eq(TrainCreditLedger::getDeleted, 0)
+                        .orderByDesc(TrainCreditLedger::getId)
+                        .last("LIMIT " + offset + "," + s));
+        List<Map<String, Object>> rows = new ArrayList<>();
+        for (TrainCreditLedger l : list) {
+            rows.add(toLedgerVO(l));
+        }
+        Map<String, Object> data = new HashMap<>();
+        data.put("total", total == null ? 0 : total);
+        data.put("page", p);
+        data.put("size", s);
+        data.put("list", rows);
+        return Result.success(data);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<Boolean> disposeObjected(Boolean isAdmin, Long operatorId, Long ledgerId, Boolean approved, String reason) {
+        String noAuth = roleGuard.requireAdminRole(isAdmin);
+        if (noAuth != null) {
+            return Result.error(noAuth);
+        }
+        if (ledgerId == null) {
+            return Result.error("id 不能为空");
+        }
+        if (approved == null) {
+            return Result.error("approved 不能为空");
+        }
+        TrainCreditLedger l = trainCreditLedgerMapper.selectById(ledgerId);
+        if (l == null || (l.getDeleted() != null && l.getDeleted() == 1)) {
+            return Result.error("学时记录不存在");
+        }
+        if (Boolean.TRUE.equals(approved)) {
+            // 驳回异议 → 恢复生效(幂等:已 effective 直接成功)
+            if (ST_EFFECTIVE.equals(l.getStatus())) {
+                return Result.success(true);
+            }
+            if (!ST_OBJECTED.equals(l.getStatus())) {
+                return Result.error("当前状态不允许该处置");
+            }
+            if (reason != null && !reason.trim().isEmpty()) {
+                l.setRemark(reason.trim());
+                l.setOperatorId(operatorId);
+                l.setUpdatedAt(new Date());
+                trainCreditLedgerMapper.updateById(l);
+            }
+            self.restoreEffective(l);
+            return Result.success(true);
+        }
+        // 否决撤销 → objected→rejected(终态),账户不增加(pending 已在 object 时扣减,沿用既有回滚路径)
+        if (ST_REJECTED.equals(l.getStatus())) {
+            return Result.success(true);
+        }
+        if (!ST_OBJECTED.equals(l.getStatus())) {
+            return Result.error("当前状态不允许该处置");
+        }
+        self.applyRollBack(l);
+        return Result.success(true);
+    }
 }
 }

+ 40 - 0
train-backend/src/main/java/com/train/service/impl/OrgServiceImpl.java

@@ -37,6 +37,7 @@ public class OrgServiceImpl implements OrgService {
 
 
     private static final String ORG_STATUS_ACTIVE = "active";
     private static final String ORG_STATUS_ACTIVE = "active";
     private static final String MEMBER_STATUS_ACTIVE = "active";
     private static final String MEMBER_STATUS_ACTIVE = "active";
+    private static final String MEMBER_STATUS_DISABLED = "disabled";
     private static final int DELETED_NORMAL = 0;
     private static final int DELETED_NORMAL = 0;
     private static final int DELETED_DEL = 1;
     private static final int DELETED_DEL = 1;
 
 
@@ -277,6 +278,45 @@ public class OrgServiceImpl implements OrgService {
         return Result.success("查询成功", rows);
         return Result.success("查询成功", rows);
     }
     }
 
 
+    @Override
+    public Result<Boolean> memberDisable(Long userId, Boolean isAdmin, Map<String, Object> body) {
+        if (body == null) {
+            return Result.error("参数不能为空");
+        }
+        Long orgId = toLong(body.get("orgId"));
+        Long memberUserId = toLong(body.get("userId"));
+        if (orgId == null || memberUserId == null) {
+            return Result.error("orgId/userId 不能为空");
+        }
+        // 权限:admin 或 该机构 active org_admin(与 memberAdd 同口径)
+        if (!Boolean.TRUE.equals(isAdmin)) {
+            String guardErr = roleGuard.requireOrgMember(userId, orgId);
+            if (guardErr != null) {
+                return Result.error(guardErr);
+            }
+            if (!isOrgAdminOf(userId, orgId)) {
+                return Result.error("仅机构管理员可禁用成员");
+            }
+        }
+        // uk org_id+user_id 定位(仅未软删行)
+        TrainOrgMember m = trainOrgMemberMapper.selectOne(
+                new LambdaQueryWrapper<TrainOrgMember>()
+                        .eq(TrainOrgMember::getOrgId, orgId)
+                        .eq(TrainOrgMember::getUserId, memberUserId)
+                        .eq(TrainOrgMember::getDeleted, DELETED_NORMAL)
+                        .last("LIMIT 1"));
+        if (m == null) {
+            return Result.error("成员不存在");
+        }
+        if (MEMBER_STATUS_DISABLED.equals(m.getStatus())) {
+            return Result.success(true); // 幂等
+        }
+        m.setStatus(MEMBER_STATUS_DISABLED);
+        m.setUpdatedAt(new Date());
+        trainOrgMemberMapper.updateById(m);
+        return Result.success(true);
+    }
+
     // ---------- 内部工具 ----------
     // ---------- 内部工具 ----------
 
 
     private boolean isOrgAdminOf(Long userId, Long orgId) {
     private boolean isOrgAdminOf(Long userId, Long orgId) {