Browse Source

format existPaperName

deason 5 years ago
parent
commit
93c6cb5af9

+ 10 - 2
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/ClonePaperService.java

@@ -70,30 +70,38 @@ public class ClonePaperService {
         if (StringUtils.isBlank(paperId)) {
             throw new PaperException("待复制的试卷ID不能为空!");
         }
+
         if (StringUtils.isBlank(courseNo)) {
             throw new PaperException("课程编码不能为空!");
         }
+
         if (user == null) {
             throw new PaperException("当前用户信息不能为空!");
         }
+
         if (user.getRootOrgId() == null) {
             throw new PaperException("当前用户的顶级机构ID不能为空!");
         }
+
         if (StringUtils.isBlank(paperName)) {
             throw new PaperException("新试卷名称不能为空!");
         }
-        String existName = paperService.checkPaperName(paperName, user.getRootOrgId().toString());
-        if (existName != null) {
+
+        boolean existName = paperService.checkPaperName(paperName, user.getRootOrgId().toString());
+        if (existName) {
             throw new PaperException("当前试卷名称重复,请重新命名!");
         }
+
         Paper oldPaper = Model.of(paperRepo.findById(paperId));
         if (oldPaper == null) {
             throw new PaperException("待复制的试卷不存在!");
         }
+
         Course course = courseService.getCourse(user.getRootOrgId(), courseNo);
         if (course == null) {
             throw new PaperException("课程信息不存在!");
         }
+
         //复制原试卷的所有试题信息
         Map<PaperDetail, List<PaperDetailUnit>> detailMaps = this.copyPaperDetails(oldPaper, user, course);
 

+ 13 - 8
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/ImportPaperService.java

@@ -1450,11 +1450,13 @@ public class ImportPaperService {
     public Map<String, Object> saveBlankPaper(String courseNo, String paperName, User user) {
         Map<String, Object> returnMap = new HashMap<>();
         Paper paper = new Paper();
-        String msg = paperService.checkPaperName(paperName, user.getRootOrgId().toString());
-        if (msg != null) {
-            returnMap.put("msg", msg);
+
+        boolean existName = paperService.checkPaperName(paperName, user.getRootOrgId().toString());
+        if (existName) {
+            returnMap.put("msg", "试卷名称重复,请重新命名!");
             return returnMap;
         }
+
         paper.setCourseNo(courseNo);
         initPaper(paper, paperName, user);
         PaperDetail pd = new PaperDetail();
@@ -1732,22 +1734,25 @@ public class ImportPaperService {
      */
     public Map<String, Object> clonePaper(String paperId, String paperName, String courseNo, User user) {
         Map<String, Object> map = new HashMap<>();
-        String msg = paperService.checkPaperName(paperName, user.getRootOrgId().toString());
-        if (msg != null) {
-            map.put("msg", msg);
+        boolean existName = paperService.checkPaperName(paperName, user.getRootOrgId().toString());
+        if (existName) {
+            map.put("msg", "试卷名称重复,请重新命名!");
             return map;
         }
+
         //根据paperId查询试卷
         Paper oldPaper = Model.of(paperRepo.findById(paperId));
         if (oldPaper == null) {
-            msg = "克隆试卷不存在";
-            map.put("msg", msg);
+            map.put("msg", "克隆试卷不存在!");
             return map;
         }
+
         //新课程
         Course course = courseService.getCourse(user.getRootOrgId(), courseNo);
+
         //克隆原试卷所有属性
         Paper newPaper = cloneOldPaper(oldPaper, paperName, course, user);
+
         //克隆所有大题和小题
         clonePaperDetails(newPaper, oldPaper, paperName, user, course);
         map.put("msg", "success");

+ 1 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/PaperService.java

@@ -203,7 +203,7 @@ public interface PaperService {
 
     public Paper selectQuestionsToPaper(String paperId, String paperDetailId, List<Question> questions, User user);
 
-    public String checkPaperName(String paperName, String orgId);
+    public boolean checkPaperName(String paperName, String orgId);
 
     public void checkPaperNameNew(String paperName, String orgId) throws Exception;
 

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

@@ -253,13 +253,13 @@ public class PaperServiceImpl implements PaperService {
             oldPaper.setExamRemark(paperExp.getExamRemark());
             if (!oldName.equals(paperExp.getName().trim())) {// 假如改变了试卷名称
                 // 则要效验试卷名称唯一性
-                String msg = this.checkPaperName(paperExp.getName().trim(), user.getRootOrgId().toString());
-                if (msg == null) {
+                boolean existName = this.checkPaperName(paperExp.getName().trim(), user.getRootOrgId().toString());
+                if (existName) {
+                    msgMap.put("msg", "试卷名称重复,请重新命名!");
+                } else {
                     formatPaper(oldPaper, user);
                     paperRepo.save(oldPaper);
                     msgMap.put("msg", "success");
-                } else {
-                    msgMap.put("msg", msg);
                 }
             } else {
                 formatPaper(oldPaper, user);
@@ -940,14 +940,12 @@ public class PaperServiceImpl implements PaperService {
         return paper;
     }
 
-    public String checkPaperName(String paperName, String orgId) {
-        String msg = null;
+    public boolean checkPaperName(String paperName, String orgId) {
         List<Paper> paperList = paperRepo.findByNameAndOrgId(paperName, orgId);
-        if (paperList != null && paperList.size() > 0) {
-            msg = "试卷名称重复,请重新命名";
+        if (CollectionUtils.isNotEmpty(paperList)) {
+            return true;
         }
-        return msg;
-
+        return false;
     }
 
     public void checkPaperNameNew(String paperName, String orgId) throws Exception {