|
|
@ -37,7 +37,6 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 畅捷通回调接口操作
|
|
|
|
* 畅捷通回调接口操作
|
|
|
|
*
|
|
|
|
|
|
|
|
* @author yuxiangyong
|
|
|
|
* @author yuxiangyong
|
|
|
|
* @create 2023-10-11 19:54
|
|
|
|
* @create 2023-10-11 19:54
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -64,11 +63,11 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected static final String REQUEST_ROOT_PATH = "https://openapi.chanjet.com";
|
|
|
|
protected static final String REQUEST_ROOT_PATH = "https://openapi.chanjet.com";
|
|
|
|
|
|
|
|
|
|
|
|
public void execute(CJTEdiCallbackRequestVo req) {
|
|
|
|
public void execute(CJTEdiCallbackRequestVo req){
|
|
|
|
String operateCallBackFlag = buildCacheUniqueKey(RedisConstants.CJT_CALLBACK_OPERATE, req.getAppId() + req.getMsgType() + req.getVoucherId());
|
|
|
|
String operateCallBackFlag = buildCacheUniqueKey(RedisConstants.CJT_CALLBACK_OPERATE, req.getAppId() + req.getMsgType() + req.getVoucherId());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Boolean operateFlag = redisCache.setCacheObjectIfAbsent(operateCallBackFlag, operateCallBackFlag, 10L, TimeUnit.MINUTES);
|
|
|
|
Boolean operateFlag = redisCache.setCacheObjectIfAbsent(operateCallBackFlag, operateCallBackFlag, 10L, TimeUnit.MINUTES);
|
|
|
|
if (!operateFlag) {
|
|
|
|
if (!operateFlag){
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
preHandle(req);
|
|
|
|
preHandle(req);
|
|
|
@ -76,27 +75,27 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
// resetTicket(req);
|
|
|
|
// resetTicket(req);
|
|
|
|
sync(req);
|
|
|
|
sync(req);
|
|
|
|
endHandle(req);
|
|
|
|
endHandle(req);
|
|
|
|
} catch (Exception e) {
|
|
|
|
}catch (Exception e){
|
|
|
|
log.error("{} execute error", this.getClass().getSimpleName(), e);
|
|
|
|
log.error("{} execute error",this.getClass().getSimpleName(),e);
|
|
|
|
if (req.getRetry() && req.getRetryCount() < 3) {
|
|
|
|
if (req.getRetry() && req.getRetryCount() < 3){
|
|
|
|
req.addRetryCount();
|
|
|
|
req.addRetryCount();
|
|
|
|
execute(req);
|
|
|
|
execute(req);
|
|
|
|
} else {
|
|
|
|
}else {
|
|
|
|
errorHandle(req, e);
|
|
|
|
errorHandle(req,e);
|
|
|
|
larkRobotHelper.sendMessageByBot(ROBOT_GROUP, buildRobotErrorCountMessage(req, e));
|
|
|
|
larkRobotHelper.sendMessageByBot(ROBOT_GROUP, buildRobotErrorCountMessage(req,e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
}finally {
|
|
|
|
redisCache.deleteObject(operateCallBackFlag);
|
|
|
|
redisCache.deleteObject(operateCallBackFlag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void preHandle(CJTEdiCallbackRequestVo req) {
|
|
|
|
private void preHandle(CJTEdiCallbackRequestVo req){
|
|
|
|
if (req.getRetryCount() > 0) {
|
|
|
|
if (req.getRetryCount() > 0){
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Date date = new Date();
|
|
|
|
Date date = new Date();
|
|
|
|
ErpLarkTempRelation erpLarkTempRelation = new ErpLarkTempRelation();
|
|
|
|
ErpLarkTempRelation erpLarkTempRelation = new ErpLarkTempRelation();
|
|
|
|
erpLarkTempRelation.setKey(req.getVoucherId());
|
|
|
|
erpLarkTempRelation.setKey(req.getBody().getString("voucherID"));
|
|
|
|
erpLarkTempRelation.setMethod(req.getMsgType());
|
|
|
|
erpLarkTempRelation.setMethod(req.getMsgType());
|
|
|
|
erpLarkTempRelation.setLarkKey(req.getAppId());
|
|
|
|
erpLarkTempRelation.setLarkKey(req.getAppId());
|
|
|
|
erpLarkTempRelation.setCreateBy("System");
|
|
|
|
erpLarkTempRelation.setCreateBy("System");
|
|
|
@ -107,33 +106,32 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
req.setTempId(erpLarkTempRelation.getId());
|
|
|
|
req.setTempId(erpLarkTempRelation.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void endHandle(CJTEdiCallbackRequestVo req) {
|
|
|
|
private void endHandle(CJTEdiCallbackRequestVo req){
|
|
|
|
if (req.getTempId() != null) {
|
|
|
|
if (req.getTempId() != null){
|
|
|
|
erpLarkTempRelationMapper.updateForCjt(FlagStatus.DELETED.getCode(), req.getTempId(), "");
|
|
|
|
erpLarkTempRelationMapper.updateForCjt(FlagStatus.DELETED.getCode(), req.getTempId(),"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void errorHandle(CJTEdiCallbackRequestVo req, Exception e) {
|
|
|
|
private void errorHandle(CJTEdiCallbackRequestVo req,Exception e){
|
|
|
|
if (req.getTempId() != null) {
|
|
|
|
if (req.getTempId() != null){
|
|
|
|
erpLarkTempRelationMapper.updateForCjt(FlagStatus.OK.getCode(), req.getTempId(), e.getMessage());
|
|
|
|
erpLarkTempRelationMapper.updateForCjt(FlagStatus.OK.getCode(), req.getTempId(),e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sync(CJTEdiCallbackRequestVo req) {
|
|
|
|
private void sync(CJTEdiCallbackRequestVo req){
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
LarkCJTRequestBody cjtRequestBody = new LarkCJTRequestBody(req.getVoucherId());
|
|
|
|
LarkCJTRequestBody cjtRequestBody = new LarkCJTRequestBody(req.getVoucherId());
|
|
|
|
LarkCJTRequest cjtRequest = new LarkCJTRequest(getRequestUrl(), cjtAccountEnum.getAppKey(), cjtAccountEnum.getAppSecret(), generateToken(req), cjtRequestBody);
|
|
|
|
LarkCJTRequest cjtRequest = new LarkCJTRequest(getRequestUrl(), cjtAccountEnum.getAppKey(), cjtAccountEnum.getAppSecret(), generateToken(req),cjtRequestBody);
|
|
|
|
LarkOkHttpHelper.post(cjtRequest);
|
|
|
|
LarkOkHttpHelper.post(cjtRequest);
|
|
|
|
JSONObject jsonObject = requestCjt(cjtRequest);
|
|
|
|
JSONObject jsonObject = requestCjt(cjtRequest);
|
|
|
|
syncRecord(req, jsonObject);
|
|
|
|
syncRecord(req,jsonObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 解析实体,并构建
|
|
|
|
* 解析实体,并构建
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param req
|
|
|
|
* @param req
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected abstract void syncRecord(CJTEdiCallbackRequestVo req, JSONObject returnBody);
|
|
|
|
protected abstract void syncRecord(CJTEdiCallbackRequestVo req,JSONObject returnBody);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取请求明细的路径
|
|
|
|
* 获取请求明细的路径
|
|
|
@ -145,52 +143,52 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected abstract String getMethodUrl();
|
|
|
|
protected abstract String getMethodUrl();
|
|
|
|
|
|
|
|
|
|
|
|
private void initContext(CJTEdiCallbackRequestVo req) {
|
|
|
|
private void initContext(CJTEdiCallbackRequestVo req){
|
|
|
|
LarkCompanyRelation companyRelation = req.getCompanyRelation();
|
|
|
|
LarkCompanyRelation companyRelation = req.getCompanyRelation();
|
|
|
|
String larkCompanyCode = req.getMsgTypeEnum().getLarkCompanyCode();
|
|
|
|
String larkCompanyCode = req.getMsgTypeEnum().getLarkCompanyCode();
|
|
|
|
if (companyRelation == null) {
|
|
|
|
if (companyRelation == null){
|
|
|
|
LarkCompanyRelation queryCompany = new LarkCompanyRelation();
|
|
|
|
LarkCompanyRelation queryCompany = new LarkCompanyRelation();
|
|
|
|
queryCompany.setAppType(larkCompanyCode);
|
|
|
|
queryCompany.setAppType(larkCompanyCode);
|
|
|
|
queryCompany.setFlag(FlagStatus.OK.getCode());
|
|
|
|
queryCompany.setFlag(FlagStatus.OK.getCode());
|
|
|
|
queryCompany.setRemark(req.getAppId());
|
|
|
|
queryCompany.setRemark(req.getAppId());
|
|
|
|
List<LarkCompanyRelation> larkCompanyRelations = larkCompanyRelationMapper.selectLarkCompanyRelationList(queryCompany);
|
|
|
|
List<LarkCompanyRelation> larkCompanyRelations = larkCompanyRelationMapper.selectLarkCompanyRelationList(queryCompany);
|
|
|
|
if (CollectionUtils.isEmpty(larkCompanyRelations)) {
|
|
|
|
if (CollectionUtils.isEmpty(larkCompanyRelations)){
|
|
|
|
throw new RuntimeException(String.format("%s 无larkCompany配置信息 appId:%s appType:%s", req.getMsgType(), req.getAppId(), larkCompanyCode));
|
|
|
|
throw new RuntimeException(String.format("%s 无larkCompany配置信息 appId:%s appType:%s",req.getMsgType(),req.getAppId(),larkCompanyCode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
companyRelation = larkCompanyRelations.get(0);
|
|
|
|
companyRelation = larkCompanyRelations.get(0);
|
|
|
|
req.setCompanyRelation(companyRelation);
|
|
|
|
req.setCompanyRelation(companyRelation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LarkTableRelation tableRelation = req.getTableRelation();
|
|
|
|
LarkTableRelation tableRelation = req.getTableRelation();
|
|
|
|
if (tableRelation == null) {
|
|
|
|
if (tableRelation == null){
|
|
|
|
LarkTableRelation queryTable = new LarkTableRelation();
|
|
|
|
LarkTableRelation queryTable = new LarkTableRelation();
|
|
|
|
queryTable.setLarkCompanyRelationId(companyRelation.getId());
|
|
|
|
queryTable.setLarkCompanyRelationId(companyRelation.getId());
|
|
|
|
queryTable.setFlag(FlagStatus.OK.getCode());
|
|
|
|
queryTable.setFlag(FlagStatus.OK.getCode());
|
|
|
|
List<LarkTableRelation> larkTableRelations = larkTableRelationMapper.selectLarkTableRelationList(queryTable);
|
|
|
|
List<LarkTableRelation> larkTableRelations = larkTableRelationMapper.selectLarkTableRelationList(queryTable);
|
|
|
|
if (CollectionUtils.isEmpty(larkTableRelations)) {
|
|
|
|
if (CollectionUtils.isEmpty(larkTableRelations)){
|
|
|
|
throw new RuntimeException(String.format("%s 无larkTableRelation配置信息 appId:%s appType:%s larkCompanyId:%s", req.getMsgType(), req.getAppId(), larkCompanyCode, companyRelation.getId()));
|
|
|
|
throw new RuntimeException(String.format("%s 无larkTableRelation配置信息 appId:%s appType:%s larkCompanyId:%s",req.getMsgType(),req.getAppId(),larkCompanyCode,companyRelation.getId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tableRelation = larkTableRelations.get(0);
|
|
|
|
tableRelation = larkTableRelations.get(0);
|
|
|
|
req.setTableRelation(tableRelation);
|
|
|
|
req.setTableRelation(tableRelation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String buildRobotErrorCountMessage(CJTEdiCallbackRequestVo req, Exception e) {
|
|
|
|
private String buildRobotErrorCountMessage(CJTEdiCallbackRequestVo req,Exception e){
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
body.put("cjtId", req.getAppId());
|
|
|
|
body.put("cjtId",req.getAppId());
|
|
|
|
body.put("msgType", req.getMsgType());
|
|
|
|
body.put("msgType",req.getMsgType());
|
|
|
|
LarkCompanyRelation companyRelation = req.getCompanyRelation();
|
|
|
|
LarkCompanyRelation companyRelation = req.getCompanyRelation();
|
|
|
|
if (companyRelation != null) {
|
|
|
|
if (companyRelation != null){
|
|
|
|
body.put("companyRelationId", companyRelation.getId());
|
|
|
|
body.put("companyRelationId",companyRelation.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LarkTableRelation tableRelation = req.getTableRelation();
|
|
|
|
LarkTableRelation tableRelation = req.getTableRelation();
|
|
|
|
if (tableRelation != null) {
|
|
|
|
if (tableRelation != null){
|
|
|
|
body.put("tableRelationId", tableRelation.getId());
|
|
|
|
body.put("tableRelationId",tableRelation.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
body.put("errorInfo", e.getMessage());
|
|
|
|
body.put("errorInfo",e.getMessage());
|
|
|
|
return body.toJSONString();
|
|
|
|
return body.toJSONString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected LarkTableRequest buildLarkTableRequest(CJTEdiCallbackRequestVo req) {
|
|
|
|
protected LarkTableRequest buildLarkTableRequest(CJTEdiCallbackRequestVo req){
|
|
|
|
LarkTableRequest request = new LarkTableRequest();
|
|
|
|
LarkTableRequest request = new LarkTableRequest();
|
|
|
|
request.setAppId(req.getLarkAppId());
|
|
|
|
request.setAppId(req.getLarkAppId());
|
|
|
|
request.setAppSecret(req.getLarkAppSecret());
|
|
|
|
request.setAppSecret(req.getLarkAppSecret());
|
|
|
@ -200,6 +198,9 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void addRecord(CJTEdiCallbackRequestVo req, JSONObject header) {
|
|
|
|
protected void addRecord(CJTEdiCallbackRequestVo req, JSONObject header) {
|
|
|
|
//多维表格id
|
|
|
|
//多维表格id
|
|
|
|
String toTableId = req.getLarkToTableId();
|
|
|
|
String toTableId = req.getLarkToTableId();
|
|
|
@ -213,24 +214,24 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
for (int i = 0; i < details.size(); i++) {
|
|
|
|
for (int i = 0; i < details.size(); i++) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JSONObject detail = details.getJSONObject(i);
|
|
|
|
JSONObject detail = details.getJSONObject(i);
|
|
|
|
String uniqueKey = buildUniqueKey(toTableId, header, detail, cjtAccountEnum);
|
|
|
|
String uniqueKey = buildUniqueKey(toTableId, header, detail,cjtAccountEnum);
|
|
|
|
Map<String, Object> larkBody = buildLarkBody(header, detail, cjtAccountEnum);
|
|
|
|
Map<String, Object> larkBody = buildLarkBody(header, detail,cjtAccountEnum);
|
|
|
|
request.setBody(larkBody);
|
|
|
|
request.setBody(larkBody);
|
|
|
|
CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(request);
|
|
|
|
CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(request);
|
|
|
|
String larkKey = respBody.getRecord().getRecordId();
|
|
|
|
String larkKey = respBody.getRecord().getRecordId();
|
|
|
|
relationList.add(buildErpLarkRelation(uniqueKey, larkKey, cjtAccountEnum.getCode(), toTableId, req.getVoucherId()));
|
|
|
|
relationList.add(buildErpLarkRelation(uniqueKey, larkKey, cjtAccountEnum.getCode(),toTableId,req.getVoucherId()));
|
|
|
|
} catch (Exception e) {
|
|
|
|
}catch (Exception e){
|
|
|
|
errorList.add(e.getMessage());
|
|
|
|
errorList.add(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CollectionUtils.isEmpty(errorList)) {
|
|
|
|
if (CollectionUtils.isEmpty(errorList)){
|
|
|
|
req.setRetry(Boolean.FALSE);
|
|
|
|
req.setRetry(Boolean.FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(relationList)) {
|
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(relationList)) {
|
|
|
|
erpLarkRelationMapper.batchInsert(relationList);
|
|
|
|
erpLarkRelationMapper.batchInsert(relationList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CollectionUtils.isNotEmpty(errorList)) {
|
|
|
|
if (CollectionUtils.isNotEmpty(errorList)){
|
|
|
|
throw new RuntimeException(String.join(",", errorList));
|
|
|
|
throw new RuntimeException(String.join(",",errorList));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -246,59 +247,65 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
LarkTableRequest request = this.buildLarkTableRequest(req);
|
|
|
|
LarkTableRequest request = this.buildLarkTableRequest(req);
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
//获取已经存在的明细
|
|
|
|
//获取已经存在的明细
|
|
|
|
List<ErpLarkRelation> existRecords = getExistRecords(req);
|
|
|
|
Map<String, ErpLarkRelation> existMap = getExistRecords(req).stream().collect(Collectors.toMap(ErpLarkRelation::getKey, Function.identity(), (K1, k2) -> K1));
|
|
|
|
if (CollectionUtils.isNotEmpty(existRecords)) {
|
|
|
|
if (existMap != null && existMap.size() > 0){
|
|
|
|
toTableId = existRecords.get(0).getLarkTable();
|
|
|
|
List<ErpLarkRelation> collect = existMap.values().stream().collect(Collectors.toList());
|
|
|
|
|
|
|
|
toTableId = collect.get(0).getLarkTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//因为可能存在修改的情况,所以这里全部删除重新创建
|
|
|
|
|
|
|
|
operateDelete(req, existRecords);
|
|
|
|
|
|
|
|
List<String> errorList = new ArrayList<>();
|
|
|
|
List<String> errorList = new ArrayList<>();
|
|
|
|
for (int i = 0; i < details.size(); i++) {
|
|
|
|
for (int i = 0; i < details.size(); i++) {
|
|
|
|
JSONObject detail = details.getJSONObject(i);
|
|
|
|
JSONObject detail = details.getJSONObject(i);
|
|
|
|
String uniqueKey = buildUniqueKey(toTableId, header, detail, cjtAccountEnum);
|
|
|
|
String uniqueKey = buildUniqueKey(toTableId, header, detail,cjtAccountEnum);
|
|
|
|
Map<String, Object> larkBody = buildLarkBody(header, detail, cjtAccountEnum);
|
|
|
|
Map<String, Object> larkBody = buildLarkBody(header, detail,cjtAccountEnum);
|
|
|
|
request.setBody(larkBody);
|
|
|
|
request.setBody(larkBody);
|
|
|
|
try {
|
|
|
|
if (existMap.containsKey(uniqueKey)){
|
|
|
|
request.setRecord(null);
|
|
|
|
try {
|
|
|
|
request.setAppTable(toTableId);
|
|
|
|
ErpLarkRelation erpLarkRelation = existMap.get(uniqueKey);
|
|
|
|
CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(request);
|
|
|
|
request.setRecord(erpLarkRelation.getLarkKey());
|
|
|
|
String larkKey = respBody.getRecord().getRecordId();
|
|
|
|
request.setAppTable(erpLarkRelation.getLarkTable());
|
|
|
|
waitCreateRelationList.add(buildErpLarkRelation(uniqueKey, larkKey, cjtAccountEnum.getCode(), toTableId, req.getVoucherId()));
|
|
|
|
larkTableHelper.updateTableRecord(request);
|
|
|
|
} catch (Exception e) {
|
|
|
|
}catch (Exception e){
|
|
|
|
errorList.add(e.getMessage());
|
|
|
|
errorList.add(e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
request.setRecord(null);
|
|
|
|
|
|
|
|
request.setAppTable(toTableId);
|
|
|
|
|
|
|
|
CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(request);
|
|
|
|
|
|
|
|
String larkKey = respBody.getRecord().getRecordId();
|
|
|
|
|
|
|
|
waitCreateRelationList.add(buildErpLarkRelation(uniqueKey, larkKey, cjtAccountEnum.getCode(),toTableId,req.getVoucherId()));
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
errorList.add(e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CollectionUtils.isEmpty(errorList)) {
|
|
|
|
if (CollectionUtils.isEmpty(errorList)){
|
|
|
|
req.setRetry(Boolean.FALSE);
|
|
|
|
req.setRetry(Boolean.FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(waitCreateRelationList)) {
|
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(waitCreateRelationList)) {
|
|
|
|
erpLarkRelationMapper.batchInsert(waitCreateRelationList);
|
|
|
|
erpLarkRelationMapper.batchInsert(waitCreateRelationList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CollectionUtils.isNotEmpty(errorList)) {
|
|
|
|
if (CollectionUtils.isNotEmpty(errorList)){
|
|
|
|
throw new RuntimeException(String.join(",", errorList));
|
|
|
|
throw new RuntimeException(String.join(",",errorList));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract String getDetailName();
|
|
|
|
protected abstract String getDetailName();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 构建唯一key
|
|
|
|
* 构建唯一key
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected abstract String buildUniqueKey(String toTableId, JSONObject header, JSONObject detail, CjtAccountEnum cjtAccountEnum);
|
|
|
|
protected abstract String buildUniqueKey(String toTableId, JSONObject header, JSONObject detail,CjtAccountEnum cjtAccountEnum);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 构建多维表格请求体的body
|
|
|
|
* 构建多维表格请求体的body
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected abstract Map<String, Object> buildLarkBody(JSONObject header, JSONObject detail, CjtAccountEnum cjtAccountEnum);
|
|
|
|
protected abstract Map<String, Object> buildLarkBody(JSONObject header, JSONObject detail,CjtAccountEnum cjtAccountEnum);
|
|
|
|
|
|
|
|
|
|
|
|
//构建飞书行与cjt唯一键的对应关系对象
|
|
|
|
//构建飞书行与cjt唯一键的对应关系对象
|
|
|
|
private ErpLarkRelation buildErpLarkRelation(String key, String larkKey, String cjt, String tableId, String cjtId) {
|
|
|
|
private ErpLarkRelation buildErpLarkRelation(String key, String larkKey, String cjt,String tableId,String cjtId) {
|
|
|
|
ErpLarkRelation erpLarkRelation = new ErpLarkRelation();
|
|
|
|
ErpLarkRelation erpLarkRelation = new ErpLarkRelation();
|
|
|
|
erpLarkRelation.setKey(key);
|
|
|
|
erpLarkRelation.setKey(key);
|
|
|
|
erpLarkRelation.setCjtId(cjtId);
|
|
|
|
erpLarkRelation.setCjtId(cjtId);
|
|
|
@ -313,7 +320,7 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
return erpLarkRelation;
|
|
|
|
return erpLarkRelation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected Object getSpecialKey(JSONObject detail, String key) {
|
|
|
|
protected Object getSpecialKey(JSONObject detail,String key){
|
|
|
|
JSONArray dynamicPropertyKeys = detail.getJSONArray("DynamicPropertyKeys");
|
|
|
|
JSONArray dynamicPropertyKeys = detail.getJSONArray("DynamicPropertyKeys");
|
|
|
|
for (int i = 0; i < dynamicPropertyKeys.size(); i++) {
|
|
|
|
for (int i = 0; i < dynamicPropertyKeys.size(); i++) {
|
|
|
|
if (key.equals(dynamicPropertyKeys.get(i))) {
|
|
|
|
if (key.equals(dynamicPropertyKeys.get(i))) {
|
|
|
@ -326,24 +333,18 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 删除无效记录
|
|
|
|
* 删除无效记录
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param req
|
|
|
|
* @param req
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected void deleteRecord(CJTEdiCallbackRequestVo req) {
|
|
|
|
protected void deleteRecord(CJTEdiCallbackRequestVo req){
|
|
|
|
|
|
|
|
LarkTableRequest request = new LarkTableRequest(req.getLarkAppId(), req.getLarkAppSecret(), req.getLarkToAppToken(),null);
|
|
|
|
|
|
|
|
Map<String,List<String>> waitDeleteLarkMap = new HashMap<>();
|
|
|
|
List<ErpLarkRelation> relationList = getExistRecords(req);
|
|
|
|
List<ErpLarkRelation> relationList = getExistRecords(req);
|
|
|
|
operateDelete(req, relationList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void operateDelete(CJTEdiCallbackRequestVo req, List<ErpLarkRelation> relationList) {
|
|
|
|
|
|
|
|
LarkTableRequest request = new LarkTableRequest(req.getLarkAppId(), req.getLarkAppSecret(), req.getLarkToAppToken(), null);
|
|
|
|
|
|
|
|
Map<String, List<String>> waitDeleteLarkMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Long> waitDeleteIdList = new ArrayList<>();
|
|
|
|
List<Long> waitDeleteIdList = new ArrayList<>();
|
|
|
|
for (ErpLarkRelation record : relationList) {
|
|
|
|
for (ErpLarkRelation record : relationList) {
|
|
|
|
String appTable = record.getLarkTable();
|
|
|
|
String appTable = record.getLarkTable();
|
|
|
|
List<String> waitDeleteLarkList = waitDeleteLarkMap.getOrDefault(appTable, new ArrayList<>());
|
|
|
|
List<String> waitDeleteLarkList = waitDeleteLarkMap.getOrDefault(appTable, new ArrayList<>());
|
|
|
|
waitDeleteLarkList.add(record.getLarkKey());
|
|
|
|
waitDeleteLarkList.add(record.getLarkKey());
|
|
|
|
waitDeleteLarkMap.put(appTable, waitDeleteLarkList);
|
|
|
|
waitDeleteLarkMap.put(appTable,waitDeleteLarkList);
|
|
|
|
waitDeleteIdList.add(record.getId());
|
|
|
|
waitDeleteIdList.add(record.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!waitDeleteLarkMap.isEmpty()) {
|
|
|
|
if (!waitDeleteLarkMap.isEmpty()) {
|
|
|
@ -359,8 +360,7 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected List<ErpLarkRelation> getExistRecords(CJTEdiCallbackRequestVo req){
|
|
|
|
protected List<ErpLarkRelation> getExistRecords(CJTEdiCallbackRequestVo req) {
|
|
|
|
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
ErpLarkRelation erpLarkRelation = new ErpLarkRelation();
|
|
|
|
ErpLarkRelation erpLarkRelation = new ErpLarkRelation();
|
|
|
|
erpLarkRelation.setRemark(cjtAccountEnum.getCode());
|
|
|
|
erpLarkRelation.setRemark(cjtAccountEnum.getCode());
|
|
|
@ -392,6 +392,7 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
// String ticket = (String) redisCache.getCacheObject(ticketCacheKey);
|
|
|
|
// String ticket = (String) redisCache.getCacheObject(ticketCacheKey);
|
|
|
|
// req.setTicket(ticket);
|
|
|
|
// req.setTicket(ticket);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
private String buildCacheUniqueKey(String key, String appKey) {
|
|
|
|
private String buildCacheUniqueKey(String key, String appKey) {
|
|
|
|
return String.format("%s:%s", key, appKey);
|
|
|
|
return String.format("%s:%s", key, appKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -403,10 +404,10 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
String tokenCacheKey = buildCacheUniqueKey(RedisConstants.CJT_TOKEN_CACHE_KEY, cjtAccountEnum.getAppKey());
|
|
|
|
String tokenCacheKey = buildCacheUniqueKey(RedisConstants.CJT_TOKEN_CACHE_KEY, cjtAccountEnum.getAppKey());
|
|
|
|
String openToken = (String) redisCache.getCacheObject(tokenCacheKey);
|
|
|
|
String openToken = (String) redisCache.getCacheObject(tokenCacheKey);
|
|
|
|
if (!StringUtils.isEmpty(openToken)) {
|
|
|
|
if (!StringUtils.isEmpty(openToken)){
|
|
|
|
req.setOpenToken(openToken);
|
|
|
|
req.setOpenToken(openToken);
|
|
|
|
return openToken;
|
|
|
|
return openToken;
|
|
|
|
} else {
|
|
|
|
}else {
|
|
|
|
throw new RuntimeException("token不存在");
|
|
|
|
throw new RuntimeException("token不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -423,7 +424,6 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return responseBody.getData();
|
|
|
|
return responseBody.getData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected String buildErrorBody(LarkCJTRequest req, String errorMessage) {
|
|
|
|
protected String buildErrorBody(LarkCJTRequest req, String errorMessage) {
|
|
|
|
JSONObject errorInfo = new JSONObject();
|
|
|
|
JSONObject errorInfo = new JSONObject();
|
|
|
|
errorInfo.put("url", req.getUrl());
|
|
|
|
errorInfo.put("url", req.getUrl());
|
|
|
|