Browse Source

异常信息补充

Signed-off-by: guoWenHao <2532478980@qq.com>
guoWenHao 8 months ago
parent
commit
47d4db22b9

+ 3 - 0
teacher-common/src/main/java/com/example/constant/MessageConstant.java

@@ -7,6 +7,9 @@ public class MessageConstant {
 
 
     public static final String PASSWORD_ERROR = "密码错误";
     public static final String PASSWORD_ERROR = "密码错误";
     public static final String ACCOUNT_NOT_FOUND = "账号不存在";
     public static final String ACCOUNT_NOT_FOUND = "账号不存在";
+    public static final String WORK_NOT_FOUND = "著作不存在";
+    public static final String AWORDS_NOT_FOUND = "获奖不存在";
+    public static final String THESIS_NOT_FOUND = "论文不存在";
     public static final String ACCOUNT_LOCKED = "账号被锁定";
     public static final String ACCOUNT_LOCKED = "账号被锁定";
     public static final String ALREADY_EXISTS = "已存在";
     public static final String ALREADY_EXISTS = "已存在";
     public static final String UNKNOWN_ERROR = "未知错误";
     public static final String UNKNOWN_ERROR = "未知错误";

+ 15 - 0
teacher-common/src/main/java/com/example/exception/AwordsNotFoundException.java

@@ -0,0 +1,15 @@
+package com.example.exception;
+
+/**
+ * 账号不存在异常
+ */
+public class AwordsNotFoundException extends BaseException {
+
+    public AwordsNotFoundException() {
+    }
+
+    public AwordsNotFoundException(String msg) {
+        super(msg);
+    }
+
+}

+ 15 - 0
teacher-common/src/main/java/com/example/exception/ThesisNotFoundException.java

@@ -0,0 +1,15 @@
+package com.example.exception;
+
+/**
+ * 账号不存在异常
+ */
+public class ThesisNotFoundException extends BaseException {
+
+    public ThesisNotFoundException() {
+    }
+
+    public ThesisNotFoundException(String msg) {
+        super(msg);
+    }
+
+}

+ 15 - 0
teacher-common/src/main/java/com/example/exception/WorkNotFoundException.java

@@ -0,0 +1,15 @@
+package com.example.exception;
+
+/**
+ * 账号不存在异常
+ */
+public class WorkNotFoundException extends BaseException {
+
+    public WorkNotFoundException() {
+    }
+
+    public WorkNotFoundException(String msg) {
+        super(msg);
+    }
+
+}

+ 5 - 0
teacher-serve/src/main/java/com/example/service/impl/AwardsServiceImpl.java

@@ -1,9 +1,11 @@
 package com.example.service.impl;
 package com.example.service.impl;
 
 
+import com.example.constant.MessageConstant;
 import com.example.context.BaseContext;
 import com.example.context.BaseContext;
 import com.example.dto.AwardsDTO;
 import com.example.dto.AwardsDTO;
 import com.example.entity.Awards;
 import com.example.entity.Awards;
 import com.example.entity.Teacher;
 import com.example.entity.Teacher;
+import com.example.exception.AwordsNotFoundException;
 import com.example.mapper.AwardsMapper;
 import com.example.mapper.AwardsMapper;
 import com.example.mapper.TeacherMapper;
 import com.example.mapper.TeacherMapper;
 import com.example.service.AwardsService;
 import com.example.service.AwardsService;
@@ -61,6 +63,9 @@ public class AwardsServiceImpl implements AwardsService {
 
 
         AwardsVO awardsVO = new AwardsVO();
         AwardsVO awardsVO = new AwardsVO();
         Awards awards = awardsMapper.getById(id);
         Awards awards = awardsMapper.getById(id);
+        if(awards == null){
+            throw new AwordsNotFoundException(MessageConstant.AWORDS_NOT_FOUND);
+        }
         BeanUtils.copyProperties(awards,awardsVO);
         BeanUtils.copyProperties(awards,awardsVO);
         return awardsVO;
         return awardsVO;
     }
     }

+ 12 - 6
teacher-serve/src/main/java/com/example/service/impl/ThesisServiceImpl.java

@@ -1,9 +1,11 @@
 package com.example.service.impl;
 package com.example.service.impl;
 
 
