xiatian 3 سال پیش
والد
کامیت
91d23f936d

+ 1 - 1
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/core/questions/api/controller/ImportPaperController.java

@@ -94,7 +94,7 @@ public class ImportPaperController extends ControllerSupport {
 			throw e;
 		} catch (Exception e) {
 			LOG.error(e.getMessage(), e);
-			throw new StatusException("500", e.getMessage());
+			throw new StatusException("500", e.getMessage(),e);
 		}
 	}
 

+ 4 - 4
examcloud-core-questions-base/src/main/resources/export_template/origin_paper/document.ftl

@@ -330,7 +330,7 @@
 				<w:rPr>
 					<w:rFonts w:hint="eastAsia" />
 				</w:rPr>
-				<w:t>${subQuestion.quesProperties[0].firstProperty.name}</w:t>
+				<w:t>${subQuestion.quesProperties[0].firstProperty.code}</w:t>
 			</w:r>
 			</#if>
 		</w:p>
@@ -361,7 +361,7 @@
 				<w:rPr>
 					<w:rFonts w:hint="eastAsia" />
 				</w:rPr>
-				<w:t>${subQuestion.quesProperties[0].secondProperty.name}</w:t>
+				<w:t>${subQuestion.quesProperties[0].secondProperty.code}</w:t>
 			</w:r>
 			</#if>
 			</#if>
@@ -492,7 +492,7 @@
 				<w:rPr>
 					<w:rFonts w:hint="eastAsia" />
 				</w:rPr>
-				<w:t>${paperDetailUnit.firstName!}</w:t>
+				<w:t>${paperDetailUnit.firstCode!}</w:t>
 			</w:r>
 		</w:p>
 		<w:p w:rsidP="00F62967" w:rsidR="00F62967"
@@ -519,7 +519,7 @@
 				<w:rPr>
 					<w:rFonts w:hint="eastAsia" />
 				</w:rPr>
-				<w:t>${paperDetailUnit.secondName!}</w:t>
+				<w:t>${paperDetailUnit.secondCode!}</w:t>
 			</w:r>
 		</w:p>
 		<w:p w:rsidP="00F62967" w:rsidR="00F62967"

+ 2 - 2
examcloud-core-questions-dao/src/main/java/cn/com/qmth/examcloud/core/questions/dao/PropertyRepo.java

@@ -19,7 +19,7 @@ public interface PropertyRepo extends MongoRepository<Property, String>, QueryBy
     //查询子节点
     List<Property> findByParentIdOrderByNumber(String parentId);
 
-    //根据课程属性id,一级id,属性名称查询
-    Property findByOrgIdAndCoursePropertyIdAndParentIdAndName(Long orgId, String coursePropertyId, String parentId, String name);
+	//根据课程属性id,一级id,属性名称查询
+    Property findByOrgIdAndCoursePropertyIdAndParentIdAndCode(Long orgId, String coursePropertyId, String parentId, String code);
 
 }

+ 13 - 0
examcloud-core-questions-dao/src/main/java/cn/com/qmth/examcloud/core/questions/dao/entity/Property.java

@@ -23,6 +23,9 @@ public class Property extends IdBase {
 
     @NotNull
     private String name;
+    
+    @NotNull
+    private String code;
 
     @NotNull
     private Integer number;//序号
@@ -77,4 +80,14 @@ public class Property extends IdBase {
         this.remark = remark;
     }
 
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+    
+    
+
 }

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

