Browse Source

不限难度

xiatian 1 year ago
parent
commit
0c030a9e77

+ 4 - 0
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/core/questions/api/controller/RandomPaperController.java

@@ -81,6 +81,10 @@ public class RandomPaperController extends ControllerSupport {
 		return randomPaperService.saveRandomPaper(domain);
 	}
 	
+	/**组卷小工具调用
+	 * @param req
+	 * @return
+	 */
 	@ApiOperation(value = "获取随机试卷")
 	@PostMapping("create")
 	public GetRandomPaperResp getRandomPaper(GetRandomPaperReq req) {

+ 1 - 1
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/enums/QuestionDifficulty.java

@@ -1,7 +1,7 @@
 package cn.com.qmth.examcloud.core.questions.base.enums;
 
 public enum QuestionDifficulty {
-	HARD("难"), MEDIUM("中"), EASY("易");
+	HARD("难"), MEDIUM("中"), EASY("易"),ANY("不限");
 
 	private final String name;
 

+ 20 - 0
examcloud-core-questions-dao/src/main/java/cn/com/qmth/examcloud/core/questions/dao/entity/dto/PaperDetailUnitStructDto.java

@@ -29,12 +29,16 @@ public class PaperDetailUnitStructDto implements Serializable {
     private Integer publicMedium;//公开中等数量
 
     private Integer publicDifficulty;//公开困难数量
+    
+    private Integer publicAnyDifficulty;//公开不限难度数量
 
     private Integer noPublicSimple;//非公开简单数量
 
     private Integer noPublicMedium;//非公开中等数量
 
     private Integer noPublicDifficulty;//非公开困难数量
+    
+    private Integer noPublicAnyDifficulty;//非公开不限难度数量
 
     public static long getSerialVersionUID() {
         return serialVersionUID;
@@ -136,4 +140,20 @@ public class PaperDetailUnitStructDto implements Serializable {
         this.noPublicDifficulty = noPublicDifficulty;
     }
 
+	public Integer getPublicAnyDifficulty() {
+		return publicAnyDifficulty;
+	}
+
+	public void setPublicAnyDifficulty(Integer publicAnyDifficulty) {
+		this.publicAnyDifficulty = publicAnyDifficulty;
+	}
+
+	public Integer getNoPublicAnyDifficulty() {
+		return noPublicAnyDifficulty;
+	}
+
+	public void setNoPublicAnyDifficulty(Integer noPublicAnyDifficulty) {
+		this.noPublicAnyDifficulty = noPublicAnyDifficulty;
+	}
+
 }

+ 30 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/PaperStructService.java

@@ -9,6 +9,7 @@ import cn.com.qmth.examcloud.core.basic.api.response.GetCourseResp;
 import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
 import cn.com.qmth.examcloud.core.questions.base.Model;
 import cn.com.qmth.examcloud.core.questions.base.enums.PaperStructType;
+import cn.com.qmth.examcloud.core.questions.base.enums.QuestionDifficulty;
 import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
 import cn.com.qmth.examcloud.core.questions.dao.PaperStructRepo;
 import cn.com.qmth.examcloud.core.questions.dao.QuesTypeNameRepo;
@@ -330,6 +331,35 @@ public class PaperStructService {
                         unitStruct.setPropertyGroup(buildGroup(unitStruct));
                         unitStructs.add(unitStruct);
                     }
+                    //公开难度不限
+                    for (int i = 0; i < unitStructDto.getPublicAnyDifficulty(); i++) {
+                        ++number;
+                        PaperDetailUnitStruct unitStruct = new PaperDetailUnitStruct();
+                        unitStruct.setDifficulty(QuestionDifficulty.ANY.getName());
+                        unitStruct.setPublicity(true);
+                        unitStruct.setId(String.valueOf(number));
+                        unitStruct.setNumber(number);
+                        unitStruct.setScore(unitStructDto.getScore());
+                        unitStruct.setQuestionType(unitStructDto.getQuestionType());
+                        unitStruct.setQuesNames(unitStructDto.getQuesNames());
+                        unitStruct.setPropertyGroup(buildGroup(unitStruct));
+                        unitStructs.add(unitStruct);
+                    }
+                    
+                    //非公开难度不限
+                    for (int i = 0; i < unitStructDto.getNoPublicAnyDifficulty(); i++) {
+                        ++number;
+                        PaperDetailUnitStruct unitStruct = new PaperDetailUnitStruct();
+                        unitStruct.setDifficulty(QuestionDifficulty.ANY.getName());
+                        unitStruct.setPublicity(false);
+                        unitStruct.setId(String.valueOf(number));
+                        unitStruct.setNumber(number);
+                        unitStruct.setScore(unitStructDto.getScore());
+                        unitStruct.setQuestionType(unitStructDto.getQuestionType());
+                        unitStruct.setQuesNames(unitStructDto.getQuesNames());
+                        unitStruct.setPropertyGroup(buildGroup(unitStruct));
+                        unitStructs.add(unitStruct);
+                    }
                 }
                 paperDetailStruct.setPaperDetailUnitStructs(unitStructs);
             }

+ 12 - 3
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/randompaper/QuestionDto.java

@@ -1,6 +1,8 @@
 package cn.com.qmth.examcloud.core.questions.service.bean.randompaper;
 
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
 import cn.com.qmth.examcloud.core.questions.dao.entity.Course;
@@ -21,7 +23,7 @@ public class QuestionDto {
 
 	private String orgId; // 机构ID
 
-	private String quesName;// 来源大题
+	private Set<String> quesName;// 来源大题
 
 	private Integer number;
 
@@ -65,13 +67,20 @@ public class QuestionDto {
 		this.orgId = orgId;
 	}
 
-	public String getQuesName() {
+
+	public Set<String> getQuesName() {
 		return quesName;
 	}
 
-	public void setQuesName(String quesName) {
+	public void setQuesName(Set<String> quesName) {
 		this.quesName = quesName;
 	}
+	public void addQuesName(String quesName) {
+		if(this.quesName==null) {
+			this.quesName=new HashSet<>();
+		}
+		this.quesName.add(quesName);
+	}
 
 	public Integer getNumber() {
 		return number;

+ 11 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/randompaper/StructQuestionInfo.java

@@ -15,6 +15,9 @@ public class StructQuestionInfo {
 	private StructQuestionCountInfo mediumInfo=new StructQuestionCountInfo();
 	@ApiModelProperty("易数量")
 	private StructQuestionCountInfo easyInfo=new StructQuestionCountInfo();
+	@ApiModelProperty("不限难度数量")
+	private StructQuestionCountInfo anyInfo=new StructQuestionCountInfo();
+	
 
 	public String getDetailName() {
 		return detailName;
@@ -64,4 +67,12 @@ public class StructQuestionInfo {
 		this.easyInfo = easyInfo;
 	}
 
+	public StructQuestionCountInfo getAnyInfo() {
+		return anyInfo;
+	}
+
+	public void setAnyInfo(StructQuestionCountInfo anyInfo) {
+		this.anyInfo = anyInfo;
+	}
+
 }

+ 8 - 2
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/GenPaperService.java

@@ -223,10 +223,16 @@ public class GenPaperService {
         List<String> quesNames = uc.getUnitStruct().getQuesNames();
         if (quesNames != null && quesNames.size() > 0) {
             if (quesNames.contains(question.getQuesName()) && !uc.finish() && (uc.getUnitStruct().getQuestionType() == question.getQuestionType())) {
-                if (question.getPropertyGroup() != null) {
-                    if (question.getPropertyGroup().contains(uc.getUnitStruct().getPropertyGroup())) {
+                if("all".equals(uc.getUnitStruct().getDifficulty())) {//难度不限
+                    if (question.getPublicity().equals(uc.getUnitStruct().getPublicity())) {
                         return true;
                     }
+                }else {
+	            	if (question.getPropertyGroup() != null) {
+	                    if (question.getPropertyGroup().contains(uc.getUnitStruct().getPropertyGroup())) {
+	                        return true;
+	                    }
+	                }
                 }
             }
         }

+ 82 - 7
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/RandomPaperServiceImpl.java

@@ -243,22 +243,33 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 					Integer simpleCount = 0;
 					Integer mediumCount = 0;
 					Integer difficultyCount = 0;
+					Integer anyCount = 0;
 					if (CollectionUtils.isNotEmpty(paperDetailStruct.getUnitStructs())) {
 						for (PaperDetailUnitStructDto unitStruct : paperDetailStruct.getUnitStructs()) {
 							simpleCount = simpleCount + unitStruct.getPublicSimple() + unitStruct.getNoPublicSimple();
 							mediumCount = mediumCount + unitStruct.getPublicMedium() + unitStruct.getNoPublicMedium();
 							difficultyCount = difficultyCount + unitStruct.getPublicDifficulty()
 									+ unitStruct.getNoPublicDifficulty();
+							anyCount=anyCount+getIntVal(unitStruct.getPublicAnyDifficulty())
+							+getIntVal(unitStruct.getNoPublicAnyDifficulty());
 						}
 					}
 					sqinfo.setHardInfo(new StructQuestionCountInfo(difficultyCount, true));
 					sqinfo.setMediumInfo(new StructQuestionCountInfo(mediumCount, true));
 					sqinfo.setEasyInfo(new StructQuestionCountInfo(simpleCount, true));
+					sqinfo.setAnyInfo(new StructQuestionCountInfo(anyCount, true));
 				}
 			}
 		}
 		return ret;
 	}
+	
+	private int getIntVal(Integer val) {
+		if(val==null) {
+			return 0;
+		}
+		return val;
+	}
 
 	private Double getExactDifficulty(PaperStruct ps) {
 		Double sum = 0.0;
@@ -270,6 +281,10 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			for (PaperDetailStruct paperDetailStruct : ps.getPaperDetailStructs()) {
 				if (CollectionUtils.isNotEmpty(paperDetailStruct.getUnitStructs())) {
 					for (PaperDetailUnitStructDto unitStruct : paperDetailStruct.getUnitStructs()) {
+						if((unitStruct.getNoPublicAnyDifficulty()!=null&&unitStruct.getNoPublicAnyDifficulty()>0)
+								||(unitStruct.getPublicAnyDifficulty()!=null&&unitStruct.getPublicAnyDifficulty()>0)) {
+							return null;
+						}
 						simpleCount = unitStruct.getPublicSimple() + unitStruct.getNoPublicSimple();
 						mediumCount = unitStruct.getPublicMedium() + unitStruct.getNoPublicMedium();
 						difficultyCount = unitStruct.getPublicDifficulty() + unitStruct.getNoPublicDifficulty();
@@ -313,7 +328,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 		cd.setQuestionList(questionList);
 		if (PaperStructType.BLUEPRINT.equals(ps.getPaperStrucType())) {
 			for (PaperDetailUnitDto unit : unitList) {
-				unit.getQuestion().setQuesName(unit.getPaperDetail().getName());
+				unit.getQuestion().addQuesName(unit.getPaperDetail().getName());
 				unit.getQuestion().setPropertyGroup(bulidPropertyGroup(unit.getQuestion()));
 				questionList.add(unit.getQuestion());
 			}
@@ -342,7 +357,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			}
 		} else if (PaperStructType.EXACT.equals(ps.getPaperStrucType())) {
 			for (PaperDetailUnitDto unit : unitList) {
-				unit.getQuestion().setQuesName(unit.getPaperDetail().getName());
+				unit.getQuestion().addQuesName(unit.getPaperDetail().getName());
 				questionList.add(unit.getQuestion());
 			}
 			if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
@@ -365,7 +380,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 						setQuestionInfoByExact(cd);
 					}
 					sqinfo.setTotalCount(sqinfo.getHardInfo().getCount() + sqinfo.getMediumInfo().getCount()
-							+ sqinfo.getEasyInfo().getCount());
+							+ sqinfo.getEasyInfo().getCount()+sqinfo.getAnyInfo().getCount());
 				}
 			}
 		}
@@ -451,6 +466,9 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			if (!si.getEasyInfo().getValid()) {
 				ret.setValid(false);
 			}
+			if (!si.getAnyInfo().getValid()) {
+				ret.setValid(false);
+			}
 		}
 	}
 
@@ -469,6 +487,9 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			if (!si.getEasyInfo().getValid()) {
 				ret.setValid(false);
 			}
+			if (!si.getAnyInfo().getValid()) {
+				ret.setValid(false);
+			}
 			for (RandomPaperQuestionDto dto : si.getHardInfo().getQuestionInfo()) {
 				dto.setQuestionDtos(new ArrayList<>());
 			}
@@ -478,6 +499,9 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			for (RandomPaperQuestionDto dto : si.getEasyInfo().getQuestionInfo()) {
 				dto.setQuestionDtos(new ArrayList<>());
 			}
+			for (RandomPaperQuestionDto dto : si.getAnyInfo().getQuestionInfo()) {
+				dto.setQuestionDtos(new ArrayList<>());
+			}
 		}
 	}
 
