|
|
@ -15,6 +15,7 @@ import com.ruoyi.flyingbook.domain.LarkCompanyRelation;
|
|
|
|
import com.ruoyi.flyingbook.domain.LarkTableRelation;
|
|
|
|
import com.ruoyi.flyingbook.domain.LarkTableRelation;
|
|
|
|
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
|
|
|
|
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
|
|
|
|
import com.ruoyi.flyingbook.mapper.ErpLarkRelationMainMapper;
|
|
|
|
import com.ruoyi.flyingbook.mapper.ErpLarkRelationMainMapper;
|
|
|
|
|
|
|
|
import com.ruoyi.flyingbook.mapper.ErpLarkRelationMapper;
|
|
|
|
import com.ruoyi.flyingbook.mapper.LarkCompanyRelationMapper;
|
|
|
|
import com.ruoyi.flyingbook.mapper.LarkCompanyRelationMapper;
|
|
|
|
import com.ruoyi.flyingbook.mapper.LarkTableRelationMapper;
|
|
|
|
import com.ruoyi.flyingbook.mapper.LarkTableRelationMapper;
|
|
|
|
import com.ruoyi.quartz.domain.*;
|
|
|
|
import com.ruoyi.quartz.domain.*;
|
|
|
@ -48,7 +49,7 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RedisCache redisCache;
|
|
|
|
private RedisCache redisCache;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
protected ErpLarkRelationMainMapper erpLarkRelationMapper;
|
|
|
|
protected ErpLarkRelationMapper erpLarkRelationMapper;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private LarkCompanyRelationMapper larkCompanyRelationMapper;
|
|
|
|
private LarkCompanyRelationMapper larkCompanyRelationMapper;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
@ -92,25 +93,26 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
private static final String REQUEST_GENERATE_TOKEN_PATH = REQUEST_ROOT_PATH + "/v1/common/auth/selfBuiltApp/generateToken";
|
|
|
|
private static final String REQUEST_GENERATE_TOKEN_PATH = REQUEST_ROOT_PATH + "/v1/common/auth/selfBuiltApp/generateToken";
|
|
|
|
|
|
|
|
|
|
|
|
private Boolean asynchronousCheck(LocalDateTime now, String cjt) {
|
|
|
|
private Boolean asynchronousCheck(LocalDateTime now, String cjt) {
|
|
|
|
int hour = now.getHour();
|
|
|
|
|
|
|
|
if ((hour == 1 && CjtAccountEnum.ONE.getCode().equals(cjt))
|
|
|
|
|
|
|
|
|| (hour == 3 && CjtAccountEnum.TWO.getCode().equals(cjt))) {
|
|
|
|
|
|
|
|
//目前只给畅捷通账号二加工单开补偿
|
|
|
|
|
|
|
|
// if ((AppType.SYNC_CJT_MANUFACTURE_ORDER_DATA_TO_MULTI_TABLE.getCode().equals(syncLarkAppType().getCode())
|
|
|
|
|
|
|
|
// && CjtAccountEnum.TWO.getCode().equals(cjt)) || (AppType.SYNC_CJT_SALE_DISPATCH_DATA_TO_MULTI_TABLE.getCode().equals(syncLarkAppType().getCode())
|
|
|
|
|
|
|
|
// && CjtAccountEnum.ONE.getCode().equals(cjt))) {
|
|
|
|
|
|
|
|
String asynchronous = getAsynchronousKey(cjt);
|
|
|
|
|
|
|
|
Object cacheObject = redisCache.getCacheObject(asynchronous);
|
|
|
|
|
|
|
|
if (cacheObject != null) {
|
|
|
|
|
|
|
|
return Boolean.FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
redisCache.setCacheObject(asynchronous, asynchronous, 2, TimeUnit.HOURS);
|
|
|
|
|
|
|
|
return Boolean.TRUE;
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// int hour = now.getHour();
|
|
|
|
|
|
|
|
// if ((hour == 1 && CjtAccountEnum.ONE.getCode().equals(cjt))
|
|
|
|
|
|
|
|
// || (hour == 3 && CjtAccountEnum.TWO.getCode().equals(cjt))) {
|
|
|
|
|
|
|
|
// //目前只给畅捷通账号二加工单开补偿
|
|
|
|
|
|
|
|
//// if ((AppType.SYNC_CJT_MANUFACTURE_ORDER_DATA_TO_MULTI_TABLE.getCode().equals(syncLarkAppType().getCode())
|
|
|
|
|
|
|
|
//// && CjtAccountEnum.TWO.getCode().equals(cjt)) || (AppType.SYNC_CJT_SALE_DISPATCH_DATA_TO_MULTI_TABLE.getCode().equals(syncLarkAppType().getCode())
|
|
|
|
|
|
|
|
//// && CjtAccountEnum.ONE.getCode().equals(cjt))) {
|
|
|
|
|
|
|
|
// String asynchronous = getAsynchronousKey(cjt);
|
|
|
|
|
|
|
|
// Object cacheObject = redisCache.getCacheObject(asynchronous);
|
|
|
|
|
|
|
|
// if (cacheObject != null) {
|
|
|
|
|
|
|
|
// return Boolean.FALSE;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// redisCache.setCacheObject(asynchronous, asynchronous, 2, TimeUnit.HOURS);
|
|
|
|
|
|
|
|
// return Boolean.TRUE;
|
|
|
|
|
|
|
|
//// } else {
|
|
|
|
|
|
|
|
//// return false;
|
|
|
|
|
|
|
|
//// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getAsynchronousKey(String cjt) {
|
|
|
|
private String getAsynchronousKey(String cjt) {
|
|
|
@ -366,7 +368,6 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
List<List<String>> rows = new ArrayList<>();
|
|
|
|
List<List<String>> rows = new ArrayList<>();
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
|
|
|
|
|
|
|
//初始化数据
|
|
|
|
//初始化数据
|
|
|
|
if (cjtRequestBody == null) {
|
|
|
|
if (cjtRequestBody == null) {
|
|
|
|
cjtRequestBody = new CJTRequestBody(page, PAGE_SIZE, getQueryFields(), getQueryCondition(context));
|
|
|
|
cjtRequestBody = new CJTRequestBody(page, PAGE_SIZE, getQueryFields(), getQueryCondition(context));
|
|
|
@ -390,7 +391,6 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
throw new RuntimeException(String.format("存在同步失败的记录 %s", errorKey));
|
|
|
|
throw new RuntimeException(String.format("存在同步失败的记录 %s", errorKey));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dataSourceTransactionManager.commit(transactionStatus);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("{} exception", this.getClassName(), e);
|
|
|
|
log.error("{} exception", this.getClassName(), e);
|
|
|
|
errorMessage = buildErrorBody(cjtRequest, e.getMessage());
|
|
|
|
errorMessage = buildErrorBody(cjtRequest, e.getMessage());
|
|
|
@ -415,7 +415,7 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
midList.add(row.get(i));
|
|
|
|
midList.add(row.get(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String uniqueKey = String.join("_", midList).toUpperCase() + "_" + addRecordRequest.getAppTable();
|
|
|
|
String uniqueKey = String.join("_", midList).toUpperCase();
|
|
|
|
result.add(uniqueKey);
|
|
|
|
result.add(uniqueKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -433,7 +433,8 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
if (CollectionUtils.isEmpty(uniqueKeyList)) {
|
|
|
|
if (CollectionUtils.isEmpty(uniqueKeyList)) {
|
|
|
|
return new HashMap<>();
|
|
|
|
return new HashMap<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return erpLarkRelationMapper.queryListByKeyListAndRemark(uniqueKeyList, getRequestUrl(), cjt)
|
|
|
|
//todo yxy 这里记得加上表id
|
|
|
|
|
|
|
|
return erpLarkRelationMapper.queryListByKeyListAndRemark(uniqueKeyList, getRequestUrl(), cjt,addRecordRequest.getAppTable())
|
|
|
|
.stream().collect(Collectors.toMap(ErpLarkRelation::getKey, ErpLarkRelation::getLarkKey, (k1, k2) -> k1));
|
|
|
|
.stream().collect(Collectors.toMap(ErpLarkRelation::getKey, ErpLarkRelation::getLarkKey, (k1, k2) -> k1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -474,6 +475,7 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
createTimeKey = "createdtime";
|
|
|
|
createTimeKey = "createdtime";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String createTime = null;
|
|
|
|
String createTime = null;
|
|
|
|
|
|
|
|
String voucherId = null;
|
|
|
|
for (List<String> row : rows) {
|
|
|
|
for (List<String> row : rows) {
|
|
|
|
String uniqueKey = null;
|
|
|
|
String uniqueKey = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -482,20 +484,28 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
for (int i = 0; i < row.size(); i++) {
|
|
|
|
for (int i = 0; i < row.size(); i++) {
|
|
|
|
String rowKey = keyList.get(i);
|
|
|
|
String rowKey = keyList.get(i);
|
|
|
|
String value = row.get(i);
|
|
|
|
String value = row.get(i);
|
|
|
|
if (createTimeKey.equals(rowKey.toLowerCase())){
|
|
|
|
String lowerCaseRowKey = rowKey.toLowerCase();
|
|
|
|
|
|
|
|
if (createTimeKey.equals(lowerCaseRowKey)){
|
|
|
|
createTime = value;
|
|
|
|
createTime = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("id".equals(lowerCaseRowKey)){
|
|
|
|
|
|
|
|
voucherId = value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CJTSyncTypeRelation cjtSyncTypeRelation = queryFieldsMap.get(rowKey);
|
|
|
|
if (uniqueFields.contains(rowKey)) {
|
|
|
|
if (uniqueFields.contains(rowKey)) {
|
|
|
|
|
|
|
|
if (cjtSyncTypeRelation != null && TableFieldTypeEnum.NUMBER.equals(cjtSyncTypeRelation.getType())){
|
|
|
|
|
|
|
|
uniqueKeyList.add(Double.valueOf(value) + "0");
|
|
|
|
|
|
|
|
}else {
|
|
|
|
uniqueKeyList.add(value);
|
|
|
|
uniqueKeyList.add(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CJTSyncTypeRelation cjtSyncTypeRelation = queryFieldsMap.get(rowKey);
|
|
|
|
}
|
|
|
|
if (cjtSyncTypeRelation == null) {
|
|
|
|
if (cjtSyncTypeRelation == null) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String larkLabel = cjtSyncTypeRelation.getLarkFileName();
|
|
|
|
String larkLabel = cjtSyncTypeRelation.getLarkFileName();
|
|
|
|
body.put(larkLabel, this.changeValueType(value, cjtSyncTypeRelation));
|
|
|
|
body.put(larkLabel, this.changeValueType(value, cjtSyncTypeRelation));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uniqueKey = String.join("_", uniqueKeyList).toUpperCase() + "_" + addRecordRequest.getAppTable();
|
|
|
|
uniqueKey = String.join("_", uniqueKeyList).toUpperCase();
|
|
|
|
Boolean existFlag = redisCache.setCacheObjectIfAbsent("CJT_JOB_CACHE:"+uniqueKey, "1", 2L, TimeUnit.HOURS);
|
|
|
|
Boolean existFlag = redisCache.setCacheObjectIfAbsent("CJT_JOB_CACHE:"+uniqueKey, "1", 2L, TimeUnit.HOURS);
|
|
|
|
if (repeatMap.containsKey(uniqueKey) || !existFlag) {
|
|
|
|
if (repeatMap.containsKey(uniqueKey) || !existFlag) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -507,7 +517,7 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
//在飞书创建一行,并根据创建返回的行id在本地保留一条映射纪律
|
|
|
|
//在飞书创建一行,并根据创建返回的行id在本地保留一条映射纪律
|
|
|
|
CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(addRecordRequest);
|
|
|
|
CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(addRecordRequest);
|
|
|
|
larkKey = respBody.getRecord().getRecordId();
|
|
|
|
larkKey = respBody.getRecord().getRecordId();
|
|
|
|
relationList.add(buildErpLarkRelation(uniqueKey, larkKey, cjt, asynchronous,createTime));
|
|
|
|
relationList.add(buildErpLarkRelation(uniqueKey, larkKey, cjt, asynchronous,createTime,voucherId,addRecordRequest.getAppTable()));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (!AppType.SYNC_CJT_SALE_DISPATCH_DATA_TO_MULTI_TABLE.equals(syncLarkAppType())) {
|
|
|
|
if (!AppType.SYNC_CJT_SALE_DISPATCH_DATA_TO_MULTI_TABLE.equals(syncLarkAppType())) {
|
|
|
|
//根据本地保留映射,确认飞书的更新行,更新后防止影响后续更新,需要将行id进行置空
|
|
|
|
//根据本地保留映射,确认飞书的更新行,更新后防止影响后续更新,需要将行id进行置空
|
|
|
@ -542,9 +552,11 @@ public abstract class SyncAccountsJobAbstract {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//构建飞书行与cjt唯一键的对应关系对象
|
|
|
|
//构建飞书行与cjt唯一键的对应关系对象
|
|
|
|
private ErpLarkRelation buildErpLarkRelation(String key, String larkKey, String cjt, Boolean asynchronous,String createTime) {
|
|
|
|
private ErpLarkRelation buildErpLarkRelation(String key, String larkKey, String cjt, Boolean asynchronous,String createTime,String voucherID,String tableId) {
|
|
|
|
ErpLarkRelation erpLarkRelation = new ErpLarkRelation();
|
|
|
|
ErpLarkRelation erpLarkRelation = new ErpLarkRelation();
|
|
|
|
erpLarkRelation.setKey(key);
|
|
|
|
erpLarkRelation.setKey(key);
|
|
|
|
|
|
|
|
erpLarkRelation.setCjtId(voucherID);
|
|
|
|
|
|
|
|
erpLarkRelation.setLarkTable(tableId);
|
|
|
|
erpLarkRelation.setLarkKey(larkKey);
|
|
|
|
erpLarkRelation.setLarkKey(larkKey);
|
|
|
|
erpLarkRelation.setMethod(getRequestUrl());
|
|
|
|
erpLarkRelation.setMethod(getRequestUrl());
|
|
|
|
erpLarkRelation.setFlag(FlagStatus.OK.getCode());
|
|
|
|
erpLarkRelation.setFlag(FlagStatus.OK.getCode());
|
|
|
|