| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- package com.ruoyi.learn.domain;
- import com.alibaba.fastjson2.JSONArray;
- import com.alibaba.fastjson2.JSONObject;
- import com.google.common.collect.Lists;
- import com.google.common.collect.Maps;
- import com.ruoyi.enums.QuestionType;
- import io.swagger.annotations.ApiModel;
- import io.swagger.annotations.ApiModelProperty;
- import lombok.AllArgsConstructor;
- import lombok.Data;
- import lombok.NoArgsConstructor;
- import org.apache.commons.collections4.CollectionUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- public class TestPaperVO {
- @ApiModel("基本组卷请求")
- @Data
- public static class TestPapersBuildReq {
- @ApiModelProperty("名称")
- String title;
- @ApiModelProperty("总分")
- Integer total;
- @ApiModelProperty("批次")
- Integer batchId;
- @ApiModelProperty("省份")
- String location;
- @ApiModelProperty("组卷方式")
- String buildType;
- @ApiModelProperty("是否定向")
- Boolean directType;
- @ApiModelProperty("科目")
- Long subjectId;
- @ApiModelProperty("考生类型")
- List<String> examTypes;
- @ApiModelProperty("班级")
- List<Long> classIds;
- @ApiModelProperty("院校")
- List<Long> universityIds;
- @ApiModelProperty("专业组(单院校有效)")
- List<String> groups;
- @ApiModelProperty("专业组(单专业组有效)")
- List<Long> planIds;
- public Map<String, Object> toMap() {
- Map<String, Object> map = Maps.newHashMap();
- map.put("batchId", batchId);
- map.put("location", location);
- map.put("examTypes", examTypes);
- map.put("classIds", classIds);
- map.put("universityIds", universityIds);
- map.put("groups", groups);
- map.put("planIds", planIds);
- return map;
- }
- }
- @ApiModel("手动")
- @Data
- public static class TestPapersHandReq extends TestPapersBuildReq {
- @ApiModelProperty("试题列表")
- List<LearnPaperQuestion> questions;
- }
- @ApiModel("智能")
- @Data
- public static class TestPapersAutoReq extends TestPapersBuildReq {
- @ApiModelProperty("试卷要求")
- PaperDef paperDef;
- }
- @Data
- public static class PaperDef {
- Long total;
- List<Long> knowIds;
- Boolean fillExclude; // 不足时是否填充排除的
- List<TestPaperVO.TypeDef> types;
- }
- @Data
- @AllArgsConstructor
- @NoArgsConstructor
- public static class TypeDef {
- String title;
- String type;
- Integer count;
- Integer score;
- }
- @Data
- @NoArgsConstructor
- public static class PaperDef2 {
- Double score;
- Integer total;
- Boolean fillExclude;
- List<TypeDef2> types;
- List<KnowledgeTypeDef2> knowTypes;
- public PaperDef2(String knowledges, String json) {
- JSONArray root = JSONArray.parseArray(json);
- this.total = 0;
- this.score = 0.0;
- this.types = Lists.newArrayList();
- this.knowTypes = Lists.newArrayList();
- Map<String, TypeDef2> typeMap = Maps.newHashMap(); // 合并题型
- root.forEach(item -> {
- JSONObject obj = (JSONObject) item;
- KnowledgeTypeDef2 ktd = new KnowledgeTypeDef2();
- ktd.setScore(obj.getDouble("score"));
- ktd.setCount(0);
- JSONArray knowledgeList = obj.getJSONArray("knowledges");
- if (null != knowledgeList && knowledgeList.size() > 0) {
- ktd.setKnowledges(knowledgeList.stream().map(t -> Long.parseLong(t.toString())).collect(Collectors.toList()));
- } else {
- ktd.setKnowledges(Stream.of(knowledges.split(",")).map(Long::parseLong).collect(Collectors.toList()));
- }
- JSONObject typeObj = obj.getJSONObject("types");
- List<TypeDef2> subTypes = Lists.newArrayList();
- for(QuestionType qt : QuestionType.values()) {
- String val = typeObj.getString(qt.name().toLowerCase());
- String[] datas;
- if(StringUtils.isBlank(val) || "0".equals(val) || (datas = val.split("/")).length < 2) {
- continue;
- }
- TypeDef2 typeDef = new TypeDef2();
- typeDef.setType(qt);
- typeDef.setTitle(qt.getTitle());
- typeDef.setCount(Integer.parseInt(datas[0]));
- typeDef.setScore(Double.parseDouble(datas[1]));
- TypeDef2 cType = typeMap.get(qt.name());
- if(null == cType) {
- cType = new TypeDef2();
- BeanUtils.copyProperties(typeDef, cType);
- cType.setScore(typeDef.getScore() * typeDef.getCount());
- types.add(cType);
- typeMap.put(qt.name(), cType);
- } else {
- cType.setScore(cType.getScore() + typeDef.getScore() * typeDef.getCount());
- cType.setCount(cType.getCount() + typeDef.getCount());
- }
- this.total += typeDef.getCount();
- ktd.setCount(ktd.getCount() + typeDef.getCount());
- subTypes.add(typeDef);
- }
- if(CollectionUtils.isNotEmpty(subTypes)) {
- ktd.setTypes(subTypes);
- knowTypes.add(ktd);
- }
- this.score += ktd.getScore();
- });
- types.forEach(t -> t.setScore(t.getScore() / t.getCount()));
- }
- }
- @Data
- public static class KnowledgeTypeDef2 {
- Integer count;
- Double score;
- List<Long> knowledges;
- List<TypeDef2> types = Lists.newArrayList();
- }
- @Data
- public static class TypeDef2 {
- String title;
- QuestionType type;
- Integer subType; // 是否子题 1是 0不是
- Integer count;
- Double score;
- }
- }
|