OpenApiController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package com.qmth.distributed.print.api;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.qmth.boot.api.annotation.Aac;
  4. import com.qmth.boot.api.annotation.BOOL;
  5. import com.qmth.boot.api.constant.ApiConstant;
  6. import com.qmth.distributed.print.business.bean.params.open.GradeOpenPageParams;
  7. import com.qmth.distributed.print.business.bean.params.open.GradeOpenParams;
  8. import com.qmth.distributed.print.business.service.OpenApiService;
  9. import com.qmth.teachcloud.common.bean.params.OpenParams;
  10. import com.qmth.teachcloud.common.bean.result.LoginResult;
  11. import com.qmth.teachcloud.common.contant.SystemConstant;
  12. import com.qmth.teachcloud.common.entity.BasicSchool;
  13. import com.qmth.teachcloud.common.entity.SysUser;
  14. import com.qmth.teachcloud.common.enums.AppSourceEnum;
  15. import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
  16. import com.qmth.teachcloud.common.service.BasicSchoolService;
  17. import com.qmth.teachcloud.common.service.SysUserService;
  18. import com.qmth.teachcloud.common.service.TeachcloudCommonService;
  19. import com.qmth.teachcloud.common.util.*;
  20. import io.swagger.annotations.*;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import org.springframework.util.CollectionUtils;
  24. import org.springframework.validation.annotation.Validated;
  25. import org.springframework.web.bind.annotation.*;
  26. import javax.annotation.Resource;
  27. import java.io.UnsupportedEncodingException;
  28. import java.net.URLDecoder;
  29. import java.security.NoSuchAlgorithmException;
  30. import java.util.*;
  31. import java.util.stream.Collectors;
  32. /**
  33. * <p>
  34. * 知学知考开放接口前端控制器
  35. * </p>
  36. *
  37. * @author wangliang
  38. * @since 2022-04-26
  39. */
  40. @Api(tags = "知学知考开放接口Controller")
  41. @RestController
  42. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_OPEN)
  43. @Validated
  44. public class OpenApiController {
  45. private static final Logger log = LoggerFactory.getLogger(OpenApiController.class);
  46. @Resource
  47. private OpenApiService openApiService;
  48. @Resource
  49. SysUserService sysUserService;
  50. @Resource
  51. TeachcloudCommonService teachcloudCommonService;
  52. @Resource
  53. BasicSchoolService basicSchoolService;
  54. @ApiOperation(value = "试卷基础配置查询")
  55. @ApiResponses({@ApiResponse(code = 200, message = "试卷基础配置查询", response = Object.class)})
  56. @PostMapping("/paper_config")
  57. @Aac(auth = BOOL.FALSE)
  58. public Result paperConfig(@ApiParam(value = "接收试卷配置数据信息", required = true) @RequestBody String result) throws UnsupportedEncodingException {
  59. Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
  60. String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
  61. log.info("paperConfigSelect进来了,result:{}", decodeJson);
  62. GradeOpenParams gradeOpenParams = JacksonUtil.readJson(decodeJson, GradeOpenParams.class);
  63. Optional.ofNullable(gradeOpenParams).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
  64. gradeOpenParams.validParams();
  65. BasicSchool basicSchool = AuthThirdUtil.hasPermission();
  66. return ResultUtil.ok(openApiService.getPaperConfig(basicSchool, gradeOpenParams.getThirdExamId(), gradeOpenParams.getGradeCourseCode()));
  67. }
  68. @ApiOperation(value = "试卷考察点查询")
  69. @ApiResponses({@ApiResponse(code = 200, message = "试卷考察点查询", response = Object.class)})
  70. @PostMapping("/paper_dimension")
  71. @Aac(auth = BOOL.FALSE)
  72. public Result paperDimension(@ApiParam(value = "试卷考察点查询", required = true) @RequestBody String result) throws UnsupportedEncodingException {
  73. Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
  74. String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
  75. log.info("paperDimensionSelect进来了,result:{}", decodeJson);
  76. GradeOpenParams gradeOpenParams = JacksonUtil.readJson(decodeJson, GradeOpenParams.class);
  77. Optional.ofNullable(gradeOpenParams).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
  78. gradeOpenParams.validParams();
  79. BasicSchool basicSchool = AuthThirdUtil.hasPermission();
  80. return ResultUtil.ok(openApiService.getPaperDimension(basicSchool, gradeOpenParams.getThirdExamId(), gradeOpenParams.getGradeCourseCode()));
  81. }
  82. @ApiOperation(value = "试卷蓝图查询")
  83. @ApiResponses({@ApiResponse(code = 200, message = "试卷蓝图查询", response = Object.class)})
  84. @PostMapping("/paper_structure")
  85. @Aac(auth = BOOL.FALSE)
  86. public Result paperStructure(@ApiParam(value = "试卷考察点查询", required = true) @RequestBody String result) throws UnsupportedEncodingException {
  87. Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
  88. String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
  89. log.info("paperStructureSelect进来了,result:{}", decodeJson);
  90. GradeOpenParams gradeOpenParams = JacksonUtil.readJson(decodeJson, GradeOpenParams.class);
  91. Optional.ofNullable(gradeOpenParams).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
  92. gradeOpenParams.validParams();
  93. BasicSchool basicSchool = AuthThirdUtil.hasPermission();
  94. return ResultUtil.ok(openApiService.getPaperStructure(basicSchool, gradeOpenParams.getThirdExamId(), gradeOpenParams.getGradeCourseCode()));
  95. }
  96. @ApiOperation(value = "试卷评价模型查询")
  97. @ApiResponses({@ApiResponse(code = 200, message = "试卷评价模型查询", response = Object.class)})
  98. @PostMapping("/paper_evaluation")
  99. @Aac(auth = BOOL.FALSE)
  100. public Result paperEvaluation(@ApiParam(value = "试卷评价模型查询", required = true) @RequestBody String result) throws UnsupportedEncodingException {
  101. Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
  102. String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
  103. log.info("paperEvaluation进来了,result:{}", decodeJson);
  104. GradeOpenParams gradeOpenParams = JacksonUtil.readJson(decodeJson, GradeOpenParams.class);
  105. Optional.ofNullable(gradeOpenParams).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
  106. gradeOpenParams.validParams();
  107. BasicSchool basicSchool = AuthThirdUtil.hasPermission();
  108. return ResultUtil.ok(openApiService.getPaperEvaluation(basicSchool, gradeOpenParams.getThirdExamId(), gradeOpenParams.getGradeCourseCode()));
  109. }
  110. @ApiOperation(value = "考生成绩查询")
  111. @ApiResponses({@ApiResponse(code = 200, message = "考生成绩查询", response = Object.class)})
  112. @PostMapping("/exam_student_score")
  113. @Aac(auth = BOOL.FALSE)
  114. public Result examStudentScore(@ApiParam(value = "考生成绩查询", required = true) @RequestBody String result) throws UnsupportedEncodingException {
  115. Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
  116. String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
  117. log.info("examStudentScore进来了,result:{}", decodeJson);
  118. GradeOpenPageParams gradeOpenPageParams = JacksonUtil.readJson(decodeJson, GradeOpenPageParams.class);
  119. Optional.ofNullable(gradeOpenPageParams).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
  120. gradeOpenPageParams.validParams();
  121. BasicSchool basicSchool = AuthThirdUtil.hasPermission();
  122. return ResultUtil.ok(openApiService.listExamStudentScore(basicSchool, gradeOpenPageParams.getThirdExamId(), gradeOpenPageParams.getGradeCourseCode(), gradeOpenPageParams.getPageNumber(), gradeOpenPageParams.getPageSize()));
  123. }
  124. @ApiOperation(value = "单点登录")
  125. @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
  126. @RequestMapping(value = "/account/login", method = RequestMethod.POST)
  127. @Aac(auth = BOOL.FALSE)
  128. public Result accountLogin(@ApiParam(value = "时间", required = true) @RequestParam String time,
  129. @ApiParam(value = "地址", required = true) @RequestParam String path,
  130. @ApiParam(value = "鉴权信息", required = true) @RequestParam String signature,
  131. @ApiParam(value = "工号", required = true) @RequestParam String account,
  132. @ApiParam(value = "返回url") @RequestParam(required = false) String returnUrl,
  133. @ApiParam(value = "其它参数") @RequestParam(required = false) String params) throws UnsupportedEncodingException, NoSuchAlgorithmException {
  134. if (Objects.isNull(time) || Objects.equals(time, "")) {
  135. throw ExceptionResultEnum.PARAMS_ERROR.exception("时间不能为空");
  136. }
  137. if (Objects.isNull(path) || Objects.equals(path, "")) {
  138. throw ExceptionResultEnum.PARAMS_ERROR.exception("路径不能为空");
  139. }
  140. if (Objects.isNull(signature) || Objects.equals(signature, "")) {
  141. throw ExceptionResultEnum.PARAMS_ERROR.exception("鉴权信息不能为空");
  142. }
  143. signature = new String(Base64Util.decode(signature), SystemConstant.CHARSET_NAME);
  144. if (Objects.isNull(account) || Objects.equals(account, "")) {
  145. throw ExceptionResultEnum.PARAMS_ERROR.exception("工号不能为空");
  146. }
  147. account = URLDecoder.decode(account, SystemConstant.CHARSET_NAME);
  148. BasicSchool basicSchool = AuthThirdUtil.hasPermissionCas(time, path, signature);
  149. OpenParams openParams = null;
  150. if (Objects.nonNull(params) && !Objects.equals(params, "")) {
  151. String decodeJson = URLDecoder.decode(params, SystemConstant.CHARSET_NAME);
  152. openParams = JacksonUtil.readJson(decodeJson, OpenParams.class);
  153. }
  154. //查询用户是否存在
  155. QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
  156. sysUserQueryWrapper.lambda().eq(SysUser::getSchoolId, basicSchool.getId())
  157. .eq(SysUser::getLoginName, account)
  158. .eq(SysUser::getEnable, true);
  159. SysUser sysUser = sysUserService.getOne(sysUserQueryWrapper);
  160. Optional.ofNullable(sysUser).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("用户不存在"));
  161. LoginResult loginResult = teachcloudCommonService.login(sysUser.getPassword(), sysUser, AppSourceEnum.CAS_THIRD);
  162. if (Objects.nonNull(returnUrl) && !Objects.equals(returnUrl, "")) {
  163. returnUrl = URLDecoder.decode(returnUrl, SystemConstant.CHARSET_NAME);
  164. }
  165. loginResult.setReturnUrl(returnUrl);
  166. return ResultUtil.ok(loginResult);
  167. }
  168. @ApiOperation(value = "西交大登录之前逻辑")
  169. @ApiResponses({@ApiResponse(code = 200, message = "用户信息", response = SysUser.class)})
  170. @RequestMapping(value = "/login_before_xju_logic", method = RequestMethod.POST)
  171. @Aac(auth = BOOL.FALSE)
  172. public Result loginBeforeXjuLogic(@ApiParam(value = "登录账号", required = true) @RequestBody String account) throws UnsupportedEncodingException {
  173. Optional.ofNullable(account).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("账号为空"));
  174. String decodeJson = URLDecoder.decode(account, SystemConstant.CHARSET_NAME);
  175. log.info("loginBeforeXjuLogic进来了,result:{}", decodeJson);
  176. account = JacksonUtil.readJson(decodeJson, String.class);
  177. BasicSchool basicSchool = AuthThirdUtil.hasPermission();
  178. Set<String> schoolCodes = new HashSet<>(Arrays.asList("xjtu", "xjtuyjs"));
  179. schoolCodes.add(basicSchool.getCode());
  180. QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
  181. basicSchoolQueryWrapper.lambda().in(BasicSchool::getCode, schoolCodes);
  182. List<BasicSchool> basicSchoolList = basicSchoolService.list(basicSchoolQueryWrapper);
  183. if (CollectionUtils.isEmpty(basicSchoolList)) {
  184. throw ExceptionResultEnum.ERROR.exception("未找到西交大学校信息");
  185. }
  186. List<Long> schoolIds = basicSchoolList.stream().map(s -> s.getId()).collect(Collectors.toList());
  187. QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
  188. sysUserQueryWrapper.lambda().eq(SysUser::getLoginName, account)
  189. .eq(SysUser::getEnable, true)
  190. .in(SysUser::getSchoolId, schoolIds);
  191. return ResultUtil.ok(sysUserService.list(sysUserQueryWrapper));
  192. }
  193. }