Commit dacae27d by guojuxing

新增用户添加事务

parent b69c851c
......@@ -3,17 +3,18 @@ package com.gic.auth.service.outer.impl;
import java.util.Date;
import java.util.List;
import com.gic.enterprise.exception.CommonException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.UserDTO;
import com.gic.auth.dto.UserResourceDTO;
import com.gic.auth.dto.UserRoleDTO;
import com.gic.auth.entity.TabSysUser;
import com.gic.auth.exception.AuthException;
import com.gic.auth.service.*;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.error.ErrorCode;
......@@ -36,6 +37,7 @@ public class UserApiServiceImpl implements UserApiService {
@Autowired
private UserResourceService userResourceService;
@Transactional(rollbackFor = Exception.class)
@Override
public ServiceResponse<Integer> saveUser(UserDTO userDTO) {
//valid param
......@@ -58,10 +60,11 @@ public class UserApiServiceImpl implements UserApiService {
return response;
} else {
//事物回滚
throw new CommonException(response);
throw new AuthException(response);
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public ServiceResponse editUser(UserDTO userDTO) {
//valid param
......@@ -85,7 +88,7 @@ public class UserApiServiceImpl implements UserApiService {
return response;
} else {
//事物回滚
throw new CommonException(response);
throw new AuthException(response);
}
}
......
......@@ -17,9 +17,9 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import com.gic.auth.exception.AuthException;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.exception.CommonException;
import com.gic.store.exception.StoreException;
/**
......@@ -28,10 +28,10 @@ import com.gic.store.exception.StoreException;
* @author hua
*/
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
private static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ResponseBody
@ExceptionHandler(Exception.class)
public RestResponse controllerException(HttpServletResponse response, Exception ex) {
logger.error("err", ex);
......@@ -58,7 +58,6 @@ public class GlobalExceptionHandler {
* @param e
* @return
*/
@ResponseBody
@ExceptionHandler(BindException.class)
public RestResponse customException(BindException e) {
List<FieldError> fieldErrors = e.getFieldErrors();
......@@ -68,10 +67,10 @@ public class GlobalExceptionHandler {
.append(fieldError.getDefaultMessage())
.append(",");
});
return getRestResponse(ErrorCode.PARAMETER_ERROR.getCode(), errorMessage.toString());
String error = errorMessage.toString();
return getRestResponse(ErrorCode.PARAMETER_ERROR.getCode(), error.substring(0, error.length() - 1));
}
@ResponseBody
@ExceptionHandler(ConstraintViolationException.class)
public RestResponse constraintViolationException(ConstraintViolationException e) {
Set<ConstraintViolation<?>> constraintViolations = e.getConstraintViolations();
......@@ -85,14 +84,14 @@ public class GlobalExceptionHandler {
* @param e
* @return
*/
@ResponseBody
@ExceptionHandler(StoreException.class)
public RestResponse customException(StoreException e) {
return getRestResponse(e.getErrorCode(), e.getMessage());
}
@ResponseBody
@ExceptionHandler(CommonException.class)
public RestResponse customException(CommonException e) {
@ExceptionHandler(AuthException.class)
public RestResponse customException(AuthException e) {
return getRestResponse(e.getErrorCode(), e.getMessage());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment