OpenApiController.java 13 KB

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