SsoController.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.qmth.distributed.print.api;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.qmth.boot.api.constant.ApiConstant;
  5. import com.qmth.distributed.print.business.service.SsoService;
  6. import com.qmth.teachcloud.common.annotation.OperationLogDetail;
  7. import com.qmth.teachcloud.common.bean.params.OpenParams;
  8. import com.qmth.teachcloud.common.contant.SystemConstant;
  9. import com.qmth.teachcloud.common.entity.SysOrg;
  10. import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
  11. import com.qmth.teachcloud.common.enums.RoleTypeEnum;
  12. import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
  13. import com.qmth.teachcloud.common.service.SysOrgService;
  14. import com.qmth.teachcloud.common.util.Result;
  15. import com.qmth.teachcloud.common.util.ResultUtil;
  16. import com.qmth.teachcloud.common.util.ServletUtil;
  17. import io.swagger.annotations.*;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RequestMethod;
  21. import org.springframework.web.bind.annotation.RequestParam;
  22. import org.springframework.web.bind.annotation.RestController;
  23. import javax.annotation.Resource;
  24. import java.io.IOException;
  25. import java.util.Map;
  26. import java.util.Objects;
  27. /**
  28. * <p>
  29. * 单点登录 前端控制器
  30. * </p>
  31. *
  32. * @author xf
  33. */
  34. @Api(tags = "单点登录Controller")
  35. @RestController
  36. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_EXAM + "/sso")
  37. public class SsoController {
  38. @Autowired
  39. SsoService ssoService;
  40. @Resource
  41. SysOrgService sysOrgService;
  42. @ApiOperation(value = "题库单点登录")
  43. @ApiResponses({@ApiResponse(code = 200, message = "题库单点登录", response = Result.class)})
  44. @RequestMapping(value = "/question_library_login", method = RequestMethod.POST)
  45. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UN_KNOW)
  46. public Result questionLibraryLogin(@ApiParam(value = "登录名", required = true) @RequestParam String loginName,
  47. @ApiParam(value = "真实姓名", required = true) @RequestParam String realName,
  48. @ApiParam(value = "角色", required = true) @RequestParam RoleTypeEnum role,
  49. @ApiParam(value = "返回url") @RequestParam(required = false) String returnUrl,
  50. @ApiParam(value = "其它参数") @RequestParam(required = false) String params) throws IOException {
  51. if (Objects.isNull(loginName) || Objects.equals(loginName, "")) {
  52. throw ExceptionResultEnum.PARAMS_ERROR.exception("登录名不能为空");
  53. }
  54. if (Objects.isNull(role)) {
  55. throw ExceptionResultEnum.PARAMS_ERROR.exception("角色不能为空");
  56. }
  57. if (role != RoleTypeEnum.SUBJECT_TEACHER && role != RoleTypeEnum.ASSIGN_TEACHER) {
  58. throw ExceptionResultEnum.ERROR.exception("角色类型超出限制");
  59. }
  60. OpenParams openParams = new OpenParams();
  61. openParams.setName(realName);
  62. openParams.setRoleName(role.name());
  63. return ResultUtil.ok(ssoService.questionLibraryLogin(loginName,realName, role, returnUrl, JSON.toJSONString(openParams)));
  64. }
  65. @ApiOperation(value = "教研分析单点登录")
  66. @ApiResponses({@ApiResponse(code = 200, message = "教研分析单点登录", response = Result.class)})
  67. @RequestMapping(value = "/analysis_login", method = RequestMethod.POST)
  68. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UN_KNOW)
  69. public Result analysisLogin(@ApiParam(value = "登录名", required = true) @RequestParam String loginName,
  70. @ApiParam(value = "角色", required = true) @RequestParam RoleTypeEnum role,
  71. @ApiParam(value = "学院名称", required = true) @RequestParam String orgName,
  72. @ApiParam(value = "真实名") @RequestParam(required = false) String realName,
  73. @ApiParam(value = "手机号码") @RequestParam(required = false) String mobileNumber,
  74. @ApiParam(value = "是否启用") @RequestParam(required = false) Boolean enable,
  75. @ApiParam(value = "返回url") @RequestParam(required = false) String returnUrl) throws IOException {
  76. if (Objects.isNull(loginName) || Objects.equals(loginName, "")) {
  77. throw ExceptionResultEnum.PARAMS_ERROR.exception("登录名不能为空");
  78. }
  79. if (Objects.isNull(role)) {
  80. throw ExceptionResultEnum.PARAMS_ERROR.exception("角色不能为空");
  81. }
  82. Long schoolId = SystemConstant.convertIdToLong(String.valueOf(ServletUtil.getRequestHeaderSchoolId()));
  83. SysOrg sysOrg = sysOrgService.getOne(new QueryWrapper<SysOrg>()
  84. .lambda()
  85. .eq(SysOrg::getSchoolId,schoolId)
  86. .eq(SysOrg::getName,orgName));
  87. if (Objects.isNull(sysOrg)){
  88. throw ExceptionResultEnum.ERROR.exception("机构不存在");
  89. }
  90. // 不是教务处老师查询开课学院
  91. if (!RoleTypeEnum.OFFICE_TEACHER.equals(role)){
  92. sysOrg = sysOrgService.findCollegeLevelOrgByOrgId(sysOrgService.getOne(new QueryWrapper<SysOrg>().lambda()
  93. .eq(SysOrg::getSchoolId,schoolId)
  94. .eq(SysOrg::getName,orgName)).getId());
  95. }
  96. if (Objects.isNull(orgName) || Objects.equals(orgName, "")) {
  97. throw ExceptionResultEnum.PARAMS_ERROR.exception("学院名称不能为空");
  98. }
  99. if (role != RoleTypeEnum.OFFICE_TEACHER && role != RoleTypeEnum.PRESIDENT && role != RoleTypeEnum.TEACHER) {
  100. throw ExceptionResultEnum.ERROR.exception("角色类型超出限制");
  101. }
  102. return ResultUtil.ok(ssoService.analysisLogin(loginName, role, sysOrg.getName(), realName, mobileNumber, enable, returnUrl));
  103. }
  104. }