feat(REQ-3600): 查询项目人员,支持根据workspaceId进行查询。 step2

This commit is contained in:
周敏 2025-02-08 13:48:09 +08:00
parent 7aa1568fe8
commit df3b1f14a5
4 changed files with 257 additions and 6 deletions

View File

@ -1,6 +1,5 @@
package cn.axzo.riven.client.req;
import cn.axzo.framework.domain.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -46,7 +45,7 @@ public class ListThirdProjectPeopleReq implements Serializable {
public void check() {
if (StringUtils.isBlank(thirdProjectId) && workspaceId == null) {
throw new ServiceException("workspaceId 和 thirdProjectId 不能都为空");
throw new IllegalArgumentException("workspaceId 和 thirdProjectId 不能都为空");
}
}
}

View File

@ -0,0 +1,252 @@
package cn.axzo.riven.config.exception;
import cn.axzo.apollo.core.exception.ApiException;
import cn.axzo.apollo.core.web.ControllerException;
import cn.axzo.foundation.exception.BusinessException;
import cn.axzo.foundation.result.ApiResult;
import cn.axzo.maokai.api.labour.common.lang.BizException;
import cn.azxo.framework.common.model.CommonResponse;
import cn.azxo.framework.common.utils.LogUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingRequestHeaderException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import javax.servlet.ServletException;
import javax.validation.ConstraintViolationException;
import java.nio.file.AccessDeniedException;
import java.util.List;
import static cn.axzo.maokai.api.labour.common.enums.ErrorCodeEnum.FORBIDDEN;
import static cn.axzo.maokai.api.labour.common.enums.ErrorCodeEnum.INVALID_PARAMETER;
import static cn.axzo.maokai.api.labour.common.enums.ErrorCodeEnum.SYSTEM_ERROR;
/**
* @author cn
* @version 1.0
* @description
* @date 2022/6/11 15:53
*/
@Order(value = 0)
@RestControllerAdvice
@Slf4j
public class ExceptionAdviceHandler {
@ExceptionHandler(value = cn.axzo.basics.common.exception.ServiceException.class)
public CommonResponse<Void> bizException(cn.axzo.basics.common.exception.ServiceException e) {
log.warn("ControllerExceptionHandler.bizException Exception", e);
return CommonResponse.error(e.getErrorCode(), e.getMessage());
}
@ExceptionHandler(value = cn.axzo.core.service.ServiceException.class)
public CommonResponse<Void> bizException(cn.axzo.core.service.ServiceException e) {
log.warn("ControllerExceptionHandler.bizException Exception", e);
return CommonResponse.error(9998, e.getMessage());
}
@ExceptionHandler(value = BizException.class)
public CommonResponse<Void> bizException(BizException e) {
log.warn("ControllerExceptionHandler.bizException Exception", e);
return CommonResponse.error(e.getBizCode(), e.getMessage());
}
@ExceptionHandler(value = ApiException.class)
public CommonResponse handleApiException(ApiException e) {
log.warn("ControllerExceptionHandler.handleApiException Exception", e);
return CommonResponse.error(e.getCode(), e.getMessage());
}
@ExceptionHandler(value = IllegalArgumentException.class)
public CommonResponse<Void> handleIllegalArgumentException(IllegalArgumentException e) {
log.warn("ControllerExceptionHandler.handleIllegalArgumentException Exception message", e);
return CommonResponse.error(INVALID_PARAMETER.getCode(), e.getMessage());
}
@ExceptionHandler(value = Exception.class)
public CommonResponse<Void> handleOtherException(Exception e) {
LogUtil.error(LogUtil.ErrorType.ERROR_SYSTEM, "ControllerExceptionHandler.handleOtherException Exception", e);
return CommonResponse.error(SYSTEM_ERROR.getCode(), SYSTEM_ERROR.getMessage());
}
@ExceptionHandler(value = Throwable.class)
public CommonResponse<Void> handleThrowableException(Throwable e) {
LogUtil.error(LogUtil.ErrorType.ERROR_SYSTEM, "ControllerExceptionHandler.handleThrowableException Exception", e);
return CommonResponse.error(SYSTEM_ERROR.getCode(), SYSTEM_ERROR.getMessage());
}
@ExceptionHandler(value = MethodArgumentNotValidException.class)
public CommonResponse<Void> handleArgumentValidException(MethodArgumentNotValidException e){
log.info("ControllerExceptionHandler.handleArgumentValidException Exception", e);
BindingResult bindingResult = e.getBindingResult();
StringBuilder errorMsg = new StringBuilder();
for (FieldError fieldError : bindingResult.getFieldErrors()) {
if (-1 == errorMsg.indexOf(fieldError.getDefaultMessage())) {
errorMsg.append(fieldError.getDefaultMessage()).append(",");
}
}
errorMsg.deleteCharAt(errorMsg.length() - 1);
return CommonResponse.error(INVALID_PARAMETER.getCode(), errorMsg.toString());
}
/**
* 捕捉Exception异常
*
* @param ex
* @return
*/
@ExceptionHandler(BusinessException.class)
public ApiResult<?> exceptionHandler(BusinessException ex) {
log.warn("业务异常", ex);
return ApiResult.error(ex.getErrorCode(), ex.getErrorMsg());
}
@ExceptionHandler(value = cn.axzo.apollo.core.service.ServiceException.class)
public CommonResponse<Void> handleServiceException(cn.axzo.apollo.core.service.ServiceException e) {
log.error("ControllerExceptionHandler.ServiceException Exception", e);
return CommonResponse.error(SYSTEM_ERROR.getCode(), e.getMessage());
}
/**
* 捕捉Exception异常
*
* @param e
* @return
*/
@ExceptionHandler(DuplicateKeyException.class)
public CommonResponse<Void> exceptionHandler(DuplicateKeyException e) {
log.info("重复数据提交", e);
return CommonResponse.error(SYSTEM_ERROR.getCode(), "重复数据提交");
}
/**
* 捕捉Exception异常
*
* @param e
* @return
*/
@ExceptionHandler(ServletException.class)
public CommonResponse<Void> exceptionHandler(ServletException e) {
LogUtil.error(LogUtil.ErrorType.ERROR_UNKNOWN, "接口异常", e);
return CommonResponse.error(SYSTEM_ERROR.getCode(), "操作失败,请联系工作人员处理");
}
/**
* 捕捉Exception异常
*
* @param e
* @return
*/
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public CommonResponse<Void> exceptionHandler(MethodArgumentTypeMismatchException e) {
log.warn("参数错误", e);
return CommonResponse.error(INVALID_PARAMETER.getCode(), "参数错误", null);
}
/**
* 捕捉Exception异常
*
* @param e
* @return
*/
@ExceptionHandler(ControllerException.class)
public CommonResponse<Void> exceptionHandler(ControllerException e) {
LogUtil.error(LogUtil.ErrorType.ERROR_UNKNOWN, "控制层异常", e);
return CommonResponse.error(e.getMessage());
}
/**
* 请求方式不正确
*
* @param e
* @return
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public CommonResponse<Void> exceptionHandler(HttpRequestMethodNotSupportedException e) {
log.warn("请求方式不正确", e);
return CommonResponse.error(INVALID_PARAMETER.getCode(), "请求方式不正确", null);
}
/**
* 参数验证失败
*
* @param e
* @return
*/
@ExceptionHandler(BindException.class)
public CommonResponse<Void> exceptionHandler(BindException e) {
List<ObjectError> allErrors = e.getBindingResult().getAllErrors();
if (CollectionUtils.isEmpty(allErrors)) {
return CommonResponse.fail("操作失败 请联系系统管理员");
}
ObjectError objectError = allErrors.get(0);
String objectErrorDefaultMessage = objectError.getDefaultMessage();
return CommonResponse.fail(objectErrorDefaultMessage);
}
/**
* 参数验证失败
*
* @param e
* @return
*/
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public CommonResponse<Void> exceptionHandler(HttpMediaTypeNotSupportedException e) {
log.warn(e.getMessage(), e);
return CommonResponse.error(INVALID_PARAMETER.getCode(), "请求的内容格式不正确", null);
}
/**
* 无权限访问接口
*
* @param e
* @return
*/
@ExceptionHandler(AccessDeniedException.class)
public CommonResponse<Void> handle401(AccessDeniedException e) {
log.warn("您没有权限访问", e);
return CommonResponse.error(FORBIDDEN.getCode(), "您没有权限访问", null);
}
@ExceptionHandler(MissingServletRequestParameterException.class)
public CommonResponse<Void> exceptionHandler(MissingServletRequestParameterException e) {
log.warn("参数错误", e);
return CommonResponse.error(INVALID_PARAMETER.getCode(), "参数错误", null);
}
@ExceptionHandler(MissingRequestHeaderException.class)
public CommonResponse<Void> exceptionHandler(MissingRequestHeaderException e) {
log.warn("参数错误", e);
return CommonResponse.error(INVALID_PARAMETER.getCode(), "参数错误", null);
}
@ExceptionHandler(HttpMessageNotReadableException.class)
public CommonResponse<Void> exceptionHandler(HttpMessageNotReadableException e) {
log.warn("参数错误", e);
if (e.getMessage().contains("out of range")) {
return CommonResponse.error("参数超出范围");
}
return CommonResponse.error(INVALID_PARAMETER.getCode(), "参数错误", null);
}
@ExceptionHandler(ConstraintViolationException.class)
public CommonResponse<Void> exceptionHandler(ConstraintViolationException e) {
log.warn("参数错误", e);
return CommonResponse.error(INVALID_PARAMETER.getCode(),
e.getConstraintViolations().iterator().next().getMessage(), null);
}
}

