@@ -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 ;
}
}