TestPaperVO.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package com.ruoyi.learn.domain;
  2. import com.alibaba.fastjson2.JSONArray;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.google.common.collect.Lists;
  5. import com.google.common.collect.Maps;
  6. import com.ruoyi.enums.QuestionType;
  7. import io.swagger.annotations.ApiModel;
  8. import io.swagger.annotations.ApiModelProperty;
  9. import lombok.AllArgsConstructor;
  10. import lombok.Data;
  11. import lombok.NoArgsConstructor;
  12. import org.apache.commons.collections4.CollectionUtils;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.BeanUtils;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.stream.Collectors;
  18. import java.util.stream.Stream;
  19. public class TestPaperVO {
  20. @ApiModel("基本组卷请求")
  21. @Data
  22. public static class TestPapersBuildReq {
  23. @ApiModelProperty("名称")
  24. String title;
  25. @ApiModelProperty("总分")
  26. Integer total;
  27. @ApiModelProperty("批次")
  28. Integer batchId;
  29. @ApiModelProperty("省份")
  30. String location;
  31. @ApiModelProperty("组卷方式")
  32. String buildType;
  33. @ApiModelProperty("是否定向")
  34. Boolean directType;
  35. @ApiModelProperty("科目")
  36. Long subjectId;
  37. @ApiModelProperty("考生类型")
  38. List<String> examTypes;
  39. @ApiModelProperty("班级")
  40. List<Long> classIds;
  41. @ApiModelProperty("院校")
  42. List<Long> universityIds;
  43. @ApiModelProperty("专业组(单院校有效)")
  44. List<String> groups;
  45. @ApiModelProperty("专业组(单专业组有效)")
  46. List<Long> planIds;
  47. public Map<String, Object> toMap() {
  48. Map<String, Object> map = Maps.newHashMap();
  49. map.put("batchId", batchId);
  50. map.put("location", location);
  51. map.put("examTypes", examTypes);
  52. map.put("classIds", classIds);
  53. map.put("universityIds", universityIds);
  54. map.put("groups", groups);
  55. map.put("planIds", planIds);
  56. return map;
  57. }
  58. }
  59. @ApiModel("手动")
  60. @Data
  61. public static class TestPapersHandReq extends TestPapersBuildReq {
  62. @ApiModelProperty("试题列表")
  63. List<LearnPaperQuestion> questions;
  64. }
  65. @ApiModel("智能")
  66. @Data
  67. public static class TestPapersAutoReq extends TestPapersBuildReq {
  68. @ApiModelProperty("试卷要求")
  69. PaperDef paperDef;
  70. }
  71. @Data
  72. public static class PaperDef {
  73. Long total;
  74. List<Long> knowIds;
  75. Boolean fillExclude; // 不足时是否填充排除的
  76. List<TestPaperVO.TypeDef> types;
  77. }
  78. @Data
  79. @AllArgsConstructor
  80. @NoArgsConstructor
  81. public static class TypeDef {
  82. String title;
  83. String type;
  84. Integer count;
  85. Integer score;
  86. }
  87. @Data
  88. @NoArgsConstructor
  89. public static class PaperDef2 {
  90. Double score;
  91. Integer total;
  92. Boolean fillExclude;
  93. List<TypeDef2> types;
  94. List<KnowledgeTypeDef2> knowTypes;
  95. public PaperDef2(String knowledges, String json) {
  96. JSONArray root = JSONArray.parseArray(json);
  97. this.total = 0;
  98. this.score = 0.0;
  99. this.types = Lists.newArrayList();
  100. this.knowTypes = Lists.newArrayList();
  101. Map<String, TypeDef2> typeMap = Maps.newHashMap(); // 合并题型
  102. root.forEach(item -> {
  103. JSONObject obj = (JSONObject) item;
  104. KnowledgeTypeDef2 ktd = new KnowledgeTypeDef2();
  105. ktd.setScore(obj.getDouble("score"));
  106. ktd.setCount(0);
  107. JSONArray knowledgeList = obj.getJSONArray("knowledges");
  108. if (null != knowledgeList && knowledgeList.size() > 0) {
  109. ktd.setKnowledges(knowledgeList.stream().map(t -> Long.parseLong(t.toString())).collect(Collectors.toList()));
  110. } else {
  111. ktd.setKnowledges(Stream.of(knowledges.split(",")).map(Long::parseLong).collect(Collectors.toList()));
  112. }
  113. JSONObject typeObj = obj.getJSONObject("types");
  114. List<TypeDef2> subTypes = Lists.newArrayList();
  115. for(QuestionType qt : QuestionType.values()) {
  116. String val = typeObj.getString(qt.name().toLowerCase());
  117. String[] datas;
  118. if(StringUtils.isBlank(val) || "0".equals(val) || (datas = val.split("/")).length < 2) {
  119. continue;
  120. }
  121. TypeDef2 typeDef = new TypeDef2();
  122. typeDef.setType(qt);
  123. typeDef.setTitle(qt.getTitle());
  124. typeDef.setCount(Integer.parseInt(datas[0]));
  125. typeDef.setScore(Double.parseDouble(datas[1]));
  126. TypeDef2 cType = typeMap.get(qt.name());
  127. if(null == cType) {
  128. cType = new TypeDef2();
  129. BeanUtils.copyProperties(typeDef, cType);
  130. cType.setScore(typeDef.getScore() * typeDef.getCount());
  131. types.add(cType);
  132. typeMap.put(qt.name(), cType);
  133. } else {
  134. cType.setScore(cType.getScore() + typeDef.getScore() * typeDef.getCount());
  135. cType.setCount(cType.getCount() + typeDef.getCount());
  136. }
  137. this.total += typeDef.getCount();
  138. ktd.setCount(ktd.getCount() + typeDef.getCount());
  139. subTypes.add(typeDef);
  140. }
  141. if(CollectionUtils.isNotEmpty(subTypes)) {
  142. ktd.setTypes(subTypes);
  143. knowTypes.add(ktd);
  144. }
  145. this.score += ktd.getScore();
  146. });
  147. types.forEach(t -> t.setScore(t.getScore() / t.getCount()));
  148. }
  149. }
  150. @Data
  151. public static class KnowledgeTypeDef2 {
  152. Integer count;
  153. Double score;
  154. List<Long> knowledges;
  155. List<TypeDef2> types = Lists.newArrayList();
  156. }
  157. @Data
  158. public static class TypeDef2 {
  159. String title;
  160. QuestionType type;
  161. Integer subType; // 是否子题 1是 0不是
  162. Integer count;
  163. Double score;
  164. }
  165. }