@@ -11,6 +11,7 @@ public class PropertyConvert {
         dto.setParentId(entity.getParentId());
         dto.setId(entity.getId());
         dto.setName(entity.getName());
+        dto.setCode(entity.getCode()); 
         dto.setNumber(entity.getNumber());
         dto.setRemark(entity.getRemark());
         return dto;
@@ -25,6 +26,7 @@ public class PropertyConvert {
         entity.setName(dto.getName());
         entity.setNumber(dto.getNumber());
         entity.setRemark(dto.getRemark());
+        entity.setCode(dto.getCode());
         return entity;
     }
 

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

@@ -18,6 +18,8 @@ public class PropertyDto implements Serializable {
     private String parentId;
 
     private String id;
+    
+    private String code;
 
     private String name;
 
@@ -94,4 +96,13 @@ public class PropertyDto implements Serializable {
         this.remark = remark;
     }
 
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+    
 }

+ 33 - 51
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/ImportPaperService.java

@@ -29,7 +29,6 @@ import org.docx4j.wml.P;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
@@ -1146,39 +1145,28 @@ public class ImportPaperService {
             }
 
             for (CourseProperty courseProperty : courseProperties) {
-                Property propertyParent = new Property();
-                propertyParent.setCoursePropertyId(courseProperty.getId());
-                propertyParent.setParentId(Property.ROOT_PARENT_ID);
-                propertyParent.setName(firstProperty);
-
                 // 查询一级属性是否存在
-                List<Property> parentProperties = propertyRepo.findAll(Example.of(propertyParent));
+                Property proParent = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdAndCode(
+                		Long.valueOf(paper.getOrgId()), courseProperty.getId(), Property.ROOT_PARENT_ID, firstProperty);
 
                 // 存在一级属性
-                if (parentProperties != null && parentProperties.size() > 0) {
+                if (proParent != null) {
                     isFirstEmpty = false;
-                    for (Property proParent : parentProperties) {
-                        Property propertySon = new Property();
-                        propertySon.setCoursePropertyId(courseProperty.getId());
-                        propertySon.setParentId(proParent.getId());
-                        propertySon.setName(secondProperty);
-
-                        // 查询二级属性
-                        List<Property> sonProperties = propertyRepo.findAll(Example.of(propertySon));
-
-                        // 存在二级属性
-                        if (sonProperties != null && sonProperties.size() > 0) {
-                            isSecondEmpty = false;
-                            for (Property proSon : sonProperties) {
-                                // 保存一级和二级属性
-                                QuesProperty quesProperty = new QuesProperty(proParent, proSon, courseProperty);
-                                String idNumber = quesProperty.getCoursePropertyName() + "-"
-                                        + quesProperty.getFirstProperty().getId() + "-"
-                                        + quesProperty.getSecondProperty().getId();
-                                quesProperty.setId(idNumber);
-                                quesProperties.add(quesProperty);
-                            }
-                        }
+
+                    // 查询二级属性
+                    Property proSon = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdAndCode(
+                    		Long.valueOf(paper.getOrgId()), courseProperty.getId(), proParent.getId(), secondProperty);
+
+                    // 存在二级属性
+                    if (proSon != null) {
+                        isSecondEmpty = false;
+                        // 保存一级和二级属性
+                        QuesProperty quesProperty = new QuesProperty(proParent, proSon, courseProperty);
+                        String idNumber = quesProperty.getCoursePropertyName() + "-"
+                                + quesProperty.getFirstProperty().getId() + "-"
+                                + quesProperty.getSecondProperty().getId();
+                        quesProperty.setId(idNumber);
+                        quesProperties.add(quesProperty);
                     }
                 }
             }
@@ -1211,32 +1199,26 @@ public class ImportPaperService {
 
             for (CourseProperty courseProperty : courseProperties) {
                 // 查询一级属性
-                Property propertyParent = new Property();
-                propertyParent.setCoursePropertyId(courseProperty.getId());
-                propertyParent.setParentId(Property.ROOT_PARENT_ID);
-                propertyParent.setName(firstProperty);
-
-                List<Property> parentProperties = propertyRepo.findAll(Example.of(propertyParent));
+                Property proParent = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdAndCode(
+                		Long.valueOf(paper.getOrgId()), courseProperty.getId(), Property.ROOT_PARENT_ID, firstProperty);
 
                 // 存在一级属性
-                if (parentProperties != null && parentProperties.size() > 0) {
+                if (proParent != null) {
                     isFirstEmpty = false;
-                    for (Property proParent : parentProperties) {
                         // 根据一级属性查询二级属性
-                        List<Property> sonProperties = propertyRepo.findByParentIdOrderByNumber(proParent.getId());
+                    List<Property> sonProperties = propertyRepo.findByParentIdOrderByNumber(proParent.getId());
 
-                        // 存在二级属性,跳过
-                        if (sonProperties != null && sonProperties.size() > 0) {
-                            continue;
-                        } else {
-                            isSecondEmpty = false;
-                            // 保存试题属性
-                            QuesProperty quesProperty = new QuesProperty(proParent, null, courseProperty);
-                            String idNumber = quesProperty.getCoursePropertyName() + "-"
-                                    + quesProperty.getFirstProperty().getId();
-                            quesProperty.setId(idNumber);
-                            quesProperties.add(quesProperty);
-                        }
+                    // 存在二级属性,跳过
+                    if (sonProperties != null && sonProperties.size() > 0) {
+                        continue;
+                    } else {
+                        isSecondEmpty = false;
+                        // 保存试题属性
+                        QuesProperty quesProperty = new QuesProperty(proParent, null, courseProperty);
+                        String idNumber = quesProperty.getCoursePropertyName() + "-"
+                                + quesProperty.getFirstProperty().getId();
+                        quesProperty.setId(idNumber);
+                        quesProperties.add(quesProperty);
                     }
                 }
             }

+ 20 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/dto/PaperDetailUnitExp.java

@@ -33,11 +33,13 @@ public class PaperDetailUnitExp implements Serializable, Comparable<PaperDetailU
      * 一级属性名称(默认取question中第一个)
      */
     private String firstName;
+    private String firstCode;
 
     /**
      * 二级属性名称(默认取question中第一个)
      */
     private String secondName;
+    private String secondCode;
 
     /**
      * 公开,非公开
@@ -155,8 +157,25 @@ public class PaperDetailUnitExp implements Serializable, Comparable<PaperDetailU
     public void setPublicity(String publicity) {
         this.publicity = publicity;
     }
+    
 
-    /**
+    public String getFirstCode() {
+		return firstCode;
+	}
+
+	public void setFirstCode(String firstCode) {
+		this.firstCode = firstCode;
+	}
+
+	public String getSecondCode() {
+		return secondCode;
+	}
+
+	public void setSecondCode(String secondCode) {
+		this.secondCode = secondCode;
+	}
+
+	/**
      * 按照number排序
      *
      * @param paperDetailUnitExp

+ 42 - 12
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/PaperServiceImpl.java

@@ -75,6 +75,7 @@ import cn.com.qmth.examcloud.core.questions.dao.ExamPaperRepo;
 import cn.com.qmth.examcloud.core.questions.dao.PaperDetailRepo;
 import cn.com.qmth.examcloud.core.questions.dao.PaperDetailUnitRepo;
 import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
+import cn.com.qmth.examcloud.core.questions.dao.PropertyRepo;
 import cn.com.qmth.examcloud.core.questions.dao.QuesBakRepo;
 import cn.com.qmth.examcloud.core.questions.dao.QuesRepo;
 import cn.com.qmth.examcloud.core.questions.dao.entity.Course;
@@ -83,6 +84,7 @@ import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
 import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetail;
 import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailUnit;
 import cn.com.qmth.examcloud.core.questions.dao.entity.PaperSearchInfo;
+import cn.com.qmth.examcloud.core.questions.dao.entity.Property;
 import cn.com.qmth.examcloud.core.questions.dao.entity.QuesOption;
 import cn.com.qmth.examcloud.core.questions.dao.entity.QuesProperty;
 import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
@@ -126,7 +128,8 @@ import cn.com.qmth.examcloud.web.support.SpringContextHolder;
 public class PaperServiceImpl implements PaperService {
 
     private static final Logger LOG = LoggerFactory.getLogger(PaperServiceImpl.class);
-
+	@Autowired
+	private PropertyRepo propertyRepo;
     @Autowired
     PaperRepo paperRepo;
 
@@ -710,6 +713,12 @@ public class PaperServiceImpl implements PaperService {
                 for (PaperDetailUnit paperDetailUnit : paperDetailUnits) {
                     PaperDetailUnitExp paperDetailUnitExp = new PaperDetailUnitExp();
                     BeanUtils.copyProperties(paperDetailUnit, paperDetailUnitExp);
+                    fillProperty(paperDetailUnitExp.getQuestion());
+                    if(!CollectionUtils.isEmpty(paperDetailUnitExp.getQuestion().getSubQuestions())) {
+                    	for(Question subque:paperDetailUnitExp.getQuestion().getSubQuestions()) {
+                    		fillProperty(subque);
+                    	}
+                    }
                     paperDetailUnitExps.add(paperDetailUnitExp);
                 }
                 // 选择题,套题下选择题 选项顺序重新排列
@@ -1805,7 +1814,6 @@ public class PaperServiceImpl implements PaperService {
                 throw new StatusException("500", "第" + mainNum + "大题没有小题");
             }
             if (paperDetail != null && paperDetail.getPaperDetailUnits() != null && paperDetail.getPaperDetailUnits().size() > 0) {
-                int minNum = 1;
                 for (PaperDetailUnitExp paperDetailUnit : paperDetail.getPaperDetailUnits()) {
                     Question question = paperDetailUnit.getQuestion();
                     question.setDifficultyDegree(question.getDifficultyDegree() * 10);
@@ -1830,7 +1838,8 @@ public class PaperServiceImpl implements PaperService {
                         //给小题设置序号
                         //                        question.setQuesBodyWord(setSubQuesNum(question.getQuesBodyWord(), minNum++));
                         //                        question.setQuesAnswerWord(setAnswerNum(question.getQuesAnswerWord()));
-                        if (paperDetail.getFirstScore() == null) {
+                    	fillProperty(question);
+                    	if (paperDetail.getFirstScore() == null) {
                             if (question.getScore() == null) {
                                 paperDetail.setFirstScore(0d);
                             } else {
@@ -1841,7 +1850,6 @@ public class PaperServiceImpl implements PaperService {
                         List<Question> subQuesList = question.getSubQuestions();
                         // 套题小题设置序号
                         if (subQuesList != null && subQuesList.size() > 0) {
-                            int index = 1;
                             for (Question subQues : subQuesList) {
                                 subQues.setDifficultyDegree(subQues.getDifficultyDegree() * 10);
                                 //                                subQues.setQuesBodyWord(setSubQuesNum(subQues.getQuesBodyWord(), index++));
@@ -1853,14 +1861,7 @@ public class PaperServiceImpl implements PaperService {
                                         paperDetail.setFirstScore(subQues.getScore());
                                     }
                                 }
-                                List<QuesOption> subOptionList = subQues.getQuesOptions();
-                                if (subOptionList != null && subOptionList.size() > 0) {
-                                    int sub_index = 0;
-                                    for (QuesOption quesOption : subOptionList) {
-                                        //                                        quesOption.setOptionBodyWord(setOptionNum(quesOption.getOptionBodyWord(), getOptionNum(sub_index)));
-                                        sub_index++;
-                                    }
-                                }
+                                fillProperty(subQues);
                             }
                         }
                     }
@@ -1869,9 +1870,11 @@ public class PaperServiceImpl implements PaperService {
                         QuesProperty quesProperty = quesProperties.get(0);
                         if (quesProperty.getFirstProperty() != null) {
                             paperDetailUnit.setFirstName(quesProperty.getFirstProperty().getName());
+                            paperDetailUnit.setFirstCode(quesProperty.getFirstProperty().getCode());
                         }
                         if (quesProperty.getSecondProperty() != null) {
                             paperDetailUnit.setSecondName(quesProperty.getSecondProperty().getName());
+                            paperDetailUnit.setSecondCode(quesProperty.getSecondProperty().getCode());
                         }
                     }
                 }
@@ -1879,6 +1882,33 @@ public class PaperServiceImpl implements PaperService {
         }
         return paperExp;
     }
+    
+    private void fillProperty(Question question) {
+    	List<QuesProperty> ret=new ArrayList<>();
+    	List<QuesProperty> quesProperties = question.getQuesProperties();
+        if (quesProperties != null && quesProperties.size() > 0) {
+        	for(QuesProperty quesProperty:quesProperties) {
+        		if (quesProperty.getFirstProperty() != null
+						&& quesProperty.getFirstProperty().getId() != null) {
+                	Property curProperty = Model.of(propertyRepo.findById(quesProperty.getFirstProperty().getId()));
+                	if(curProperty==null) {
+                		continue;
+                	}
+                	quesProperty.setFirstProperty(curProperty);
+                }
+                if (quesProperty.getSecondProperty() != null
+						&& quesProperty.getSecondProperty().getId() != null) {
+                	Property curProperty = Model.of(propertyRepo.findById(quesProperty.getSecondProperty().getId()));
+                	if(curProperty==null) {
+                		continue;
+                	}
+                	quesProperty.setSecondProperty(curProperty);
+                }
+                ret.add(quesProperty);
+        	}
+        }
+        question.setQuesProperties(ret);
+    }
 
     /**
      * 设置题号

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

@@ -78,6 +78,9 @@ public class PropertyServiceImpl implements PropertyService {
         if (StringUtils.isEmpty(dto.getName())) {
             throw new StatusException(Constants.SYS_CODE_500, "属性名不能为空!");
         }
+        if (StringUtils.isEmpty(dto.getCode())) {
+            throw new StatusException(Constants.SYS_CODE_500, "编码不能为空!");
+        }
 
         if (StringUtils.isBlank(dto.getId())) {
             dto.setId(null);//剔除空字符串ID(导致异常数据)
@@ -86,9 +89,9 @@ public class PropertyServiceImpl implements PropertyService {
         Property property = PropertyConvert.of(dto);
         if (property.getId() == null) {
             //新增
-            Property existProperty = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdAndName(property.getOrgId(), property.getCoursePropertyId(), property.getParentId(), property.getName());
+            Property existProperty = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdAndCode(property.getOrgId(), property.getCoursePropertyId(), property.getParentId(), property.getCode());
             if (existProperty != null) {
-                throw new StatusException(Constants.SYS_CODE_500, "属性名已经存在!");
+                throw new StatusException(Constants.SYS_CODE_500, "编码已经存在!");
             }
 
             Integer number = 0;
@@ -105,11 +108,11 @@ public class PropertyServiceImpl implements PropertyService {
                 throw new StatusException(Constants.SYS_CODE_500, "当前属性已不存在!");
             }
 
-            if (!oldProperty.getName().equals(property.getName())) {
+            if (!oldProperty.getCode().equals(property.getCode())) {
                 //检查是否重名
-                Property existProperty = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdAndName(property.getOrgId(), property.getCoursePropertyId(), property.getParentId(), property.getName());
+                Property existProperty = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdAndCode(property.getOrgId(), property.getCoursePropertyId(), property.getParentId(), property.getCode());
                 if (existProperty != null) {
-                    throw new StatusException(Constants.SYS_CODE_500, "属性名已经存在!");
+                    throw new StatusException(Constants.SYS_CODE_500, "编码已经存在!");
                 }
             }
         }