From f7e5bf0de0bff2d4a746dda35d6cc8e323d7bdd6 Mon Sep 17 00:00:00 2001 From: wanghu Date: Wed, 23 Sep 2026 08:34:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=A7=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SubjectDictService.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/main/java/com/yunhai/homework/service/impl/SubjectDictService.java diff --git a/src/main/java/com/yunhai/homework/service/impl/SubjectDictService.java b/src/main/java/com/yunhai/homework/service/impl/SubjectDictService.java new file mode 100644 index 0000000..8315dec --- /dev/null +++ b/src/main/java/com/yunhai/homework/service/impl/SubjectDictService.java @@ -0,0 +1,78 @@ +package com.yunhai.homework.service.impl; + +import com.yunhai.homework.model.bsch.SchInfoDto; +import com.yunhai.homework.model.bsch.SchSubjectDto; +import com.yunhai.homework.service.IClassService; +import com.yunhai.homework.utils.UserContext; +import com.yunhai.platform.apistd.BizException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 本校学科字典门面(bschclass SubInfo/GetSchSublist): + * 学科编码 → 名称解析,供各作业列表回填 subjectName 与学科清单输出共用。 + * 无学校身份或远端不可用时降级为空字典,仅影响名称展示(回退编码),不阻断业务本身。 + */ +@Service +public class SubjectDictService { + + private static final Logger log = LoggerFactory.getLogger(SubjectDictService.class); + + private final IClassService classService; + + public SubjectDictService(IClassService classService) { + this.classService = classService; + } + + /** + * 当前登录人学校的学科字典(保留 SubInfo 排序号,学科清单场景按其排序输出)。 + */ + public List dictionary() { + try { + Integer schId = UserContext.getSchId(); + if (schId == null) { + return Collections.emptyList(); + } + SchInfoDto sch = classService.getSchFirst(schId); + if (sch == null || !StringUtils.hasText(sch.getSchSerId())) { + return Collections.emptyList(); + } + return classService.getSchSubList(sch.getSchSerId()); + } catch (BizException e) { + log.warn("[subjectDict] 本校学科字典拉取失败, 降级为编码展示: {}", e.getMessage()); + return Collections.emptyList(); + } + } + + /** + * 学科编码 → 名称映射(列表回填 subjectName 用,一次批量外呼)。 + */ + public Map nameMap() { + Map names = new HashMap<>(); + for (SchSubjectDto subject : dictionary()) { + if (subject != null && StringUtils.hasText(subject.getSubId()) + && StringUtils.hasText(subject.getSubName())) { + names.put(subject.getSubId(), subject.getSubName()); + } + } + return names; + } + + /** + * 学科编码 → 名称:映射命中取名称,未命中或映射缺失时回退编码本身。 + */ + public String resolve(String code, Map names) { + if (!StringUtils.hasText(code)) { + return null; + } + String name = names == null ? null : names.get(code); + return StringUtils.hasText(name) ? name : code; + } +}