@@ -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<SchSubjectDto> 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<String, String> nameMap() {
|
||||||
|
Map<String, String> 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<String, String> names) {
|
||||||
|
if (!StringUtils.hasText(code)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String name = names == null ? null : names.get(code);
|
||||||
|
return StringUtils.hasText(name) ? name : code;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user