|
|
@@ -0,0 +1,468 @@
|
|
|
+package com.train.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.train.common.Result;
|
|
|
+import com.train.entity.TrainAttendance;
|
|
|
+import com.train.entity.TrainCreditAccount;
|
|
|
+import com.train.entity.TrainCreditLedger;
|
|
|
+import com.train.mapper.TrainAttendanceMapper;
|
|
|
+import com.train.mapper.TrainCreditAccountMapper;
|
|
|
+import com.train.mapper.TrainCreditLedgerMapper;
|
|
|
+import com.train.service.CreditService;
|
|
|
+import com.train.service.CfcCreditSyncService;
|
|
|
+import com.train.service.RoleGuard;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.Year;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 学时服务实现(账户 + 台账 + 生效 + 异议回滚)
|
|
|
+ *
|
|
|
+ * 关键口径(对齐设计 §2.3 + 数据模型):
|
|
|
+ * - 单一账户多来源:账户 uk(user_id) 仅存当年,跨年 ensureAccount 原地重置;历史年由 ledger 聚合
|
|
|
+ * - 学时一律分钟整数;pending 不计入 effective;T+3 到期生效(可配 app.credit.effective-delay-hours)
|
|
|
+ * - ledger↔attendance 双写按 source_id=attendance.id 关联,同事务翻转
|
|
|
+ * - effectiveDue 全量扫 pending+到期(禁限定当天),逐条单事务容错(对齐 FollowUpTask 范式)
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class CreditServiceImpl implements CreditService {
|
|
|
+
|
|
|
+ private static final String ST_PENDING = "pending";
|
|
|
+ private static final String ST_EFFECTIVE = "effective";
|
|
|
+ private static final String ST_OBJECTED = "objected";
|
|
|
+ private static final String ST_REJECTED = "rejected";
|
|
|
+ private static final String ACC_ACTIVE = "active";
|
|
|
+ private static final String ACC_SETTLED = "settled";
|
|
|
+
|
|
|
+ private static final String SRC_ATTENDANCE = "attendance";
|
|
|
+ private static final String CAT_THEORY = "theory";
|
|
|
+ private static final String CAT_PRACTICE = "practice";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TrainCreditAccountMapper trainCreditAccountMapper;
|
|
|
+ @Resource
|
|
|
+ private TrainCreditLedgerMapper trainCreditLedgerMapper;
|
|
|
+ @Resource
|
|
|
+ private TrainAttendanceMapper trainAttendanceMapper;
|
|
|
+ @Resource
|
|
|
+ private RoleGuard roleGuard;
|
|
|
+ @Resource
|
|
|
+ private CfcCreditSyncService cfcCreditSyncService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自注入代理:绕过 self-invocation,使 applyEffective/applyRollBack 的 @Transactional 生效。
|
|
|
+ * @Lazy 避免初始化循环依赖。
|
|
|
+ */
|
|
|
+ @Lazy
|
|
|
+ @Resource
|
|
|
+ private CreditService self;
|
|
|
+
|
|
|
+ /** 学时生效延迟小时(T+3,可配) */
|
|
|
+ @Value("${app.credit.effective-delay-hours:72}")
|
|
|
+ private Integer effectiveDelayHours;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TrainCreditAccount ensureAccount(Long userId, Integer year) {
|
|
|
+ int curYear = year == null ? Year.now().getValue() : year;
|
|
|
+ TrainCreditAccount acc = trainCreditAccountMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<TrainCreditAccount>()
|
|
|
+ .eq(TrainCreditAccount::getUserId, userId)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (acc == null) {
|
|
|
+ TrainCreditAccount created = new TrainCreditAccount();
|
|
|
+ created.setUserId(userId);
|
|
|
+ created.setYear(curYear);
|
|
|
+ created.setTotalHours(0);
|
|
|
+ created.setTheoryHours(0);
|
|
|
+ created.setPracticeHours(0);
|
|
|
+ created.setEffectiveHours(0);
|
|
|
+ created.setPendingHours(0);
|
|
|
+ created.setStatus(ACC_ACTIVE);
|
|
|
+ try {
|
|
|
+ trainCreditAccountMapper.insert(created);
|
|
|
+ return created;
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 并发首建:uk(user_id) 冲突 → 回查已存在行
|
|
|
+ return trainCreditAccountMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<TrainCreditAccount>()
|
|
|
+ .eq(TrainCreditAccount::getUserId, userId)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 跨年原地重置(只存当年,历史年由 ledger 聚合)
|
|
|
+ if (acc.getYear() == null || acc.getYear() != curYear) {
|
|
|
+ acc.setYear(curYear);
|
|
|
+ acc.setTotalHours(0);
|
|
|
+ acc.setTheoryHours(0);
|
|
|
+ acc.setPracticeHours(0);
|
|
|
+ acc.setEffectiveHours(0);
|
|
|
+ acc.setPendingHours(0);
|
|
|
+ acc.setStatus(ACC_ACTIVE);
|
|
|
+ trainCreditAccountMapper.updateById(acc);
|
|
|
+ }
|
|
|
+ return acc;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Map<String, Object>> mine(Long userId, Integer year) {
|
|
|
+ int curYear = year == null ? Year.now().getValue() : year;
|
|
|
+ TrainCreditAccount acc = ensureAccount(userId, curYear);
|
|
|
+ Map<String, Object> vo;
|
|
|
+ if (acc.getYear() != null && acc.getYear() == curYear) {
|
|
|
+ // 当年读账户
|
|
|
+ vo = new HashMap<>();
|
|
|
+ vo.put("year", acc.getYear());
|
|
|
+ vo.put("totalHours", acc.getTotalHours() == null ? 0 : acc.getTotalHours());
|
|
|
+ vo.put("theoryHours", acc.getTheoryHours() == null ? 0 : acc.getTheoryHours());
|
|
|
+ vo.put("practiceHours", acc.getPracticeHours() == null ? 0 : acc.getPracticeHours());
|
|
|
+ vo.put("effectiveHours", acc.getEffectiveHours() == null ? 0 : acc.getEffectiveHours());
|
|
|
+ vo.put("pendingHours", acc.getPendingHours() == null ? 0 : acc.getPendingHours());
|
|
|
+ vo.put("status", acc.getStatus());
|
|
|
+ } else {
|
|
|
+ // 历史年 ledger 聚合(status=effective)
|
|
|
+ vo = aggregateYear(userId, curYear);
|
|
|
+ }
|
|
|
+ // 单位红线:全部返回分钟整数(换算只在展示层)
|
|
|
+ return Result.success(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> aggregateYear(Long userId, int year) {
|
|
|
+ List<TrainCreditLedger> list = trainCreditLedgerMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainCreditLedger>()
|
|
|
+ .eq(TrainCreditLedger::getUserId, userId)
|
|
|
+ .eq(TrainCreditLedger::getYear, year)
|
|
|
+ .eq(TrainCreditLedger::getStatus, ST_EFFECTIVE)
|
|
|
+ .eq(TrainCreditLedger::getDeleted, 0));
|
|
|
+ long theory = 0, practice = 0, total = 0;
|
|
|
+ for (TrainCreditLedger l : list) {
|
|
|
+ int h = l.getHours() == null ? 0 : l.getHours();
|
|
|
+ total += h;
|
|
|
+ if (CAT_THEORY.equals(l.getSourceCategory())) {
|
|
|
+ theory += h;
|
|
|
+ } else if (CAT_PRACTICE.equals(l.getSourceCategory())) {
|
|
|
+ practice += h;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> vo = new HashMap<>();
|
|
|
+ vo.put("year", year);
|
|
|
+ vo.put("totalHours", (int) total);
|
|
|
+ vo.put("theoryHours", (int) theory);
|
|
|
+ vo.put("practiceHours", (int) practice);
|
|
|
+ vo.put("effectiveHours", (int) total);
|
|
|
+ vo.put("pendingHours", 0);
|
|
|
+ vo.put("status", ACC_SETTLED);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<List<Map<String, Object>>> pending(Long userId) {
|
|
|
+ List<TrainCreditLedger> list = trainCreditLedgerMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainCreditLedger>()
|
|
|
+ .eq(TrainCreditLedger::getUserId, userId)
|
|
|
+ .eq(TrainCreditLedger::getStatus, ST_PENDING)
|
|
|
+ .eq(TrainCreditLedger::getDeleted, 0)
|
|
|
+ .orderByDesc(TrainCreditLedger::getCreatedAt));
|
|
|
+ List<Map<String, Object>> rows = new ArrayList<>();
|
|
|
+ for (TrainCreditLedger l : list) {
|
|
|
+ rows.add(toLedgerVO(l));
|
|
|
+ }
|
|
|
+ return Result.success(rows);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> toLedgerVO(TrainCreditLedger l) {
|
|
|
+ Map<String, Object> m = new HashMap<>();
|
|
|
+ m.put("ledgerId", l.getId());
|
|
|
+ m.put("sourceType", l.getSourceType());
|
|
|
+ m.put("sourceCategory", l.getSourceCategory());
|
|
|
+ m.put("hours", l.getHours() == null ? 0 : l.getHours()); // 分钟
|
|
|
+ m.put("status", l.getStatus());
|
|
|
+ m.put("effectiveAt", l.getEffectiveAt());
|
|
|
+ m.put("sourceDesc", l.getSourceDesc());
|
|
|
+ m.put("createdAt", l.getCreatedAt());
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Result<Void> object(Long userId, Long ledgerId, String reason) {
|
|
|
+ if (userId == null || ledgerId == null) {
|
|
|
+ return Result.error("参数不完整");
|
|
|
+ }
|
|
|
+ TrainCreditLedger l = trainCreditLedgerMapper.selectById(ledgerId);
|
|
|
+ if (l == null || (l.getDeleted() != null && l.getDeleted() == 1)) {
|
|
|
+ return Result.error("学时记录不存在");
|
|
|
+ }
|
|
|
+ if (!userId.equals(l.getUserId())) {
|
|
|
+ return Result.error("无权操作他人学时记录");
|
|
|
+ }
|
|
|
+ // 仅 pending 可提异议(已生效走申诉外流程)
|
|
|
+ if (!ST_PENDING.equals(l.getStatus())) {
|
|
|
+ return Result.error("当前状态不允许提异议");
|
|
|
+ }
|
|
|
+ l.setStatus(ST_OBJECTED);
|
|
|
+ l.setRemark(reason);
|
|
|
+ l.setUpdatedAt(new Date());
|
|
|
+ trainCreditLedgerMapper.updateById(l);
|
|
|
+ // 回写 attendance(source_id=attendance.id)→ objected,扣减账户 pending
|
|
|
+ if (SRC_ATTENDANCE.equals(l.getSourceType())) {
|
|
|
+ TrainAttendance att = trainAttendanceMapper.selectById(parseLong(l.getSourceId()));
|
|
|
+ if (att != null && ST_PENDING.equals(att.getStatus())) {
|
|
|
+ att.setStatus(ST_OBJECTED);
|
|
|
+ att.setObjectReason(reason);
|
|
|
+ att.setObjectedBy(userId);
|
|
|
+ att.setObjectedAt(new Date());
|
|
|
+ att.setUpdatedAt(new Date());
|
|
|
+ trainAttendanceMapper.updateById(att);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 扣减账户 pending_hours
|
|
|
+ deductPending(l.getUserId(), l.getHours() == null ? 0 : l.getHours());
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deductPending(Long userId, int hours) {
|
|
|
+ if (hours <= 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ TrainCreditAccount acc = trainCreditAccountMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<TrainCreditAccount>()
|
|
|
+ .eq(TrainCreditAccount::getUserId, userId)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (acc == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int pending = acc.getPendingHours() == null ? 0 : acc.getPendingHours();
|
|
|
+ acc.setPendingHours(Math.max(0, pending - hours));
|
|
|
+ acc.setUpdatedAt(new Date());
|
|
|
+ trainCreditAccountMapper.updateById(acc);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long parseLong(String v) {
|
|
|
+ if (v == null || v.trim().isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return Long.valueOf(v.trim());
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean ledgerPending(Long userId, String sourceType, String sourceId, String category,
|
|
|
+ Integer hours, String desc) {
|
|
|
+ if (userId == null || sourceId == null || hours == null || hours <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 幂等:uk(user_id, source_type, source_id) 命中即跳过
|
|
|
+ Long cnt = trainCreditLedgerMapper.selectCount(
|
|
|
+ new LambdaQueryWrapper<TrainCreditLedger>()
|
|
|
+ .eq(TrainCreditLedger::getUserId, userId)
|
|
|
+ .eq(TrainCreditLedger::getSourceType, sourceType)
|
|
|
+ .eq(TrainCreditLedger::getSourceId, sourceId)
|
|
|
+ .eq(TrainCreditLedger::getDeleted, 0));
|
|
|
+ if (cnt != null && cnt > 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ Date effAt = addHours(now, effectiveDelayHours == null ? 72 : effectiveDelayHours);
|
|
|
+ TrainCreditLedger l = new TrainCreditLedger();
|
|
|
+ l.setUserId(userId);
|
|
|
+ l.setYear(Year.of(yearOf(effAt)).getValue()); // 年度归属=effective_at 年度
|
|
|
+ l.setSourceType(sourceType);
|
|
|
+ l.setSourceCategory(category);
|
|
|
+ l.setSourceId(sourceId);
|
|
|
+ l.setHours(hours);
|
|
|
+ l.setStatus(ST_PENDING);
|
|
|
+ l.setEffectiveAt(effAt);
|
|
|
+ l.setSourceDesc(desc);
|
|
|
+ l.setDeleted(0);
|
|
|
+ try {
|
|
|
+ trainCreditLedgerMapper.insert(l);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 并发幂等命中
|
|
|
+ log.debug("ledger 幂等命中,跳过: userId={}, source={}:{}, err={}", userId, sourceType, sourceId, e.getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 账户 pending 累加
|
|
|
+ TrainCreditAccount acc = ensureAccount(userId, Year.now().getValue());
|
|
|
+ int pending = acc.getPendingHours() == null ? 0 : acc.getPendingHours();
|
|
|
+ acc.setPendingHours(pending + hours);
|
|
|
+ acc.setUpdatedAt(now);
|
|
|
+ trainCreditAccountMapper.updateById(acc);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private int yearOf(Date d) {
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ c.setTime(d);
|
|
|
+ return c.get(Calendar.YEAR);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date addHours(Date base, int hours) {
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ c.setTime(base);
|
|
|
+ c.add(Calendar.HOUR_OF_DAY, hours);
|
|
|
+ return c.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int effectiveDue() {
|
|
|
+ // 全量扫 pending 且到期(禁限定当天);启动/重启补偿幂等
|
|
|
+ List<TrainCreditLedger> list = trainCreditLedgerMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainCreditLedger>()
|
|
|
+ .eq(TrainCreditLedger::getStatus, ST_PENDING)
|
|
|
+ .eq(TrainCreditLedger::getDeleted, 0)
|
|
|
+ .le(TrainCreditLedger::getEffectiveAt, new Date())
|
|
|
+ .last("LIMIT 500"));
|
|
|
+ int ok = 0;
|
|
|
+ for (TrainCreditLedger l : list) {
|
|
|
+ try {
|
|
|
+ self.applyEffective(l);
|
|
|
+ // 生效成功后触发 cfc 学时回填(失败 warn 不阻塞;幂等键 sourceType:sourceId)
|
|
|
+ try {
|
|
|
+ cfcCreditSyncService.push(l.getUserId(), l.getSourceType(), l.getSourceId(), l.getHours());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("cfc 学时回填触发失败: syncKey={}:{}, err={}", l.getSourceType(), l.getSourceId(), e.getMessage());
|
|
|
+ }
|
|
|
+ ok++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("学时生效失败(跳过): ledgerId={}, err={}", l.getId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ok > 0) {
|
|
|
+ log.info("学时到期生效完成: 本批 {} 条", ok);
|
|
|
+ }
|
|
|
+ return ok;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 单条生效:单事务,ledger pending→effective + attendance 翻转 + 账户累加 */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void applyEffective(TrainCreditLedger l) {
|
|
|
+ // 前置再校验(防并发重复生效)
|
|
|
+ TrainCreditLedger cur = trainCreditLedgerMapper.selectById(l.getId());
|
|
|
+ if (cur == null || !ST_PENDING.equals(cur.getStatus())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ cur.setStatus(ST_EFFECTIVE);
|
|
|
+ cur.setUpdatedAt(now);
|
|
|
+ trainCreditLedgerMapper.updateById(cur);
|
|
|
+ // attendance 双写翻转
|
|
|
+ if (SRC_ATTENDANCE.equals(cur.getSourceType())) {
|
|
|
+ TrainAttendance att = trainAttendanceMapper.selectById(parseLong(cur.getSourceId()));
|
|
|
+ if (att != null && ST_PENDING.equals(att.getStatus())) {
|
|
|
+ att.setStatus(ST_EFFECTIVE);
|
|
|
+ att.setEffectiveAt(now);
|
|
|
+ att.setUpdatedAt(now);
|
|
|
+ trainAttendanceMapper.updateById(att);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 账户累加:effective + 分类 + total
|
|
|
+ TrainCreditAccount acc = ensureAccount(cur.getUserId(), Year.now().getValue());
|
|
|
+ int h = cur.getHours() == null ? 0 : cur.getHours();
|
|
|
+ int pending = acc.getPendingHours() == null ? 0 : acc.getPendingHours();
|
|
|
+ int effective = acc.getEffectiveHours() == null ? 0 : acc.getEffectiveHours();
|
|
|
+ int theory = acc.getTheoryHours() == null ? 0 : acc.getTheoryHours();
|
|
|
+ int practice = acc.getPracticeHours() == null ? 0 : acc.getPracticeHours();
|
|
|
+ int total = acc.getTotalHours() == null ? 0 : acc.getTotalHours();
|
|
|
+ acc.setEffectiveHours(effective + h);
|
|
|
+ acc.setPendingHours(Math.max(0, pending - h));
|
|
|
+ if (CAT_THEORY.equals(cur.getSourceCategory())) {
|
|
|
+ acc.setTheoryHours(theory + h);
|
|
|
+ } else if (CAT_PRACTICE.equals(cur.getSourceCategory())) {
|
|
|
+ acc.setPracticeHours(practice + h);
|
|
|
+ }
|
|
|
+ acc.setTotalHours(total + h);
|
|
|
+ acc.setUpdatedAt(now);
|
|
|
+ trainCreditAccountMapper.updateById(acc);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int rollBackObjected() {
|
|
|
+ List<TrainCreditLedger> list = trainCreditLedgerMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainCreditLedger>()
|
|
|
+ .eq(TrainCreditLedger::getStatus, ST_OBJECTED)
|
|
|
+ .eq(TrainCreditLedger::getDeleted, 0)
|
|
|
+ .last("LIMIT 500"));
|
|
|
+ int ok = 0;
|
|
|
+ for (TrainCreditLedger l : list) {
|
|
|
+ try {
|
|
|
+ self.applyRollBack(l);
|
|
|
+ ok++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("学时异议回滚失败(跳过): ledgerId={}, err={}", l.getId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ok > 0) {
|
|
|
+ log.info("学时异议回滚完成: 本批 {} 条", ok);
|
|
|
+ }
|
|
|
+ return ok;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 单条回滚:单事务,ledger objected→rejected(终态)+ attendance 翻转 */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void applyRollBack(TrainCreditLedger l) {
|
|
|
+ TrainCreditLedger cur = trainCreditLedgerMapper.selectById(l.getId());
|
|
|
+ if (cur == null || !ST_OBJECTED.equals(cur.getStatus())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ cur.setStatus(ST_REJECTED);
|
|
|
+ cur.setUpdatedAt(now);
|
|
|
+ trainCreditLedgerMapper.updateById(cur);
|
|
|
+ if (SRC_ATTENDANCE.equals(cur.getSourceType())) {
|
|
|
+ TrainAttendance att = trainAttendanceMapper.selectById(parseLong(cur.getSourceId()));
|
|
|
+ if (att != null && ST_OBJECTED.equals(att.getStatus())) {
|
|
|
+ att.setStatus(ST_REJECTED);
|
|
|
+ att.setUpdatedAt(now);
|
|
|
+ trainAttendanceMapper.updateById(att);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // pending 已在 object 时扣减,此处无需再动账户
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Map<String, Object>> ledgerPending(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_PENDING)
|
|
|
+ .eq(TrainCreditLedger::getDeleted, 0));
|
|
|
+ List<TrainCreditLedger> list = trainCreditLedgerMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainCreditLedger>()
|
|
|
+ .eq(TrainCreditLedger::getStatus, ST_PENDING)
|
|
|
+ .eq(TrainCreditLedger::getDeleted, 0)
|
|
|
+ .orderByAsc(TrainCreditLedger::getEffectiveAt)
|
|
|
+ .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);
|
|
|
+ }
|
|
|
+}
|