diff --git a/src/main/java/com/jsh/erp/controller/FunctionsController.java b/src/main/java/com/jsh/erp/controller/FunctionsController.java index 51c45e70..3ed5aa21 100644 --- a/src/main/java/com/jsh/erp/controller/FunctionsController.java +++ b/src/main/java/com/jsh/erp/controller/FunctionsController.java @@ -41,7 +41,7 @@ public class FunctionsController { @PostMapping(value = "/findMenu") public JSONArray findMenu(@RequestParam(value="pNumber") String pNumber, @RequestParam(value="hasFunctions") String hasFunctions, - HttpServletRequest request) { + HttpServletRequest request)throws Exception { //存放数据json数组 JSONArray dataArray = new JSONArray(); try { @@ -124,7 +124,7 @@ public class FunctionsController { */ @PostMapping(value = "/findRoleFunctions") public JSONArray findRoleFunctions(@RequestParam("UBType") String type, @RequestParam("UBKeyId") String keyId, - HttpServletRequest request) { + HttpServletRequest request)throws Exception { JSONArray arr = new JSONArray(); try { List dataListFun = functionsService.findRoleFunctions("0"); @@ -277,7 +277,7 @@ public class FunctionsController { */ @GetMapping(value = "/findByIds") public BaseResponseInfo findByIds(@RequestParam("functionsIds") String functionsIds, - HttpServletRequest request) { + HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); try { List dataList = functionsService.findByIds(functionsIds); diff --git a/src/main/java/com/jsh/erp/exception/GlobalExceptionHandler.java b/src/main/java/com/jsh/erp/exception/GlobalExceptionHandler.java index 46765fe6..a699dc0b 100644 --- a/src/main/java/com/jsh/erp/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/jsh/erp/exception/GlobalExceptionHandler.java @@ -35,6 +35,14 @@ public class GlobalExceptionHandler { status.put(ExceptionConstants.GLOBAL_RETURNS_CODE, ExceptionConstants.SERVICE_SYSTEM_ERROR_CODE); status.put(ExceptionConstants.GLOBAL_RETURNS_MESSAGE, ExceptionConstants.SERVICE_SYSTEM_ERROR_MSG); log.error("Global Exception Occured => url : {}, msg : {}", request.getRequestURL(), e.getMessage()); + /** + * create by: qiankunpingtai + * create time: 2019/4/18 17:41 + * website:https://qiankunpingtai.cn + * description: + * 这里输出完整的堆栈信息,否则有些异常完全不知道哪里出错了。 + */ + log.error("Global Exception Occured => url : {}", request.getRequestURL(), e); e.printStackTrace(); return status; } diff --git a/src/main/java/com/jsh/erp/service/functions/FunctionsComponent.java b/src/main/java/com/jsh/erp/service/functions/FunctionsComponent.java index 7ec2c311..a48aaff3 100644 --- a/src/main/java/com/jsh/erp/service/functions/FunctionsComponent.java +++ b/src/main/java/com/jsh/erp/service/functions/FunctionsComponent.java @@ -21,16 +21,16 @@ public class FunctionsComponent implements ICommonQuery { private FunctionsService functionsService; @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 getFunctionsList(map); } - private List getFunctionsList(Map map) { + private List getFunctionsList(Map map) throws Exception{ String search = map.get(Constants.SEARCH); String name = StringUtil.getInfo(search, "name"); String type = StringUtil.getInfo(search, "type"); @@ -39,7 +39,7 @@ public class FunctionsComponent 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"); String type = StringUtil.getInfo(search, "type"); @@ -47,27 +47,27 @@ public class FunctionsComponent implements ICommonQuery { } @Override - public int insert(String beanJson, HttpServletRequest request) { + public int insert(String beanJson, HttpServletRequest request)throws Exception { return functionsService.insertFunctions(beanJson, request); } @Override - public int update(String beanJson, Long id) { + public int update(String beanJson, Long id)throws Exception { return functionsService.updateFunctions(beanJson, id); } @Override - public int delete(Long id) { + public int delete(Long id)throws Exception { return functionsService.deleteFunctions(id); } @Override - public int batchDelete(String ids) { + public int batchDelete(String ids)throws Exception { return functionsService.batchDeleteFunctions(ids); } @Override - public int checkIsNameExist(Long id, String name) { + public int checkIsNameExist(Long id, String name)throws Exception { return functionsService.checkIsNameExist(id, name); } diff --git a/src/main/java/com/jsh/erp/service/functions/FunctionsService.java b/src/main/java/com/jsh/erp/service/functions/FunctionsService.java index 1429b367..11e63de4 100644 --- a/src/main/java/com/jsh/erp/service/functions/FunctionsService.java +++ b/src/main/java/com/jsh/erp/service/functions/FunctionsService.java @@ -2,11 +2,14 @@ package com.jsh.erp.service.functions; import com.alibaba.fastjson.JSONObject; import com.jsh.erp.constants.BusinessConstants; +import com.jsh.erp.constants.ExceptionConstants; +import com.jsh.erp.datasource.entities.DepotItem; import com.jsh.erp.datasource.entities.Functions; import com.jsh.erp.datasource.entities.FunctionsExample; import com.jsh.erp.datasource.entities.User; import com.jsh.erp.datasource.mappers.FunctionsMapper; import com.jsh.erp.datasource.mappers.FunctionsMapperEx; +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.StringUtil; @@ -36,92 +39,205 @@ public class FunctionsService { @Resource private LogService logService; - public Functions getFunctions(long id) { - return functionsMapper.selectByPrimaryKey(id); + public Functions getFunctions(long id)throws Exception { + Functions result=null; + try{ + result=functionsMapper.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 getFunctions() { + public List getFunctions()throws Exception { FunctionsExample example = new FunctionsExample(); example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - return functionsMapper.selectByExample(example); + List list=null; + try{ + list=functionsMapper.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, String type, int offset, int rows) { - return functionsMapperEx.selectByConditionFunctions(name, type, offset, rows); + public List select(String name, String type, int offset, int rows)throws Exception { + List list=null; + try{ + list=functionsMapperEx.selectByConditionFunctions(name, type, 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 countFunctions(String name, String type) { - return functionsMapperEx.countsByFunctions(name, type); + public Long countFunctions(String name, String type)throws Exception { + Long result=null; + try{ + result=functionsMapperEx.countsByFunctions(name, type); + }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 insertFunctions(String beanJson, HttpServletRequest request) { + public int insertFunctions(String beanJson, HttpServletRequest request)throws Exception { Functions depot = JSONObject.parseObject(beanJson, Functions.class); - return functionsMapper.insertSelective(depot); + int result=0; + try{ + result=functionsMapper.insertSelective(depot); + }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 updateFunctions(String beanJson, Long id) { + public int updateFunctions(String beanJson, Long id) throws Exception{ Functions depot = JSONObject.parseObject(beanJson, Functions.class); depot.setId(id); - return functionsMapper.updateByPrimaryKeySelective(depot); + int result=0; + try{ + result=functionsMapper.updateByPrimaryKeySelective(depot); + }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 deleteFunctions(Long id) { - return functionsMapper.deleteByPrimaryKey(id); + public int deleteFunctions(Long id)throws Exception { + int result=0; + try{ + result=functionsMapper.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 batchDeleteFunctions(String ids) { + public int batchDeleteFunctions(String ids)throws Exception { List idList = StringUtil.strToLongList(ids); FunctionsExample example = new FunctionsExample(); example.createCriteria().andIdIn(idList); - return functionsMapper.deleteByExample(example); + int result=0; + try{ + result=functionsMapper.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 int checkIsNameExist(Long id, String name) { + public int checkIsNameExist(Long id, String name)throws Exception { FunctionsExample example = new FunctionsExample(); example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - List list = functionsMapper.selectByExample(example); - return list.size(); + List list=null; + try{ + list = functionsMapper.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==null?0:list.size(); } - public List getRoleFunctions(String pNumber) { + public List getRoleFunctions(String pNumber)throws Exception { FunctionsExample example = new FunctionsExample(); example.createCriteria().andEnabledEqualTo(true).andPnumberEqualTo(pNumber) .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); example.setOrderByClause("Sort"); - List list = functionsMapper.selectByExample(example); + List list=null; + try{ + list = functionsMapper.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 findRoleFunctions(String pnumber){ + public List findRoleFunctions(String pnumber)throws Exception{ FunctionsExample example = new FunctionsExample(); example.createCriteria().andEnabledEqualTo(true).andPnumberEqualTo(pnumber) .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); example.setOrderByClause("Sort"); - List list = functionsMapper.selectByExample(example); + List list=null; + try{ + list =functionsMapper.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 findByIds(String functionsIds){ + public List findByIds(String functionsIds)throws Exception{ List idList = StringUtil.strToLongList(functionsIds); FunctionsExample example = new FunctionsExample(); example.createCriteria().andEnabledEqualTo(true).andIdIn(idList) .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); example.setOrderByClause("Sort asc"); - List list = functionsMapper.selectByExample(example); + List list=null; + try{ + list =functionsMapper.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; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public int batchDeleteFunctionsByIds(String ids) { + public int batchDeleteFunctionsByIds(String ids)throws Exception { logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_FUNCTIONS, new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); User userInfo=userService.getCurrentUser(); String [] idArray=ids.split(","); - return functionsMapperEx.batchDeleteFunctionsByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); + int result=0; + try{ + result =functionsMapperEx.batchDeleteFunctionsByIds(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; } }