REQ-3300: 回调
This commit is contained in:
parent
8c8269cdc1
commit
d5945d6681
@ -1,13 +1,13 @@
|
||||
|
||||
package cn.axzo.nanopart.ess.server.dao;
|
||||
|
||||
import cn.axzo.nanopart.ess.api.utils.YesOrNo;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import cn.axzo.nanopart.ess.server.entity.EssLog;
|
||||
import cn.axzo.nanopart.ess.server.mapper.EssLogMapper;
|
||||
import cn.axzo.nanopart.ess.server.utils.BizAssertions;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.base.Throwables;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
@ -27,10 +27,7 @@ public class EssLogDao extends ServiceImpl<EssLogMapper, EssLog> {
|
||||
EssLog log = new EssLog();
|
||||
log.setContext(context);
|
||||
log.setSubject(String.valueOf(subject));
|
||||
if (exception != null) {
|
||||
log.setIsError(YesOrNo.YES);
|
||||
log.addLogContent("exception", Throwables.getStackTraceAsString(exception));
|
||||
}
|
||||
log.setError(exception);
|
||||
if (logContents != null && logContents.length > 0) {
|
||||
BizAssertions.assertTrue(logContents.length % 2 == 0, "logContents must be even");
|
||||
for (int i = 0; i < logContents.length; i += 2) {
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
|
||||
package cn.axzo.nanopart.ess.server.entity;
|
||||
|
||||
import cn.axzo.nanopart.ess.api.utils.YesOrNo;
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import cn.axzo.nanopart.ess.api.utils.YesOrNo;
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -51,6 +53,13 @@ public class EssLog extends BaseEntity<EssLog> {
|
||||
logContent.put(key, value);
|
||||
}
|
||||
|
||||
public void setError(Exception exception) {
|
||||
if (exception == null)
|
||||
return;
|
||||
setIsError(YesOrNo.YES);
|
||||
addLogContent("exception", Throwables.getStackTraceAsString(exception));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
|
||||
@ -1,6 +1,27 @@
|
||||
|
||||
package cn.axzo.nanopart.ess.server.ess.controller;
|
||||
|
||||
import static cn.axzo.nanopart.ess.api.request.CallbackRequest.ContractStateChanged;
|
||||
import static cn.axzo.nanopart.ess.api.request.CallbackRequest.OrgPersonJoin;
|
||||
import static cn.axzo.nanopart.ess.api.request.CallbackRequest.SealOperate;
|
||||
import static cn.axzo.nanopart.ess.server.utils.IdBuilder.idbuilder;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.maokai.api.vo.response.OrganizationalUnitVO;
|
||||
import cn.axzo.nanopart.ess.api.EssCallbackApi;
|
||||
@ -27,28 +48,9 @@ import cn.axzo.nanopart.ess.server.ess.domain.OrgOpenId;
|
||||
import cn.axzo.nanopart.ess.server.ess.domain.PersonOpenId;
|
||||
import cn.axzo.nanopart.ess.server.ess.support.EssSupport;
|
||||
import cn.axzo.nanopart.ess.server.ess.support.OrgProfiles;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.axzo.nanopart.ess.api.request.CallbackRequest.ContractStateChanged;
|
||||
import static cn.axzo.nanopart.ess.api.request.CallbackRequest.OrgPersonJoin;
|
||||
import static cn.axzo.nanopart.ess.api.request.CallbackRequest.SealOperate;
|
||||
import static cn.axzo.nanopart.ess.server.utils.IdBuilder.idbuilder;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
@ -202,15 +204,18 @@ class CallbackController implements EssCallbackApi, InitializingBean {
|
||||
public ApiResult<Object> callback(CallbackRequest request) {
|
||||
log.info("ess callback: {}", request);
|
||||
Object subject = null;
|
||||
CallbackType callbackType = CallbackType.parse(request.getMsgType()).orElse(null);
|
||||
CallbackHandler handler = callbackType == null ? null : handlers.get(callbackType);
|
||||
EssLog essLog = new EssLog();
|
||||
essLog.addLogContent("interested", handler != null);
|
||||
try {
|
||||
CallbackType callbackType = CallbackType.parse(request.getMsgType()).orElse(null);
|
||||
CallbackHandler handler = callbackType == null ? null : handlers.get(callbackType);
|
||||
if (handler != null) {
|
||||
subject = transactionTemplate.execute(unused -> {
|
||||
try {
|
||||
return handler.handle(request);
|
||||
}
|
||||
catch (Exception e) {
|
||||
essLog.setError(e);
|
||||
log.warn("callback failed", e);
|
||||
// wrap exception to make it throw to yoke
|
||||
throw new RuntimeException(e);
|
||||
@ -223,22 +228,14 @@ class CallbackController implements EssCallbackApi, InitializingBean {
|
||||
return ApiResult.ok("success");
|
||||
}
|
||||
finally {
|
||||
saveRequest(request, subject);
|
||||
String callbackTypeStr = callbackType == null ? "" : "[" + callbackType + "]";
|
||||
essLog.setContext(String.format("ess:callback:%s%s", request.getMsgType(), callbackTypeStr));
|
||||
essLog.setSubject(subject == null ? "" : String.valueOf(subject));
|
||||
essLog.addLogContent("request", request);
|
||||
essLogDao.save(essLog);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveRequest(CallbackRequest request, Object subject) {
|
||||
EssLog essLog = new EssLog();
|
||||
CallbackType callbackType = CallbackType.parse(request.getMsgType()).orElse(null);
|
||||
String callbackTypeStr = callbackType == null ? "" : "[" + callbackType + "]";
|
||||
essLog.setContext(String.format("ess:callback:%s%s", request.getMsgType(), callbackTypeStr));
|
||||
essLog.setSubject("");
|
||||
if (subject != null)
|
||||
essLog.setSubject(String.valueOf(subject));
|
||||
essLog.addLogContent("request", request);
|
||||
essLogDao.save(essLog);
|
||||
}
|
||||
|
||||
private void registerHandler(CallbackType callbackType, CallbackHandler handler) {
|
||||
handlers.put(callbackType, handler);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user