异常封装之角色信息后台修改
This commit is contained in:
@@ -37,7 +37,7 @@ public class RoleController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping(value = "/findUserRole")
|
@PostMapping(value = "/findUserRole")
|
||||||
public JSONArray findUserRole(@RequestParam("UBType") String type, @RequestParam("UBKeyId") String keyId,
|
public JSONArray findUserRole(@RequestParam("UBType") String type, @RequestParam("UBKeyId") String keyId,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request)throws Exception {
|
||||||
JSONArray arr = new JSONArray();
|
JSONArray arr = new JSONArray();
|
||||||
try {
|
try {
|
||||||
List<Role> dataList = roleService.findUserRole();
|
List<Role> dataList = roleService.findUserRole();
|
||||||
@@ -76,7 +76,7 @@ public class RoleController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/list")
|
@PostMapping(value = "/list")
|
||||||
public List<Role> list(HttpServletRequest request) {
|
public List<Role> list(HttpServletRequest request)throws Exception {
|
||||||
return roleService.getRole();
|
return roleService.getRole();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,16 +19,16 @@ public class RoleComponent implements ICommonQuery {
|
|||||||
private RoleService roleService;
|
private RoleService roleService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object selectOne(String condition) {
|
public Object selectOne(String condition)throws Exception {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<?> select(Map<String, String> map) {
|
public List<?> select(Map<String, String> map)throws Exception {
|
||||||
return getRoleList(map);
|
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 search = map.get(Constants.SEARCH);
|
||||||
String name = StringUtil.getInfo(search, "name");
|
String name = StringUtil.getInfo(search, "name");
|
||||||
String order = QueryUtils.order(map);
|
String order = QueryUtils.order(map);
|
||||||
@@ -37,34 +37,34 @@ public class RoleComponent implements ICommonQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long counts(Map<String, String> map) {
|
public Long counts(Map<String, String> map) throws Exception{
|
||||||
String search = map.get(Constants.SEARCH);
|
String search = map.get(Constants.SEARCH);
|
||||||
String name = StringUtil.getInfo(search, "name");
|
String name = StringUtil.getInfo(search, "name");
|
||||||
return roleService.countRole(name);
|
return roleService.countRole(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insert(String beanJson, HttpServletRequest request) {
|
public int insert(String beanJson, HttpServletRequest request)throws Exception {
|
||||||
return roleService.insertRole(beanJson, request);
|
return roleService.insertRole(beanJson, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(String beanJson, Long id) {
|
public int update(String beanJson, Long id)throws Exception {
|
||||||
return roleService.updateRole(beanJson, id);
|
return roleService.updateRole(beanJson, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Long id) {
|
public int delete(Long id)throws Exception {
|
||||||
return roleService.deleteRole(id);
|
return roleService.deleteRole(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int batchDelete(String ids) {
|
public int batchDelete(String ids)throws Exception {
|
||||||
return roleService.batchDeleteRole(ids);
|
return roleService.batchDeleteRole(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int checkIsNameExist(Long id, String name) {
|
public int checkIsNameExist(Long id, String name)throws Exception {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ package com.jsh.erp.service.role;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.jsh.erp.constants.BusinessConstants;
|
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.Role;
|
||||||
import com.jsh.erp.datasource.entities.RoleExample;
|
import com.jsh.erp.datasource.entities.RoleExample;
|
||||||
import com.jsh.erp.datasource.entities.User;
|
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.RoleMapper;
|
||||||
import com.jsh.erp.datasource.mappers.RoleMapperEx;
|
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.log.LogService;
|
||||||
import com.jsh.erp.service.user.UserService;
|
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 com.jsh.erp.utils.StringUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
@@ -23,10 +23,10 @@ import javax.annotation.Resource;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class RoleService {
|
public class RoleService {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(RoleService.class);
|
||||||
@Resource
|
@Resource
|
||||||
private RoleMapper roleMapper;
|
private RoleMapper roleMapper;
|
||||||
|
|
||||||
@@ -37,55 +37,135 @@ public class RoleService {
|
|||||||
@Resource
|
@Resource
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
public Role getRole(long id) {
|
public Role getRole(long id)throws Exception {
|
||||||
return roleMapper.selectByPrimaryKey(id);
|
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();
|
RoleExample example = new RoleExample();
|
||||||
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
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) {
|
public List<Role> select(String name, int offset, int rows)throws Exception {
|
||||||
return roleMapperEx.selectByConditionRole(name, offset, rows);
|
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) {
|
public Long countRole(String name)throws Exception {
|
||||||
return roleMapperEx.countsByRole(name);
|
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)
|
@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);
|
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)
|
@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 role = JSONObject.parseObject(beanJson, Role.class);
|
||||||
role.setId(id);
|
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)
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||||
public int deleteRole(Long id) {
|
public int deleteRole(Long id)throws Exception {
|
||||||
return roleMapper.deleteByPrimaryKey(id);
|
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)
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||||
public int batchDeleteRole(String ids) {
|
public int batchDeleteRole(String ids) throws Exception{
|
||||||
List<Long> idList = StringUtil.strToLongList(ids);
|
List<Long> idList = StringUtil.strToLongList(ids);
|
||||||
RoleExample example = new RoleExample();
|
RoleExample example = new RoleExample();
|
||||||
example.createCriteria().andIdIn(idList);
|
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();
|
RoleExample example = new RoleExample();
|
||||||
example.setOrderByClause("Id");
|
example.setOrderByClause("Id");
|
||||||
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
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;
|
return list;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -104,6 +184,15 @@ public class RoleService {
|
|||||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||||
User userInfo=userService.getCurrentUser();
|
User userInfo=userService.getCurrentUser();
|
||||||
String [] idArray=ids.split(",");
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user