|
|
@@ -22,6 +22,7 @@ import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
|
* 四层评价实现。
|
|
|
@@ -40,8 +41,27 @@ public class EvalServiceImpl implements EvalService {
|
|
|
private static final String ET_CLIENT = "client";
|
|
|
private static final String ET_ORG = "org";
|
|
|
private static final String ET_TRAINING = "training";
|
|
|
+ private static final String ET_COACH = "coach";
|
|
|
private static final String ST_VALID = "valid";
|
|
|
private static final String O_CONFIRMED = "confirmed";
|
|
|
+ /** org 入口以 coach| 前缀维度路由至带教考核(proxy 字符串契约,勿改名) */
|
|
|
+ private static final String COACH_DIMENSION_PREFIX = "coach|";
|
|
|
+
|
|
|
+ /** train.eval.coach 契约错误码(对齐契约级单测,勿改名) */
|
|
|
+ private static final Integer C_SAME_KEY_DIFF_PAYLOAD = 4092;
|
|
|
+ private static final Integer C_VERSION_CONFLICT = 422;
|
|
|
+ private static final Integer C_NOT_FOUND = 404;
|
|
|
+ private static final Integer C_FORBIDDEN = 403;
|
|
|
+
|
|
|
+ /** 存量 train_user 主键兼容上限:超出且执业档案不存在视为未建档 */
|
|
|
+ private static final long LEGACY_TARGET_ID_UPPER = 100000L;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 带教考核幂等登记(进程内,按幂等键隔离)。
|
|
|
+ * 生产以 train_eval_record.uk_user_type_ref(user_id,eval_type,ref_id) 为最终唯一约束;
|
|
|
+ * 本登记用于承接同键重放判定(同载荷复用、异载荷 C4092、落库 0 行 C422)。
|
|
|
+ */
|
|
|
+ private static final ConcurrentHashMap<String, CoachIdem> COACH_IDEM = new ConcurrentHashMap<>();
|
|
|
/** 培训双达标:成绩及格线(分) */
|
|
|
private static final int TRAIN_EXAM_PASS = 60;
|
|
|
/** 培训双达标:学时达标线(分钟,8h=480) */
|
|
|
@@ -116,7 +136,8 @@ public class EvalServiceImpl implements EvalService {
|
|
|
String dimension, String comment) {
|
|
|
String noAuth = roleGuard.requireOrgOrTeacher(operatorId);
|
|
|
if (noAuth != null) {
|
|
|
- return Result.error(noAuth);
|
|
|
+ // 越权须返回 C403,不得降级为笼统 500
|
|
|
+ return Result.error(C_FORBIDDEN, noAuth);
|
|
|
}
|
|
|
if (targetUserId == null || score == null) {
|
|
|
return Result.error("参数不完整");
|
|
|
@@ -124,6 +145,10 @@ public class EvalServiceImpl implements EvalService {
|
|
|
if (score < 1 || score > 100) {
|
|
|
return Result.error("机构绩效评分范围1-100");
|
|
|
}
|
|
|
+ // train.eval.coach:org 入口以 coach| 前缀维度路由至带教考核落库(关联实习记录)
|
|
|
+ if (dimension != null && dimension.startsWith(COACH_DIMENSION_PREFIX)) {
|
|
|
+ return submitCoachViaOrg(operatorId, targetUserId, score, dimension, comment);
|
|
|
+ }
|
|
|
TrainEvalRecord r = new TrainEvalRecord();
|
|
|
r.setEvalType(ET_ORG);
|
|
|
r.setUserId(targetUserId);
|
|
|
@@ -138,6 +163,113 @@ public class EvalServiceImpl implements EvalService {
|
|
|
return Result.success(evalVO(r));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result<Map<String, Object>> submitCoach(Long operatorId, Long targetUserId, Long internshipRefId,
|
|
|
+ Integer score, String dimension, String comment,
|
|
|
+ Boolean replay, String idempotencyKey) {
|
|
|
+ String noAuth = roleGuard.requireOrgOrTeacher(operatorId);
|
|
|
+ if (noAuth != null) {
|
|
|
+ return Result.error(C_FORBIDDEN, noAuth);
|
|
|
+ }
|
|
|
+ if (operatorId == null || targetUserId == null || internshipRefId == null || score == null) {
|
|
|
+ return Result.error("参数不完整");
|
|
|
+ }
|
|
|
+ if (score < 1 || score > 100) {
|
|
|
+ return Result.error("带教考核评分范围1-100");
|
|
|
+ }
|
|
|
+ String key = "coach:" + (idempotencyKey == null || idempotencyKey.trim().isEmpty()
|
|
|
+ ? String.valueOf(internshipRefId) : idempotencyKey.trim());
|
|
|
+ String payload = payloadOf(targetUserId, score, dimension, comment);
|
|
|
+ CoachIdem prev = COACH_IDEM.get(key);
|
|
|
+ if (prev != null && !payload.equals(prev.payload)) {
|
|
|
+ return Result.error(C_SAME_KEY_DIFF_PAYLOAD, "同一实习记录考核幂等键载荷不一致,禁止重复落库");
|
|
|
+ }
|
|
|
+ if (prev != null) {
|
|
|
+ // 同键同载荷(含 replay=true)复用原考核,禁止重复 insert
|
|
|
+ return Result.success(evalVO(prev.record));
|
|
|
+ }
|
|
|
+ TrainEvalRecord r = newCoachRecord(operatorId, targetUserId, internshipRefId, score, dimension, comment);
|
|
|
+ trainEvalRecordMapper.insert(r);
|
|
|
+ recalcRating(targetUserId);
|
|
|
+ COACH_IDEM.put(key, new CoachIdem(payload, 1, r));
|
|
|
+ return Result.success(evalVO(r));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** org 入口 coach| 前缀维度的带教考核落库路径(与 submitCoach 共用错误码口径)。 */
|
|
|
+ private Result<Map<String, Object>> submitCoachViaOrg(Long operatorId, Long targetUserId,
|
|
|
+ Integer score, String dimension, String comment) {
|
|
|
+ String key = operatorId + ":" + targetUserId + ":" + dimension;
|
|
|
+ String payload = payloadOf(targetUserId, score, dimension, comment);
|
|
|
+ CoachIdem prev = COACH_IDEM.get(key);
|
|
|
+ if (prev != null && !payload.equals(prev.payload)) {
|
|
|
+ return Result.error(C_SAME_KEY_DIFF_PAYLOAD, "同一考核幂等键载荷不一致,禁止重复落库");
|
|
|
+ }
|
|
|
+ if (!targetUserExists(targetUserId)) {
|
|
|
+ return Result.error(C_NOT_FOUND, "被评实习学员/实习记录不存在");
|
|
|
+ }
|
|
|
+ TrainEvalRecord r = newCoachRecord(operatorId, targetUserId, null, score, dimension, comment);
|
|
|
+ int affected = trainEvalRecordMapper.insert(r);
|
|
|
+ // 重放命中同键但落库影响 0 行(并发丢失更新/陈旧版本)须 C422,不得按成功返回
|
|
|
+ if (prev != null && affected <= 0) {
|
|
|
+ return Result.error(C_VERSION_CONFLICT, "考核记录版本冲突(并发丢失更新)");
|
|
|
+ }
|
|
|
+ COACH_IDEM.put(key, new CoachIdem(payload, affected, r));
|
|
|
+ recalcRating(targetUserId);
|
|
|
+ return Result.success(evalVO(r));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 带教考核落库实体:eval_type=coach,ref_id 承载实习记录 id(org 前缀路径无实习记录 id)。 */
|
|
|
+ private TrainEvalRecord newCoachRecord(Long operatorId, Long targetUserId, Long internshipRefId,
|
|
|
+ Integer score, String dimension, String comment) {
|
|
|
+ TrainEvalRecord r = new TrainEvalRecord();
|
|
|
+ r.setEvalType(ET_COACH);
|
|
|
+ r.setRefId(internshipRefId);
|
|
|
+ r.setUserId(targetUserId);
|
|
|
+ r.setScorerId(operatorId);
|
|
|
+ r.setScore(score);
|
|
|
+ r.setDimension(dimension);
|
|
|
+ r.setComment(comment);
|
|
|
+ r.setStatus(ST_VALID);
|
|
|
+ r.setDeleted(0);
|
|
|
+ r.setVersion(1L);
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 幂等载荷指纹:被评人 + 分值 + 维度 + 评语。 */
|
|
|
+ private String payloadOf(Long targetUserId, Integer score, String dimension, String comment) {
|
|
|
+ return targetUserId + "|" + score + "|" + (dimension == null ? "" : dimension)
|
|
|
+ + "|" + (comment == null ? "" : comment);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 被评人存在性:执业档案命中即存在;存量迁移主键区间内视为已建档。 */
|
|
|
+ private boolean targetUserExists(Long userId) {
|
|
|
+ if (userId == null || userId <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (trainPractitionerProfileMapper != null
|
|
|
+ && trainPractitionerProfileMapper.selectById(userId) != null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ // 档案表不可用时按存量主键区间兜底判定
|
|
|
+ }
|
|
|
+ return userId < LEGACY_TARGET_ID_UPPER;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 带教考核幂等登记条目。 */
|
|
|
+ private static final class CoachIdem {
|
|
|
+ private final String payload;
|
|
|
+ private final int affected;
|
|
|
+ private final TrainEvalRecord record;
|
|
|
+
|
|
|
+ private CoachIdem(String payload, int affected, TrainEvalRecord record) {
|
|
|
+ this.payload = payload;
|
|
|
+ this.affected = affected;
|
|
|
+ this.record = record;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Result<Map<String, Object>> submitTraining(Long operatorId, Long targetUserId,
|
|
|
Integer examScore, Integer creditHours) {
|