VoluntaryController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. package com.ruoyi.web.controller.ie;
  2. import com.alibaba.fastjson2.JSONObject;
  3. import com.google.common.collect.Lists;
  4. import com.ruoyi.common.annotation.Log;
  5. import com.ruoyi.common.core.controller.BaseController;
  6. import com.ruoyi.common.core.domain.AjaxResult;
  7. import com.ruoyi.common.core.domain.R;
  8. import com.ruoyi.common.core.domain.entity.SysUser;
  9. import com.ruoyi.common.core.page.TableDataInfo;
  10. import com.ruoyi.common.enums.BusinessType;
  11. import com.ruoyi.common.utils.NumberUtils;
  12. import com.ruoyi.common.utils.PageUtils;
  13. import com.ruoyi.common.utils.SecurityUtils;
  14. import com.ruoyi.common.utils.StringUtils;
  15. import com.ruoyi.ie.service.IAWishRecordService;
  16. import com.ruoyi.syzy.service.IBBusiWishLocationSubmitsService;
  17. import com.ruoyi.web.domain.Constant;
  18. import com.ruoyi.web.domain.VoluntaryDto;
  19. import com.ruoyi.web.service.CommService;
  20. import com.ruoyi.web.service.VoluntaryService;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. import io.swagger.annotations.ApiParam;
  24. import org.springframework.web.bind.annotation.*;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.stream.Collectors;
  29. @RestController
  30. @Api(tags = "志愿-单招")
  31. public class VoluntaryController extends BaseController {
  32. private final VoluntaryService voluntaryService;
  33. private final IAWishRecordService aWishRecordService;
  34. private final IBBusiWishLocationSubmitsService busiWishLocationSubmitsService;
  35. private final CommService commService;
  36. public VoluntaryController(VoluntaryService voluntaryService, IAWishRecordService aWishRecordService, IBBusiWishLocationSubmitsService busiWishLocationSubmitsService, CommService commService) {
  37. this.voluntaryService = voluntaryService;
  38. this.aWishRecordService = aWishRecordService;
  39. this.busiWishLocationSubmitsService = busiWishLocationSubmitsService;
  40. this.commService = commService;
  41. }
  42. @PostMapping("getAIRenderRules")
  43. @ApiOperation("查询规则")
  44. public R<List<VoluntaryDto.AIRenderRule>> getAIRenderRules(@RequestBody VoluntaryDto.AIRenderRequest req) {
  45. return voluntaryService.getAIRenderRules(req);
  46. }
  47. @PostMapping("postSingleResultSample")
  48. @ApiOperation("单院校专业结果")
  49. public R<VoluntaryDto.SingleResponse> postSingleResultSample(@RequestBody VoluntaryDto.SingleRequest req) {
  50. return R.ok();
  51. }
  52. @PostMapping("postCalculateResult")
  53. @ApiOperation("技能分计算")
  54. public R<VoluntaryDto.SingleResponse> postCalculateResult(@RequestBody String data) {
  55. commService.requireVip();
  56. VoluntaryDto.SingleRequest req = new VoluntaryDto.SingleRequest();
  57. JSONObject root = JSONObject.parseObject(data);
  58. Map<String, String> form = req.getForm();
  59. for (String field : root.keySet()) {
  60. form.put(field, root.getString(field));
  61. }
  62. req.setUniversityCode(form.remove("universityCode"));
  63. req.setMajorCode(form.remove("majorCode"));
  64. req.setMajorEnrollCode(form.remove("majorEnrollCode"));
  65. return voluntaryService.postSingleResult(req, true);
  66. }
  67. @PostMapping("postSingleResult")
  68. @ApiOperation("单院校专业结果")
  69. public R<VoluntaryDto.SingleResponse> postSingleResult(@RequestBody String data) {
  70. commService.requireVip();
  71. VoluntaryDto.SingleRequest req = new VoluntaryDto.SingleRequest();
  72. JSONObject root = JSONObject.parseObject(data);
  73. Map<String, String> form = req.getForm();
  74. for (String field : root.keySet()) {
  75. form.put(field, root.getString(field));
  76. }
  77. req.setUniversityCode(form.remove("universityCode"));
  78. req.setMajorCode(form.remove("majorCode"));
  79. req.setMajorEnrollCode(form.remove("majorEnrollCode"));
  80. return voluntaryService.postSingleResult(req, false);
  81. }
  82. @PostMapping("postMultipleResultSample")
  83. @ApiOperation("多院校专业结果")
  84. public R<List<VoluntaryDto.SingleResponse>> postMultipleResultSample(@RequestBody VoluntaryDto.MultipleRequest req) {
  85. return R.ok();
  86. }
  87. @PostMapping("postMultipleResult")
  88. @ApiOperation("多院校专业结果")
  89. public R<List<VoluntaryDto.SingleResponse>> postMultipleResult(@RequestBody String data) {
  90. commService.requireVip();
  91. VoluntaryDto.MultipleRequest req = new VoluntaryDto.MultipleRequest();
  92. JSONObject root = JSONObject.parseObject(data);
  93. req.setMajorCategory(root.getString("majorCategory"));
  94. req.setUniversities(getCollegeMajor(root));
  95. root.remove("majorCategory");
  96. root.remove("universities");
  97. return voluntaryService.postMultipleResult(req, false);
  98. }
  99. private List<VoluntaryDto.CollegeMajorDto> getCollegeMajor(JSONObject root) {
  100. List<VoluntaryDto.CollegeMajorDto> universities = Lists.newArrayList();
  101. if (root.containsKey("universities")) {
  102. root.getJSONArray("universities").forEach(l -> {
  103. JSONObject lo = (JSONObject) l;
  104. VoluntaryDto.CollegeMajorDto cm = new VoluntaryDto.CollegeMajorDto();
  105. cm.setCode(lo.getString("code"));
  106. List<String> marjorCodeList = Lists.newArrayList();
  107. if(lo.containsKey("majorCodes")) {
  108. lo.getJSONArray("majorCodes").forEach(lm -> {
  109. marjorCodeList.add((String) lm);
  110. });
  111. }
  112. cm.setMajorCodes(marjorCodeList);
  113. Map<String, String> form = cm.getForm();
  114. for (String field : lo.keySet()) {
  115. form.put(field, lo.getString(field));
  116. }
  117. universities.add(cm);
  118. });
  119. }
  120. return universities;
  121. }
  122. @PostMapping("postAIResultSample")
  123. @ApiOperation("AI多院校专业结果")
  124. public TableDataInfo postAIResultSample(@RequestBody VoluntaryDto.AIRequest req) {
  125. return new TableDataInfo(Lists.newArrayList(), 0);
  126. }
  127. @PostMapping("postAIResult")
  128. @ApiOperation("AI多院校专业结果")
  129. public TableDataInfo postAIResult(@RequestBody String data) {
  130. commService.requireVip();
  131. VoluntaryDto.AIRequest req = new VoluntaryDto.AIRequest();
  132. JSONObject root = JSONObject.parseObject(data);
  133. req.setPageNum(root.getInteger("pageNum"));
  134. req.setPageSize(root.getInteger("pageSize"));
  135. req.setMajorCategory(root.getString("majorCategory"));
  136. req.setUniversities(getCollegeMajor(root));
  137. root.remove("pageNum");
  138. root.remove("pageSize");
  139. root.remove("majorCategory");
  140. root.remove("universities");
  141. VoluntaryDto.AIRequestFilter filter = req.getFilter();
  142. if (root.containsKey("filter")) {
  143. String tempValue;
  144. JSONObject filterObj = root.getJSONObject("filter");
  145. if (StringUtils.isNotBlank(tempValue = filterObj.getString("enumPickType"))) {
  146. try {
  147. filter.setEnumPickType(VoluntaryDto.EnumPickType.valueOf(tempValue));
  148. } catch (IllegalArgumentException e) {
  149. }
  150. }
  151. if (StringUtils.isNotBlank(tempValue = filterObj.getString("enumPickEmpty"))) {
  152. try {
  153. filter.setEnumPickEmpty(NumberUtils.isNumeric(tempValue) ? VoluntaryDto.EnumPickEmpty.values()[Integer.parseInt(tempValue)] : VoluntaryDto.EnumPickEmpty.valueOf(tempValue));
  154. } catch (IllegalArgumentException e) {
  155. }
  156. }
  157. if (filterObj.containsKey("hasClearing")) {
  158. filter.setHasClearing(filterObj.getBoolean("hasClearing")); // true: 仅看补录 false:不看补录 null:不限。默认null
  159. }
  160. if (filterObj.containsKey("majorTypes")) {
  161. filter.setMajorTypes(filterObj.getJSONArray("majorTypes").stream().map(t -> (String) t).collect(Collectors.toList()));
  162. }
  163. if (filterObj.containsKey("keyword")) {
  164. filter.setKeyword(filterObj.getString("keyword"));
  165. }
  166. if (filterObj.containsKey("level")) {
  167. filter.setLevel(filterObj.getJSONArray("level").stream().map(t -> (String) t).collect(Collectors.toList()));
  168. }
  169. if (filterObj.containsKey("type")) {
  170. filter.setType(filterObj.getJSONArray("type").stream().map(t -> (String) t).collect(Collectors.toList()));
  171. }
  172. if (filterObj.containsKey("natureTypeCN")) {
  173. filter.setNatureTypeCN(filterObj.getJSONArray("natureTypeCN").stream().map(t -> (String) t).collect(Collectors.toList()));
  174. }
  175. if (filterObj.containsKey("location")) {
  176. filter.setLocation(filterObj.getJSONArray("location").stream().map(t -> (String) t).collect(Collectors.toList()));
  177. }
  178. root.remove("filter");
  179. }
  180. Map<String, String> form = req.getForm();
  181. for (String field : root.keySet()) {
  182. form.put(field, root.getString(field));
  183. }
  184. return voluntaryService.postAIResult(req);
  185. }
  186. // 填报
  187. @GetMapping("getVoluntaryConfig")
  188. @ApiOperation("取填报配置信息")
  189. public R<VoluntaryDto.VoluntaryConfig> getVoluntaryConfig() { // 如果有填报配置相关,放在这里
  190. return voluntaryService.getVoluntaryConfig();
  191. }
  192. @GetMapping("getVoluntaryList")
  193. @ApiOperation("查询志愿列表")
  194. public TableDataInfo getVoluntaryList(@ApiParam @RequestParam(required = false) VoluntaryDto.EnumVoluntaryType type,
  195. @ApiParam @RequestParam Integer pageNum, @ApiParam @RequestParam Integer pageSize) { // 我的志愿表 // 后台填充快照缺省
  196. PageUtils.startPage(pageNum, pageSize);
  197. List<JSONObject> list = voluntaryService.getVoluntaryList(type);
  198. return getDataTable(list);
  199. }
  200. @PostMapping("submitVoluntary")
  201. @ApiOperation("填报志愿")
  202. public R<Long> submitVoluntary(@RequestBody String body) { // 填报 // 前端+后台按需要剔除一些不需快照的信息(目前主要是院校信息)
  203. JSONObject model = JSONObject.parseObject(body);
  204. return voluntaryService.submitVoluntary(model);
  205. }
  206. @GetMapping("getVoluntary")
  207. @ApiOperation("查询志愿详情")
  208. public R<JSONObject> getVoluntary(@ApiParam @RequestParam Long id) { // 志愿表详情 // 后台填充快照缺省
  209. return voluntaryService.getVoluntary(id);
  210. }
  211. @Log(title = "删除志愿记录", businessType = BusinessType.DELETE)
  212. @DeleteMapping("removeVoluntary/{id}")
  213. public AjaxResult remove(@PathVariable Long id)
  214. {
  215. Map cond = new HashMap();
  216. cond.put("userId", SecurityUtils.getLoginUser().getUserId());
  217. cond.put("id", id);
  218. return toAjax(aWishRecordService.deleteAWishRecordByMap(cond));
  219. }
  220. @GetMapping("getExamTypesNoToken")
  221. @ApiOperation("查询考生类型")
  222. public R<List<String>> getExamTypesNoToken(@RequestParam(required = false) String provinceName) {
  223. return getExamTypes(provinceName, null);
  224. }
  225. @GetMapping("getExamTypes")
  226. @ApiOperation("查询考生类型")
  227. public R<List<String>> getExamTypes(@RequestParam(required = false) String provinceName) {
  228. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  229. return getExamTypes(StringUtils.isNotBlank(provinceName) ? provinceName : sysUser.getLocation(), sysUser);
  230. }
  231. private R<List<String>> getExamTypes(String provinceName, SysUser sysUser) {
  232. List<String> examTypes;
  233. if(Constant.PROVINCE_HUNAN.equals(provinceName)) {
  234. examTypes = Lists.newArrayList(Constant.EXAM_TYPE_PG, Constant.EXAM_TYPE_ZZ);
  235. } else if(Constant.PROVINCE_HENAN.equals(provinceName)) {
  236. examTypes = Lists.newArrayList(Constant.EXAM_TYPE_ZG);
  237. } else {
  238. examTypes = Lists.newArrayList(Constant.EXAM_TYPE_PG, Constant.EXAM_TYPE_ZZ, Constant.EXAM_TYPE_ZG);
  239. }
  240. return R.ok(examTypes); // TODO MF
  241. }
  242. @GetMapping("getExamMajorsNoToken")
  243. @ApiOperation("查询考生专业类")
  244. public R<List<Map>> getExamMajorsNoToken(String provinceName, String examType) {
  245. return getExamMajors(provinceName, examType, null); // TODO MF
  246. }
  247. @GetMapping("getExamMajors")
  248. @ApiOperation("查询考生专业类")
  249. public R<List<Map>> getExamMajors(String provinceName, String examType) {
  250. SysUser sysUser = SecurityUtils.getLoginUser().getUser(); // TODO MF
  251. return getExamMajors(StringUtils.isNotBlank(provinceName) ? provinceName : sysUser.getLocation(), StringUtils.isNotBlank(examType) ? examType : sysUser.getExamType().title(), sysUser);
  252. }
  253. private R<List<Map>> getExamMajors(String provinceName, String examType, SysUser sysUser) {
  254. List<Map> examMajors;
  255. examMajors = busiWishLocationSubmitsService.examMajors(provinceName).stream().map(t -> {
  256. Map d = new HashMap();
  257. d.put("code", t.getCourse());
  258. d.put("name", t.getCourseName());
  259. return d;
  260. }).collect(Collectors.toList());
  261. return R.ok(examMajors); // TODO MF
  262. }
  263. }