异常封装之功能信息后台修改

This commit is contained in:
qiankunpingtai
2019-04-18 17:58:52 +08:00
parent 17cb110836
commit f7bd049f5a
4 changed files with 163 additions and 39 deletions

View File

@@ -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<Functions> 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<Functions> dataList = functionsService.findByIds(functionsIds);

View File

@@ -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
* websitehttps://qiankunpingtai.cn
* description:
* 这里输出完整的堆栈信息,否则有些异常完全不知道哪里出错了。
*/
log.error("Global Exception Occured => url : {}", request.getRequestURL(), e);
e.printStackTrace();
return status;
}

View File

@@ -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<String, String> map) {
public List<?> select(Map<String, String> map)throws Exception {
return getFunctionsList(map);
}
private List<?> getFunctionsList(Map<String, String> map) {
private List<?> getFunctionsList(Map<String, String> 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<String, String> map) {
public Long counts(Map<String, String> 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);
}

View File

@@ -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<Functions> getFunctions() {
public List<Functions> getFunctions()throws Exception {
FunctionsExample example = new FunctionsExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
return functionsMapper.selectByExample(example);
List<Functions> 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<Functions> select(String name, String type, int offset, int rows) {
return functionsMapperEx.selectByConditionFunctions(name, type, offset, rows);
public List<Functions> select(String name, String type, int offset, int rows)throws Exception {
List<Functions> 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<Long> 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<Functions> list = functionsMapper.selectByExample(example);
return list.size();
List<Functions> 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<Functions> getRoleFunctions(String pNumber) {
public List<Functions> getRoleFunctions(String pNumber)throws Exception {
FunctionsExample example = new FunctionsExample();
example.createCriteria().andEnabledEqualTo(true).andPnumberEqualTo(pNumber)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("Sort");
List<Functions> list = functionsMapper.selectByExample(example);
List<Functions> 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<Functions> findRoleFunctions(String pnumber){
public List<Functions> findRoleFunctions(String pnumber)throws Exception{
FunctionsExample example = new FunctionsExample();
example.createCriteria().andEnabledEqualTo(true).andPnumberEqualTo(pnumber)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("Sort");
List<Functions> list = functionsMapper.selectByExample(example);
List<Functions> 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<Functions> findByIds(String functionsIds){
public List<Functions> findByIds(String functionsIds)throws Exception{
List<Long> idList = StringUtil.strToLongList(functionsIds);
FunctionsExample example = new FunctionsExample();
example.createCriteria().andEnabledEqualTo(true).andIdIn(idList)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("Sort asc");
List<Functions> list = functionsMapper.selectByExample(example);
List<Functions> 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;
}
}