报表更新数据弃用中间表

报表弃用中间表
YXY 12 months ago
parent a565d32782
commit fe56661e21

@ -3,6 +3,7 @@ package com.ruoyi.quartz.task.CJT;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.lark.oapi.service.bitable.v1.model.AppTableRecord; import com.lark.oapi.service.bitable.v1.model.AppTableRecord;
import com.lark.oapi.service.bitable.v1.model.BatchCreateAppTableRecordRespBody; import com.lark.oapi.service.bitable.v1.model.BatchCreateAppTableRecordRespBody;
import com.lark.oapi.service.bitable.v1.model.ListAppTableRecordRespBody;
import com.ruoyi.common.constant.RedisConstants; import com.ruoyi.common.constant.RedisConstants;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.AppType; import com.ruoyi.common.enums.AppType;
@ -94,10 +95,11 @@ public class SyncReportJob {
initLarkInfo(context); initLarkInfo(context);
//重置ticket //重置ticket
resetTicket(context); resetTicket(context);
preSync(context); // preSync(context);
cleanTableDate(context);
//执行分页同步 //执行分页同步
sync(context); sync(context);
finish(context); // finish(context);
} catch (Exception e) { } catch (Exception e) {
log.error("{} 执行失败", getClassName(), e); log.error("{} 执行失败", getClassName(), e);
larkRobotHelper.sendMessageByBot(ROBOT_GROUP, buildRobotErrorCountMessage(e)); larkRobotHelper.sendMessageByBot(ROBOT_GROUP, buildRobotErrorCountMessage(e));
@ -212,18 +214,18 @@ public class SyncReportJob {
private void preSync(CJTJobContext context) { private void preSync(CJTJobContext context) {
CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(context.getCjt()); CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(context.getCjt());
if (cjtAccountEnum == null){ if (cjtAccountEnum == null) {
return; return;
} }
Long maxId = erpLarkTempRelationMapper.selectMaxId(getReportName(), FlagStatus.OK.getCode(),cjtAccountEnum.getAppKey()); Long maxId = erpLarkTempRelationMapper.selectMaxId(getReportName(), FlagStatus.OK.getCode(), cjtAccountEnum.getAppKey());
context.setErpLarkTempRelationMaxId(maxId); context.setErpLarkTempRelationMaxId(maxId);
erpLarkTempRelationMapper.updateByMethod(getReportName(), FlagStatus.DELETED.getCode(),maxId,cjtAccountEnum.getAppKey()); erpLarkTempRelationMapper.updateByMethod(getReportName(), FlagStatus.DELETED.getCode(), maxId, cjtAccountEnum.getAppKey());
} }
private void finish(CJTJobContext context) { private void finish(CJTJobContext context) {
try { try {
CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(context.getCjt()); CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(context.getCjt());
if (cjtAccountEnum == null){ if (cjtAccountEnum == null) {
return; return;
} }
LarkCompanyRelation companyRelation = context.getCompanyRelation(); LarkCompanyRelation companyRelation = context.getCompanyRelation();
@ -250,17 +252,43 @@ public class SyncReportJob {
request.setRecords(larkKeyList.toArray(new String[0])); request.setRecords(larkKeyList.toArray(new String[0]));
larkTableHelper.deleteTableRecordBatch(request); larkTableHelper.deleteTableRecordBatch(request);
} }
erpLarkTempRelationMapper.deleteByMethod(getReportName(), FlagStatus.DELETED.getCode(),context.getErpLarkTempRelationMaxId(),cjtAccountEnum.getAppKey()); erpLarkTempRelationMapper.deleteByMethod(getReportName(), FlagStatus.DELETED.getCode(), context.getErpLarkTempRelationMaxId(), cjtAccountEnum.getAppKey());
} catch (Exception e) { } catch (Exception e) {
log.info("Sync report job finish error", e); log.info("Sync report job finish error", e);
} }
} }
private void cleanTableDate(CJTJobContext context) {
CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(context.getCjt());
if (cjtAccountEnum == null) {
return;
}
LarkCompanyRelation companyRelation = context.getCompanyRelation();
LarkTableRelation tableRelation = context.getTableRelation();
LarkTableRequest request = new LarkTableRequest(companyRelation.getAppId(), companyRelation.getSecret(), tableRelation.getToAppToken(), tableRelation.getToTableId());
request.setPageSize(500);
AppTableRecord[] items = null;
do {
try {
List<String> larkKeyList = new ArrayList<>();
ListAppTableRecordRespBody respBody = larkTableHelper.listTableRecord(request);
items = respBody.getItems();
for (AppTableRecord item : items) {
larkKeyList.add(item.getRecordId());
}
request.setRecords(larkKeyList.toArray(new String[0]));
larkTableHelper.deleteTableRecordBatch(request);
} catch (Exception e) {
log.info("Sync report job finish error", e);
}
} while (items != null && items.length > 0);
}
private Boolean executeDetail(CJTJobContext context, CJTRequest cjtRequest, LarkTableRequest addRecordRequest) { private Boolean executeDetail(CJTJobContext context, CJTRequest cjtRequest, LarkTableRequest addRecordRequest) {
cjtRequest.setOpenToken(generateToken(context)); cjtRequest.setOpenToken(generateToken(context));
//请求接口并序列化数据 //请求接口并序列化数据
CJTResponseReportBodyDetail bodyDetail = request(cjtRequest); CJTResponseReportBodyDetail bodyDetail = request(cjtRequest);
if (bodyDetail == null){ if (bodyDetail == null) {
return Boolean.FALSE; return Boolean.FALSE;
} }
//实际返回数据 //实际返回数据
@ -293,7 +321,6 @@ public class SyncReportJob {
try { try {
//错误唯一键 //错误唯一键
List<AppTableRecord> list = new ArrayList<>(); List<AppTableRecord> list = new ArrayList<>();
List<ErpLarkTempRelation> waitCreateList = new ArrayList<>();
for (CJTResponseReportBodyDetailRow row : rows) { for (CJTResponseReportBodyDetailRow row : rows) {
Map<String, Object> body = buildLarkBody(row); Map<String, Object> body = buildLarkBody(row);
addRecordRequest.setBody(body); addRecordRequest.setBody(body);
@ -301,16 +328,10 @@ public class SyncReportJob {
appTableRecord.setFields(body); appTableRecord.setFields(body);
list.add(appTableRecord); list.add(appTableRecord);
} }
if (CollectionUtils.isNotEmpty(list)){ if (CollectionUtils.isNotEmpty(list)) {
addRecordRequest.setAppTableRecords(list.toArray(new AppTableRecord[0])); addRecordRequest.setAppTableRecords(list.toArray(new AppTableRecord[0]));
//在飞书创建一行并根据创建返回的行id在本地保留一条映射纪律 //在飞书创建一行并根据创建返回的行id在本地保留一条映射纪律
BatchCreateAppTableRecordRespBody resp = larkTableHelper.addTableRecordBatch(addRecordRequest); larkTableHelper.addTableRecordBatch(addRecordRequest);
for (AppTableRecord record : resp.getRecords()) {
buildTempList(waitCreateList,record.getRecordId(),cjt);
}
if (CollectionUtils.isNotEmpty(waitCreateList)){
erpLarkTempRelationMapper.batchInsert(waitCreateList);
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error("{} addOrUpdate exception", this.getClassName(), e); log.error("{} addOrUpdate exception", this.getClassName(), e);
@ -318,9 +339,9 @@ public class SyncReportJob {
return errorKey; return errorKey;
} }
private void buildTempList(List<ErpLarkTempRelation> waitCreateList,String recordId, String cjt){ private void buildTempList(List<ErpLarkTempRelation> waitCreateList, String recordId, String cjt) {
CjtAccountEnum byCode = CjtAccountEnum.getByCode(cjt); CjtAccountEnum byCode = CjtAccountEnum.getByCode(cjt);
if (byCode == null){ if (byCode == null) {
return; return;
} }
ErpLarkTempRelation erpLarkTempRelation = new ErpLarkTempRelation(); ErpLarkTempRelation erpLarkTempRelation = new ErpLarkTempRelation();

Loading…
Cancel
Save