Browse Source

Merge remote-tracking branch 'origin/dev' into dev

guq 6 years ago
parent
commit
182f331fd1

+ 10 - 1
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/basic/service/impl/SubjectServiceImpl.java

@@ -12,7 +12,6 @@ import com.usoftchina.smartschool.school.dto.ListReqDTO;
 import com.usoftchina.smartschool.school.exception.BizExceptionCode;
 import com.usoftchina.smartschool.school.mapper.SubjectMapper;
 import com.usoftchina.smartschool.school.po.Subject;
-import com.usoftchina.smartschool.school.po.SysStudent;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
@@ -51,13 +50,23 @@ public class SubjectServiceImpl implements SubjectService {
         }
         Long id = formdata.getSubject_id();
         Long school = BaseContextHolder.getSchoolId();
+        Integer check = 0;
         if (StringUtils.isEmpty(id) || "0".equals(id.toString())) {
             formdata.setSchool_id(school);
             formdata.setSubject_status(1);
+            //检测科目是否存在
+            check = subjectMapper.checkSubject(formdata.getSubject_name());
+            if (check > 0) {
+                throw new BizException(BizExceptionCode.EXISTS_SUBJECT);
+            }
             subjectMapper.insertSelective(formdata);
            id = formdata.getSubject_id();
         } else {
             //更新
+            check = subjectMapper.checkSubject(formdata.getSubject_name());
+            if (check > 0) {
+                throw new BizException(BizExceptionCode.EXISTS_SUBJECT);
+            }
             subjectMapper.updateByPrimaryKeySelective(formdata);
         }
         return new DocBaseDTO(formdata.getSubject_id());

+ 1 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/exception/BizExceptionCode.java

@@ -21,6 +21,7 @@ public enum BizExceptionCode implements BaseExceptionCode {
     EXISTS_CURRICULUM(500005,"存在课表,无法删除"),
     EXISTS_TEACHER_CLASS(500006,"存在任课班级,无法删除"),
     TEACHERS_EXISTS_CLASS(500006,"%s存在任课班级,无法删除"),
+    EXISTS_SUBJECT(500007,"科目已存在"),
     EXISTS_SUBJECT_TEACHER(5000012, "该课程存在班级与任课教师,禁止删除"),
     EXISTS_SCORE_PUBLISH(5000013, "存在已发布成绩,禁止删除"),
     EXISTS_CLASS(500011, "存在班级,无法删除"),

+ 2 - 0
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/mapper/SubjectMapper.java

@@ -26,4 +26,6 @@ public interface SubjectMapper {
     Integer checkTeacherClass(Long id);
 
     Integer checkCurriculum(Long id);
+
+    Integer checkSubject(String subject_name);
 }

+ 4 - 0
applications/school/school-server/src/main/resources/mapper/SubjectMapper.xml

@@ -110,4 +110,8 @@
     cur_tues=#{id} or cur_wed=#{id} or cur_thur=#{id} or cur_fri=#{id}
     or cur_sat=#{id}
   </select>
+
+  <select id="checkSubject" parameterType="String" resultType="integer">
+    select count(1) from subject where  subject_name= #{subject_name}
+  </select>
 </mapper>