Bläddra i källkod

fix 资料商品

he2802 3 år sedan
förälder
incheckning
7214c017d4

+ 21 - 4
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseChapterServiceImpl.java

@@ -1,14 +1,13 @@
 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.course.bo.*;
-import com.zhongzheng.modules.course.domain.CourseChapter;
-import com.zhongzheng.modules.course.domain.CourseChapterBusiness;
-import com.zhongzheng.modules.course.domain.CourseChapterSection;
-import com.zhongzheng.modules.course.domain.CourseSectionBusiness;
+import com.zhongzheng.modules.course.domain.*;
 import com.zhongzheng.modules.course.mapper.CourseChapterMapper;
 import com.zhongzheng.modules.course.mapper.CourseSectionMapper;
 import com.zhongzheng.modules.course.service.ICourseChapterBusinessService;
@@ -167,6 +166,9 @@ public class CourseChapterServiceImpl extends ServiceImpl<CourseChapterMapper, C
      */
     private void validEntityBeforeSave(CourseChapter entity){
         //TODO 做一些数据校验,如唯一约束
+        if(checkNameUnique(entity)){
+            throw new CustomException("名称重复");
+        }
     }
 
     @Override
@@ -176,4 +178,19 @@ public class CourseChapterServiceImpl extends ServiceImpl<CourseChapterMapper, C
         }
         return this.removeByIds(ids);
     }
+
+    private boolean checkNameUnique(CourseChapter entity) {
+        CourseChapter info = getOne(new LambdaQueryWrapper<CourseChapter>()
+                .eq(CourseChapter::getPrefixName,entity.getPrefixName()).eq(CourseChapter::getName,entity.getName()).last("limit 1"));
+        if (Validator.isNotNull(info)) {
+            if(Validator.isNotEmpty(entity.getChapterId())){
+                if(entity.getChapterId() != info.getChapterId()){
+                    return true;
+                }
+            }else{
+                return true;
+            }
+        }
+        return false;
+    }
 }

+ 20 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseModuleServiceImpl.java

@@ -1,7 +1,9 @@
 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.course.bo.*;
@@ -152,6 +154,9 @@ public class CourseModuleServiceImpl extends ServiceImpl<CourseModuleMapper, Cou
      */
     private void validEntityBeforeSave(CourseModule entity){
         //TODO 做一些数据校验,如唯一约束
+        if(checkNameUnique(entity)){
+            throw new CustomException("名称重复");
+        }
     }
 
     @Override
@@ -161,4 +166,19 @@ public class CourseModuleServiceImpl extends ServiceImpl<CourseModuleMapper, Cou
         }
         return this.removeByIds(ids);
     }
+
+    private boolean checkNameUnique(CourseModule entity) {
+        CourseModule info = getOne(new LambdaQueryWrapper<CourseModule>()
+                .eq(CourseModule::getPrefixName,entity.getPrefixName()).eq(CourseModule::getModuleName,entity.getModuleName()).last("limit 1"));
+        if (Validator.isNotNull(info)) {
+            if(Validator.isNotEmpty(entity.getModuleId())){
+                if(entity.getModuleId() != info.getModuleId()){
+                    return true;
+                }
+            }else{
+                return true;
+            }
+        }
+        return false;
+    }
 }

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

@@ -1,13 +1,16 @@
 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.course.bo.CourseSectionAddBo;
 import com.zhongzheng.modules.course.bo.CourseSectionBusinessAddBo;
 import com.zhongzheng.modules.course.bo.CourseSectionEditBo;
 import com.zhongzheng.modules.course.bo.CourseSectionQueryBo;
+import com.zhongzheng.modules.course.domain.Course;
 import com.zhongzheng.modules.course.domain.CourseSection;
 import com.zhongzheng.modules.course.domain.CourseSectionBusiness;
 import com.zhongzheng.modules.course.mapper.CourseSectionMapper;
@@ -133,6 +136,9 @@ public class CourseSectionServiceImpl extends ServiceImpl<CourseSectionMapper, C
      */
     private void validEntityBeforeSave(CourseSection entity){
         //TODO 做一些数据校验,如唯一约束
+        if(checkNameUnique(entity)){
+            throw new CustomException("名称重复");
+        }
     }
 
     @Override
@@ -142,4 +148,19 @@ public class CourseSectionServiceImpl extends ServiceImpl<CourseSectionMapper, C
         }
         return this.removeByIds(ids);
     }
+
+    private boolean checkNameUnique(CourseSection entity) {
+        CourseSection info = getOne(new LambdaQueryWrapper<CourseSection>()
+                .eq(CourseSection::getPrefixName,entity.getPrefixName()).eq(CourseSection::getName,entity.getName()).last("limit 1"));
+        if (Validator.isNotNull(info)) {
+            if(Validator.isNotEmpty(entity.getSectionId())){
+                if(entity.getSectionId() != info.getSectionId()){
+                    return true;
+                }
+            }else{
+                return true;
+            }
+        }
+        return false;
+    }
 }