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