@ -164,7 +164,7 @@ public class UserController {
if ( school = = null ) {
if ( school = = null ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该学校不存在" ) ;
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该学校不存在" ) ;
}
}
if ( ! canManage SchoolStructure ( userId , schoolId ) ) {
if ( ! canManage Faculty ( userId , schoolId ) ) {
return noManagePermission ( ) ;
return noManagePermission ( ) ;
}
}
//查询该学校下院系下 专业名称是否重复
//查询该学校下院系下 专业名称是否重复
@ -220,7 +220,7 @@ public class UserController {
if ( schoolFaculty = = null ) {
if ( schoolFaculty = = null ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "院系不存在" ) ;
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "院系不存在" ) ;
}
}
if ( ! canManage SchoolStructure ( userId , schoolFaculty . getSchoolId ( ) ) ) {
if ( ! canManage Faculty ( userId , schoolFaculty . getSchoolId ( ) ) ) {
return noManagePermission ( ) ;
return noManagePermission ( ) ;
}
}
if ( hasMajorUnderFaculty ( schoolFacultyId ) ) {
if ( hasMajorUnderFaculty ( schoolFacultyId ) ) {
@ -244,7 +244,7 @@ public class UserController {
if ( existing = = null ) {
if ( existing = = null ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "院系不存在" ) ;
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "院系不存在" ) ;
}
}
if ( ! canManage SchoolStructure ( userId , existing . getSchoolId ( ) ) ) {
if ( ! canManage Faculty ( userId , existing . getSchoolId ( ) ) ) {
return noManagePermission ( ) ;
return noManagePermission ( ) ;
}
}
int i = schoolFacultyMapper . updateByPrimaryKey ( schoolFaculty ) ;
int i = schoolFacultyMapper . updateByPrimaryKey ( schoolFaculty ) ;
@ -272,7 +272,7 @@ public class UserController {
if ( school = = null ) {
if ( school = = null ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该学校不存在" ) ;
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该学校不存在" ) ;
}
}
if ( ! canManage School Structure( userId , schoolId ) ) {
if ( ! canManage Major Structure( userId , schoolId ) ) {
return noManagePermission ( ) ;
return noManagePermission ( ) ;
}
}
//再根据schoolFacultyId查询 如果不存在则返回
//再根据schoolFacultyId查询 如果不存在则返回
@ -374,8 +374,8 @@ public class UserController {
@ApiOperation ( "班级管理-添加班级" )
@ApiOperation ( "班级管理-添加班级" )
@AnonymousAccess
@AnonymousAccess
public ResultEntity addSchoolClass ( @ApiParam ( "学校ID" ) @RequestParam String schoolId ,
public ResultEntity addSchoolClass ( @ApiParam ( "学校ID" ) @RequestParam String schoolId ,
@ApiParam ( "院系ID" ) @RequestParam String schoolFacultyId ,
@ApiParam ( "院系ID" ) @RequestParam ( required = false ) String schoolFacultyId ,
@ApiParam ( "专业ID" ) @RequestParam String schoolMajorId ,
@ApiParam ( "专业ID" ) @RequestParam ( required = false ) String schoolMajorId ,
@ApiParam ( "班级名称" ) @RequestParam String className ,
@ApiParam ( "班级名称" ) @RequestParam String className ,
@RequestParam ( required = false ) String userId ,
@RequestParam ( required = false ) String userId ,
@RequestParam ( required = false ) String classType ,
@RequestParam ( required = false ) String classType ,
@ -386,18 +386,22 @@ public class UserController {
if ( school = = null ) {
if ( school = = null ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该学校不存在" ) ;
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该学校不存在" ) ;
}
}
//再根据schoolFacultyId查询 如果不存在则返回
String requestedClassType = StringUtils . defaultIfBlank ( classType , StringUtils . isBlank ( userId ) ? "ADMIN" : "TEACHING" ) ;
SchoolFaculty schoolFaculty = schoolFacultyMapper . selectByPrimaryKey ( schoolFacultyId ) ;
boolean majorManagementEnabled = isMajorManagementEnabled ( schoolId ) ;
if ( schoolFaculty = = null ) {
if ( ! isAdminClassManagementEnabled ( schoolId ) & & ! "TEACHING" . equals ( requestedClassType ) ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该院系不存在" ) ;
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "当前学校只支持教学班" ) ;
}
}
//再根据schoolMajorId查询 如果不存在则返回
if ( majorManagementEnabled ) {
SchoolMajor schoolMajor = schoolMajorMapper . selectByPrimaryKey ( schoolMajorId ) ;
SchoolFaculty schoolFaculty = schoolFacultyMapper . selectByPrimaryKey ( schoolFacultyId ) ;
if ( schoolMajor = = null ) {
if ( schoolFaculty = = null ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该专业不存在" ) ;
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该院系不存在" ) ;
}
SchoolMajor schoolMajor = schoolMajorMapper . selectByPrimaryKey ( schoolMajorId ) ;
if ( schoolMajor = = null ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "该专业不存在" ) ;
}
}
}
//查询班级名称是否存在
//查询班级名称是否存在
String requestedClassType = StringUtils . defaultIfBlank ( classType , StringUtils . isBlank ( userId ) ? "ADMIN" : "TEACHING" ) ;
if ( ! canCreateSchoolClass ( userId , schoolId , requestedClassType ) ) {
if ( ! canCreateSchoolClass ( userId , schoolId , requestedClassType ) ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "No permission to add this class type" ) ;
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "No permission to add this class type" ) ;
}
}
@ -2016,7 +2020,7 @@ public class UserController {
}
}
Userinfo operator = userinfoMapper . selectByPrimaryKey ( operatorId ) ;
Userinfo operator = userinfoMapper . selectByPrimaryKey ( operatorId ) ;
if ( isPlatformAdmin ( operator ) ) {
if ( isPlatformAdmin ( operator ) ) {
return true ;
return ! "ADMIN" . equals ( classType ) | | isAdminClassManagementEnabled ( schoolId ) ;
}
}
if ( ! Integer . valueOf ( 3 ) . equals ( operator = = null ? null : operator . getRole ( ) )
if ( ! Integer . valueOf ( 3 ) . equals ( operator = = null ? null : operator . getRole ( ) )
| | ! StringUtils . equals ( operator . getSchoolId ( ) , schoolId ) ) {
| | ! StringUtils . equals ( operator . getSchoolId ( ) , schoolId ) ) {
@ -2026,7 +2030,7 @@ public class UserController {
return true ;
return true ;
}
}
if ( "ADMIN" . equals ( classType ) ) {
if ( "ADMIN" . equals ( classType ) ) {
return true ;
return isAdminClassManagementEnabled ( schoolId ) ;
}
}
return false ;
return false ;
}
}
@ -2048,10 +2052,11 @@ public class UserController {
return false ;
return false ;
}
}
if ( isPlatformAdmin ( operator ) ) {
if ( isPlatformAdmin ( operator ) ) {
return true ;
return isAdminClassManagementEnabled ( schoolClass . getSchoolId ( ) ) ;
}
}
return isSchoolTeacher ( operator )
return isSchoolTeacher ( operator )
& & StringUtils . equals ( operator . getSchoolId ( ) , schoolClass . getSchoolId ( ) ) ;
& & StringUtils . equals ( operator . getSchoolId ( ) , schoolClass . getSchoolId ( ) )
& & isAdminClassManagementEnabled ( schoolClass . getSchoolId ( ) ) ;
}
}
private boolean canManageSchoolStructure ( String operatorId , String schoolId ) {
private boolean canManageSchoolStructure ( String operatorId , String schoolId ) {
@ -2062,7 +2067,43 @@ public class UserController {
if ( isPlatformAdmin ( operator ) ) {
if ( isPlatformAdmin ( operator ) ) {
return true ;
return true ;
}
}
return isTeacherAdmin ( operator ) & & StringUtils . equals ( operator . getSchoolId ( ) , schoolId ) ;
return isTeacherAdmin ( operator )
& & StringUtils . equals ( operator . getSchoolId ( ) , schoolId )
& & ! isTeacherRosterMode ( schoolId ) ;
}
private boolean canManageFaculty ( String operatorId , String schoolId ) {
return hasSchoolStructureAuthority ( operatorId , schoolId ) & & isFacultyManagementEnabled ( schoolId ) ;
}
private boolean canManageMajorStructure ( String operatorId , String schoolId ) {
return hasSchoolStructureAuthority ( operatorId , schoolId ) & & isMajorManagementEnabled ( schoolId ) ;
}
private boolean hasSchoolStructureAuthority ( String operatorId , String schoolId ) {
if ( StringUtils . isAnyBlank ( operatorId , schoolId ) ) {
return false ;
}
Userinfo operator = userinfoMapper . selectByPrimaryKey ( operatorId ) ;
return isPlatformAdmin ( operator )
| | ( isTeacherAdmin ( operator ) & & StringUtils . equals ( operator . getSchoolId ( ) , schoolId ) ) ;
}
private boolean isFacultyManagementEnabled ( String schoolId ) {
return schoolProductConfigService ! = null & & schoolProductConfigService . isFacultyManagementEnabled ( schoolId ) ;
}
private boolean isMajorManagementEnabled ( String schoolId ) {
return schoolProductConfigService ! = null & & schoolProductConfigService . isMajorManagementEnabled ( schoolId ) ;
}
private boolean isAdminClassManagementEnabled ( String schoolId ) {
return schoolProductConfigService ! = null & & schoolProductConfigService . isAdminClassManagementEnabled ( schoolId ) ;
}
private boolean isTeacherRosterMode ( String schoolId ) {
return schoolProductConfigService ! = null
& & schoolProductConfigService . isTeacherRosterManaged ( schoolId ) ;
}
}
private boolean canManageMajor ( String operatorId , String schoolMajorId ) {
private boolean canManageMajor ( String operatorId , String schoolMajorId ) {
@ -2074,7 +2115,7 @@ public class UserController {
return false ;
return false ;
}
}
SchoolFaculty faculty = schoolFacultyMapper . selectByPrimaryKey ( major . getSchoolFacultyId ( ) ) ;
SchoolFaculty faculty = schoolFacultyMapper . selectByPrimaryKey ( major . getSchoolFacultyId ( ) ) ;
return faculty ! = null & & canManage School Structure( operatorId , faculty . getSchoolId ( ) ) ;
return faculty ! = null & & canManage Major Structure( operatorId , faculty . getSchoolId ( ) ) ;
}
}
private boolean teacherHasCreatedClass ( String teacherId ) {
private boolean teacherHasCreatedClass ( String teacherId ) {