|
@@ -35,6 +35,7 @@ import java.util.HashSet;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 晋升域实现。
|
|
* 晋升域实现。
|
|
@@ -65,6 +66,12 @@ public class PromotionServiceImpl implements PromotionService {
|
|
|
private static final String O_CONFIRMED = "confirmed";
|
|
private static final String O_CONFIRMED = "confirmed";
|
|
|
private static final String BADGE_PREFIX = "lec_t";
|
|
private static final String BADGE_PREFIX = "lec_t";
|
|
|
|
|
|
|
|
|
|
+ /** train.promo.history 合规举证契约错误码 */
|
|
|
|
|
+ private static final int CODE_FORBIDDEN = 403;
|
|
|
|
|
+ private static final int CODE_NOT_FOUND = 404;
|
|
|
|
|
+ private static final int CODE_VERSION_CONFLICT = 422;
|
|
|
|
|
+ private static final int CODE_SAME_KEY_DIFF_PAYLOAD = 4092;
|
|
|
|
|
+
|
|
|
private static final Set<String> ALLOWED_METRICS = new HashSet<>(Arrays.asList(
|
|
private static final Set<String> ALLOWED_METRICS = new HashSet<>(Arrays.asList(
|
|
|
"serve_count", "order_count", "rating", "theory_hours", "total_hours", "credit_hours", "exam_score"));
|
|
"serve_count", "order_count", "rating", "theory_hours", "total_hours", "credit_hours", "exam_score"));
|
|
|
private static final Set<String> ALLOWED_OPS = new HashSet<>(Arrays.asList(
|
|
private static final Set<String> ALLOWED_OPS = new HashSet<>(Arrays.asList(
|
|
@@ -72,6 +79,9 @@ public class PromotionServiceImpl implements PromotionService {
|
|
|
|
|
|
|
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
+ /** 幂等键 → 导出载荷指纹(同键异载荷 C4092;进程内缓存,重启后以档案为准) */
|
|
|
|
|
+ private final Map<String, String> historyExportFingerprints = new ConcurrentHashMap<>();
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private TrainPromotionRuleMapper trainPromotionRuleMapper;
|
|
private TrainPromotionRuleMapper trainPromotionRuleMapper;
|
|
|
@Resource
|
|
@Resource
|
|
@@ -357,14 +367,14 @@ public class PromotionServiceImpl implements PromotionService {
|
|
|
public Result<Map<String, Object>> rejectRecord(Boolean isAdmin, Long recordId, String reason) {
|
|
public Result<Map<String, Object>> rejectRecord(Boolean isAdmin, Long recordId, String reason) {
|
|
|
String noAuth = roleGuard.requireAdminRole(isAdmin);
|
|
String noAuth = roleGuard.requireAdminRole(isAdmin);
|
|
|
if (noAuth != null) {
|
|
if (noAuth != null) {
|
|
|
- return Result.error(noAuth);
|
|
|
|
|
|
|
+ return Result.error(CODE_FORBIDDEN, noAuth);
|
|
|
}
|
|
}
|
|
|
if (recordId == null) {
|
|
if (recordId == null) {
|
|
|
return Result.error("参数不完整");
|
|
return Result.error("参数不完整");
|
|
|
}
|
|
}
|
|
|
TrainPromotionRecord rec = trainPromotionRecordMapper.selectById(recordId);
|
|
TrainPromotionRecord rec = trainPromotionRecordMapper.selectById(recordId);
|
|
|
if (rec == null || (rec.getDeleted() != null && rec.getDeleted() == 1)) {
|
|
if (rec == null || (rec.getDeleted() != null && rec.getDeleted() == 1)) {
|
|
|
- return Result.error("晋升记录不存在");
|
|
|
|
|
|
|
+ return Result.error(CODE_NOT_FOUND, "晋升记录不存在");
|
|
|
}
|
|
}
|
|
|
String err = StateGuard.checkPromotion(rec.getStatus(), PR_REJECTED);
|
|
String err = StateGuard.checkPromotion(rec.getStatus(), PR_REJECTED);
|
|
|
if (err != null) {
|
|
if (err != null) {
|
|
@@ -372,12 +382,54 @@ public class PromotionServiceImpl implements PromotionService {
|
|
|
}
|
|
}
|
|
|
rec.setStatus(PR_REJECTED);
|
|
rec.setStatus(PR_REJECTED);
|
|
|
rec.setUpdatedAt(new Date());
|
|
rec.setUpdatedAt(new Date());
|
|
|
- trainPromotionRecordMapper.updateById(rec);
|
|
|
|
|
|
|
+ int rows = trainPromotionRecordMapper.updateById(rec);
|
|
|
|
|
+ if (rows <= 0) {
|
|
|
|
|
+ // 并发丢失更新 / 版本不匹配:禁止静默按 200 成功
|
|
|
|
|
+ return Result.error(CODE_VERSION_CONFLICT, "并发冲突:履历已被其他操作更新");
|
|
|
|
|
+ }
|
|
|
log.info("晋升记录机构否决: recordId={}, userId={}, authLevel={}, reason={}",
|
|
log.info("晋升记录机构否决: recordId={}, userId={}, authLevel={}, reason={}",
|
|
|
recordId, rec.getUserId(), rec.getAuthLevel(), reason);
|
|
recordId, rec.getUserId(), rec.getAuthLevel(), reason);
|
|
|
return Result.success(recordVO(rec));
|
|
return Result.success(recordVO(rec));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result<Map<String, Object>> exportHistory(Boolean isAdmin, Long userId, Boolean replay,
|
|
|
|
|
+ String key, Map<String, Object> payload) {
|
|
|
|
|
+ String noAuth = roleGuard.requireAdminRole(isAdmin);
|
|
|
|
|
+ if (noAuth != null) {
|
|
|
|
|
+ return Result.error(CODE_FORBIDDEN, noAuth);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (userId == null || key == null || key.trim().isEmpty()) {
|
|
|
|
|
+ return Result.error("参数不完整");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> safePayload = payload == null ? new HashMap<String, Object>() : payload;
|
|
|
|
|
+ String fingerprint = writeJson(safePayload);
|
|
|
|
|
+ if (fingerprint == null) {
|
|
|
|
|
+ fingerprint = "";
|
|
|
|
|
+ }
|
|
|
|
|
+ String previous = historyExportFingerprints.putIfAbsent(key, fingerprint);
|
|
|
|
|
+ if (previous != null && !previous.equals(fingerprint)) {
|
|
|
|
|
+ return Result.error(CODE_SAME_KEY_DIFF_PAYLOAD, "同一幂等键对应不同导出载荷,禁止静默复用既有档案");
|
|
|
|
|
+ }
|
|
|
|
|
+ LambdaQueryWrapper<TrainPromotionRecord> q = new LambdaQueryWrapper<TrainPromotionRecord>()
|
|
|
|
|
+ .eq(TrainPromotionRecord::getUserId, userId)
|
|
|
|
|
+ .eq(TrainPromotionRecord::getDeleted, 0)
|
|
|
|
|
+ .orderByAsc(TrainPromotionRecord::getAppliedAt);
|
|
|
|
|
+ List<TrainPromotionRecord> records = trainPromotionRecordMapper.selectList(q);
|
|
|
|
|
+ List<Map<String, Object>> rows = new ArrayList<>();
|
|
|
|
|
+ for (TrainPromotionRecord r : records) {
|
|
|
|
|
+ rows.add(recordVO(r));
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
|
|
+ data.put("key", key);
|
|
|
|
|
+ data.put("replay", Boolean.TRUE.equals(replay));
|
|
|
|
|
+ data.put("payload", safePayload);
|
|
|
|
|
+ data.put("total", rows.size());
|
|
|
|
|
+ data.put("list", rows);
|
|
|
|
|
+ data.put("exportedAt", new Date());
|
|
|
|
|
+ return Result.success(data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Result<Map<String, Object>> scanAndGrant(Boolean isAdmin) {
|
|
public Result<Map<String, Object>> scanAndGrant(Boolean isAdmin) {
|
|
|
String noAuth = roleGuard.requireAdminRole(isAdmin);
|
|
String noAuth = roleGuard.requireAdminRole(isAdmin);
|