【修改】 解决考点服务器没有根据点位授权的专业进行显示的BUG

This commit is contained in:
dlaren
2025-08-11 14:52:28 +08:00
parent 851cc9e1cb
commit c07e8910d2
10 changed files with 293 additions and 42 deletions

View File

@@ -295,7 +295,7 @@ public class ExamQuestionController {
if (!file.getFile().getOriginalFilename().endsWith(".c")) {
return CommonResult.error(100810, "请上传.c文件");
}
return CommonResult.success(new String(file.getFile().getBytes(), StandardCharsets.UTF_8));
return CommonResult.success(new String(file.getFile().getBytes(), "GBK"));
}
}

View File

@@ -13,12 +13,16 @@ import pc.exam.pp.framework.tenant.core.service.TenantFrameworkService;
import pc.exam.pp.module.exam.controller.admin.rabbitmq.vo.PushAudioRequestVo;
import pc.exam.pp.module.exam.controller.admin.rabbitmq.vo.PushRequestVo;
import pc.exam.pp.module.exam.controller.admin.rabbitmq.vo.RabbitMQSendInfoVO;
import pc.exam.pp.module.exam.controller.admin.specialty.vo.TenantSpcialtyVo;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.specialty.ExamSpecialty;
import pc.exam.pp.module.exam.dal.mysql.specialty.ExamSpecialtyMapper;
import pc.exam.pp.module.exam.service.question.ExamQuestionServiceImpl;
import pc.exam.pp.module.exam.utils.rabbitmq.RabbitmqUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static pc.exam.pp.module.system.enums.ErrorCodeConstants.RABBITMQ_NOT_EXISTS;
import static pc.exam.pp.module.system.enums.ErrorCodeConstants.RABBITMQ_NAME_NOT_NULL;
@@ -34,6 +38,8 @@ public class RabbitMQController {
private RabbitmqUtils rabbitMqService;
@Resource
private ExamQuestionServiceImpl examQuestionService;
@Resource
ExamSpecialtyMapper examSpecialtyMapper;
/**
@@ -170,6 +176,23 @@ public class RabbitMQController {
public CommonResult doPush(@RequestBody PushRequestVo request) {
List<String> queueNames = request.getQueueNames();
List<String> questionIds = request.getQuestionIds();
// 需要查询对应试题的专业,考点服务器是否存在
for (String quId : questionIds) {
// 查询试题信息
ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(quId);
String courseName = examQuestion.getCourseName();
// 通过Name查询专业信息
ExamSpecialty examSpecialty = examSpecialtyMapper.selectExamSpecialtyBySpNameOne(courseName);
for (String queueName : queueNames) {
String teantId = queueName.split("_")[0];
List<TenantSpcialtyVo> tenantSpcialtyVos = examSpecialtyMapper.selectTenantSpcialtyList(Long.valueOf(teantId));
// 判断是否存在
Optional<TenantSpcialtyVo> result = tenantSpcialtyVos.stream().filter(quLists -> quLists.getSpecialtyId().equals(examSpecialty.getSpId())).findFirst();
if (!result.isPresent()) {
return CommonResult.error(1_005_005_023, "试题{" + examQuestion.getQuNum() + "},对应考点服务器{" + queueName + "}专业不存在");
}
}
}
for (String queueName : queueNames) {
RabbitMQSendInfoVO rabbitMQSendInfoVO = new RabbitMQSendInfoVO();
rabbitMQSendInfoVO.setType("0");

View File

@@ -0,0 +1,18 @@
package pc.exam.pp.module.exam.controller.admin.specialty.vo;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.*;
@Data
public class TenantSpcialtyVo {
@TableId(value = "id")
private Long id;
private Long tenantId;
private Long specialtyId;
private String points;
}

View File

@@ -1,16 +1,20 @@
package pc.exam.pp.module.exam.dal.mysql.specialty;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtListReqVo;
import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtyQueryVo;
import pc.exam.pp.module.exam.controller.admin.specialty.vo.TenantSpcialtyVo;
import pc.exam.pp.module.exam.dal.dataobject.knowledge.ExamKnowledgePoints;
import pc.exam.pp.module.exam.dal.dataobject.monitor.TentSpecialy;
import pc.exam.pp.module.exam.dal.dataobject.specialty.ExamSpecialty;
import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsXlsx;
import pc.exam.pp.module.exam.service.monitor.vo.IdParentPair;
import pc.exam.pp.module.exam.service.monitor.vo.SpecialtyRelation;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -22,8 +26,11 @@ import java.util.Set;
* @date 2025-03-24
*/
@Mapper
public interface ExamSpecialtyMapper extends BaseMapperX<ExamSpecialty>
{
public interface ExamSpecialtyMapper extends BaseMapperX<ExamSpecialty> {
default List<ExamSpecialty> selectListByParentId(Collection<Long> parentIds) {
return selectList(ExamSpecialty::getParentId, parentIds);
}
/**
* 查询数据
*
@@ -32,7 +39,18 @@ public interface ExamSpecialtyMapper extends BaseMapperX<ExamSpecialty>
*/
ExamSpecialty selectExamSpecialtyBySpId(Long spId);
/**
* 查询数据
*
* @param name 名称
* @return 数据信息
*/
ExamSpecialty selectExamSpecialtyBySpNameOne(String name);
List<ExamSpecialty> selectExamSpecialtyBySpName(String spName);
List<TenantSpcialtyVo> selectTenantSpcialtyList(Long id);
/**
* 查询数据parentId
*
@@ -114,19 +132,17 @@ public interface ExamSpecialtyMapper extends BaseMapperX<ExamSpecialty>
String getRoleById(String id);
ExamSpecialty selectBySpecCourseSub(@Param("specialtyName") String specialtyName
,@Param("courseName") String courseName
,@Param("subjectName") String subjectName);
, @Param("courseName") String courseName
, @Param("subjectName") String subjectName);
ExamKnowledgePoints selectByPointsSub(@Param("specialtyName") String specialtyName
, @Param("chapteridDictText")String chapteridDictText
, @Param("pointNames") String pointNames);
ExamKnowledgePoints selectByPointsSub(@Param("specialtyName") String specialtyName
, @Param("chapteridDictText") String chapteridDictText
, @Param("pointNames") String pointNames);
List<SpecialtyRelation> selectAllSpecialtyRelations(); // 返回 sp_id 和 parent_id
List<IdParentPair> selectAllIdToParent(Long loginTenantId);
}

View File

@@ -123,11 +123,24 @@
where sp_id = #{spId}
</select>
<select id="selectExamSpecialtyBySpName" parameterType="String" resultType="pc.exam.pp.module.exam.dal.dataobject.specialty.ExamSpecialty">
<select id="selectExamSpecialtyBySpNameOne" parameterType="String" resultType="ExamSpecialty">
SELECT *
from exam_specialty
where sp_name = #{name}
</select>
<select id="selectExamSpecialtyBySpName" parameterType="String"
resultType="pc.exam.pp.module.exam.dal.dataobject.specialty.ExamSpecialty">
SELECT *
from exam_specialty
where sp_name = #{spName}
</select>
<select id="selectTenantSpcialtyList" parameterType="Long"
resultType="pc.exam.pp.module.exam.controller.admin.specialty.vo.TenantSpcialtyVo">
SELECT *
from exam_tenant_specialty
where tenant_id = #{id}
</select>
<select id="selectExamSpecialtyByParentId"
resultType="pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtyQueryVo">

View File

@@ -130,7 +130,6 @@ public class UserController {
@GetMapping("/page")
@Operation(summary = "获得用户分页列表")
@PreAuthorize("@ss.hasPermission('system:user:query')")
public CommonResult<PageResult<UserRespVO>> getUserPage(@Valid UserPageReqVO pageReqVO) {
// 获得用户分页列表
PageResult<AdminUserDO> pageResult = userService.getUserPage(pageReqVO);
@@ -268,9 +267,15 @@ public class UserController {
@GetMapping("/getSpeciatListByUser")
@Operation(summary = "获取专业信息,判断用户类型")
public CommonResult<List<SpecialtyQueryVo>> getListByUser() {
List<SpecialtyQueryVo> list = userService.getListByUser();
return success(BeanUtils.toBean(list, SpecialtyQueryVo.class));
}
@GetMapping("/getSpeciatListByTenantId")
@Operation(summary = "获取专业信息,判断用户类型")
public CommonResult<List<SpecialtyQueryVo>> getSpeciatListByTenantId() {
List<SpecialtyQueryVo> list = userService.getSpeciatListByTenantId();
return success(BeanUtils.toBean(list, SpecialtyQueryVo.class));
}
}

View File

@@ -31,4 +31,8 @@ public interface TenantSpecialtyMapper extends BaseMapperX<TenantSpcialtyDO> {
default List<TenantSpcialtyDO> getSpecialtyPoints(Long id) {
return selectList(TenantSpcialtyDO::getTenantId, id);
}
default void deleteByTeantId (Long id) {
delete(TenantSpcialtyDO::getTenantId, id);
};
}

View File

@@ -68,10 +68,8 @@ public class TenantServiceImpl implements TenantService {
private RabbitmqUtils rabbitMqService;
@Resource
private TenantMapper tenantMapper;
@Resource
private TenantSpecialtyMapper tenantSpecialtyMapper;
@Resource
private TenantPackageService tenantPackageService;
@Resource
@@ -119,12 +117,10 @@ public class TenantServiceImpl implements TenantService {
tenantMapper.insert(tenant);
// 创建租户对应的专业的授权点数
Long tenantId = tenant.getId();
String queueName=tenantId.toString()+"_Queue";
String queueName = tenantId.toString() + "_Queue";
tenant.setQueueName(queueName);
tenantMapper.updateById(tenant);
tenantSpecialtyMapper.deleteByTeantId(tenantId);
for (TenantSpecialtyPointsVO specialtyPointsVO : createReqVO.getTenantSpecialtyPointsVOList()) {
// 新增数据
specialtyPointsVO.setTenantId(tenantId);
@@ -177,12 +173,13 @@ public class TenantServiceImpl implements TenantService {
validTenantWebsiteDuplicate(updateReqVO.getWebsite(), updateReqVO.getId());
// 校验套餐被禁用
TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId());
// 更新租户
TenantDO updateObj = BeanUtils.toBean(updateReqVO, TenantDO.class);
tenantMapper.updateById(updateObj);
// 创建租户对应的专业的授权点数
Long tenantId = tenant.getId();
// 先删除在继续添加
tenantSpecialtyMapper.deleteByTeantId(tenantId);
for (TenantSpecialtyPointsVO specialtyPointsVO : updateReqVO.getTenantSpecialtyPointsVOList()) {
// 新增数据
specialtyPointsVO.setTenantId(tenantId);

View File

@@ -273,5 +273,10 @@ public interface AdminUserService {
* @return 全部信息集合
*/
List<SpecialtyQueryVo> getListByUser();
/**
* 获取专业信息,判断考点服务器数据
*
* @return 全部信息集合
*/
List<SpecialtyQueryVo> getSpeciatListByTenantId();
}

View File

@@ -15,7 +15,6 @@ import pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils;
import pc.exam.pp.framework.tenant.core.context.TenantContextHolder;
import pc.exam.pp.framework.web.core.util.WebFrameworkUtils;
import pc.exam.pp.module.exam.controller.admin.classs.vo.ClassSaveReqVO;
import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtListByUserReqVo;
import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtyQueryVo;
import pc.exam.pp.module.exam.dal.dataobject.classs.ClassDO;
import pc.exam.pp.module.exam.dal.dataobject.specialty.ExamSpecialty;
@@ -30,7 +29,6 @@ import pc.exam.pp.module.system.controller.admin.user.vo.profile.UserProfileUpda
import pc.exam.pp.module.system.controller.admin.user.vo.user.*;
import pc.exam.pp.module.system.dal.dataobject.dept.DeptDO;
import pc.exam.pp.module.system.dal.dataobject.dept.UserPostDO;
import pc.exam.pp.module.system.dal.dataobject.tenant.TenantDO;
import pc.exam.pp.module.system.dal.dataobject.tenant.TenantSpcialtyDO;
import pc.exam.pp.module.system.dal.dataobject.user.AdminUserDO;
import pc.exam.pp.module.system.dal.dataobject.user.TeacherClassDO;
@@ -78,12 +76,10 @@ public class AdminUserServiceImpl implements AdminUserService {
@Resource
private AdminUserMapper userMapper;
@Resource
private ClassMapper classMapper;
@Resource
private ClassService classService;
@Resource
private DeptService deptService;
@Resource
@@ -95,22 +91,18 @@ public class AdminUserServiceImpl implements AdminUserService {
@Resource
@Lazy // 延迟,避免循环依赖报错
private TenantService tenantService;
@Resource
private UserPostMapper userPostMapper;
@Resource
private TeacherClassMapper teacherClassMapper;
@Resource
private TeacherSpecialtyMapper teacherSpecialtyMapper;
@Resource
private FileApi fileApi;
@Resource
private ConfigApi configApi;
@Resource
private ExamSpecialtyMapper examSpecialtyMapper;
@Resource
TenantSpecialtyMapper tenantSpecialtyMapper;
@@ -147,6 +139,7 @@ public class AdminUserServiceImpl implements AdminUserService {
LogRecordContext.putVariable("user", user);
return user.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_CREATE_SUB_TYPE, bizNo = "{{#user.id}}",
@@ -315,7 +308,6 @@ public class AdminUserServiceImpl implements AdminUserService {
}
@Override
@Transactional(rollbackFor = Exception.class)
@LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
@@ -355,7 +347,7 @@ public class AdminUserServiceImpl implements AdminUserService {
}
}
private void updateTeacherSpecialty (UserSaveReqVO reqVO, AdminUserDO updateObj) {
private void updateTeacherSpecialty(UserSaveReqVO reqVO, AdminUserDO updateObj) {
Long userId = reqVO.getId();
Set<Long> dbSpecialtyIds = convertSet(teacherSpecialtyMapper.selectListByUserId(userId), TeacherSpecialtyDO::getSpecialtyId);
// 计算新增和删除的岗位编号
@@ -513,6 +505,7 @@ public class AdminUserServiceImpl implements AdminUserService {
public AdminUserDO getUser(Long id) {
return userMapper.selectById(id);
}
@Override
public List<UserRespVO> getUserById(Long id) {
return userMapper.selectUserByIdList(id);
@@ -587,7 +580,7 @@ public class AdminUserServiceImpl implements AdminUserService {
}
private AdminUserDO validateUserForCreateOrUpdate(Long id, String username, String mobile, String email,
Long deptId, Set<Long> postIds) {
Long deptId, Set<Long> postIds) {
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
return DataPermissionUtils.executeIgnore(() -> {
// 校验用户存在
@@ -674,6 +667,7 @@ public class AdminUserServiceImpl implements AdminUserService {
/**
* 校验旧密码
*
* @param id 用户 id
* @param oldPassword 旧密码
*/
@@ -708,7 +702,7 @@ public class AdminUserServiceImpl implements AdminUserService {
// 2.1.1 校验字段是否符合要求
try {
ValidationUtils.validate(BeanUtils.toBean(importUser, UserSaveReqVO.class).setPassword(initPassword));
} catch (ConstraintViolationException ex){
} catch (ConstraintViolationException ex) {
respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage());
return;
}
@@ -769,7 +763,7 @@ public class AdminUserServiceImpl implements AdminUserService {
// 2.1.1 校验字段是否符合要求
try {
ValidationUtils.validate(BeanUtils.toBean(importUser, UserSaveReqVO.class).setPassword(password));
} catch (ConstraintViolationException ex){
} catch (ConstraintViolationException ex) {
respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage());
return;
}
@@ -862,14 +856,84 @@ public class AdminUserServiceImpl implements AdminUserService {
} else {
// 需要先界定 数据范围通过考点服务器ID进行查询考点服务器的授权范围
List<TenantSpcialtyDO> tenantSpcialtyDOS = tenantSpecialtyMapper.getSpecialtyPoints(tenantId);
// 判断用户类型 管理员所有专业
if (adminUserDO.getUserType().equals("0")) {
// 查询所有专业数据
specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyAll();
} else {
// 通过ID查询对应的科目信息
for (TenantSpcialtyDO spcialtyDO : tenantSpcialtyDOS) {
ExamSpecialty examSpecialty = examSpecialtyMapper.selectExamSpecialtyBySpId(spcialtyDO.getSpecialtyId());
// 获取对应的父级参数
ExamSpecialty examSpecialtyForUp = examSpecialtyMapper.selectExamSpecialtyBySpId(examSpecialty.getParentId());
if (examSpecialty.getParentId() == 0) {
// 说明是整个专业下面所有的
List<ExamSpecialty> examSpecialties = getChildExamSpecialtyList(Collections.singleton(examSpecialtyForUp.getSpId()));
for (ExamSpecialty examSpecialtyInfo : examSpecialties) {
// 检查是否已存在相同ID的元素
boolean exists = specialtyQueryVos.stream()
.anyMatch(v -> v.getId().equals(examSpecialtyInfo.getSpId()));
if (!exists) {
SpecialtyQueryVo specialtyQueryVo = new SpecialtyQueryVo();
specialtyQueryVo.setStatus(examSpecialtyInfo.getStatus());
specialtyQueryVo.setName(examSpecialtyInfo.getSpName());
specialtyQueryVo.setAncestors(examSpecialtyInfo.getAncestors());
specialtyQueryVo.setOrderNum(examSpecialtyInfo.getOrderNum());
specialtyQueryVo.setId(examSpecialtyInfo.getSpId());
specialtyQueryVo.setRoles(examSpecialtyInfo.getRoles());
specialtyQueryVo.setParentId(examSpecialtyInfo.getParentId());
specialtyQueryVo.setAncestors(examSpecialtyInfo.getAncestors());
specialtyQueryVos.add(specialtyQueryVo);
}
}
} else {
// 检查是否已存在相同ID的元素
boolean exists = specialtyQueryVos.stream()
.anyMatch(v -> v.getId().equals(examSpecialty.getSpId()));
if (!exists) {
SpecialtyQueryVo specialtyQueryVo = new SpecialtyQueryVo();
specialtyQueryVo.setStatus(examSpecialty.getStatus());
specialtyQueryVo.setName(examSpecialty.getSpName());
specialtyQueryVo.setAncestors(examSpecialty.getAncestors());
specialtyQueryVo.setOrderNum(examSpecialty.getOrderNum());
specialtyQueryVo.setId(examSpecialty.getSpId());
specialtyQueryVo.setRoles(examSpecialty.getRoles());
specialtyQueryVo.setParentId(examSpecialty.getParentId());
specialtyQueryVo.setAncestors(examSpecialty.getAncestors());
specialtyQueryVos.add(specialtyQueryVo);
}
boolean existsUp = specialtyQueryVos.stream()
.anyMatch(v -> v.getId().equals(examSpecialtyForUp.getSpId()));
if (!existsUp) {
SpecialtyQueryVo specialtyQueryVo = new SpecialtyQueryVo();
specialtyQueryVo.setStatus(examSpecialtyForUp.getStatus());
specialtyQueryVo.setName(examSpecialtyForUp.getSpName());
specialtyQueryVo.setAncestors(examSpecialtyForUp.getAncestors());
specialtyQueryVo.setOrderNum(examSpecialtyForUp.getOrderNum());
specialtyQueryVo.setId(examSpecialtyForUp.getSpId());
specialtyQueryVo.setRoles(examSpecialtyForUp.getRoles());
specialtyQueryVo.setParentId(examSpecialtyForUp.getParentId());
specialtyQueryVo.setAncestors(examSpecialtyForUp.getAncestors());
specialtyQueryVos.add(specialtyQueryVo);
}
List<ExamSpecialty> examSpecialties = getChildExamSpecialtyList(Collections.singleton(examSpecialty.getSpId()));
for (ExamSpecialty examSpecialtyInfo : examSpecialties) {
// 检查是否已存在相同ID的元素
boolean existsDown = specialtyQueryVos.stream()
.anyMatch(v -> v.getId().equals(examSpecialtyInfo.getSpId()));
if (!existsDown) {
SpecialtyQueryVo specialtyQueryVo = new SpecialtyQueryVo();
specialtyQueryVo.setStatus(examSpecialtyInfo.getStatus());
specialtyQueryVo.setName(examSpecialtyInfo.getSpName());
specialtyQueryVo.setAncestors(examSpecialtyInfo.getAncestors());
specialtyQueryVo.setOrderNum(examSpecialtyInfo.getOrderNum());
specialtyQueryVo.setId(examSpecialtyInfo.getSpId());
specialtyQueryVo.setRoles(examSpecialtyInfo.getRoles());
specialtyQueryVo.setParentId(examSpecialtyInfo.getParentId());
specialtyQueryVo.setAncestors(examSpecialtyInfo.getAncestors());
specialtyQueryVos.add(specialtyQueryVo);
}
}
}
}
// 通过ID查询下面的参数
// 判断用户类型 管理员所有专业 , 不是管理员的话需要筛选
if (!adminUserDO.getUserType().equals("0")) {
// 判断专业是否为空,为空的话查询所有
if (adminUserDO.getSpecialtyIds() == null) {
// 查询所有数据
@@ -893,6 +957,95 @@ public class AdminUserServiceImpl implements AdminUserService {
return specialtyQueryVos;
}
@Override
public List<SpecialtyQueryVo> getSpeciatListByTenantId() {
// 获取考点ID
Long tenantId = TenantContextHolder.getTenantId();
List<SpecialtyQueryVo> specialtyQueryVos = new ArrayList<>();
if (tenantId == 1) {
specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyAll();
} else {
// 需要先界定 数据范围通过考点服务器ID进行查询考点服务器的授权范围
List<TenantSpcialtyDO> tenantSpcialtyDOS = tenantSpecialtyMapper.getSpecialtyPoints(tenantId);
// 通过ID查询对应的科目信息
for (TenantSpcialtyDO spcialtyDO : tenantSpcialtyDOS) {
ExamSpecialty examSpecialty = examSpecialtyMapper.selectExamSpecialtyBySpId(spcialtyDO.getSpecialtyId());
// 获取对应的父级参数
ExamSpecialty examSpecialtyForUp = examSpecialtyMapper.selectExamSpecialtyBySpId(examSpecialty.getParentId());
if (examSpecialty.getParentId() == 0) {
// 说明是整个专业下面所有的
List<ExamSpecialty> examSpecialties = getChildExamSpecialtyList(Collections.singleton(examSpecialtyForUp.getSpId()));
for (ExamSpecialty examSpecialtyInfo : examSpecialties) {
// 检查是否已存在相同ID的元素
boolean exists = specialtyQueryVos.stream()
.anyMatch(v -> v.getId().equals(examSpecialtyInfo.getSpId()));
if (!exists) {
SpecialtyQueryVo specialtyQueryVo = new SpecialtyQueryVo();
specialtyQueryVo.setStatus(examSpecialtyInfo.getStatus());
specialtyQueryVo.setName(examSpecialtyInfo.getSpName());
specialtyQueryVo.setAncestors(examSpecialtyInfo.getAncestors());
specialtyQueryVo.setOrderNum(examSpecialtyInfo.getOrderNum());
specialtyQueryVo.setId(examSpecialtyInfo.getSpId());
specialtyQueryVo.setRoles(examSpecialtyInfo.getRoles());
specialtyQueryVo.setParentId(examSpecialtyInfo.getParentId());
specialtyQueryVo.setAncestors(examSpecialtyInfo.getAncestors());
specialtyQueryVos.add(specialtyQueryVo);
}
}
} else {
// 检查是否已存在相同ID的元素
boolean exists = specialtyQueryVos.stream()
.anyMatch(v -> v.getId().equals(examSpecialty.getSpId()));
if (!exists) {
SpecialtyQueryVo specialtyQueryVo = new SpecialtyQueryVo();
specialtyQueryVo.setStatus(examSpecialty.getStatus());
specialtyQueryVo.setName(examSpecialty.getSpName());
specialtyQueryVo.setAncestors(examSpecialty.getAncestors());
specialtyQueryVo.setOrderNum(examSpecialty.getOrderNum());
specialtyQueryVo.setId(examSpecialty.getSpId());
specialtyQueryVo.setRoles(examSpecialty.getRoles());
specialtyQueryVo.setParentId(examSpecialty.getParentId());
specialtyQueryVo.setAncestors(examSpecialty.getAncestors());
specialtyQueryVos.add(specialtyQueryVo);
}
boolean existsUp = specialtyQueryVos.stream()
.anyMatch(v -> v.getId().equals(examSpecialtyForUp.getSpId()));
if (!existsUp) {
SpecialtyQueryVo specialtyQueryVo = new SpecialtyQueryVo();
specialtyQueryVo.setStatus(examSpecialtyForUp.getStatus());
specialtyQueryVo.setName(examSpecialtyForUp.getSpName());
specialtyQueryVo.setAncestors(examSpecialtyForUp.getAncestors());
specialtyQueryVo.setOrderNum(examSpecialtyForUp.getOrderNum());
specialtyQueryVo.setId(examSpecialtyForUp.getSpId());
specialtyQueryVo.setRoles(examSpecialtyForUp.getRoles());
specialtyQueryVo.setParentId(examSpecialtyForUp.getParentId());
specialtyQueryVo.setAncestors(examSpecialtyForUp.getAncestors());
specialtyQueryVos.add(specialtyQueryVo);
}
List<ExamSpecialty> examSpecialties = getChildExamSpecialtyList(Collections.singleton(examSpecialty.getSpId()));
for (ExamSpecialty examSpecialtyInfo : examSpecialties) {
// 检查是否已存在相同ID的元素
boolean existsDown = specialtyQueryVos.stream()
.anyMatch(v -> v.getId().equals(examSpecialtyInfo.getSpId()));
if (!existsDown) {
SpecialtyQueryVo specialtyQueryVo = new SpecialtyQueryVo();
specialtyQueryVo.setStatus(examSpecialtyInfo.getStatus());
specialtyQueryVo.setName(examSpecialtyInfo.getSpName());
specialtyQueryVo.setAncestors(examSpecialtyInfo.getAncestors());
specialtyQueryVo.setOrderNum(examSpecialtyInfo.getOrderNum());
specialtyQueryVo.setId(examSpecialtyInfo.getSpId());
specialtyQueryVo.setRoles(examSpecialtyInfo.getRoles());
specialtyQueryVo.setParentId(examSpecialtyInfo.getParentId());
specialtyQueryVo.setAncestors(examSpecialtyInfo.getAncestors());
specialtyQueryVos.add(specialtyQueryVo);
}
}
}
}
}
return specialtyQueryVos;
}
/**
* 对密码进行加密
*
@@ -903,4 +1056,21 @@ public class AdminUserServiceImpl implements AdminUserService {
return passwordEncoder.encode(password);
}
public List<ExamSpecialty> getChildExamSpecialtyList(Collection<Long> ids) {
List<ExamSpecialty> children = new LinkedList<>();
// 遍历每一层
Collection<Long> parentIds = ids;
for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环
// 查询当前层所有的子Xlsx考点
List<ExamSpecialty> Xlsxs = examSpecialtyMapper.selectListByParentId(parentIds);
// 1. 如果没有子Xlsx考点则结束遍历
if (CollUtil.isEmpty(Xlsxs)) {
break;
}
// 2. 如果有子Xlsx考点继续遍历
children.addAll(Xlsxs);
parentIds = convertSet(Xlsxs, ExamSpecialty::getSpId);
}
return children;
}
}