Commit efd9df07 authored by YangZhaoJun1's avatar YangZhaoJun1

处理自定义异常

parent ac12e2d9
...@@ -68,7 +68,7 @@ public class BClassController extends PaginationController<BClass> { ...@@ -68,7 +68,7 @@ public class BClassController extends PaginationController<BClass> {
public Result remove(String id) { public Result remove(String id) {
PersistModel data = bClassService.removeBClass(id); PersistModel data = bClassService.removeBClass(id);
return Result.builder(data, return Result.builder(data,
data.getInfluenceReason(), MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
id); id);
} }
......
...@@ -72,8 +72,7 @@ public class BClassServiceImpl implements BClassService { ...@@ -72,8 +72,7 @@ public class BClassServiceImpl implements BClassService {
@Override @Override
public PersistModel removeBClass(String id) { public PersistModel removeBClass(String id) {
if(brClassStudentRepository.selectStuentNumByClassId(id)>0) { if(brClassStudentRepository.selectStuentNumByClassId(id)>0) {
//throw new ServiceException(ResultServiceEnums.CLASS_HAS_STUDENTS); throw new ServiceException(ResultServiceEnums.CLASS_HAS_STUDENTS);
return new PersistModel(1, (ResultServiceEnums.CLASS_HAS_STUDENTS).getMessage());
} }
int line = bClassRepository.deleteByPrimaryKey(id); int line = bClassRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS); return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
......
...@@ -74,7 +74,7 @@ public class BLessonController extends PaginationController<BLesson> { ...@@ -74,7 +74,7 @@ public class BLessonController extends PaginationController<BLesson> {
public Result remove(String id) { public Result remove(String id) {
PersistModel data = bLessonService.removeBLesson(id); PersistModel data = bLessonService.removeBLesson(id);
return Result.builder(data, return Result.builder(data,
data.getInfluenceReason(), MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
id); id);
} }
......
...@@ -166,8 +166,7 @@ public class BLessonServiceImpl implements BLessonService { ...@@ -166,8 +166,7 @@ public class BLessonServiceImpl implements BLessonService {
@Override @Override
public PersistModel removeBLesson(String id) { public PersistModel removeBLesson(String id) {
if(bSlRepository.selectslNumByLesson(id)>0) { if(bSlRepository.selectslNumByLesson(id)>0) {
//throw new ServiceException(ResultServiceEnums.LESSON_HAS_SL); throw new ServiceException(ResultServiceEnums.LESSON_HAS_SL);
return new PersistModel(1, (ResultServiceEnums.LESSON_HAS_SL).getMessage());
} }
int line = bLessonRepository.deleteByPrimaryKey(id); int line = bLessonRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS); return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
......
...@@ -127,7 +127,7 @@ public class BStudentController extends PaginationController<BStudent> { ...@@ -127,7 +127,7 @@ public class BStudentController extends PaginationController<BStudent> {
public Result remove(String id) { public Result remove(String id) {
PersistModel data = bStudentService.removeBBStudent(id); PersistModel data = bStudentService.removeBBStudent(id);
return Result.builder(data, return Result.builder(data,
data.getInfluenceReason(), MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
id); id);
} }
......
...@@ -249,13 +249,12 @@ public class BStudentServiceImpl implements BStudentService { ...@@ -249,13 +249,12 @@ public class BStudentServiceImpl implements BStudentService {
@Transactional(propagation = Propagation.REQUIRED,readOnly = false) @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel removeBBStudent(String id) { public PersistModel removeBBStudent(String id) {
if(brSlStudentRepository.selectSlNumByStuId(id)>0) { if(brSlStudentRepository.selectSlNumByStuId(id)>0) {
return new PersistModel(1, (ResultServiceEnums.STUDENT_HAS_SL).getMessage()); throw new ServiceException(ResultServiceEnums.STUDENT_HAS_SL);
//throw new ServiceException(ResultServiceEnums.STUDENT_HAS_SL);
} }
BStudent bStudent = new BStudent(); BStudent bStudent = new BStudent();
bStudent.setBusinessId(id); bStudent.setBusinessId(id);
BStudent student = bStudentRepository.selectOne(bStudent); BStudent student = bStudentRepository.selectOne(bStudent);
sysUserMapper.deleteByPrimaryKey(student.getCode()); sysUserMapper.deleteByCode(student.getCode());
int line = bStudentRepository.deleteByPrimaryKey(id); int line = bStudentRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS); return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
} }
......
...@@ -66,7 +66,7 @@ public class BTeacherController extends PaginationController<BTeacher> { ...@@ -66,7 +66,7 @@ public class BTeacherController extends PaginationController<BTeacher> {
public Result remove(String id) { public Result remove(String id) {
PersistModel data = bTeacherService.removeBTeacher(id); PersistModel data = bTeacherService.removeBTeacher(id);
return Result.builder(data, return Result.builder(data,
data.getInfluenceReason(), MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
id); id);
} }
......
...@@ -196,13 +196,12 @@ public class BTeacherServiceImpl implements BTeacherService { ...@@ -196,13 +196,12 @@ public class BTeacherServiceImpl implements BTeacherService {
@Transactional(propagation = Propagation.REQUIRED,readOnly = false) @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel removeBTeacher(String id) { public PersistModel removeBTeacher(String id) {
if(bSlRepository.selectSlNumByStuent(id)>0) { if(bSlRepository.selectSlNumByStuent(id)>0) {
//throw new ServiceException(ResultServiceEnums.TEACHER_HAS_SL); throw new ServiceException(ResultServiceEnums.TEACHER_HAS_SL);
return new PersistModel(1, (ResultServiceEnums.TEACHER_HAS_SL).getMessage());
} }
BTeacher bTeacher = new BTeacher(); BTeacher bTeacher = new BTeacher();
bTeacher.setBusinessId(id); bTeacher.setBusinessId(id);
BTeacher teacher = bTeacherRepository.selectOne(bTeacher); BTeacher teacher = bTeacherRepository.selectOne(bTeacher);
sysUserMapper.deleteByPrimaryKey(teacher.getCode()); sysUserMapper.deleteByCode(teacher.getCode());
int line = bTeacherRepository.deleteByPrimaryKey(id); int line = bTeacherRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS); return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
} }
......
...@@ -116,7 +116,7 @@ public class BTermController extends PaginationController<BTerm> { ...@@ -116,7 +116,7 @@ public class BTermController extends PaginationController<BTerm> {
public Result remove(String id) { public Result remove(String id) {
PersistModel data = bTermService.removeBTerm(id); PersistModel data = bTermService.removeBTerm(id);
return Result.builder(data, return Result.builder(data,
data.getInfluenceReason(), MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
id); id);
} }
......
...@@ -71,8 +71,7 @@ public class BTermServiceImpl implements BTermService { ...@@ -71,8 +71,7 @@ public class BTermServiceImpl implements BTermService {
@Transactional(propagation = Propagation.REQUIRED,readOnly = false) @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel removeBTerm(String id) { public PersistModel removeBTerm(String id) {
if(bSlRepository.selectslNumByTermId(id)>0) { if(bSlRepository.selectslNumByTermId(id)>0) {
return new PersistModel(1, (ResultServiceEnums.TERM_HAS_SL).getMessage()); throw new ServiceException(ResultServiceEnums.TERM_HAS_SL);
//throw new ServiceException(ResultServiceEnums.TERM_HAS_SL);
} }
int line = bTermRepository.deleteByPrimaryKey(id); int line = bTermRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS); return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
......
...@@ -81,8 +81,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter { ...@@ -81,8 +81,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
if (handler instanceof HandlerMethod) { if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler; HandlerMethod handlerMethod = (HandlerMethod) handler;
if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误” if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误”
result.setCode(ResultCode.SERVICE_ERROR).setMessage(e.getMessage()); result = ResultGenerator.genFailResult(e.getMessage());
//result = ResultGenerator.genFailResult(e.getMessage());
log.info(e.getMessage()); log.info(e.getMessage());
} else if (e instanceof AuthenticationException) { } else if (e instanceof AuthenticationException) {
if (e instanceof BadCredentialsException) if (e instanceof BadCredentialsException)
...@@ -151,7 +150,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter { ...@@ -151,7 +150,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
private void responseResult(HttpServletResponse response, Result result) { private void responseResult(HttpServletResponse response, Result result) {
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "application/json;charset=UTF-8"); response.setHeader("Content-type", "application/json;charset=UTF-8");
response.setStatus(result.getCode()); response.setStatus(200);
try { try {
response.getWriter().write(JSON.toJSONString(result)); response.getWriter().write(JSON.toJSONString(result));
} catch (IOException ex) { } catch (IOException ex) {
......
package org.rcisoft.sys.user.dao; package org.rcisoft.sys.user.dao;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.sys.user.entity.SysUser; import org.rcisoft.sys.user.entity.SysUser;
import org.rcisoft.sys.user.entity.UserRole; import org.rcisoft.sys.user.entity.UserRole;
...@@ -43,4 +40,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> { ...@@ -43,4 +40,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
@Select("SELECT u.business_id from s_user u left join ${tab} s on u.login_name = s.code where s.business_id = #{id}") @Select("SELECT u.business_id from s_user u left join ${tab} s on u.login_name = s.code where s.business_id = #{id}")
String selectUserIdByStuOrTeaId(@Param("id") String id, @Param("tab") String table); String selectUserIdByStuOrTeaId(@Param("id") String id, @Param("tab") String table);
@Delete("delete from s_user where login_name = #{code}")
int deleteByCode(String code);
} }
server: server:
port: 8081 port: 8081
context-path: / #ContextPath must start with '/' and not end with '/' context-path: /edu #ContextPath must start with '/' and not end with '/'
tomcat: tomcat:
max-threads: 300 max-threads: 300
#uri-encoding: UTF-8 #uri-encoding: UTF-8
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment