diff --git a/src/main/java/com/jsh/erp/controller/RoleController.java b/src/main/java/com/jsh/erp/controller/RoleController.java index 99ab8843..acef713d 100644 --- a/src/main/java/com/jsh/erp/controller/RoleController.java +++ b/src/main/java/com/jsh/erp/controller/RoleController.java @@ -37,7 +37,7 @@ public class RoleController { */ @PostMapping(value = "/findUserRole") public JSONArray findUserRole(@RequestParam("UBType") String type, @RequestParam("UBKeyId") String keyId, - HttpServletRequest request) { + HttpServletRequest request)throws Exception { JSONArray arr = new JSONArray(); try { List dataList = roleService.findUserRole(); @@ -76,7 +76,7 @@ public class RoleController { } @PostMapping(value = "/list") - public List list(HttpServletRequest request) { + public List list(HttpServletRequest request)throws Exception { return roleService.getRole(); } diff --git a/src/main/java/com/jsh/erp/service/role/RoleComponent.java b/src/main/java/com/jsh/erp/service/role/RoleComponent.java index dfbd0bf6..9c491a15 100644 --- a/src/main/java/com/jsh/erp/service/role/RoleComponent.java +++ b/src/main/java/com/jsh/erp/service/role/RoleComponent.java @@ -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 map) { + public List select(Map map)throws Exception { return getRoleList(map); } - private List getRoleList(Map map) { + private List getRoleList(Map 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 map) { + public Long counts(Map 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; } diff --git a/src/main/java/com/jsh/erp/service/role/RoleService.java b/src/main/java/com/jsh/erp/service/role/RoleService.java index a2ed728f..74267a23 100644 --- a/src/main/java/com/jsh/erp/service/role/RoleService.java +++ b/src/main/java/com/jsh/erp/service/role/RoleService.java @@ -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 getRole() { + public List getRole()throws Exception { RoleExample example = new RoleExample(); example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - return roleMapper.selectByExample(example); + List 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 select(String name, int offset, int rows) { - return roleMapperEx.selectByConditionRole(name, offset, rows); + public List select(String name, int offset, int rows)throws Exception { + List 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 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 findUserRole(){ + public List findUserRole()throws Exception{ RoleExample example = new RoleExample(); example.setOrderByClause("Id"); example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - List list = roleMapper.selectByExample(example); + List 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; } }