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 examTypes; @ApiModelProperty("班级") List classIds; @ApiModelProperty("院校") List universityIds; @ApiModelProperty("专业组(单院校有效)") List groups; @ApiModelProperty("专业组(单专业组有效)") List planIds; public Map toMap() { Map 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 questions; } @ApiModel("智能") @Data public static class TestPapersAutoReq extends TestPapersBuildReq { @ApiModelProperty("试卷要求") PaperDef paperDef; } @Data public static class PaperDef { Long total; List knowIds; Boolean fillExclude; // 不足时是否填充排除的 List 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 types; List 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 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 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 knowledges; List types = Lists.newArrayList(); } @Data public static class TypeDef2 { String title; QuestionType type; Integer subType; // 是否子题 1是 0不是 Integer count; Double score; } }