Quellcode durchsuchen

fix 资料商品

he2802 vor 3 Jahren
Ursprung
Commit
91bcef4d0f

+ 21 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionServiceImpl.java

@@ -1,8 +1,10 @@
 package com.zhongzheng.modules.bank.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
+import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.modules.bank.bo.*;
@@ -13,6 +15,7 @@ import com.zhongzheng.modules.bank.service.IExamQuestionService;
 import com.zhongzheng.modules.bank.service.IQuestionBusinessService;
 import com.zhongzheng.modules.bank.service.IQuestionService;
 import com.zhongzheng.modules.bank.vo.QuestionVo;
+import com.zhongzheng.modules.base.domain.ApplyAreas;
 import com.zhongzheng.modules.course.bo.CourseChapterSectionListAddBo;
 import com.zhongzheng.modules.course.domain.CourseChapterSection;
 import com.zhongzheng.modules.course.service.ICourseChapterSectionService;
@@ -153,6 +156,9 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
      */
     private void validEntityBeforeSave(Question entity){
         //TODO 做一些数据校验,如唯一约束
+        if(checkNameUnique(entity)&&Validator.isEmpty(entity.getQuestionId())){
+            throw new CustomException("名称重复");
+        }
     }
 
     @Override
@@ -162,4 +168,19 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         }
         return this.removeByIds(ids);
     }
+
+    private boolean checkNameUnique(Question entity) {
+        Question info = getOne(new LambdaQueryWrapper<Question>()
+                .eq(Question::getPrefixName,entity.getPrefixName()).ne(Question::getContent,entity.getContent()).last("limit 1"));
+        if (Validator.isNotNull(info)) {
+            if(Validator.isNotEmpty(entity.getQuestionId())){
+                if(entity.getQuestionId() != info.getQuestionId()){
+                    return true;
+                }
+            }else{
+                return true;
+            }
+        }
+        return false;
+    }
 }

+ 21 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseServiceImpl.java

@@ -1,9 +1,12 @@
 package com.zhongzheng.modules.course.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
+import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.modules.bank.domain.Question;
 import com.zhongzheng.modules.course.bo.CourseAddBo;
 import com.zhongzheng.modules.course.bo.CourseEditBo;
 import com.zhongzheng.modules.course.bo.CourseQueryBo;
@@ -120,6 +123,9 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
      */
     private void validEntityBeforeSave(Course entity){
         //TODO 做一些数据校验,如唯一约束
+        if(checkNameUnique(entity)){
+            throw new CustomException("名称重复");
+        }
     }
 
     @Override
@@ -129,4 +135,19 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
         }
         return this.removeByIds(ids);
     }
+
+    private boolean checkNameUnique(Course entity) {
+        Course info = getOne(new LambdaQueryWrapper<Course>()
+                .eq(Course::getPrefixName,entity.getPrefixName()).eq(Course::getCourseName,entity.getCourseName()).last("limit 1"));
+        if (Validator.isNotNull(info)) {
+            if(Validator.isNotEmpty(entity.getCourseId())){
+                if(entity.getCourseId() != info.getCourseId()){
+                    return true;
+                }
+            }else{
+                return true;
+            }
+        }
+        return false;
+    }
 }