From fe56661e2129b09d3866e404edb536ec85e366c0 Mon Sep 17 00:00:00 2001 From: YXY <932687738@qq.com> Date: Tue, 10 Oct 2023 22:22:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=A1=A8=E6=9B=B4=E6=96=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BC=83=E7=94=A8=E4=B8=AD=E9=97=B4=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/quartz/task/CJT/SyncReportJob.java | 59 +++++++++++++------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/CJT/SyncReportJob.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/CJT/SyncReportJob.java index e2bdb5c..3c297d8 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/CJT/SyncReportJob.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/CJT/SyncReportJob.java @@ -3,6 +3,7 @@ package com.ruoyi.quartz.task.CJT; import com.alibaba.fastjson.JSONObject; 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.ListAppTableRecordRespBody; import com.ruoyi.common.constant.RedisConstants; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.AppType; @@ -94,10 +95,11 @@ public class SyncReportJob { initLarkInfo(context); //重置ticket resetTicket(context); - preSync(context); +// preSync(context); + cleanTableDate(context); //执行分页同步 sync(context); - finish(context); +// finish(context); } catch (Exception e) { log.error("{} 执行失败", getClassName(), e); larkRobotHelper.sendMessageByBot(ROBOT_GROUP, buildRobotErrorCountMessage(e)); @@ -212,18 +214,18 @@ public class SyncReportJob { private void preSync(CJTJobContext context) { CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(context.getCjt()); - if (cjtAccountEnum == null){ + if (cjtAccountEnum == null) { return; } - Long maxId = erpLarkTempRelationMapper.selectMaxId(getReportName(), FlagStatus.OK.getCode(),cjtAccountEnum.getAppKey()); + Long maxId = erpLarkTempRelationMapper.selectMaxId(getReportName(), FlagStatus.OK.getCode(), cjtAccountEnum.getAppKey()); 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) { try { CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(context.getCjt()); - if (cjtAccountEnum == null){ + if (cjtAccountEnum == null) { return; } LarkCompanyRelation companyRelation = context.getCompanyRelation(); @@ -250,17 +252,43 @@ public class SyncReportJob { request.setRecords(larkKeyList.toArray(new String[0])); 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) { 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 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) { cjtRequest.setOpenToken(generateToken(context)); //请求接口并序列化数据 CJTResponseReportBodyDetail bodyDetail = request(cjtRequest); - if (bodyDetail == null){ + if (bodyDetail == null) { return Boolean.FALSE; } //实际返回数据 @@ -293,7 +321,6 @@ public class SyncReportJob { try { //错误唯一键 List list = new ArrayList<>(); - List waitCreateList = new ArrayList<>(); for (CJTResponseReportBodyDetailRow row : rows) { Map body = buildLarkBody(row); addRecordRequest.setBody(body); @@ -301,16 +328,10 @@ public class SyncReportJob { appTableRecord.setFields(body); list.add(appTableRecord); } - if (CollectionUtils.isNotEmpty(list)){ + if (CollectionUtils.isNotEmpty(list)) { addRecordRequest.setAppTableRecords(list.toArray(new AppTableRecord[0])); //在飞书创建一行,并根据创建返回的行id在本地保留一条映射纪律 - BatchCreateAppTableRecordRespBody resp = larkTableHelper.addTableRecordBatch(addRecordRequest); - for (AppTableRecord record : resp.getRecords()) { - buildTempList(waitCreateList,record.getRecordId(),cjt); - } - if (CollectionUtils.isNotEmpty(waitCreateList)){ - erpLarkTempRelationMapper.batchInsert(waitCreateList); - } + larkTableHelper.addTableRecordBatch(addRecordRequest); } } catch (Exception e) { log.error("{} addOrUpdate exception", this.getClassName(), e); @@ -318,9 +339,9 @@ public class SyncReportJob { return errorKey; } - private void buildTempList(List waitCreateList,String recordId, String cjt){ + private void buildTempList(List waitCreateList, String recordId, String cjt) { CjtAccountEnum byCode = CjtAccountEnum.getByCode(cjt); - if (byCode == null){ + if (byCode == null) { return; } ErpLarkTempRelation erpLarkTempRelation = new ErpLarkTempRelation();