Quellcode durchsuchen

修改异常捕获

tags/24080901
WendyYang vor 5 Monaten
Ursprung
Commit
1472750160
2 geänderte Dateien mit 34 neuen und 21 gelöschten Zeilen
  1. +22
    -13
      hz-pm-api/src/main/java/com/hz/pm/api/common/handler/GlobalExceptionHandler.java
  2. +12
    -8
      hz-pm-api/src/main/java/com/hz/pm/api/meeting/manage/MeetingManage.java

+ 22
- 13
hz-pm-api/src/main/java/com/hz/pm/api/common/handler/GlobalExceptionHandler.java Datei anzeigen

@@ -2,6 +2,7 @@ package com.hz.pm.api.common.handler;

import com.hz.pm.api.common.exception.ReturnException;
import com.ningdatech.basic.enumeration.Status;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.model.ApiResponse;
import com.ningdatech.basic.util.CollUtils;
import lombok.extern.slf4j.Slf4j;
@@ -33,46 +34,54 @@ import java.util.stream.Collectors;
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class GlobalExceptionHandler {

public static final int ERROR_CODE = Status.BAD_REQUEST.getCode();

@ResponseBody
@ExceptionHandler(value = NoHandlerFoundException.class)
public ApiResponse<Void> noHandlerFoundException(NoHandlerFoundException e) {
public ApiResponse<Void> catchException(NoHandlerFoundException e) {
return ApiResponse.ofStatus(Status.REQUEST_NOT_FOUND);
}

@ResponseBody
@ExceptionHandler(value = {MethodArgumentNotValidException.class, BindException.class})
public ApiResponse<Void> bindException(BindException e) {
public ApiResponse<Void> catchException(BindException e) {
String msg = e.getAllErrors().stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.collect(Collectors.joining(" "));
return ApiResponse.of(Status.BAD_REQUEST.getCode(), msg);
return ApiResponse.of(ERROR_CODE, msg);
}

@ResponseBody
@ExceptionHandler(value = ConstraintViolationException.class)
public ApiResponse<Void> constraintViolationException(ConstraintViolationException e) {
String msg = CollUtils.join(e.getConstraintViolations(), ConstraintViolation::getMessage, " ");
return ApiResponse.of(Status.BAD_REQUEST.getCode(), msg);
public ApiResponse<Void> catchException(ConstraintViolationException e) {
String msg = CollUtils.join(e.getConstraintViolations(),
ConstraintViolation::getMessage, " ");
return ApiResponse.of(ERROR_CODE, msg);
}

@ResponseBody
@ExceptionHandler(value = AccessDeniedException.class)
public ApiResponse<Void> accessDeniedException(AccessDeniedException e) {
log.error("异常信息: {} ", e.getMessage(), e);
return ApiResponse.of(Status.BAD_REQUEST.getCode(), "暂无操作权限");
public ApiResponse<Void> catchException(AccessDeniedException e) {
return ApiResponse.of(ERROR_CODE, "暂无操作权限");
}

@ResponseBody
@ExceptionHandler(value = Exception.class)
public ApiResponse<Void> handlerException(Exception e) {
public ApiResponse<Void> catchException(Exception e) {
log.error("异常信息: {} ", e.getMessage(), e);
return ApiResponse.of(Status.BAD_REQUEST.getCode(), "系统异常,请联系管理员");
return ApiResponse.of(ERROR_CODE, "系统异常,请联系管理员");
}

@ResponseBody
@ExceptionHandler(value = ReturnException.class)
public ApiResponse<Void> returnException(ReturnException e) {
return ApiResponse.of(Status.BAD_REQUEST.getCode(), e.getMessage());
public ApiResponse<Void> catchException(ReturnException e) {
return ApiResponse.of(ERROR_CODE, e.getMessage());
}

@ResponseBody
@ExceptionHandler(value = BizException.class)
public ApiResponse<Void> catchException(BizException e) {
return ApiResponse.of(ERROR_CODE, e.getMessage());
}

}

+ 12
- 8
hz-pm-api/src/main/java/com/hz/pm/api/meeting/manage/MeetingManage.java Datei anzeigen

@@ -16,6 +16,7 @@ import com.hz.pm.api.common.exception.ReturnException;
import com.hz.pm.api.common.helper.RegionCacheHelper;
import com.hz.pm.api.common.model.constant.BizConst;
import com.hz.pm.api.common.util.BizUtils;
import com.hz.pm.api.common.util.EnvironmentUtil;
import com.hz.pm.api.expert.entity.ExpertUserFullInfo;
import com.hz.pm.api.expert.service.IExpertUserFullInfoService;
import com.hz.pm.api.external.MhApiClient;
@@ -103,6 +104,7 @@ public class MeetingManage {
private final IMeetingExpertJudgeService meetingExpertJudgeService;
private final MhApiClient mhApiClient;
private final IUserInfoService userInfoService;
private final EnvironmentUtil environmentUtil;

private static final String INVITED_RULE_CREATE = "INVITED_RULE_CREATE:";

@@ -682,15 +684,15 @@ public class MeetingManage {
Long meetingId = req.getMeetingId();
String key = "CANCEL_MEETING:" + meetingId;
if (!distributedLock.lock(key, RETRY_TIMES)) {
throw BizException.wrap("正在取消会议,请刷新后重试");
throw ReturnException.wrap("正在取消会议");
}
try {
Meeting meeting = meetingService.getById(meetingId);
if (MeetingStatusEnum.CANCELED.eq(meeting.getStatus())) {
throw BizException.wrap("会议已取消");
throw ReturnException.wrap("会议已取消");
}
if (meeting.getStartTime().isBefore(LocalDateTime.now())) {
throw BizException.wrap("会议已开始,暂时无法取消");
throw ReturnException.wrap("会议已开始,暂时无法取消");
}
Wrapper<Meeting> meetingUpdate = Wrappers.lambdaUpdate(Meeting.class)
.set(Meeting::getStatus, MeetingStatusEnum.CANCELED.getCode())
@@ -714,10 +716,10 @@ public class MeetingManage {
Long userId = expertId == null ? LoginUserUtil.getUserId() : expertId;
MeetingExpert me = meetingExpertService.getByMeetingIdAndExpertId(meetingId, userId);
if (me == null) {
throw BizException.wrap("未被邀请参加此会议");
throw ReturnException.wrap("未被邀请参加此会议");
}
if (AGREED.eq(me.getStatus())) {
throw BizException.wrap("未确认参加此会议");
throw ReturnException.wrap("未确认参加此会议");
}
ExpertUserFullInfo userInfo = expertUserFullInfoService.getByUserId(userId);
Meeting meeting = meetingService.getById(meetingId);
@@ -736,12 +738,12 @@ public class MeetingManage {
public void confirmAttendByManager(ExpertConfirmReq req) {
String key = "CONFIRM_ATTEND:" + req.getExpertMeetingId();
if (!distributedLock.lock(key, RETRY_TIMES)) {
throw BizException.wrap("操作失败,请重试!");
throw ReturnException.wrap("操作失败,请重试!");
}
try {
MeetingExpert me = meetingExpertService.getById(req.getExpertMeetingId());
if (!NOTICING.eq(me.getStatus())) {
throw BizException.wrap("操作失败,请重试!");
throw ReturnException.wrap("操作失败,请重试!");
}
Integer status = (Boolean.TRUE.equals(req.getAgreed()) ? AGREED : REFUSED).getCode();
Wrapper<MeetingExpert> update = Wrappers.lambdaUpdate(MeetingExpert.class)
@@ -867,7 +869,9 @@ public class MeetingManage {
.in(MeetingExpert::getId, currConfirmedMeIds)
.set(MeetingExpert::getConfirmedRoster, Boolean.TRUE);
meetingExpertService.update(meUpdate);
meetingNotifyHelper.sendConfirmedRosterMsg(expertNoticing, meeting);
if (environmentUtil.isProdEnv()) {
meetingNotifyHelper.sendConfirmedRosterMsg(expertNoticing, meeting);
}
} finally {
distributedLock.releaseLock(key);
}


Laden…
Abbrechen
Speichern