异常封装之用户信息后台修改

This commit is contained in:
qiankunpingtai
2019-04-19 15:21:03 +08:00
parent fed6bd0fb7
commit bcc3ae4e8d
3 changed files with 251 additions and 62 deletions

View File

@@ -59,7 +59,7 @@ public class UserController {
@PostMapping(value = "/login") @PostMapping(value = "/login")
public BaseResponseInfo login(@RequestParam(value = "loginame", required = false) String loginame, public BaseResponseInfo login(@RequestParam(value = "loginame", required = false) String loginame,
@RequestParam(value = "password", required = false) String password, @RequestParam(value = "password", required = false) String password,
HttpServletRequest request) { HttpServletRequest request)throws Exception {
logger.info("============用户登录 login 方法调用开始=============="); logger.info("============用户登录 login 方法调用开始==============");
String msgTip = ""; String msgTip = "";
User user=null; User user=null;
@@ -150,7 +150,7 @@ public class UserController {
} }
@GetMapping(value = "/getUserSession") @GetMapping(value = "/getUserSession")
public BaseResponseInfo getSessionUser(HttpServletRequest request) { public BaseResponseInfo getSessionUser(HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
try { try {
Map<String, Object> data = new HashMap<String, Object>(); Map<String, Object> data = new HashMap<String, Object>();
@@ -171,7 +171,7 @@ public class UserController {
} }
@GetMapping(value = "/logout") @GetMapping(value = "/logout")
public BaseResponseInfo logout(HttpServletRequest request, HttpServletResponse response) { public BaseResponseInfo logout(HttpServletRequest request, HttpServletResponse response)throws Exception {
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
try { try {
request.getSession().removeAttribute("user"); request.getSession().removeAttribute("user");
@@ -206,7 +206,7 @@ public class UserController {
@PostMapping(value = "/updatePwd") @PostMapping(value = "/updatePwd")
public String updatePwd(@RequestParam("userId") Long userId, @RequestParam("password") String password, public String updatePwd(@RequestParam("userId") Long userId, @RequestParam("password") String password,
@RequestParam("oldpwd") String oldpwd, HttpServletRequest request) { @RequestParam("oldpwd") String oldpwd, HttpServletRequest request)throws Exception {
Integer flag = 0; Integer flag = 0;
Map<String, Object> objectMap = new HashMap<String, Object>(); Map<String, Object> objectMap = new HashMap<String, Object>();
try { try {
@@ -242,7 +242,7 @@ public class UserController {
* @return * @return
*/ */
@GetMapping(value = "/getAllList") @GetMapping(value = "/getAllList")
public BaseResponseInfo getAllList(HttpServletRequest request) { public BaseResponseInfo getAllList(HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
try { try {
Map<String, Object> data = new HashMap<String, Object>(); Map<String, Object> data = new HashMap<String, Object>();
@@ -425,7 +425,7 @@ public class UserController {
} }
@GetMapping("/getTenantStatus") @GetMapping("/getTenantStatus")
public BaseResponseInfo getTenantStatus(HttpServletRequest request) { public BaseResponseInfo getTenantStatus(HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
try { try {
Map<String, Object> data = new HashMap<String, Object>(); Map<String, Object> data = new HashMap<String, Object>();

View File

@@ -18,16 +18,16 @@ public class UserComponent implements ICommonQuery {
private UserService userService; private UserService userService;
@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 getUserList(map); return getUserList(map);
} }
private List<?> getUserList(Map<String, String> map) { private List<?> getUserList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH); String search = map.get(Constants.SEARCH);
String userName = StringUtil.getInfo(search, "userName"); String userName = StringUtil.getInfo(search, "userName");
String loginName = StringUtil.getInfo(search, "loginName"); String loginName = StringUtil.getInfo(search, "loginName");
@@ -37,7 +37,7 @@ public class UserComponent 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 userName = StringUtil.getInfo(search, "userName"); String userName = StringUtil.getInfo(search, "userName");
String loginName = StringUtil.getInfo(search, "loginName"); String loginName = StringUtil.getInfo(search, "loginName");
@@ -45,27 +45,27 @@ public class UserComponent implements ICommonQuery {
} }
@Override @Override
public int insert(String beanJson, HttpServletRequest request) { public int insert(String beanJson, HttpServletRequest request)throws Exception {
return userService.insertUser(beanJson, request); return userService.insertUser(beanJson, request);
} }
@Override @Override
public int update(String beanJson, Long id) { public int update(String beanJson, Long id)throws Exception {
return userService.updateUser(beanJson, id); return userService.updateUser(beanJson, id);
} }
@Override @Override
public int delete(Long id) { public int delete(Long id)throws Exception {
return userService.deleteUser(id); return userService.deleteUser(id);
} }
@Override @Override
public int batchDelete(String ids) { public int batchDelete(String ids)throws Exception {
return userService.batchDeleteUser(ids); return userService.batchDeleteUser(ids);
} }
@Override @Override
public int checkIsNameExist(Long id, String name) { public int checkIsNameExist(Long id, String name)throws Exception {
return userService.checkIsNameExist(id, name); return userService.checkIsNameExist(id, name);
} }

View File

@@ -11,16 +11,17 @@ import com.jsh.erp.datasource.entities.UserEx;
import com.jsh.erp.datasource.entities.UserExample; import com.jsh.erp.datasource.entities.UserExample;
import com.jsh.erp.datasource.mappers.UserMapper; import com.jsh.erp.datasource.mappers.UserMapper;
import com.jsh.erp.datasource.mappers.UserMapperEx; import com.jsh.erp.datasource.mappers.UserMapperEx;
import com.jsh.erp.datasource.vo.TreeNode;
import com.jsh.erp.datasource.vo.TreeNodeEx; import com.jsh.erp.datasource.vo.TreeNodeEx;
import com.jsh.erp.exception.BusinessRunTimeException; 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.orgaUserRel.OrgaUserRelService; import com.jsh.erp.service.orgaUserRel.OrgaUserRelService;
import com.jsh.erp.service.userBusiness.UserBusinessService; import com.jsh.erp.service.userBusiness.UserBusinessService;
import com.jsh.erp.utils.*; import com.jsh.erp.utils.ExceptionCodeConstants;
import com.jsh.erp.utils.JshException;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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;
@@ -28,9 +29,11 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.URLEncoder;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service @Service
public class UserService { public class UserService {
@@ -51,21 +54,57 @@ public class UserService {
private UserBusinessService userBusinessService; private UserBusinessService userBusinessService;
public User getUser(long id) { public User getUser(long id)throws Exception {
return userMapper.selectByPrimaryKey(id); User result=null;
try{
result=userMapper.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<User> getUser() { public List<User> getUser()throws Exception {
UserExample example = new UserExample(); UserExample example = new UserExample();
return userMapper.selectByExample(example); List<User> list=null;
try{
list=userMapper.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<User> select(String userName, String loginName, int offset, int rows) { public List<User> select(String userName, String loginName, int offset, int rows)throws Exception {
return userMapperEx.selectByConditionUser(userName, loginName, offset, rows); List<User> list=null;
try{
list=userMapperEx.selectByConditionUser(userName, loginName, 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 countUser(String userName, String loginName) { public Long countUser(String userName, String loginName)throws Exception {
return userMapperEx.countsByUser(userName, loginName); Long result=null;
try{
result=userMapperEx.countsByUser(userName, loginName);
}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;
} }
/** /**
* create by: cjl * create by: cjl
@@ -77,7 +116,7 @@ public class UserService {
* @return int * @return int
*/ */
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertUser(String beanJson, HttpServletRequest request) { public int insertUser(String beanJson, HttpServletRequest request)throws Exception {
User user = JSONObject.parseObject(beanJson, User.class); User user = JSONObject.parseObject(beanJson, User.class);
String password = "123456"; String password = "123456";
//因密码用MD5加密需要对密码进行转化 //因密码用MD5加密需要对密码进行转化
@@ -88,7 +127,16 @@ public class UserService {
e.printStackTrace(); e.printStackTrace();
logger.error(">>>>>>>>>>>>>>转化MD5字符串错误 " + e.getMessage()); logger.error(">>>>>>>>>>>>>>转化MD5字符串错误 " + e.getMessage());
} }
return userMapper.insertSelective(user); int result=0;
try{
result=userMapper.insertSelective(user);
}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;
} }
/** /**
* create by: cjl * create by: cjl
@@ -100,10 +148,19 @@ public class UserService {
* @return int * @return int
*/ */
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateUser(String beanJson, Long id) { public int updateUser(String beanJson, Long id) throws Exception{
User user = JSONObject.parseObject(beanJson, User.class); User user = JSONObject.parseObject(beanJson, User.class);
user.setId(id); user.setId(id);
return userMapper.updateByPrimaryKeySelective(user); int result=0;
try{
result=userMapper.updateByPrimaryKeySelective(user);
}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;
} }
/** /**
* create by: cjl * create by: cjl
@@ -118,7 +175,16 @@ public class UserService {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER, logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(user.getId()).toString(), new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(user.getId()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
return userMapper.updateByPrimaryKeySelective(user); int result=0;
try{
result=userMapper.updateByPrimaryKeySelective(user);
}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;
} }
/** /**
* create by: cjl * create by: cjl
@@ -137,20 +203,47 @@ public class UserService {
User user = new User(); User user = new User();
user.setId(id); user.setId(id);
user.setPassword(md5Pwd); user.setPassword(md5Pwd);
return userMapper.updateByPrimaryKeySelective(user); int result=0;
try{
result=userMapper.updateByPrimaryKeySelective(user);
}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 deleteUser(Long id) { public int deleteUser(Long id)throws Exception {
return userMapper.deleteByPrimaryKey(id); int result=0;
try{
result= userMapper.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 batchDeleteUser(String ids) { public int batchDeleteUser(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids); List<Long> idList = StringUtil.strToLongList(ids);
UserExample example = new UserExample(); UserExample example = new UserExample();
example.createCriteria().andIdIn(idList); example.createCriteria().andIdIn(idList);
return userMapper.deleteByExample(example); int result=0;
try{
result= userMapper.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 validateUser(String username, String password) throws JshException { public int validateUser(String username, String password) throws JshException {
@@ -162,6 +255,8 @@ public class UserService {
example.createCriteria().andLoginameEqualTo(username); example.createCriteria().andLoginameEqualTo(username);
list = userMapper.selectByExample(example); list = userMapper.selectByExample(example);
} catch (Exception e) { } catch (Exception e) {
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
logger.error(">>>>>>>>访问验证用户姓名是否存在后台信息异常", e); logger.error(">>>>>>>>访问验证用户姓名是否存在后台信息异常", e);
return ExceptionCodeConstants.UserExceptionCode.USER_ACCESS_EXCEPTION; return ExceptionCodeConstants.UserExceptionCode.USER_ACCESS_EXCEPTION;
} }
@@ -188,22 +283,41 @@ public class UserService {
} }
} }
public User getUserByUserName(String username) { public User getUserByUserName(String username)throws Exception {
UserExample example = new UserExample(); UserExample example = new UserExample();
example.createCriteria().andLoginameEqualTo(username); example.createCriteria().andLoginameEqualTo(username);
List<User> list = userMapper.selectByExample(example); List<User> list=null;
User user = list.get(0); try{
list= userMapper.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);
}
User user =null;
if(list!=null&&list.size()>0){
user = list.get(0);
}
return user; return user;
} }
public int checkIsNameExist(Long id, String name) { public int checkIsNameExist(Long id, String name)throws Exception {
UserExample example = new UserExample(); UserExample example = new UserExample();
List <Byte> userStatus=new ArrayList<Byte>(); List <Byte> userStatus=new ArrayList<Byte>();
userStatus.add(BusinessConstants.USER_STATUS_DELETE); userStatus.add(BusinessConstants.USER_STATUS_DELETE);
userStatus.add(BusinessConstants.USER_STATUS_BANNED); userStatus.add(BusinessConstants.USER_STATUS_BANNED);
example.createCriteria().andIdNotEqualTo(id).andLoginameEqualTo(name).andStatusNotIn(userStatus); example.createCriteria().andIdNotEqualTo(id).andLoginameEqualTo(name).andStatusNotIn(userStatus);
List<User> list = userMapper.selectByExample(example); List<User> list=null;
return list.size(); try{
list= userMapper.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();
} }
/** /**
* create by: cjl * create by: cjl
@@ -213,13 +327,22 @@ public class UserService {
* @Param: * @Param:
* @return com.jsh.erp.datasource.entities.User * @return com.jsh.erp.datasource.entities.User
*/ */
public User getCurrentUser(){ public User getCurrentUser()throws Exception{
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
return (User)request.getSession().getAttribute("user"); return (User)request.getSession().getAttribute("user");
} }
public List<UserEx> getUserList(Map<String, Object> parameterMap) throws Exception{ public List<UserEx> getUserList(Map<String, Object> parameterMap) throws Exception{
return userMapperEx.getUserList(parameterMap); List<UserEx> list=null;
try{
list= userMapperEx.getUserList(parameterMap);
}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) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addUserAndOrgUserRel(UserEx ue) throws Exception{ public void addUserAndOrgUserRel(UserEx ue) throws Exception{
@@ -277,8 +400,16 @@ public class UserService {
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER); ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
} }
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL); ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
int i=userMapperEx.addUser(ue); int result=0;
if(i>0){ try{
result= userMapperEx.addUser(ue);
}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);
}
if(result>0){
return ue; return ue;
} }
return null; return null;
@@ -303,7 +434,15 @@ public class UserService {
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER); ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
} }
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL); ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
int i = userMapperEx.addUser(ue); int result=0;
try{
result= userMapperEx.addUser(ue);
}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);
}
//更新租户id //更新租户id
User user = new User(); User user = new User();
user.setId(ue.getId()); user.setId(ue.getId());
@@ -317,7 +456,7 @@ public class UserService {
ubArr.add(manageRoleId); ubArr.add(manageRoleId);
ubObj.put("value", ubArr.toString()); ubObj.put("value", ubArr.toString());
userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); userBusinessService.insertUserBusiness(ubObj.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if (i > 0) { if (result > 0) {
return ue; return ue;
} }
return null; return null;
@@ -328,7 +467,14 @@ public class UserService {
public void updateUserTenant(User user) throws Exception{ public void updateUserTenant(User user) throws Exception{
UserExample example = new UserExample(); UserExample example = new UserExample();
example.createCriteria().andIdEqualTo(user.getId()); example.createCriteria().andIdEqualTo(user.getId());
userMapper.updateByPrimaryKeySelective(user); try{
userMapper.updateByPrimaryKeySelective(user);
}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);
}
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
@@ -380,9 +526,17 @@ public class UserService {
} }
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public UserEx updateUser(UserEx ue){ public UserEx updateUser(UserEx ue)throws Exception{
int i=userMapperEx.updateUser(ue); int result =0;
if(i>0){ try{
result=userMapperEx.updateUser(ue);
}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);
}
if(result>0){
return ue; return ue;
} }
return null; return null;
@@ -395,7 +549,7 @@ public class UserService {
* @Param: userEx * @Param: userEx
* @return void * @return void
*/ */
public void checkUserNameAndLoginName(UserEx userEx){ public void checkUserNameAndLoginName(UserEx userEx)throws Exception{
List<User> list=null; List<User> list=null;
if(userEx==null){ if(userEx==null){
return; return;
@@ -454,14 +608,32 @@ public class UserService {
/** /**
* 通过用户名获取用户列表 * 通过用户名获取用户列表
* */ * */
public List<User> getUserListByUserName(String userName){ public List<User> getUserListByUserName(String userName)throws Exception{
return userMapperEx.getUserListByUserNameOrLoginName(userName,null); List<User> list =null;
try{
list=userMapperEx.getUserListByUserNameOrLoginName(userName,null);
}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<User> getUserListByloginName(String loginName){ public List<User> getUserListByloginName(String loginName){
return userMapperEx.getUserListByUserNameOrLoginName(null,loginName); List<User> list =null;
try{
list=userMapperEx.getUserListByUserNameOrLoginName(null,loginName);
}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;
} }
/** /**
* 批量删除用户 * 批量删除用户
@@ -472,8 +644,16 @@ public class UserService {
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(), new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
String idsArray[]=ids.split(","); String idsArray[]=ids.split(",");
int i= userMapperEx.batDeleteOrUpdateUser(idsArray,BusinessConstants.USER_STATUS_DELETE); int result =0;
if(i<1){ try{
result=userMapperEx.batDeleteOrUpdateUser(idsArray,BusinessConstants.USER_STATUS_DELETE);
}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);
}
if(result<1){
logger.error("异常码[{}],异常提示[{}],参数,ids:[{}]", logger.error("异常码[{}],异常提示[{}],参数,ids:[{}]",
ExceptionConstants.USER_DELETE_FAILED_CODE,ExceptionConstants.USER_DELETE_FAILED_MSG,ids); ExceptionConstants.USER_DELETE_FAILED_CODE,ExceptionConstants.USER_DELETE_FAILED_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.USER_DELETE_FAILED_CODE, throw new BusinessRunTimeException(ExceptionConstants.USER_DELETE_FAILED_CODE,
@@ -481,7 +661,16 @@ public class UserService {
} }
} }
public List<TreeNodeEx> getOrganizationUserTree() { public List<TreeNodeEx> getOrganizationUserTree()throws Exception {
return userMapperEx.getNodeTree(); List<TreeNodeEx> list =null;
try{
list=userMapperEx.getNodeTree();
}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;
} }
} }