Commit efd9df07 authored by YangZhaoJun1's avatar YangZhaoJun1

处理自定义异常

parent ac12e2d9
......@@ -68,7 +68,7 @@ public class BClassController extends PaginationController<BClass> {
public Result remove(String id) {
PersistModel data = bClassService.removeBClass(id);
return Result.builder(data,
data.getInfluenceReason(),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
......
......@@ -72,8 +72,7 @@ public class BClassServiceImpl implements BClassService {
@Override
public PersistModel removeBClass(String id) {
if(brClassStudentRepository.selectStuentNumByClassId(id)>0) {
//throw new ServiceException(ResultServiceEnums.CLASS_HAS_STUDENTS);
return new PersistModel(1, (ResultServiceEnums.CLASS_HAS_STUDENTS).getMessage());
throw new ServiceException(ResultServiceEnums.CLASS_HAS_STUDENTS);
}
int line = bClassRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
......
......@@ -74,7 +74,7 @@ public class BLessonController extends PaginationController<BLesson> {
public Result remove(String id) {
PersistModel data = bLessonService.removeBLesson(id);
return Result.builder(data,
data.getInfluenceReason(),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
......
......@@ -166,8 +166,7 @@ public class BLessonServiceImpl implements BLessonService {
@Override
public PersistModel removeBLesson(String id) {
if(bSlRepository.selectslNumByLesson(id)>0) {
//throw new ServiceException(ResultServiceEnums.LESSON_HAS_SL);
return new PersistModel(1, (ResultServiceEnums.LESSON_HAS_SL).getMessage());
throw new ServiceException(ResultServiceEnums.LESSON_HAS_SL);
}
int line = bLessonRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
......
......@@ -127,7 +127,7 @@ public class BStudentController extends PaginationController<BStudent> {
public Result remove(String id) {
PersistModel data = bStudentService.removeBBStudent(id);
return Result.builder(data,
data.getInfluenceReason(),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
......
......@@ -249,13 +249,12 @@ public class BStudentServiceImpl implements BStudentService {
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel removeBBStudent(String id) {
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.setBusinessId(id);
BStudent student = bStudentRepository.selectOne(bStudent);
sysUserMapper.deleteByPrimaryKey(student.getCode());
sysUserMapper.deleteByCode(student.getCode());
int line = bStudentRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
}
......
......@@ -66,7 +66,7 @@ public class BTeacherController extends PaginationController<BTeacher> {
public Result remove(String id) {
PersistModel data = bTeacherService.removeBTeacher(id);
return Result.builder(data,
data.getInfluenceReason(),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
......
......@@ -196,13 +196,12 @@ public class BTeacherServiceImpl implements BTeacherService {
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel removeBTeacher(String id) {
if(bSlRepository.selectSlNumByStuent(id)>0) {
//throw new ServiceException(ResultServiceEnums.TEACHER_HAS_SL);
return new PersistModel(1, (ResultServiceEnums.TEACHER_HAS_SL).getMessage());
throw new ServiceException(ResultServiceEnums.TEACHER_HAS_SL);
}
BTeacher bTeacher = new BTeacher();
bTeacher.setBusinessId(id);
BTeacher teacher = bTeacherRepository.selectOne(bTeacher);
sysUserMapper.deleteByPrimaryKey(teacher.getCode());
sysUserMapper.deleteByCode(teacher.getCode());
int line = bTeacherRepository.deleteByPrimaryKey(id);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
}
......
......@@ -116,7 +116,7 @@ public class BTermController extends PaginationController<BTerm> {
public Result remove(String id) {
PersistModel data = bTermService.removeBTerm(id);
return Result.builder(data,
data.getInfluenceReason(),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
......
......@@ -71,8 +71,7 @@ public class BTermServiceImpl implements BTermService {
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel removeBTerm(String id) {
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);
return new PersistModel(line, MessageConstant.MESSAGE_ALERT_SUCCESS);
......
......@@ -81,8 +81,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
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());
} else if (e instanceof AuthenticationException) {
if (e instanceof BadCredentialsException)
......@@ -151,7 +150,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
private void responseResult(HttpServletResponse response, Result result) {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "application/json;charset=UTF-8");
response.setStatus(result.getCode());
response.setStatus(200);
try {
response.getWriter().write(JSON.toJSONString(result));
} catch (IOException ex) {
......
package org.rcisoft.sys.user.dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.*;
import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.sys.user.entity.SysUser;
import org.rcisoft.sys.user.entity.UserRole;
......@@ -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}")
String selectUserIdByStuOrTeaId(@Param("id") String id, @Param("tab") String table);
@Delete("delete from s_user where login_name = #{code}")
int deleteByCode(String code);
}
server:
port: 8081
context-path: / #ContextPath must start with '/' and not end with '/'
context-path: /edu #ContextPath must start with '/' and not end with '/'
tomcat:
max-threads: 300
#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