异常封装之角色信息后台修改

This commit is contained in:
qiankunpingtai
2019-04-19 11:02:55 +08:00
parent f1ced5a839
commit 8b6ae069f1
3 changed files with 124 additions and 35 deletions

View File

@@ -19,16 +19,16 @@ public class RoleComponent implements ICommonQuery {
private RoleService roleService;
@Override
public Object selectOne(String condition) {
public Object selectOne(String condition)throws Exception {
return null;
}
@Override
public List<?> select(Map<String, String> map) {
public List<?> select(Map<String, String> map)throws Exception {
return getRoleList(map);
}
private List<?> getRoleList(Map<String, String> map) {
private List<?> getRoleList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String order = QueryUtils.order(map);
@@ -37,34 +37,34 @@ public class RoleComponent implements ICommonQuery {
}
@Override
public Long counts(Map<String, String> map) {
public Long counts(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
return roleService.countRole(name);
}
@Override
public int insert(String beanJson, HttpServletRequest request) {
public int insert(String beanJson, HttpServletRequest request)throws Exception {
return roleService.insertRole(beanJson, request);
}
@Override
public int update(String beanJson, Long id) {
public int update(String beanJson, Long id)throws Exception {
return roleService.updateRole(beanJson, id);
}
@Override
public int delete(Long id) {
public int delete(Long id)throws Exception {
return roleService.deleteRole(id);
}
@Override
public int batchDelete(String ids) {
public int batchDelete(String ids)throws Exception {
return roleService.batchDeleteRole(ids);
}
@Override
public int checkIsNameExist(Long id, String name) {
public int checkIsNameExist(Long id, String name)throws Exception {
return 0;
}

View File

@@ -2,18 +2,18 @@ package com.jsh.erp.service.role;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Role;
import com.jsh.erp.datasource.entities.RoleExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.entities.UserExample;
import com.jsh.erp.datasource.mappers.RoleMapper;
import com.jsh.erp.datasource.mappers.RoleMapperEx;
import com.jsh.erp.datasource.mappers.UserMapper;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.RegExpTools;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
@@ -23,10 +23,10 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class RoleService {
private Logger logger = LoggerFactory.getLogger(RoleService.class);
@Resource
private RoleMapper roleMapper;
@@ -37,55 +37,135 @@ public class RoleService {
@Resource
private UserService userService;
public Role getRole(long id) {
return roleMapper.selectByPrimaryKey(id);
public Role getRole(long id)throws Exception {
Role result=null;
try{
result=roleMapper.selectByPrimaryKey(id);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return result;
}
public List<Role> getRole() {
public List<Role> getRole()throws Exception {
RoleExample example = new RoleExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
return roleMapper.selectByExample(example);
List<Role> list=null;
try{
list=roleMapper.selectByExample(example);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return list;
}
public List<Role> select(String name, int offset, int rows) {
return roleMapperEx.selectByConditionRole(name, offset, rows);
public List<Role> select(String name, int offset, int rows)throws Exception {
List<Role> list=null;
try{
list=roleMapperEx.selectByConditionRole(name, offset, rows);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return list;
}
public Long countRole(String name) {
return roleMapperEx.countsByRole(name);
public Long countRole(String name)throws Exception {
Long result=null;
try{
result=roleMapperEx.countsByRole(name);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertRole(String beanJson, HttpServletRequest request) {
public int insertRole(String beanJson, HttpServletRequest request)throws Exception {
Role role = JSONObject.parseObject(beanJson, Role.class);
return roleMapper.insertSelective(role);
int result=0;
try{
result=roleMapper.insertSelective(role);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateRole(String beanJson, Long id) {
public int updateRole(String beanJson, Long id) throws Exception{
Role role = JSONObject.parseObject(beanJson, Role.class);
role.setId(id);
return roleMapper.updateByPrimaryKeySelective(role);
int result=0;
try{
result=roleMapper.updateByPrimaryKeySelective(role);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteRole(Long id) {
return roleMapper.deleteByPrimaryKey(id);
public int deleteRole(Long id)throws Exception {
int result=0;
try{
result=roleMapper.deleteByPrimaryKey(id);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteRole(String ids) {
public int batchDeleteRole(String ids) throws Exception{
List<Long> idList = StringUtil.strToLongList(ids);
RoleExample example = new RoleExample();
example.createCriteria().andIdIn(idList);
return roleMapper.deleteByExample(example);
int result=0;
try{
result=roleMapper.deleteByExample(example);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
public List<Role> findUserRole(){
public List<Role> findUserRole()throws Exception{
RoleExample example = new RoleExample();
example.setOrderByClause("Id");
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Role> list = roleMapper.selectByExample(example);
List<Role> list=null;
try{
list=roleMapper.selectByExample(example);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return list;
}
/**
@@ -104,6 +184,15 @@ public class RoleService {
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
return roleMapperEx.batchDeleteRoleByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
int result=0;
try{
result=roleMapperEx.batchDeleteRoleByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
}