package com.qmth.distributed.print.api; import com.alibaba.fastjson.JSON; 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.dto.StudentNumberConfigDto; import com.qmth.distributed.print.business.bean.dto.StudentNumberLetterRelationShipDto; 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.contant.SystemConstant; import com.qmth.teachcloud.common.entity.*; import com.qmth.teachcloud.common.enums.ExceptionResultEnum; import com.qmth.teachcloud.common.enums.FlowMsgTypeEnum; import com.qmth.teachcloud.common.enums.log.OperationTypeEnum; import com.qmth.teachcloud.common.service.*; import com.qmth.teachcloud.common.util.RedisUtil; import com.qmth.teachcloud.common.util.Result; import com.qmth.teachcloud.common.util.ResultUtil; import io.swagger.annotations.*; import org.apache.ibatis.annotations.Param; 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; @Resource private FileUploadService fileUploadService; @Resource private RedisUtil redisUtil; @ApiOperation(value = "数据还原") @ApiResponses({@ApiResponse(code = 200, message = "数据还原信息", response = ResultUtil.class)}) @RequestMapping(value = "/backup", method = RequestMethod.POST) @OperationLogDetail(operationType = OperationTypeEnum.UPDATE) public Result sysadminBackup(@ApiParam(value = "学校ID", required = true) @RequestParam Long schoolId) { mySQLDatabaseBackup.backupAndDeleteData(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 sysConfigQuestionHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.QUESTION_HOST_URL); SysConfig sysConfigTeachcloudReportHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.TEACHCLOUD_REPORT_HOST_URL); SysConfig sysConfigOpenFlowMsgPush = commonCacheService.addSysConfigCache(schoolId, SystemConstant.OPEN_FLOW_MESSAGE_PUSH); SysConfig sysConfigFlowMsgType = commonCacheService.addSysConfigCache(schoolId, SystemConstant.FLOW_MESSAGE_TYPE); SysConfig sysConfigMqHostUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.MQ_HOST_URL); List 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(sysConfigTeachcloudReportHostUrl)) { sysConfigResultList.add(new SysConfigResult(sysConfigTeachcloudReportHostUrl)); } else { sysConfigResultList.add(new SysConfigResult(null, SystemConstant.TEACHCLOUD_REPORT_HOST_URL, "教研分析地址", "", 4)); } if (Objects.nonNull(sysConfigOpenFlowMsgPush)) { sysConfigResultList.add(new SysConfigResult(sysConfigOpenFlowMsgPush)); } else { sysConfigResultList.add(new SysConfigResult(null, SystemConstant.OPEN_FLOW_MESSAGE_PUSH, "是否开启消息推送", "false", 5)); } if (Objects.nonNull(sysConfigFlowMsgType)) { sysConfigResultList.add(new SysConfigResult(sysConfigFlowMsgType)); } else { sysConfigResultList.add(new SysConfigResult(null, SystemConstant.FLOW_MESSAGE_TYPE, "消息类型", FlowMsgTypeEnum.STANDARD, 6)); } if (Objects.nonNull(sysConfigMqHostUrl)) { sysConfigResultList.add(new SysConfigResult(sysConfigMqHostUrl)); } else { sysConfigResultList.add(new SysConfigResult(null, SystemConstant.MQ_HOST_URL, "消息中心地址", "", 7)); } 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(operationType = OperationTypeEnum.SAVE) 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 sysConfigResultList = sysAdminSetParam.getParam(); List 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() { SysAdminSetResult sysAdminSetResult = new SysAdminSetResult(); List list = new ArrayList<>(); // pdf全局格式 SysConfig sysPdfConfig = commonCacheService.addSysConfigCache(SystemConstant.SYS_PDF_SIZE_LIST); Optional.ofNullable(sysPdfConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置全局上传试卷规格")); SysConfigResult pdfCell = new SysConfigResult(sysPdfConfig); pdfCell.setValue(Arrays.asList(sysPdfConfig.getConfigValue().replaceAll("\\[", "").replaceAll("\\]", "").split(", "))); list.add(pdfCell); // 题卡全局格式 SysConfig sysCardConfig = commonCacheService.addSysConfigCache(SystemConstant.SYS_CARD_SIZE_LIST); Optional.ofNullable(sysCardConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置全局上传试卷规格")); SysConfigResult cardCell = new SysConfigResult(sysCardConfig); cardCell.setValue(Arrays.asList(sysCardConfig.getConfigValue().replaceAll("\\[", "").replaceAll("\\]", "").split(", "))); list.add(cardCell); sysAdminSetResult.setResult(list); 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) { List resultList = new ArrayList<>(); // 试卷规格 SysConfig sysConfigPdfSize = commonCacheService.addSysConfigCache(schoolId, SystemConstant.PDF_SIZE_LIST); List pdfSize; SysConfigResult sysPdfConfigResult; if (Objects.nonNull(sysConfigPdfSize)) { pdfSize = Arrays.asList( sysConfigPdfSize.getConfigValue().replaceAll("\\[", "").replaceAll("\\]", "").split(", ")); sysPdfConfigResult = new SysConfigResult(sysConfigPdfSize); sysPdfConfigResult.setValue(pdfSize); } else { sysPdfConfigResult = new SysConfigResult(null, SystemConstant.PDF_SIZE_LIST, "允许上传试卷规格", new ArrayList<>(), 1); } resultList.add(sysPdfConfigResult); // 题卡规格 SysConfig sysConfigCardSize = commonCacheService.addSysConfigCache(schoolId, SystemConstant.CARD_SIZE_LIST); List cardSize; SysConfigResult sysCardConfigResult; if (Objects.nonNull(sysConfigCardSize)) { cardSize = Arrays.asList( sysConfigCardSize.getConfigValue().replaceAll("\\[", "").replaceAll("\\]", "").split(", ")); sysCardConfigResult = new SysConfigResult(sysConfigCardSize); sysCardConfigResult.setValue(cardSize); } else { sysCardConfigResult = new SysConfigResult(null, SystemConstant.CARD_SIZE_LIST, "允许上传题卡规格", new ArrayList<>(), 2); } resultList.add(sysCardConfigResult); SysAdminSetResult sysAdminSetResult = new SysAdminSetResult(schoolId); sysAdminSetResult.setResult(resultList); return ResultUtil.ok(sysAdminSetResult); } @ApiOperation(value = "试卷规格配置保存") @ApiResponses({@ApiResponse(code = 200, message = "试卷规格配置信息", response = ResultUtil.class)}) @RequestMapping(value = "/paper/save", method = RequestMethod.POST) @Transactional @OperationLogDetail(operationType = OperationTypeEnum.SAVE) 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 sysConfigResultList = sysAdminSetParam.getParam(); List 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 = "/student_number_config/select", method = RequestMethod.POST) public Result sysadminStudentNumberConfigSelect(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) { List resultList = new ArrayList<>(); // 试卷规格 SysConfig sysConfig = commonCacheService.addSysConfigCache(schoolId, SystemConstant.STUDENT_NUMBER_ALLOCATION); SysConfigResult sysConfigResult; if (Objects.nonNull(sysConfig)) { sysConfigResult = new SysConfigResult(sysConfig); StudentNumberConfigDto studentNumberConfigDto = JSON.parseObject(sysConfig.getConfigValue(), StudentNumberConfigDto.class); sysConfigResult.setValue(studentNumberConfigDto); } else { StudentNumberConfigDto studentNumberConfigDto = new StudentNumberConfigDto(); studentNumberConfigDto.setDigit(0); studentNumberConfigDto.setContainsLetter(false); sysConfigResult = new SysConfigResult(null, SystemConstant.STUDENT_NUMBER_ALLOCATION, "学号配置", studentNumberConfigDto, 1); } resultList.add(sysConfigResult); SysAdminSetResult sysAdminSetResult = new SysAdminSetResult(schoolId); sysAdminSetResult.setResult(resultList); return ResultUtil.ok(sysAdminSetResult); } @ApiOperation(value = "学号配置保存") @ApiResponses({@ApiResponse(code = 200, message = "学号配置保存信息", response = ResultUtil.class)}) @RequestMapping(value = "/student_number_config/save", method = RequestMethod.POST) @Transactional public Result sysadminStudentNumberConfigSave(@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 sysConfigResultList = sysAdminSetParam.getParam(); List sysConfigList = new ArrayList<>(); for (SysConfigResult s : sysConfigResultList) { StudentNumberConfigDto studentNumberConfigDto = JSON.parseObject(JSON.toJSONString(s.getValue()), StudentNumberConfigDto.class); Integer digit = studentNumberConfigDto.getDigit(); Boolean containsLetter = studentNumberConfigDto.getContainsLetter(); List relationList = studentNumberConfigDto.getRelationList(); if (containsLetter && CollectionUtils.isEmpty(relationList)) { throw ExceptionResultEnum.ERROR.exception("学号配置中,包含字母时,必须配置字母对应关系"); } for (StudentNumberLetterRelationShipDto studentNumberLetterRelationShipDto : relationList) { Integer columnIndex = studentNumberLetterRelationShipDto.getColumnIndex(); if (columnIndex > digit) { throw ExceptionResultEnum.ERROR.exception(String.format("第[%s]列,字母所在列不能超过学号位数", columnIndex)); } String[] letters = studentNumberLetterRelationShipDto.getLetters(); int x = letters.length; if (x > 10) { throw ExceptionResultEnum.ERROR.exception(String.format("第[%s]列,字母对应关系中,字母个数不能超过10", columnIndex)); } int y = (int) Arrays.stream(letters).distinct().count(); if (x != y) { throw ExceptionResultEnum.ERROR.exception(String.format("第[%s]列,字母对应关系中,字母不能重复", columnIndex)); } for (String letter : letters) { // 正则判断必须是大写字母 if (!letter.matches("[A-Z]")) { throw ExceptionResultEnum.ERROR.exception(String.format("第[%s]列,字母对应关系中,[%s]必须为大写字母", columnIndex, letter)); } } } SysConfig sysConfig = new SysConfig(sysAdminSetParam.getSchoolId(), s, true); 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 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(operationType = OperationTypeEnum.SAVE) 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 sysConfigResultList = sysAdminSetParam.getParam(); List 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 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(operationType = OperationTypeEnum.SAVE) public Result schoolPrivilegeSave(@Valid @RequestBody SysAdminSetParam tSchoolPrivilegeParam, BindingResult bindingResult) throws NoSuchAlgorithmException { if (bindingResult.hasErrors()) { return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage()); } Set roleSetIds = null; QueryWrapper tSchoolPrivilegeQueryWrapper = new QueryWrapper<>(); tSchoolPrivilegeQueryWrapper.lambda().eq(TSchoolPrivilege::getSchoolId, tSchoolPrivilegeParam.getSchoolId()); List tSchoolPrivileges = tSchoolPrivilegeService.list(tSchoolPrivilegeQueryWrapper); if (!CollectionUtils.isEmpty(tSchoolPrivileges)) {//编辑 Set 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 sysRoleQueryWrapper = new QueryWrapper<>(); sysRoleQueryWrapper.lambda().eq(SysRole::getSchoolId, tSchoolPrivilegeParam.getSchoolId()); List sysRoleList = sysRoleService.list(sysRoleQueryWrapper); if (!CollectionUtils.isEmpty(sysRoleList)) { QueryWrapper sysRolePrivilegeQueryWrapper = new QueryWrapper<>(); sysRolePrivilegeQueryWrapper.lambda() .in(SysRolePrivilege::getRoleId, sysRoleList.stream().map(s -> s.getId()).collect(Collectors.toList())) .in(SysRolePrivilege::getPrivilegeId, changePrivilegeSetIds); List 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 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(tSchoolPrivilegeParam.getSchoolId(), l); //绑定该角色的用户都需要清除鉴权缓存 List 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); } } } } // 更新用户菜单缓存 Set userMenuCacheKeySet = (Set) redisUtil.getKeyPatterns(SystemConstant.USER_MENU_CACHE_LIKE); for (String key : userMenuCacheKeySet) { String userId = key.substring(key.lastIndexOf(":") + 1); commonCacheService.updateUserMenuCache(Long.valueOf(userId)); commonCacheService.updateUserAuthCache(Long.valueOf(userId)); } // 更新自定义菜单 sysPrivilegeService.updateCustomList(); 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 tSchoolPrivilegeList = commonCacheService.addSchoolPrivilegeCache(schoolId); List 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 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(operationType = OperationTypeEnum.SAVE) public Result schoolRoleSave(@Valid @RequestBody SysAdminSetParam tSchoolPrivilegeParam, BindingResult bindingResult) throws NoSuchAlgorithmException { if (bindingResult.hasErrors()) { return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage()); } Set userSetIds = new HashSet<>(); QueryWrapper tSchoolRoleQueryWrapper = new QueryWrapper<>(); tSchoolRoleQueryWrapper.lambda().eq(TSchoolRole::getSchoolId, tSchoolPrivilegeParam.getSchoolId()); List tSchoolRoles = tSchoolRoleService.list(tSchoolRoleQueryWrapper); if (!CollectionUtils.isEmpty(tSchoolRoles)) {//编辑 Set 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 sysUserRoleList = sysUserRoleService.listByRoleIdsAndSchoolId(changeRoleSetIds, tSchoolPrivilegeParam.getSchoolId()); if (!CollectionUtils.isEmpty(sysUserRoleList)) { List 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 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 tSchoolRoleList = commonCacheService.addSchoolRoleCache(schoolId); List 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); } @ApiOperation(value = "课程目标达成度模板配置查询") @ApiResponses({@ApiResponse(code = 200, message = "课程目标达成度模板配置查询", response = CustomPrivilegeResult.class)}) @RequestMapping(value = "/course/degree/select", method = RequestMethod.POST) public Result sysadminCourseDegreeSelect(@ApiParam(value = "学校id ", required = true) @RequestParam Long schoolId) { SysConfig sysConfig = commonCacheService.addSysConfigCache(schoolId, SystemConstant.SCHOOL_COURSE_DEGREE_TEMPLATE); SysConfigResult sysConfigResult = new SysConfigResult(); if (sysConfig != null) { sysConfigResult = new SysConfigResult(sysConfig); if (sysConfigResult != null && sysConfigResult.getValue() != null) { sysConfigResult.setValue(fileUploadService.filePreview(Long.valueOf(sysConfigResult.getValue().toString()))); } } return ResultUtil.ok(sysConfigResult); } @ApiOperation(value = "课程目标达成度模板配置保存") @ApiResponses({@ApiResponse(code = 200, message = "课程目标达成度模板配置保存", response = CustomPrivilegeResult.class)}) @RequestMapping(value = "/course/degree/save", method = RequestMethod.POST) public Result sysadminCourseDegreeSave(@ApiParam(value = "学校ID", required = true) @RequestParam Long schoolId, @ApiParam(value = "附件ID", required = true) @RequestParam Long attachmentId) { SysConfig sysConfig = commonCacheService.addSysConfigCache(schoolId, SystemConstant.SCHOOL_COURSE_DEGREE_TEMPLATE); if (sysConfig == null) { sysConfig = new SysConfig(schoolId, SystemConstant.SCHOOL_COURSE_DEGREE_TEMPLATE, "课程目标达成度模板配置", String.valueOf(attachmentId)); } else { sysConfig.setConfigValue(String.valueOf(attachmentId)); } if (sysConfigService.saveOrUpdate(sysConfig)) { commonCacheService.updateSysConfigCache(schoolId, sysConfig.getConfigKey()); } SysConfigResult sysConfigResult = new SysConfigResult(sysConfig); if (sysConfigResult != null && sysConfigResult.getValue() != null) { sysConfigResult.setValue(fileUploadService.filePreview(Long.valueOf(sysConfigResult.getValue().toString()))); } return ResultUtil.ok(sysConfigResult); } @ApiOperation(value = "数据同步参数查询") @ApiResponses({@ApiResponse(code = 200, message = "系统试卷规格配置信息", response = CustomPrivilegeResult.class)}) @RequestMapping(value = "/data/sync/select", method = RequestMethod.POST) public Result dataSyncSelect(@ApiParam(value = "schoolId") @Param(value = "schoolId") Long schoolId) { SysAdminSetResult sysAdminSetResult = new SysAdminSetResult(); List list = new ArrayList<>(); // 数据库类型 SysConfig datasourceType = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_TYPE); list.add(datasourceType != null ? new SysConfigResult(datasourceType) : new SysConfigResult(null, SystemConstant.DATA_DATASOURCE_TYPE, "数据库类型", "", 1)); // 数据库HOST SysConfig datasourceHost = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_HOST); list.add(datasourceHost != null ? new SysConfigResult(datasourceHost) : new SysConfigResult(null, SystemConstant.DATA_DATASOURCE_HOST, "HOST", "", 2)); // 数据库PORT SysConfig datasourcePort = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_PORT); list.add(datasourcePort != null ? new SysConfigResult(datasourcePort) : new SysConfigResult(null, SystemConstant.DATA_DATASOURCE_PORT, "端口", "", 3)); // 数据库DataName SysConfig datasourceDataName = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_DATANAME); list.add(datasourceDataName != null ? new SysConfigResult(datasourceDataName) : new SysConfigResult(null, SystemConstant.DATA_DATASOURCE_DATANAME, "数据库名", "", 4)); // 数据库用户名 SysConfig datasourceUserName = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_USERNAME); list.add(datasourceUserName != null ? new SysConfigResult(datasourceUserName) : new SysConfigResult(null, SystemConstant.DATA_DATASOURCE_USERNAME, "用户名", "", 5)); // 数据库密码 SysConfig datasourcePassword = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_PASSWORD); list.add(datasourcePassword != null ? new SysConfigResult(datasourcePassword) : new SysConfigResult(null, SystemConstant.DATA_DATASOURCE_PASSWORD, "密码", "", 6)); sysAdminSetResult.setResult(list); return ResultUtil.ok(sysAdminSetResult); } @ApiOperation(value = "数据同步参数保存") @ApiResponses({@ApiResponse(code = 200, message = "同步配置信息", response = ResultUtil.class)}) @RequestMapping(value = "/data/sync/save", method = RequestMethod.POST) @Transactional @OperationLogDetail(operationType = OperationTypeEnum.SAVE) public Result dataSyncSave(@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 sysConfigResultList = sysAdminSetParam.getParam(); List 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 = "/ai/robot/select", method = RequestMethod.POST) public Result aiRobotSelect(@ApiParam(value = "schoolId") @Param(value = "schoolId") Long schoolId) { SysAdminSetResult sysAdminSetResult = new SysAdminSetResult(); List list = new ArrayList<>(); // 是否开启机器人 SysConfig aiRobotSwitch = commonCacheService.addSysConfigCache(schoolId, SystemConstant.AI_ROBOT_ENABLE); list.add(aiRobotSwitch != null ? new SysConfigResult(aiRobotSwitch) : new SysConfigResult(null, SystemConstant.AI_ROBOT_ENABLE, "是否启用机器人", "false", 1)); // 机器人链接 SysConfig aiRobotUrl = commonCacheService.addSysConfigCache(schoolId, SystemConstant.AI_ROBOT_URL); list.add(aiRobotUrl != null ? new SysConfigResult(aiRobotUrl) : new SysConfigResult(null, SystemConstant.AI_ROBOT_URL, "机器人链接", "https://dify.qmth.com.cn/chat/O5OzUXL2hAOsr86c", 2)); sysAdminSetResult.setResult(list); return ResultUtil.ok(sysAdminSetResult); } @ApiOperation(value = "机器人参数保存") @ApiResponses({@ApiResponse(code = 200, message = "机器人信息", response = ResultUtil.class)}) @RequestMapping(value = "/ai/robot/save", method = RequestMethod.POST) @Transactional @OperationLogDetail(operationType = OperationTypeEnum.SAVE) public Result aiRobotSave(@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 sysConfigResultList = sysAdminSetParam.getParam(); List 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); } }