|
|
@ -37,6 +37,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 畅捷通回调接口操作
|
|
|
|
* 畅捷通回调接口操作
|
|
|
|
|
|
|
|
*
|
|
|
|
* @author yuxiangyong
|
|
|
|
* @author yuxiangyong
|
|
|
|
* @create 2023-10-11 19:54
|
|
|
|
* @create 2023-10-11 19:54
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -95,7 +96,7 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Date date = new Date();
|
|
|
|
Date date = new Date();
|
|
|
|
ErpLarkTempRelation erpLarkTempRelation = new ErpLarkTempRelation();
|
|
|
|
ErpLarkTempRelation erpLarkTempRelation = new ErpLarkTempRelation();
|
|
|
|
erpLarkTempRelation.setKey(req.getBody().getString("voucherID"));
|
|
|
|
erpLarkTempRelation.setKey(req.getVoucherId());
|
|
|
|
erpLarkTempRelation.setMethod(req.getMsgType());
|
|
|
|
erpLarkTempRelation.setMethod(req.getMsgType());
|
|
|
|
erpLarkTempRelation.setLarkKey(req.getAppId());
|
|
|
|
erpLarkTempRelation.setLarkKey(req.getAppId());
|
|
|
|
erpLarkTempRelation.setCreateBy("System");
|
|
|
|
erpLarkTempRelation.setCreateBy("System");
|
|
|
@ -129,6 +130,7 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 解析实体,并构建
|
|
|
|
* 解析实体,并构建
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param req
|
|
|
|
* @param req
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected abstract void syncRecord(CJTEdiCallbackRequestVo req, JSONObject returnBody);
|
|
|
|
protected abstract void syncRecord(CJTEdiCallbackRequestVo req, JSONObject returnBody);
|
|
|
@ -198,9 +200,6 @@ 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();
|
|
|
@ -247,27 +246,18 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
LarkTableRequest request = this.buildLarkTableRequest(req);
|
|
|
|
LarkTableRequest request = this.buildLarkTableRequest(req);
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
CjtAccountEnum cjtAccountEnum = req.getCjtAccountEnum();
|
|
|
|
//获取已经存在的明细
|
|
|
|
//获取已经存在的明细
|
|
|
|
Map<String, ErpLarkRelation> existMap = getExistRecords(req).stream().collect(Collectors.toMap(ErpLarkRelation::getKey, Function.identity(), (K1, k2) -> K1));
|
|
|
|
List<ErpLarkRelation> existRecords = getExistRecords(req);
|
|
|
|
if (existMap != null && existMap.size() > 0){
|
|
|
|
if (CollectionUtils.isNotEmpty(existRecords)) {
|
|
|
|
List<ErpLarkRelation> collect = existMap.values().stream().collect(Collectors.toList());
|
|
|
|
toTableId = existRecords.get(0).getLarkTable();
|
|
|
|
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);
|
|
|
|
if (existMap.containsKey(uniqueKey)){
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ErpLarkRelation erpLarkRelation = existMap.get(uniqueKey);
|
|
|
|
|
|
|
|
request.setRecord(erpLarkRelation.getLarkKey());
|
|
|
|
|
|
|
|
request.setAppTable(erpLarkRelation.getLarkTable());
|
|
|
|
|
|
|
|
larkTableHelper.updateTableRecord(request);
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
errorList.add(e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
request.setRecord(null);
|
|
|
|
request.setRecord(null);
|
|
|
|
request.setAppTable(toTableId);
|
|
|
|
request.setAppTable(toTableId);
|
|
|
@ -278,10 +268,10 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
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(waitCreateRelationList)) {
|
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(waitCreateRelationList)) {
|
|
|
|
erpLarkRelationMapper.batchInsert(waitCreateRelationList);
|
|
|
|
erpLarkRelationMapper.batchInsert(waitCreateRelationList);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -290,16 +280,19 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
@ -333,12 +326,18 @@ public abstract class CJTOperateCallBackAbstract {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 删除无效记录
|
|
|
|
* 删除无效记录
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param req
|
|
|
|
* @param req
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected void deleteRecord(CJTEdiCallbackRequestVo req) {
|
|
|
|
protected void deleteRecord(CJTEdiCallbackRequestVo 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);
|
|
|
|
LarkTableRequest request = new LarkTableRequest(req.getLarkAppId(), req.getLarkAppSecret(), req.getLarkToAppToken(), null);
|
|
|
|
Map<String, List<String>> waitDeleteLarkMap = new HashMap<>();
|
|
|
|
Map<String, List<String>> waitDeleteLarkMap = new HashMap<>();
|
|
|
|
List<ErpLarkRelation> relationList = getExistRecords(req);
|
|
|
|
|
|
|
|
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();
|
|
|
@ -360,6 +359,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();
|
|
|
@ -392,7 +392,6 @@ 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -424,6 +423,7 @@ 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());
|
|
|
|