@@ -527,6 +551,21 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			cd.setNeedCount(us.getPublicSimple());
 			setQuestionInfoByExactItem(cd);
 		}
+		//不限难度的一定要在最后抽题
+		if (getIntVal(us.getPublicAnyDifficulty()) > 0) {
+			cd.setSi(sqinfo.getAnyInfo());
+			cd.setPub(true);
+			cd.setDifficulty(QuestionDifficulty.ANY.getName());
+			cd.setNeedCount(us.getPublicAnyDifficulty());
+			setQuestionInfoByExactItem(cd);
+		}
+		if (getIntVal(us.getNoPublicAnyDifficulty()) > 0) {
+			cd.setSi(sqinfo.getAnyInfo());
+			cd.setPub(false);
+			cd.setDifficulty(QuestionDifficulty.ANY.getName());
+			cd.setNeedCount(us.getNoPublicAnyDifficulty());
+			setQuestionInfoByExactItem(cd);
+		}
 	}
 
 	private void setQuestionInfoByExactItem(StructQuestionCheckDto cd) {
@@ -667,13 +706,34 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			return "第" + detailNumber + "大题 " + fp.getName() + "-" + pubstr + "-" + difficulty + "题源数量不满足";
 		}
 	}
+	
+	private boolean checkHas(List<String> list,Set<String> set) {
+		if(list==null||set==null) {
+			return false;
+		}
+		if(list.size()==0||set.size()==0) {
+			return false;
+		}
+		for(String s:list) {
+			if(set.contains(s)) {
+				return true;
+			}
+		}
+		return false;
+	}
 
 	private boolean checkExactQuesType(List<String> quesNames, QuesStructType st, Boolean pub, String difficulty,
 			QuestionDto question) {
 		if (CollectionUtils.isNotEmpty(quesNames)) {
-			if (quesNames.contains(question.getQuesName()) && st.equals(question.getQuestionType())) {
-				if (question.getPublicity().equals(pub) && question.getDifficulty().equals(difficulty)) {
-					return true;
+			if (checkHas(quesNames, question.getQuesName())&& st.equals(question.getQuestionType())) {
+				if(QuestionDifficulty.ANY.getName().equals(difficulty)) {
+					if (question.getPublicity().equals(pub)) {
+						return true;
+					}
+				}else {
+					if (question.getPublicity().equals(pub) && question.getDifficulty().equals(difficulty)) {
+						return true;
+					}
 				}
 			}
 		}
@@ -683,7 +743,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 	private boolean checkBlueQuesType(List<String> quesNames, QuesStructType st, String propertyGroup,
 			QuestionDto question) {
 		if (CollectionUtils.isNotEmpty(quesNames)) {
-			if (quesNames.contains(question.getQuesName()) && st.equals(question.getQuestionType())) {
+			if (checkHas(quesNames, question.getQuesName()) && st.equals(question.getQuestionType())) {
 				if (question.getPropertyGroup() != null) {
 					if (question.getPropertyGroup().contains(propertyGroup)) {
 						return true;
@@ -1016,6 +1076,21 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			param.setKey(key);
 			createUnit(param);
 		}
+		//不限难度的一定要在最后抽题
+		if (getIntVal(us.getPublicAnyDifficulty()) > 0) {
+			param.setUnitCount(us.getPublicAnyDifficulty());
+			String key = param.getDetailNumber() + "-" + param.getIndex() + "-" + true + "-"
+					+ QuestionDifficulty.ANY.getName();
+			param.setKey(key);
+			createUnit(param);
+		}
+		if (getIntVal(us.getNoPublicAnyDifficulty()) > 0) {
+			param.setUnitCount(us.getNoPublicAnyDifficulty());
+			String key = param.getDetailNumber() + "-" + param.getIndex() + "-" + false + "-"
+					+ QuestionDifficulty.ANY.getName();
+			param.setKey(key);
+			createUnit(param);
+		}
 	}
 
 	private void createUnitByBlueProp(CreateDefaultPaperParam param) {