package com.qmth.distributed.print.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.backup.MySQLDatabaseBackup;
import com.qmth.distributed.print.business.bean.params.SysAdminSetParam;
import com.qmth.distributed.print.business.bean.result.CustomPrivilegeResult;
import com.qmth.distributed.print.business.bean.result.SysAdminSetResult;
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
import com.qmth.teachcloud.common.bean.dto.PrivilegeDto;
import com.qmth.teachcloud.common.bean.result.SysConfigResult;
import com.qmth.teachcloud.common.bean.result.SysConfigResultOption;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.entity.*;
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
import com.qmth.teachcloud.common.enums.SyncModeEnum;
import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
import com.qmth.teachcloud.common.service.*;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: 超管设置
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2021/10/29
 */
@Api(tags = "超管设置Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_SET)
//@Aac(auth = BOOL.FALSE, strict = BOOL.FALSE)
public class SysAdminSetController {

    @Resource
    SysPrivilegeService sysPrivilegeService;

    @Resource
    TSchoolPrivilegeService tSchoolPrivilegeService;

    @Resource
    SysRolePrivilegeService sysRolePrivilegeService;

    @Resource
    SysRoleService sysRoleService;

    @Resource
    CommonCacheService commonCacheService;

    @Resource
    SysUserRoleService sysUserRoleService;

    @Resource
    TeachcloudCommonService commonService;

    @Resource
    SysConfigService sysConfigService;

    @Resource
    MySQLDatabaseBackup mySQLDatabaseBackup;

    @Resource
    TSchoolRoleService tSchoolRoleService;

    @ApiOperation(value = "数据还原")
    @ApiResponses({@ApiResponse(code = 200, message = "数据还原信息", response = ResultUtil.class)})
    @RequestMapping(value = "/backup", method = RequestMethod.POST)
    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UPDATE)
    public Result sysadminBackup(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) throws Exception {
        mySQLDatabaseBackup.exportDatabaseTool();
        mySQLDatabaseBackup.deleteDbTool(SystemConstant.PRINT_DELETE_DATA_FILE_NAME, schoolId);
        return ResultUtil.ok(true);
    }

    @ApiOperation(value = "同步配置查询")
    @ApiResponses({@ApiResponse(code = 200, message = "同步配置信息", response = SysAdminSetResult.class)})
    @RequestMapping(value = "/sync/select", method = RequestMethod.POST)
    public Result sysadminSyncSelect(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) {
        SysConfig sysConfigCloudMarkSyncMode = commonCacheService.addSysConfigCache(schoolId, SystemConstant.CLOUDMARK_SYNC_MODE);
        SysConfig sysConfigQuestionHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.QUESTION_HOST_URL);
        SysConfig sysConfigCloudmarkHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.CLOUDMARK_HOST_URL);
        SysConfig sysConfigTeachcloudReportHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.TEACHCLOUD_REPORT_HOST_URL);

        List<SysConfigResult> sysConfigResultList = new ArrayList<>();
        if (Objects.nonNull(sysConfigQuestionHostUrl)) {
            sysConfigResultList.add(new SysConfigResult(sysConfigQuestionHostUrl));
        } else {
            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.QUESTION_HOST_URL, "题库地址", "", 1));
        }

        if (Objects.nonNull(sysConfigCloudmarkHostUrl)) {
            sysConfigResultList.add(new SysConfigResult(sysConfigCloudmarkHostUrl));
        } else {
            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.CLOUDMARK_HOST_URL, "云阅卷地址", "", 2));
        }

        SysConfigResult sysConfigResult;
        if (Objects.nonNull(sysConfigCloudMarkSyncMode)) {
            sysConfigResult = new SysConfigResult(sysConfigCloudMarkSyncMode);
        } else {
            sysConfigResult = new SysConfigResult(null, SystemConstant.CLOUDMARK_SYNC_MODE, "云阅卷同步规则", SyncModeEnum.BY_SCHOOL.name(), 3);
        }
        List<SysConfigResultOption> options = new ArrayList<>();
        options.add(new SysConfigResultOption(SyncModeEnum.BY_SCHOOL.getTitle(), SyncModeEnum.BY_SCHOOL.name()));
        options.add(new SysConfigResultOption(SyncModeEnum.BY_COLLEGE.getTitle(), SyncModeEnum.BY_COLLEGE.name()));
        sysConfigResult.setOptions(options);
        sysConfigResultList.add(sysConfigResult);

        if (Objects.nonNull(sysConfigTeachcloudReportHostUrl)) {
            sysConfigResultList.add(new SysConfigResult(sysConfigTeachcloudReportHostUrl));
        } else {
            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.TEACHCLOUD_REPORT_HOST_URL, "教研分析地址", "", 4));
        }
        return ResultUtil.ok(new SysAdminSetResult(schoolId, sysConfigResultList));
    }

    @ApiOperation(value = "同步配置保存")
    @ApiResponses({@ApiResponse(code = 200, message = "同步配置信息", response = ResultUtil.class)})
    @RequestMapping(value = "/sync/save", method = RequestMethod.POST)
    @Transactional
    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EDIT)
    public Result sysadminSyncSave(@Valid @RequestBody SysAdminSetParam sysAdminSetParam, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        Optional.ofNullable(sysAdminSetParam.getParam()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("同步配置地址不能为空"));

        List<SysConfigResult> sysConfigResultList = sysAdminSetParam.getParam();
        List<SysConfig> sysConfigList = new ArrayList<>();
        for (SysConfigResult s : sysConfigResultList) {
            sysConfigList.add(new SysConfig(sysAdminSetParam.getSchoolId(), s));
        }
        sysConfigService.saveOrUpdateBatch(sysConfigList);

        for (SysConfigResult s : sysConfigResultList) {
            commonCacheService.updateSysConfigCache(sysAdminSetParam.getSchoolId(), s.getCode());
        }
        return ResultUtil.ok(true);
    }

    @ApiOperation(value = "系统试卷规格配置查询")
    @ApiResponses({@ApiResponse(code = 200, message = "系统试卷规格配置信息", response = CustomPrivilegeResult.class)})
    @RequestMapping(value = "/paper/sys/select", method = RequestMethod.POST)
    public Result sysadminPaperSysSelect() {
        SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.SYS_PDF_SIZE_LIST);
        Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置全局上传试卷规格"));
        SysAdminSetResult sysAdminSetResult = new SysAdminSetResult();
        SysConfigResult sysConfigResult = new SysConfigResult(sysConfig);
        sysConfigResult.setValue(Arrays.asList(sysConfigResult.getValue().toString().replaceAll("\\[", "").replaceAll("\\]", "").split(", ")));
        sysAdminSetResult.setResult(Arrays.asList(sysConfigResult));
        return ResultUtil.ok(sysAdminSetResult);
    }

    @ApiOperation(value = "试卷规格配置查询")
    @ApiResponses({@ApiResponse(code = 200, message = "试卷规格配置信息", response = SysAdminSetResult.class)})
    @RequestMapping(value = "/paper/select", method = RequestMethod.POST)
    public Result sysadminPaperSelect(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) {
        SysConfig sysConfigPdfSize = commonCacheService.addSysConfigCache(schoolId, SystemConstant.PDF_SIZE_LIST);
        List<String> pdfSize = null;
        SysConfigResult sysConfigResult = null;
        if (Objects.nonNull(sysConfigPdfSize)) {
            pdfSize = Arrays.asList(sysConfigPdfSize.getConfigValue().replaceAll("\\[", "").replaceAll("\\]", "").split(", "));
            sysConfigResult = new SysConfigResult(sysConfigPdfSize);
            sysConfigResult.setValue(pdfSize);
        } else {
            sysConfigResult = new SysConfigResult(null, SystemConstant.PDF_SIZE_LIST, "允许上传试卷规格", new ArrayList<>(), 1);
        }
        SysAdminSetResult sysAdminSetResult = new SysAdminSetResult(schoolId);
        sysAdminSetResult.setResult(Arrays.asList(sysConfigResult));
        return ResultUtil.ok(sysAdminSetResult);
    }

    @ApiOperation(value = "试卷规格配置保存")
    @ApiResponses({@ApiResponse(code = 200, message = "试卷规格配置信息", response = ResultUtil.class)})
    @RequestMapping(value = "/paper/save", method = RequestMethod.POST)
    @Transactional
    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EDIT)
    public Result sysadminPaperSave(@Valid @RequestBody SysAdminSetParam sysAdminSetParam, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        Optional.ofNullable(sysAdminSetParam.getParam()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("试卷规格配置不能为空"));

        List<SysConfigResult> sysConfigResultList = sysAdminSetParam.getParam();
        List<SysConfig> sysConfigList = new ArrayList<>();
        for (SysConfigResult s : sysConfigResultList) {
            SysConfig sysConfig = new SysConfig(sysAdminSetParam.getSchoolId(), s);
            sysConfig.setConfigValue(Arrays.asList(s.getValue().toString().replaceAll("\\[", "").replaceAll("\\]", "").split(", ")).toString());
            sysConfigList.add(sysConfig);
        }
        sysConfigService.saveOrUpdateBatch(sysConfigList);

        for (SysConfigResult s : sysConfigResultList) {
            commonCacheService.updateSysConfigCache(sysAdminSetParam.getSchoolId(), s.getCode());
        }
        return ResultUtil.ok(true);
    }

    @ApiOperation(value = "用户验证查询")
    @ApiResponses({@ApiResponse(code = 200, message = "用户验证信息", response = SysAdminSetResult.class)})
    @RequestMapping(value = "/user/select", method = RequestMethod.POST)
    public Result sysadminUserSelect(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) {
        SysConfig sysConfigAccount = commonCacheService.addSysConfigCache(schoolId, SystemConstant.ACCOUNT_SMS_VERIFY);
        SysConfig sysConfigTeachcloudExchangeHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.TEACHCLOUD_EXCHANGE_HOST_URL);
        List<SysConfigResult> sysConfigResultList = new ArrayList<>();
        if (Objects.nonNull(sysConfigAccount)) {
            sysConfigResultList.add(new SysConfigResult(sysConfigAccount));
        } else {
            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.ACCOUNT_SMS_VERIFY, "用户/密码模式是否开启短信验证", false, 1));
        }
        if (Objects.nonNull(sysConfigTeachcloudExchangeHostUrl)) {
            sysConfigResultList.add(new SysConfigResult(sysConfigTeachcloudExchangeHostUrl));
        } else {
            sysConfigResultList.add(new SysConfigResult(null, SystemConstant.TEACHCLOUD_EXCHANGE_HOST_URL, "第三方统一身份认证", "", 2));
        }
        return ResultUtil.ok(new SysAdminSetResult(schoolId, sysConfigResultList));
    }

    @ApiOperation(value = "用户验证保存")
    @ApiResponses({@ApiResponse(code = 200, message = "用户验证信息", response = ResultUtil.class)})
    @RequestMapping(value = "/user/save", method = RequestMethod.POST)
    @Transactional
    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EDIT)
    public Result sysadminUserSave(@Valid @RequestBody SysAdminSetParam sysAdminSetParam, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        Optional.ofNullable(sysAdminSetParam.getParam()).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("用户/密码模式是否开启不能为空"));

        List<SysConfigResult> sysConfigResultList = sysAdminSetParam.getParam();
        List<SysConfig> sysConfigList = new ArrayList<>();
        for (SysConfigResult s : sysConfigResultList) {
            sysConfigList.add(new SysConfig(sysAdminSetParam.getSchoolId(), s));
        }
        sysConfigService.saveOrUpdateBatch(sysConfigList);

        for (SysConfigResult s : sysConfigResultList) {
            commonCacheService.updateSysConfigCache(sysAdminSetParam.getSchoolId(), s.getCode());
        }
        return ResultUtil.ok(true);
    }

    @ApiOperation(value = "查询自定义菜单权限")
    @ApiResponses({@ApiResponse(code = 200, message = "菜单权限信息", response = CustomPrivilegeResult.class)})
    @RequestMapping(value = "/menu/custom/list", method = RequestMethod.POST)
    public Result customMenuList() {
        List<PrivilegeDto> customPrivilegeList = sysPrivilegeService.addCustomList();
        return ResultUtil.ok(new CustomPrivilegeResult(customPrivilegeList));
    }

    @ApiOperation(value = "学校新增/修改自定义菜单权限")
    @ApiResponses({@ApiResponse(code = 200, message = "菜单权限信息", response = ResultUtil.class)})
    @RequestMapping(value = "/menu/custom/save", method = RequestMethod.POST)
    @Transactional
    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EDIT)
    public Result schoolPrivilegeSave(@Valid @RequestBody SysAdminSetParam tSchoolPrivilegeParam, BindingResult bindingResult) throws NoSuchAlgorithmException {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        Set<Long> roleSetIds = null;
        QueryWrapper<TSchoolPrivilege> tSchoolPrivilegeQueryWrapper = new QueryWrapper<>();
        tSchoolPrivilegeQueryWrapper.lambda().eq(TSchoolPrivilege::getSchoolId, tSchoolPrivilegeParam.getSchoolId());
        List<TSchoolPrivilege> tSchoolPrivileges = tSchoolPrivilegeService.list(tSchoolPrivilegeQueryWrapper);
        if (!CollectionUtils.isEmpty(tSchoolPrivileges)) {//编辑
            Set<Long> changePrivilegeSetIds = tSchoolPrivileges.stream().filter(s -> !Arrays.asList(tSchoolPrivilegeParam.getPrivilegeIds()).contains(s.getPrivilegeId()))
                    .collect(Collectors.toList())
                    .stream().map(s -> s.getPrivilegeId())
                    .collect(Collectors.toSet());
            //数据发生改变
            if (!CollectionUtils.isEmpty(changePrivilegeSetIds)) {
                //查询该菜单下所有角色，删除该角色所发生改变的菜单数据
                QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
                sysRoleQueryWrapper.lambda().eq(SysRole::getSchoolId, tSchoolPrivilegeParam.getSchoolId());
                List<SysRole> sysRoleList = sysRoleService.list(sysRoleQueryWrapper);

                if (!CollectionUtils.isEmpty(sysRoleList)) {
                    QueryWrapper<SysRolePrivilege> sysRolePrivilegeQueryWrapper = new QueryWrapper<>();
                    sysRolePrivilegeQueryWrapper.lambda()
                            .in(SysRolePrivilege::getRoleId, sysRoleList.stream().map(s -> s.getId()).collect(Collectors.toList()))
                            .in(SysRolePrivilege::getPrivilegeId, changePrivilegeSetIds);
                    List<SysRolePrivilege> sysRolePrivilegeList = sysRolePrivilegeService.list(sysRolePrivilegeQueryWrapper);
                    //仅删除绑定了该权限的角色用户缓存
                    roleSetIds = sysRolePrivilegeList.stream().map(s -> s.getRoleId()).collect(Collectors.toSet());
                    sysRolePrivilegeService.remove(sysRolePrivilegeQueryWrapper);
                }
            }
            tSchoolPrivilegeService.remove(tSchoolPrivilegeQueryWrapper);
        }
        Long[] privilegeIds = tSchoolPrivilegeParam.getPrivilegeIds();
        if (Objects.nonNull(privilegeIds) && privilegeIds.length > 0) {
            List<TSchoolPrivilege> tSchoolPrivilegeList = new ArrayList<>();
            for (int i = 0; i < privilegeIds.length; i++) {
                tSchoolPrivilegeList.add(new TSchoolPrivilege(tSchoolPrivilegeParam.getSchoolId(), privilegeIds[i]));
            }
            tSchoolPrivilegeService.saveBatch(tSchoolPrivilegeList);
        }
        commonCacheService.removeSchoolPrivilegeCache(tSchoolPrivilegeParam.getSchoolId());

        //清缓存
        if (!CollectionUtils.isEmpty(roleSetIds)) {
            for (Long l : roleSetIds) {
                commonCacheService.removeRoleCache(l);
                commonCacheService.removeRolePrivilegeCache(l);
                //绑定该角色的用户都需要清除鉴权缓存
                List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(l);
                for (SysUserRole s : sysUserRoleList) {
                    SysUser user = commonCacheService.userCache(s.getUserId());
                    if (Objects.nonNull(user)) {
                        commonService.removeUserInfo(s.getUserId(), true);
                    } else {
                        sysUserRoleService.removeById(s);
                    }
                }
            }
        }
        return ResultUtil.ok(true);
    }

    @ApiOperation(value = "学校已绑定自定义菜单权限列表")
    @ApiResponses({@ApiResponse(code = 200, message = "菜单权限信息", response = SysAdminSetResult.class)})
    @RequestMapping(value = "/menu/custom/get_school_custom_privileges", method = RequestMethod.POST)
    public Result getSchoolPrivileges(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) {
        List<TSchoolPrivilege> tSchoolPrivilegeList = commonCacheService.addSchoolPrivilegeCache(schoolId);
        List<String> privilegeIdList = tSchoolPrivilegeList.stream().map(s -> String.valueOf(s.getPrivilegeId())).collect(Collectors.toList());
        SysAdminSetResult sysAdminSetResult = new SysAdminSetResult(schoolId);
        sysAdminSetResult.setPrivilegeIdList(CollectionUtils.isEmpty(privilegeIdList) ? new ArrayList<>() : privilegeIdList);
        return ResultUtil.ok(sysAdminSetResult);
    }

    @ApiOperation(value = "查询自定义角色权限")
    @ApiResponses({@ApiResponse(code = 200, message = "角色权限信息", response = CustomPrivilegeResult.class)})
    @RequestMapping(value = "/role/custom/list", method = RequestMethod.POST)
    public Result customRoleList() {
        List<SysRole> sysRoleList = commonCacheService.addCustomRoleCache();
        CustomPrivilegeResult customPrivilegeResult = new CustomPrivilegeResult();
        customPrivilegeResult.setCustomRoleList(sysRoleList);
        return ResultUtil.ok(sysRoleList);
    }

    @ApiOperation(value = "学校新增/修改自定义角色权限")
    @ApiResponses({@ApiResponse(code = 200, message = "角色权限信息", response = ResultUtil.class)})
    @RequestMapping(value = "/role/custom/save", method = RequestMethod.POST)
    @Transactional
    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EDIT)
    public Result schoolRoleSave(@Valid @RequestBody SysAdminSetParam tSchoolPrivilegeParam, BindingResult bindingResult) throws NoSuchAlgorithmException {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        Set<Long> userSetIds = new HashSet<>();
        QueryWrapper<TSchoolRole> tSchoolRoleQueryWrapper = new QueryWrapper<>();
        tSchoolRoleQueryWrapper.lambda().eq(TSchoolRole::getSchoolId, tSchoolPrivilegeParam.getSchoolId());
        List<TSchoolRole> tSchoolRoles = tSchoolRoleService.list(tSchoolRoleQueryWrapper);
        if (!CollectionUtils.isEmpty(tSchoolRoles)) {//编辑
            Set<Long> changeRoleSetIds = tSchoolRoles.stream().filter(s -> !Arrays.asList(tSchoolPrivilegeParam.getRoleIds()).contains(s.getRoleId()))
                    .collect(Collectors.toList())
                    .stream().map(s -> s.getRoleId())
                    .collect(Collectors.toSet());
            //数据发生改变
            if (!CollectionUtils.isEmpty(changeRoleSetIds)) {
                //查询该角色下所有用户，删除该角色所发生改变的用户数据
                List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleIdsAndSchoolId(changeRoleSetIds, tSchoolPrivilegeParam.getSchoolId());

                if (!CollectionUtils.isEmpty(sysUserRoleList)) {
                    List<Long> ids = new ArrayList<>(sysUserRoleList.size());
                    for (SysUserRole s : sysUserRoleList) {
                        userSetIds.add(s.getUserId());
                        ids.add(s.getId());
                    }
                    sysUserRoleService.removeByIds(ids);
                }
            }
            tSchoolRoleService.remove(tSchoolRoleQueryWrapper);
        }
        Long[] roleIds = tSchoolPrivilegeParam.getRoleIds();
        if (Objects.nonNull(roleIds) && roleIds.length > 0) {
            List<TSchoolRole> tSchoolRoleList = new ArrayList<>();
            for (int i = 0; i < roleIds.length; i++) {
                tSchoolRoleList.add(new TSchoolRole(tSchoolPrivilegeParam.getSchoolId(), roleIds[i]));
            }
            tSchoolRoleService.saveBatch(tSchoolRoleList);
        }

        commonCacheService.removeSchoolRoleCache(tSchoolPrivilegeParam.getSchoolId());
        //清缓存
        if (!CollectionUtils.isEmpty(userSetIds)) {
            for (Long l : userSetIds) {
                SystemConstant.deleteUserCache(l);
            }
        }
        return ResultUtil.ok(true);
    }

    @ApiOperation(value = "学校已绑定自定义角色权限列表")
    @ApiResponses({@ApiResponse(code = 200, message = "角色权限信息", response = SysAdminSetResult.class)})
    @RequestMapping(value = "/role/custom/get_school_custom_roles", method = RequestMethod.POST)
    public Result getSchoolRoles(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) {
        List<TSchoolRole> tSchoolRoleList = commonCacheService.addSchoolRoleCache(schoolId);
        List<String> roleIdList = tSchoolRoleList.stream().map(s -> String.valueOf(s.getRoleId())).collect(Collectors.toList());
        SysAdminSetResult sysAdminSetResult = new SysAdminSetResult(schoolId);
        sysAdminSetResult.setRoleIdList(CollectionUtils.isEmpty(roleIdList) ? new ArrayList<>() : roleIdList);
        return ResultUtil.ok(sysAdminSetResult);
    }
}