+import com.example.constant.MessageConstant;
 import com.example.context.BaseContext;
 import com.example.context.BaseContext;
 import com.example.dto.ThesisDTO;
 import com.example.dto.ThesisDTO;
 import com.example.entity.Awards;
 import com.example.entity.Awards;
 import com.example.entity.Thesis;
 import com.example.entity.Thesis;
+import com.example.exception.ThesisNotFoundException;
 import com.example.mapper.ThesisMapper;
 import com.example.mapper.ThesisMapper;
 import com.example.service.ThesisService;
 import com.example.service.ThesisService;
 import com.example.vo.ThesisVO;
 import com.example.vo.ThesisVO;
@@ -16,11 +18,12 @@ public class ThesisServiceImpl implements ThesisService {
 
 
     @Autowired
     @Autowired
     private ThesisMapper thesisMapper;
     private ThesisMapper thesisMapper;
+
     @Override
     @Override
     public void uploadThesis(ThesisDTO thesisDTO) {
     public void uploadThesis(ThesisDTO thesisDTO) {
         Thesis thesis = new Thesis();
         Thesis thesis = new Thesis();
         BeanUtils.copyProperties(thesisDTO, thesis);
         BeanUtils.copyProperties(thesisDTO, thesis);
-        Long id= BaseContext.getCurrentId();
+        Long id = BaseContext.getCurrentId();
         thesis.setTeacherId(id);
         thesis.setTeacherId(id);
         thesisMapper.uploadThesis(thesis);
         thesisMapper.uploadThesis(thesis);
         thesisMapper.addThesisNum(id);
         thesisMapper.addThesisNum(id);
@@ -28,17 +31,20 @@ public class ThesisServiceImpl implements ThesisService {
 
 
     @Override
     @Override
     public void updateThesis(ThesisDTO thesisDTO, Long id) {
     public void updateThesis(ThesisDTO thesisDTO, Long id) {
-        Thesis thesis=new Thesis();
-        BeanUtils.copyProperties(thesisDTO,thesis);
+        Thesis thesis = new Thesis();
+        BeanUtils.copyProperties(thesisDTO, thesis);
         thesis.setId(id);
         thesis.setId(id);
         thesisMapper.updateThesis(thesis);
         thesisMapper.updateThesis(thesis);
     }
     }
 
 
     @Override
     @Override
     public ThesisVO getById(Long id) {
     public ThesisVO getById(Long id) {
-        ThesisVO thesisVO=new ThesisVO();
-        Thesis thesis=thesisMapper.getById(id);
-        BeanUtils.copyProperties(thesis,thesisVO);
+        ThesisVO thesisVO = new ThesisVO();
+        Thesis thesis = thesisMapper.getById(id);
+        if (thesis == null) {
+            throw new ThesisNotFoundException(MessageConstant.THESIS_NOT_FOUND);
+        }
+        BeanUtils.copyProperties(thesis, thesisVO);
         return thesisVO;
         return thesisVO;
     }
     }
 
 

+ 5 - 0
teacher-serve/src/main/java/com/example/service/impl/WorkServiceImpl.java

@@ -1,10 +1,12 @@
 package com.example.service.impl;
 package com.example.service.impl;
 
 
+import com.example.constant.MessageConstant;
 import com.example.context.BaseContext;
 import com.example.context.BaseContext;
 import com.example.dto.AwardsDTO;
 import com.example.dto.AwardsDTO;
 import com.example.dto.WorkDTO;
 import com.example.dto.WorkDTO;
 import com.example.entity.Awards;
 import com.example.entity.Awards;
 import com.example.entity.Work;
 import com.example.entity.Work;
+import com.example.exception.WorkNotFoundException;
 import com.example.mapper.WorkMapper;
 import com.example.mapper.WorkMapper;
 import com.example.service.WorkService;
 import com.example.service.WorkService;
 import com.example.vo.WorkVO;
 import com.example.vo.WorkVO;
@@ -57,6 +59,9 @@ public class WorkServiceImpl implements WorkService {
     public WorkVO getById(Long id) {
     public WorkVO getById(Long id) {
         WorkVO workVO = new WorkVO();
         WorkVO workVO = new WorkVO();
         Work work = workMapper.getById(id);
         Work work = workMapper.getById(id);
+        if(work == null){
+            throw new WorkNotFoundException(MessageConstant.WORK_NOT_FOUND);
+        }
         BeanUtils.copyProperties(work,workVO);
         BeanUtils.copyProperties(work,workVO);
         return workVO;
         return workVO;
     }
     }