异常response处理
This commit is contained in:
@@ -227,4 +227,27 @@ public class SysDepartmentDTO {
|
|||||||
}
|
}
|
||||||
return resultList;
|
return resultList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static RegionDO convertRegionDO(SysDepartmentDTO dept, Multimap<String, String> leaderDeptMap, RegionDO parentRegion){
|
||||||
|
RegionDO region = new RegionDO();
|
||||||
|
region.setRegionId(dept.getId());
|
||||||
|
region.setName(dept.getName());
|
||||||
|
region.setParentId(dept.getParentId());
|
||||||
|
region.setUnclassifiedFlag(CommonConstants.ZERO);
|
||||||
|
region.setLeaderUserId(dept.getLeaderUserId());
|
||||||
|
region.setOrderNum(dept.getDepartOrder());
|
||||||
|
region.setThirdDeptId(dept.getId());
|
||||||
|
region.setCreateTime(System.currentTimeMillis());
|
||||||
|
region.setUpdateTime(System.currentTimeMillis());
|
||||||
|
String regionPath = parentRegion.getRegionPath() + region.getRegionId() + CommonConstants.PATH_SPILT;
|
||||||
|
region.setRegionPath(regionPath);
|
||||||
|
region.setDeleted(Boolean.FALSE);
|
||||||
|
if(CollectionUtils.isNotEmpty(dept.getDeptManagerUseridList())){
|
||||||
|
for (String leader : dept.getDeptManagerUseridList()) {
|
||||||
|
leaderDeptMap.put(leader, dept.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return region;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
package com.cool.store.handler;
|
package com.cool.store.handler;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
import com.cool.store.constants.CommonConstants;
|
||||||
import com.cool.store.exception.ApiException;
|
import com.cool.store.exception.ApiException;
|
||||||
import com.cool.store.exception.ServiceException;
|
import com.cool.store.exception.ServiceException;
|
||||||
|
import com.cool.store.response.ResponseResult;
|
||||||
import com.cool.store.response.error.ErrorResponse;
|
import com.cool.store.response.error.ErrorResponse;
|
||||||
|
import com.cool.store.utils.UUIDUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.MDC;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhangchenbiao
|
* @author zhangchenbiao
|
||||||
* @FileName: CustomExceptionHandler
|
* @FileName: CustomExceptionHandler
|
||||||
@@ -21,24 +32,41 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|||||||
public class CustomExceptionHandler {
|
public class CustomExceptionHandler {
|
||||||
|
|
||||||
@ExceptionHandler(value = ServiceException.class)
|
@ExceptionHandler(value = ServiceException.class)
|
||||||
public ResponseEntity<ErrorResponse> handleCustomException(ServiceException e) {
|
public void handleCustomException(ServiceException e, HttpServletResponse httpServletResponse) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
|
ResponseResult responseResult = new ResponseResult(e.getErrorCode(), e.getMessage());
|
||||||
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
responseResult(httpServletResponse, responseResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value = ApiException.class)
|
@ExceptionHandler(value = ApiException.class)
|
||||||
public ResponseEntity<ErrorResponse> handleCustomException(ApiException e) {
|
public void handleCustomException(ApiException e, HttpServletResponse httpServletResponse) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
|
ResponseResult responseResult = new ResponseResult(e.getErrorCode(), e.getMessage());
|
||||||
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
responseResult(httpServletResponse, responseResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value = Exception.class)
|
@ExceptionHandler(value = Exception.class)
|
||||||
public ResponseEntity<ErrorResponse> handleException(Exception e) {
|
public void handleException(Exception e, HttpServletResponse httpServletResponse) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
|
ResponseResult responseResult = new ResponseResult(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
|
||||||
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
responseResult(httpServletResponse, responseResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void responseResult(HttpServletResponse response, ResponseResult result) {
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-type", "application/json;charset=UTF-8");
|
||||||
|
String requestId = MDC.get(CommonConstants.REQUEST_ID);
|
||||||
|
if(StringUtils.isBlank(requestId)){
|
||||||
|
requestId = UUIDUtils.get32UUID();
|
||||||
|
}
|
||||||
|
result.setRequestId(requestId);
|
||||||
|
result.setData(null);
|
||||||
|
try {
|
||||||
|
response.getWriter().write(JSONObject.toJSONString(result, SerializerFeature.WriteNullStringAsEmpty));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error(ex.getMessage(),ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,28 @@ public class ISVHttpRequest {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门详情
|
||||||
|
* @param deptId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public SysDepartmentDTO getDepartmentDetail(String deptId){
|
||||||
|
String url = isvDomain + "/corp/getDepartmentDetail";
|
||||||
|
HashMap requestMap = new HashMap();
|
||||||
|
requestMap.put("deptId", deptId);
|
||||||
|
ResultDTO responseEntity = null;
|
||||||
|
try {
|
||||||
|
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
|
||||||
|
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||||
|
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
|
||||||
|
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SysDepartmentDTO.class);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("调用isv出错{}", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public AuthScopeDTO getAuthScope(){
|
public AuthScopeDTO getAuthScope(){
|
||||||
String url = isvDomain + "/corp/getAuthScope";
|
String url = isvDomain + "/corp/getAuthScope";
|
||||||
HashMap requestMap = new HashMap();
|
HashMap requestMap = new HashMap();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,18 +81,21 @@ public class AliyunServiceImpl implements AliyunService {
|
|||||||
RecognizeIdentityCardResponse idCardResponse = client.recognizeIdentityCardAdvance(recognizeIdentityCardAdvanceRequest, runtime);
|
RecognizeIdentityCardResponse idCardResponse = client.recognizeIdentityCardAdvance(recognizeIdentityCardAdvanceRequest, runtime);
|
||||||
log.info("身份证解析结果:{}", JSONObject.toJSONString(idCardResponse));
|
log.info("身份证解析结果:{}", JSONObject.toJSONString(idCardResponse));
|
||||||
RecognizeIdentityCardResponseBody.RecognizeIdentityCardResponseBodyDataFrontResult frontResult = Optional.ofNullable(idCardResponse).map(o -> o.getBody()).map(o -> o.data).map(o -> o.frontResult).orElse(null);
|
RecognizeIdentityCardResponseBody.RecognizeIdentityCardResponseBodyDataFrontResult frontResult = Optional.ofNullable(idCardResponse).map(o -> o.getBody()).map(o -> o.data).map(o -> o.frontResult).orElse(null);
|
||||||
String username = frontResult.name;
|
if(Objects.nonNull(frontResult)){
|
||||||
String liveAddress = frontResult.address;
|
String username = frontResult.name;
|
||||||
String birthdate = frontResult.birthDate;
|
String liveAddress = frontResult.address;
|
||||||
if(StringUtils.isNotBlank(birthdate)){
|
String birthdate = frontResult.birthDate;
|
||||||
birthdate = convertDate(birthdate, "yyyyMMdd");
|
if(StringUtils.isNotBlank(birthdate)){
|
||||||
|
birthdate = convertDate(birthdate, "yyyyMMdd");
|
||||||
|
}
|
||||||
|
String sex = frontResult.gender;
|
||||||
|
String idCard = frontResult.IDNumber;
|
||||||
|
String nation = frontResult.nationality;
|
||||||
|
IdentityCardInfoVO result = new IdentityCardInfoVO(username, liveAddress, birthdate, sex, idCard, nation);
|
||||||
|
log.info("身份证解析:{}", JSONObject.toJSONString(result));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
String sex = frontResult.gender;
|
return null;
|
||||||
String idCard = frontResult.IDNumber;
|
|
||||||
String nation = frontResult.nationality;
|
|
||||||
IdentityCardInfoVO result = new IdentityCardInfoVO(username, liveAddress, birthdate, sex, idCard, nation);
|
|
||||||
log.info("身份证解析:{}", JSONObject.toJSONString(result));
|
|
||||||
return result;
|
|
||||||
} catch (com.aliyun.tea.TeaException e) {
|
} catch (com.aliyun.tea.TeaException e) {
|
||||||
log.error("身份证解析报错TeaException:{}", e);
|
log.error("身份证解析报错TeaException:{}", e);
|
||||||
throw new ApiException(e.getMessage());
|
throw new ApiException(e.getMessage());
|
||||||
|
|||||||
@@ -209,9 +209,14 @@ public class EnterpriseSyncServiceImpl implements EnterpriseSyncService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deptUpdateEvent(DepartmentEventDTO param) {
|
public void deptUpdateEvent(DepartmentEventDTO param) {
|
||||||
|
SysDepartmentDTO departmentDetail = isvHttpRequest.getDepartmentDetail(param.getDepartmentId());
|
||||||
|
if(Objects.isNull(departmentDetail)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
log.info("部门变更:{}", JSONObject.toJSONString(param));
|
log.info("部门变更:{}", JSONObject.toJSONString(param));
|
||||||
switch (parseValue(param.getEventType())){
|
switch (parseValue(param.getEventType())){
|
||||||
case DEPARTMENT_CREATED:
|
case DEPARTMENT_CREATED:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case DEPARTMENT_UPDATED:
|
case DEPARTMENT_UPDATED:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user