View File

@ -4,7 +4,7 @@
<!-- 导入安心筑全局日志配置 -->
<include resource="logback/logback-axzo.xml" />
<!-- 覆盖开发环境日志配置 -->
<springProfile name="local,dev">
<springProfile name="local,dev,test">
<logger name="cn.axzo" level="DEBUG" />
</springProfile>
</configuration>

View File

@ -55,7 +55,7 @@ public class ThirdPartPersonController implements ThirdPartPersonApi {
param.check();
ThirdProject thirdProject = thirdProjectDao.lambdaQuery().eq(ThirdProject::getThirdCode, param.getThirdCode())
.eq(StrUtil.isNotBlank(param.getThirdProjectId()), ThirdProject::getThirdProjectId, param.getThirdProjectId())
.apply(param.getWorkspaceId() != null, " extra -> '$.workspaceId' = {0} ", param.getWorkspaceId())
.apply(param.getWorkspaceId() != null, " third_project_ext -> '$.workspaceId' = {0} ", param.getWorkspaceId())
.eq(ThirdProject::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.one();
if (thirdProject == null){
@ -66,7 +66,7 @@ public class ThirdPartPersonController implements ThirdPartPersonApi {
}
List<ThirdProjectPersonRes> result = thirdProjectPersonDao.lambdaQuery()
.eq(ThirdProjectPerson::getThirdCode, param.getThirdCode())
.eq(ThirdProjectPerson::getThirdProjectId, param.getThirdProjectId())
.eq(ThirdProjectPerson::getThirdProjectId, thirdProject.getThirdProjectId())
.in(CollUtil.isNotEmpty(param.getThirdUniquePersonIds()), ThirdProjectPerson::getThirdUniquePersonId, param.getThirdUniquePersonIds())
.eq(ThirdProjectPerson::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.list()
@ -97,7 +97,7 @@ public class ThirdPartPersonController implements ThirdPartPersonApi {
List<ThirdProjectPersonRes> result = thirdProjectPersonDao.lambdaQuery()
.eq(ThirdProjectPerson::getThirdCode, param.getThirdCode())
.eq(ThirdProjectPerson::getThirdProjectId, param.getThirdProjectId())
.eq(ThirdProjectPerson::getThirdProjectId, thirdProject.getThirdProjectId())
.in(ThirdProjectPerson::getThirdUniquePersonId, thirdPersonMap.keySet())
.eq(ThirdProjectPerson::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.list()