diff --git a/src/main/java/com/jsh/erp/controller/UserBusinessController.java b/src/main/java/com/jsh/erp/controller/UserBusinessController.java index 66ef1dc9..155a6aa3 100644 --- a/src/main/java/com/jsh/erp/controller/UserBusinessController.java +++ b/src/main/java/com/jsh/erp/controller/UserBusinessController.java @@ -36,7 +36,7 @@ public class UserBusinessController { @GetMapping(value = "/getBasicData") public BaseResponseInfo getBasicData(@RequestParam(value = "KeyId") String keyId, @RequestParam(value = "Type") String type, - HttpServletRequest request) { + HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); try { List list = userBusinessService.getBasicData(keyId, type); @@ -55,7 +55,7 @@ public class UserBusinessController { @GetMapping(value = "/checkIsValueExist") public String checkIsValueExist(@RequestParam(value ="type", required = false) String type, @RequestParam(value ="keyId", required = false) String keyId, - HttpServletRequest request) { + HttpServletRequest request)throws Exception { Map objectMap = new HashMap(); Long id = userBusinessService.checkIsValueExist(type, keyId); if(id != null) { @@ -76,7 +76,7 @@ public class UserBusinessController { @PostMapping(value = "/updateBtnStr") public BaseResponseInfo updateBtnStr(@RequestParam(value ="userBusinessId", required = false) Long userBusinessId, @RequestParam(value ="btnStr", required = false) String btnStr, - HttpServletRequest request) { + HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); try { int back = userBusinessService.updateBtnStr(userBusinessId, btnStr); diff --git a/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessComponent.java b/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessComponent.java index dabdd340..04ca587f 100644 --- a/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessComponent.java +++ b/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessComponent.java @@ -22,21 +22,21 @@ public class UserBusinessComponent implements ICommonQuery { private UserBusinessService userBusinessService; @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 getUserBusinessList(map); } - private List getUserBusinessList(Map map) { + private List getUserBusinessList(Map map)throws Exception { return null; } @Override - public Long counts(Map map) { + public Long counts(Map map)throws Exception { return BusinessConstants.DEFAULT_LIST_NULL_NUMBER; } @@ -51,17 +51,17 @@ public class UserBusinessComponent implements ICommonQuery { } @Override - public int delete(Long id) { + public int delete(Long id)throws Exception { return userBusinessService.deleteUserBusiness(id); } @Override - public int batchDelete(String ids) { + public int batchDelete(String ids)throws Exception { return userBusinessService.batchDeleteUserBusiness(ids); } @Override - public int checkIsNameExist(Long id, String name) { + public int checkIsNameExist(Long id, String name)throws Exception { return userBusinessService.checkIsNameExist(id, name); } diff --git a/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessService.java b/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessService.java index 69d264c9..d769a6cb 100644 --- a/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessService.java +++ b/src/main/java/com/jsh/erp/service/userBusiness/UserBusinessService.java @@ -2,16 +2,14 @@ package com.jsh.erp.service.userBusiness; import com.alibaba.fastjson.JSONObject; import com.jsh.erp.constants.BusinessConstants; -import com.jsh.erp.datasource.entities.App; -import com.jsh.erp.datasource.entities.Functions; -import com.jsh.erp.datasource.entities.User; -import com.jsh.erp.datasource.entities.UserBusiness; -import com.jsh.erp.datasource.entities.UserBusinessExample; +import com.jsh.erp.constants.ExceptionConstants; +import com.jsh.erp.datasource.entities.*; import com.jsh.erp.datasource.mappers.UserBusinessMapper; +import com.jsh.erp.datasource.mappers.UserBusinessMapperEx; +import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.service.CommonQueryManager; import com.jsh.erp.service.app.AppService; import com.jsh.erp.service.functions.FunctionsService; -import com.jsh.erp.datasource.mappers.UserBusinessMapperEx; import com.jsh.erp.service.log.LogService; import com.jsh.erp.service.user.UserService; import com.jsh.erp.utils.StringUtil; @@ -25,11 +23,7 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Date; -import java.util.List; -import java.util.Set; +import java.util.*; @Service public class UserBusinessService { @@ -53,77 +47,145 @@ public class UserBusinessService { @Resource private CommonQueryManager configResourceManager; - public UserBusiness getUserBusiness(long id) { - return userBusinessMapper.selectByPrimaryKey(id); + public UserBusiness getUserBusiness(long id)throws Exception { + UserBusiness result=null; + try{ + result=userBusinessMapper.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 getUserBusiness() { + public List getUserBusiness()throws Exception { UserBusinessExample example = new UserBusinessExample(); example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - return userBusinessMapper.selectByExample(example); + List list=null; + try{ + list=userBusinessMapper.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 insertUserBusiness(String beanJson, HttpServletRequest request) throws Exception { UserBusiness userBusiness = JSONObject.parseObject(beanJson, UserBusiness.class); - int inserts = userBusinessMapper.insertSelective(userBusiness); - // 更新应用权限 - if (BusinessConstants.TYPE_NAME_ROLE_FUNCTIONS.equals(userBusiness.getType()) && inserts > 0) { - inserts = insertOrUpdateAppValue(BusinessConstants.TYPE_NAME_ROLE_APP, userBusiness.getKeyid(), userBusiness.getValue()); + int result=0; + try{ + result=userBusinessMapper.insertSelective(userBusiness); + }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 inserts; + // 更新应用权限 + if (BusinessConstants.TYPE_NAME_ROLE_FUNCTIONS.equals(userBusiness.getType()) && result > 0) { + result = insertOrUpdateAppValue(BusinessConstants.TYPE_NAME_ROLE_APP, userBusiness.getKeyid(), userBusiness.getValue()); + } + return result; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) public int updateUserBusiness(String beanJson, Long id) throws Exception { UserBusiness userBusiness = JSONObject.parseObject(beanJson, UserBusiness.class); userBusiness.setId(id); - int updates = userBusinessMapper.updateByPrimaryKeySelective(userBusiness); - // 更新应用权限 - if (BusinessConstants.TYPE_NAME_ROLE_FUNCTIONS.equals(userBusiness.getType()) && updates > 0) { - updates = insertOrUpdateAppValue(BusinessConstants.TYPE_NAME_ROLE_APP, userBusiness.getKeyid(), userBusiness.getValue()); + int result=0; + try{ + result=userBusinessMapper.updateByPrimaryKeySelective(userBusiness); + }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 updates; + // 更新应用权限 + if (BusinessConstants.TYPE_NAME_ROLE_FUNCTIONS.equals(userBusiness.getType()) && result > 0) { + result = insertOrUpdateAppValue(BusinessConstants.TYPE_NAME_ROLE_APP, userBusiness.getKeyid(), userBusiness.getValue()); + } + return result; } @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public int deleteUserBusiness(Long id) { - return userBusinessMapper.deleteByPrimaryKey(id); + public int deleteUserBusiness(Long id)throws Exception { + int result=0; + try{ + result=userBusinessMapper.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 batchDeleteUserBusiness(String ids) { + public int batchDeleteUserBusiness(String ids)throws Exception { List idList = StringUtil.strToLongList(ids); UserBusinessExample example = new UserBusinessExample(); example.createCriteria().andIdIn(idList); - return userBusinessMapper.deleteByExample(example); + int result=0; + try{ + result=userBusinessMapper.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 { return 1; } - public List getBasicData(String keyId, String type){ + public List getBasicData(String keyId, String type)throws Exception{ UserBusinessExample example = new UserBusinessExample(); example.createCriteria().andKeyidEqualTo(keyId).andTypeEqualTo(type) .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - List list = userBusinessMapper.selectByExample(example); + List list=null; + try{ + list= userBusinessMapper.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 Long checkIsValueExist(String type, String keyId) { + public Long checkIsValueExist(String type, String keyId)throws Exception { UserBusinessExample example = new UserBusinessExample(); example.createCriteria().andTypeEqualTo(type).andKeyidEqualTo(keyId) .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - List list = userBusinessMapper.selectByExample(example); + List list=null; + try{ + list= userBusinessMapper.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); + } Long id = null; - if(list.size() > 0) { + if(list!=null&&list.size() > 0) { id = list.get(0).getId(); } return id; } - public Boolean checkIsUserBusinessExist(String TypeVale, String KeyIdValue, String UBValue) { + public Boolean checkIsUserBusinessExist(String TypeVale, String KeyIdValue, String UBValue)throws Exception { UserBusinessExample example = new UserBusinessExample(); String newVaule = "%" + UBValue + "%"; if(TypeVale !=null && KeyIdValue !=null) { @@ -133,8 +195,16 @@ public class UserBusinessService { example.createCriteria().andValueLike(newVaule) .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); } - List list = userBusinessMapper.selectByExample(example); - if(list.size() > 0) { + List list=null; + try{ + list= userBusinessMapper.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); + } + if(list!=null&&list.size() > 0) { return true; } else { return false; @@ -150,23 +220,48 @@ public class UserBusinessService { userBusiness.setBtnstr(btnStr); UserBusinessExample example = new UserBusinessExample(); example.createCriteria().andIdEqualTo(userBusinessId); - return userBusinessMapper.updateByExampleSelective(userBusiness, example); + int result=0; + try{ + result= userBusinessMapper.updateByExampleSelective(userBusiness, 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 findRoleByUserId(String userId){ + public List findRoleByUserId(String userId)throws Exception{ UserBusinessExample example = new UserBusinessExample(); example.createCriteria().andKeyidEqualTo(userId).andTypeEqualTo("UserRole") .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - List list = userBusinessMapper.selectByExample(example); + List list=null; + try{ + list= userBusinessMapper.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 findAppByRoles(String roles){ + public List findAppByRoles(String roles)throws Exception{ List rolesList = StringUtil.strToStringList(roles); UserBusinessExample example = new UserBusinessExample(); example.createCriteria().andKeyidIn(rolesList).andTypeEqualTo("RoleAPP") .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); - List list = userBusinessMapper.selectByExample(example); + List list=null; + try{ + list= userBusinessMapper.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; } @@ -177,7 +272,16 @@ public class UserBusinessService { ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); User userInfo=userService.getCurrentUser(); String [] idArray=ids.split(","); - return userBusinessMapperEx.batchDeleteUserBusinessByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); + int result=0; + try{ + result= userBusinessMapperEx.batchDeleteUserBusinessByIds(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; } /** @@ -188,48 +292,45 @@ public class UserBusinessService { * @return */ public int insertOrUpdateAppValue(String type, String keyId, String functionIds) throws Exception{ - - int updates = 0; - + int result=0; functionIds = functionIds.replaceAll("\\]\\[", ","). replaceAll("\\[","").replaceAll("\\]",""); - List functionsList = functionsService.findByIds(functionIds); - if (!CollectionUtils.isEmpty(functionsList)) { - Set appNumbers = new HashSet<>(); String appNumber; for (Functions functions : functionsList) { - appNumber = functions.getNumber().substring(0, 2); appNumbers.add(appNumber); } - List appNumberList = new ArrayList<>(appNumbers); List appList = appService.findAppByNumber(appNumberList); - StringBuilder appIdSb = new StringBuilder(); - if (!CollectionUtils.isEmpty(appList)) { for (App app : appList) { appIdSb.append("[" + app.getId() + "]"); } - List userBusinessList = getBasicData(keyId, type); - if(userBusinessList.size() > 0) { - UserBusiness userBusiness = userBusinessList.get(0); - userBusiness.setValue(appIdSb.toString()); - updates = userBusinessMapper.updateByPrimaryKeySelective(userBusiness); - } else { - UserBusiness userBusiness = new UserBusiness(); - userBusiness.setType(type); - userBusiness.setKeyid(keyId); - userBusiness.setValue(appIdSb.toString()); - updates = userBusinessMapper.insertSelective(userBusiness); + try{ + if(userBusinessList.size() > 0) { + UserBusiness userBusiness = userBusinessList.get(0); + userBusiness.setValue(appIdSb.toString()); + result = userBusinessMapper.updateByPrimaryKeySelective(userBusiness); + } else { + UserBusiness userBusiness = new UserBusiness(); + userBusiness.setType(type); + userBusiness.setKeyid(keyId); + userBusiness.setValue(appIdSb.toString()); + result = userBusinessMapper.insertSelective(userBusiness); + } + }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 updates; + return result; } }