|
|
@@ -51,6 +51,10 @@ public class PractitionerServiceImpl implements PractitionerService {
|
|
|
private static final String ORG_MEMBER_STATUS_ACTIVE = "active";
|
|
|
/** 资质核验状态:verified 已核(有效证书口径) */
|
|
|
private static final String LICENSE_VERIFY_VERIFIED = "verified";
|
|
|
+ /** 资质核验状态:pending 待核 */
|
|
|
+ private static final String LICENSE_VERIFY_PENDING = "pending";
|
|
|
+ /** 资质核验状态:rejected 驳回 */
|
|
|
+ private static final String LICENSE_VERIFY_REJECTED = "rejected";
|
|
|
/** 学时台账状态:effective 已生效 */
|
|
|
private static final String LEDGER_STATUS_EFFECTIVE = "effective";
|
|
|
|
|
|
@@ -241,6 +245,143 @@ public class PractitionerServiceImpl implements PractitionerService {
|
|
|
return Result.success(data);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result<Long> addLicense(Long userId, Map<String, Object> body) {
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.error("请先登录");
|
|
|
+ }
|
|
|
+ if (body == null || body.get("licenseType") == null || body.get("licenseNo") == null
|
|
|
+ || body.get("issuer") == null || body.get("issuedAt") == null) {
|
|
|
+ return Result.error("参数不完整:licenseType/licenseNo/issuer/issuedAt 必填");
|
|
|
+ }
|
|
|
+ String licenseType = str(body.get("licenseType")).trim();
|
|
|
+ String licenseNo = str(body.get("licenseNo")).trim();
|
|
|
+ if (licenseType.isEmpty() || licenseNo.isEmpty()) {
|
|
|
+ return Result.error("参数不完整:licenseType/licenseNo 不能为空");
|
|
|
+ }
|
|
|
+ Date issuedAt = parseDate(body.get("issuedAt"));
|
|
|
+ if (issuedAt == null) {
|
|
|
+ return Result.error("issuedAt 日期格式无效(yyyy-MM-dd)");
|
|
|
+ }
|
|
|
+ // 唯一键 uk(user_id, license_type, license_no) 预检(软删行视为仍占用,保持唯一语义)
|
|
|
+ TrainPractitionerLicense exist = trainPractitionerLicenseMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<TrainPractitionerLicense>()
|
|
|
+ .eq(TrainPractitionerLicense::getUserId, userId)
|
|
|
+ .eq(TrainPractitionerLicense::getLicenseType, licenseType)
|
|
|
+ .eq(TrainPractitionerLicense::getLicenseNo, licenseNo)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (exist != null) {
|
|
|
+ return Result.error("该资质已存在");
|
|
|
+ }
|
|
|
+ TrainPractitionerLicense lic = new TrainPractitionerLicense();
|
|
|
+ lic.setUserId(userId);
|
|
|
+ lic.setLicenseType(licenseType);
|
|
|
+ lic.setLicenseNo(licenseNo);
|
|
|
+ lic.setIssuer(str(body.get("issuer")));
|
|
|
+ lic.setIssuedAt(issuedAt);
|
|
|
+ lic.setExpireAt(parseDate(body.get("expireAt")));
|
|
|
+ lic.setFileId(toLong(body.get("fileId")));
|
|
|
+ lic.setFileUrl(str(body.get("fileUrl")));
|
|
|
+ lic.setVerifyStatus(LICENSE_VERIFY_PENDING);
|
|
|
+ lic.setDeleted(DELETED_NORMAL);
|
|
|
+ lic.setCreatedAt(new Date());
|
|
|
+ lic.setUpdatedAt(new Date());
|
|
|
+ try {
|
|
|
+ trainPractitionerLicenseMapper.insert(lic);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // uk 并发冲突兜底
|
|
|
+ log.warn("资质证书插入冲突: userId={}, licenseType={}, licenseNo={}, err={}",
|
|
|
+ userId, licenseType, licenseNo, e.getMessage());
|
|
|
+ return Result.error("该资质已存在");
|
|
|
+ }
|
|
|
+ return Result.success(lic.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<List<Map<String, Object>>> listLicenses(Long userId) {
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.error("请先登录");
|
|
|
+ }
|
|
|
+ List<TrainPractitionerLicense> list = trainPractitionerLicenseMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainPractitionerLicense>()
|
|
|
+ .eq(TrainPractitionerLicense::getUserId, userId)
|
|
|
+ .eq(TrainPractitionerLicense::getDeleted, DELETED_NORMAL)
|
|
|
+ .orderByDesc(TrainPractitionerLicense::getId));
|
|
|
+ List<Map<String, Object>> rows = new ArrayList<>();
|
|
|
+ if (list != null) {
|
|
|
+ for (TrainPractitionerLicense lic : list) {
|
|
|
+ rows.add(licenseVO(lic));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.success(rows);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Map<String, Object>> adminLicenseList(Long userId, Boolean isAdmin, Map<String, Object> body) {
|
|
|
+ if (!Boolean.TRUE.equals(isAdmin)) {
|
|
|
+ return Result.error("需要管理员权限");
|
|
|
+ }
|
|
|
+ int page = body == null ? 1 : toInt(body.get("page"), 1);
|
|
|
+ int size = body == null ? 20 : toInt(body.get("size"), 20);
|
|
|
+ if (page < 1) {
|
|
|
+ page = 1;
|
|
|
+ }
|
|
|
+ if (size < 1) {
|
|
|
+ size = 20;
|
|
|
+ }
|
|
|
+ if (size > 100) {
|
|
|
+ size = 100;
|
|
|
+ }
|
|
|
+ Long filterUserId = body == null ? null : toLong(body.get("userId"));
|
|
|
+ String verifyStatus = body == null ? null : str(body.get("verifyStatus"));
|
|
|
+
|
|
|
+ LambdaQueryWrapper<TrainPractitionerLicense> qw = new LambdaQueryWrapper<>();
|
|
|
+ qw.eq(TrainPractitionerLicense::getDeleted, DELETED_NORMAL);
|
|
|
+ if (filterUserId != null) {
|
|
|
+ qw.eq(TrainPractitionerLicense::getUserId, filterUserId);
|
|
|
+ }
|
|
|
+ if (verifyStatus != null && !verifyStatus.trim().isEmpty()) {
|
|
|
+ qw.eq(TrainPractitionerLicense::getVerifyStatus, verifyStatus.trim());
|
|
|
+ }
|
|
|
+ Long total = trainPractitionerLicenseMapper.selectCount(qw);
|
|
|
+ if (total == null) {
|
|
|
+ total = 0L;
|
|
|
+ }
|
|
|
+ int offset = (page - 1) * size;
|
|
|
+ qw.orderByDesc(TrainPractitionerLicense::getId).last("LIMIT " + offset + "," + size);
|
|
|
+ List<TrainPractitionerLicense> list = trainPractitionerLicenseMapper.selectList(qw);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("total", total);
|
|
|
+ result.put("page", page);
|
|
|
+ result.put("size", size);
|
|
|
+ result.put("list", list);
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Boolean> verifyLicense(Long operatorId, Boolean isAdmin, Map<String, Object> body) {
|
|
|
+ if (!Boolean.TRUE.equals(isAdmin)) {
|
|
|
+ return Result.error("需要管理员权限");
|
|
|
+ }
|
|
|
+ if (body == null || body.get("licenseId") == null || body.get("approved") == null) {
|
|
|
+ return Result.error("参数不完整:licenseId/approved 必填");
|
|
|
+ }
|
|
|
+ Long licenseId = toLong(body.get("licenseId"));
|
|
|
+ boolean approved = Boolean.parseBoolean(body.get("approved").toString().trim());
|
|
|
+ TrainPractitionerLicense lic = trainPractitionerLicenseMapper.selectById(licenseId);
|
|
|
+ if (lic == null) {
|
|
|
+ return Result.error("资质证书不存在");
|
|
|
+ }
|
|
|
+ lic.setVerifyStatus(approved ? LICENSE_VERIFY_VERIFIED : LICENSE_VERIFY_REJECTED);
|
|
|
+ lic.setVerifiedBy(operatorId);
|
|
|
+ lic.setVerifiedAt(new Date());
|
|
|
+ lic.setRemark(str(body.get("rejectReason")));
|
|
|
+ lic.setUpdatedAt(new Date());
|
|
|
+ trainPractitionerLicenseMapper.updateById(lic);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
// ---------- 内部工具 ----------
|
|
|
|
|
|
private LambdaQueryWrapper<TrainPractitionerProfile> baseWrapper(String keyword, String level,
|
|
|
@@ -520,4 +661,46 @@ public class PractitionerServiceImpl implements PractitionerService {
|
|
|
return def;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /** 资质证书 VO(用户端 listLicenses 用) */
|
|
|
+ private Map<String, Object> licenseVO(TrainPractitionerLicense lic) {
|
|
|
+ Map<String, Object> m = new HashMap<>();
|
|
|
+ m.put("id", lic.getId());
|
|
|
+ m.put("userId", lic.getUserId());
|
|
|
+ m.put("licenseType", lic.getLicenseType());
|
|
|
+ m.put("licenseNo", lic.getLicenseNo());
|
|
|
+ m.put("issuer", lic.getIssuer());
|
|
|
+ m.put("issuedAt", fmt(lic.getIssuedAt()));
|
|
|
+ m.put("expireAt", fmt(lic.getExpireAt()));
|
|
|
+ m.put("fileId", lic.getFileId());
|
|
|
+ m.put("fileUrl", lic.getFileUrl());
|
|
|
+ m.put("verifyStatus", lic.getVerifyStatus());
|
|
|
+ m.put("verifiedBy", lic.getVerifiedBy());
|
|
|
+ m.put("verifiedAt", fmt(lic.getVerifiedAt()));
|
|
|
+ m.put("remark", lic.getRemark());
|
|
|
+ m.put("createdAt", fmt(lic.getCreatedAt()));
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 日期解析:接受 Date 或 yyyy-MM-dd / yyyy-MM-dd HH:mm 字符串;非法返回 null */
|
|
|
+ private Date parseDate(Object v) {
|
|
|
+ if (v == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (v instanceof Date) {
|
|
|
+ return (Date) v;
|
|
|
+ }
|
|
|
+ String s = v.toString().trim();
|
|
|
+ if (s.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (s.length() > 10) {
|
|
|
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(s);
|
|
|
+ }
|
|
|
+ return new SimpleDateFormat("yyyy-MM-dd").parse(s);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|