修改唯一键
continuous-integration/drone/push Build is passing Details

odoo切换查询方式
YXY 1 year ago
parent 6c8b353fe2
commit f1c33378ca

@ -3,6 +3,8 @@ package com.ruoyi.flyingbook.LarkHelper;
import com.lark.oapi.Client; import com.lark.oapi.Client;
import com.lark.oapi.core.cache.ICache; import com.lark.oapi.core.cache.ICache;
import com.lark.oapi.core.enums.AppType; import com.lark.oapi.core.enums.AppType;
import com.lark.oapi.core.httpclient.OkHttpTransport;
import com.lark.oapi.okhttp.OkHttpClient;
import com.lark.oapi.service.bitable.v1.model.*; import com.lark.oapi.service.bitable.v1.model.*;
import com.ruoyi.flyingbook.domain.lark.LarkRequest; import com.ruoyi.flyingbook.domain.lark.LarkRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -10,6 +12,7 @@ import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
/** /**
* @author yuxiangyong * @author yuxiangyong
@ -32,6 +35,17 @@ public class LarkHelper {
return Client.newBuilder(request.getAppId(), request.getAppSecret()) return Client.newBuilder(request.getAppId(), request.getAppSecret())
.marketplaceApp() .marketplaceApp()
.appType(AppType.SELF_BUILT) .appType(AppType.SELF_BUILT)
.httpTransport(okHttpTransport())
.build(); .build();
} }
public OkHttpTransport okHttpTransport() {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(20, TimeUnit.SECONDS)
.writeTimeout(100, TimeUnit.SECONDS)
.readTimeout(100, TimeUnit.SECONDS)
.build();
OkHttpTransport okHttpTransport = new OkHttpTransport(okHttpClient);
return okHttpTransport;
}
} }

@ -58,7 +58,9 @@ public class ManufactureOrderSyncJob extends SyncAccountsJobAbstract {
return Arrays.asList( return Arrays.asList(
"code", "code",
"manufactureorderdetails_inventory_code", "manufactureorderdetails_inventory_code",
"manufactureorderdetails_pubuserdefnvc2"); "manufactureorderdetails_pubuserdefnvc2",
"manufactureorderdetails_quantity",
"manufactureorderdetails_sourcevouchercode");
} }
@Override @Override

@ -1,6 +1,7 @@
package com.ruoyi.quartz.task.CJT; package com.ruoyi.quartz.task.CJT;
import com.ruoyi.common.enums.AppType; import com.ruoyi.common.enums.AppType;
import com.ruoyi.common.enums.CjtAccountEnum;
import com.ruoyi.common.enums.TableFieldTypeEnum; import com.ruoyi.common.enums.TableFieldTypeEnum;
import com.ruoyi.common.enums.TableRelationTypeEnum; import com.ruoyi.common.enums.TableRelationTypeEnum;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
@ -44,10 +45,19 @@ public class PurchaseArrivalOpenSyncJob extends SyncAccountsJobAbstract{
@Override @Override
protected List<String> getUniqueFields(String cjt) { protected List<String> getUniqueFields(String cjt) {
CjtAccountEnum cjtAccountEnum = CjtAccountEnum.getByCode(cjt);
if (cjtAccountEnum != null && cjtAccountEnum.equals(CjtAccountEnum.TWO)){
return Arrays.asList( return Arrays.asList(
"code", "code",
"details_inventory_code", "details_inventory_code",
"details_detailmemo"); "details_detailmemo");
}
return Arrays.asList(
"code",
"details_inventory_code",
"details_detailmemo",
"details_quantity");
} }
@Override @Override

@ -54,13 +54,15 @@ public class SaleDeliverySyncJob extends SyncAccountsJobAbstract {
"saledeliverydetails_saleordercode",//销售订单号 "saledeliverydetails_saleordercode",//销售订单号
"saledeliverydetails_inventory_code",//存货编码 "saledeliverydetails_inventory_code",//存货编码
"saledeliverydetails_quantity",//数量 "saledeliverydetails_quantity",//数量
"memo");//备注1 "memo",//备注1
"saledeliverydetails_detailmemo");//明细备注1
} }
List<String> list = new ArrayList<>(Arrays.asList( List<String> list = new ArrayList<>(Arrays.asList(
"code",//单据编号 "code",//单据编号
"saledeliverydetails_inventory_code", "saledeliverydetails_inventory_code",
"saledeliverydetails_detailmemo")); "saledeliverydetails_detailmemo",
"saledeliverydetails_quantity"));
return list; return list;
} }

@ -52,13 +52,15 @@ public class SaleOrderSyncJob extends SyncAccountsJobAbstract{
"code",//编号 "code",//编号
"saleorderdetails_inventory_code",//存货编码 "saleorderdetails_inventory_code",//存货编码
"saleorderdetails_pubuserdefnvc1",//钢板面 "saleorderdetails_pubuserdefnvc1",//钢板面
"saleorderdetails_detailmemo");//明细备注 "saleorderdetails_detailmemo",//明细备注
"saleorderdetails_quantity");//数量
} }
List<String> list = Arrays.asList( List<String> list = Arrays.asList(
"code", "code",
"saleorderdetails_inventory_code", "saleorderdetails_inventory_code",
"saleorderdetails_detailmemo"); "saleorderdetails_detailmemo",
"saleorderdetails_quantity");
return list; return list;
} }

@ -2,6 +2,7 @@ package com.ruoyi.quartz.task.CJT;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.lark.oapi.core.utils.Lists; import com.lark.oapi.core.utils.Lists;
import com.lark.oapi.service.bitable.v1.model.AppTableRecord;
import com.lark.oapi.service.bitable.v1.model.CreateAppTableRecordRespBody; import com.lark.oapi.service.bitable.v1.model.CreateAppTableRecordRespBody;
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;
@ -10,6 +11,7 @@ import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper; import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper;
import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper; import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper;
import com.ruoyi.flyingbook.domain.ErpLarkRelation; import com.ruoyi.flyingbook.domain.ErpLarkRelation;
import com.ruoyi.flyingbook.domain.ErpLarkTempRelation;
import com.ruoyi.flyingbook.domain.LarkCompanyRelation; 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;
@ -62,7 +64,7 @@ public abstract class SyncAccountsJobAbstract {
/** /**
* *
*/ */
protected static final Integer PAGE_SIZE = 20; protected static final Integer PAGE_SIZE = 50;
public static final String RETRY_KEY = "RETRY_CJT:%s:%s"; public static final String RETRY_KEY = "RETRY_CJT:%s:%s";
@ -82,9 +84,8 @@ public abstract class SyncAccountsJobAbstract {
private Boolean asynchronousCheck(LocalDateTime now, String cjt) { private Boolean asynchronousCheck(LocalDateTime now, String cjt) {
int hour = now.getHour(); int hour = now.getHour();
if (hour != 1) { if ((hour == 0 && CjtAccountEnum.ONE.getCode().equals(cjt))
return Boolean.FALSE; || (hour == 1 && CjtAccountEnum.TWO.getCode().equals(cjt))) {
}
//目前只给畅捷通账号二加工单开补偿劝降 //目前只给畅捷通账号二加工单开补偿劝降
if ((AppType.SYNC_CJT_MANUFACTURE_ORDER_DATA_TO_MULTI_TABLE.getCode().equals(syncLarkAppType().getCode()) 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.TWO.getCode().equals(cjt)) || (AppType.SYNC_CJT_SALE_DISPATCH_DATA_TO_MULTI_TABLE.getCode().equals(syncLarkAppType().getCode())
@ -100,6 +101,8 @@ public abstract class SyncAccountsJobAbstract {
return false; return false;
} }
} }
return false;
}
private String getAsynchronousKey(String cjt) { private String getAsynchronousKey(String cjt) {
return String.format("%s:%s:%s", RedisConstants.CJT_ASYNCHRONOUS, syncLarkAppType().getCode(), cjt); return String.format("%s:%s:%s", RedisConstants.CJT_ASYNCHRONOUS, syncLarkAppType().getCode(), cjt);
@ -109,16 +112,15 @@ public abstract class SyncAccountsJobAbstract {
CJTJobContext context = new CJTJobContext(); CJTJobContext context = new CJTJobContext();
Boolean asynchronous = asynchronousCheck(now, cjt); Boolean asynchronous = asynchronousCheck(now, cjt);
context.setAsynchronous(asynchronous); context.setAsynchronous(asynchronous);
LocalDate localDate = LocalDate.now().minusDays(1L);
if (StringUtils.isEmpty(queryFromTime)) { if (StringUtils.isEmpty(queryFromTime)) {
queryFromTime = asynchronous queryFromTime = asynchronous
? DateUtils.startOfDate(localDate) ? DateUtils.startOfDate(LocalDate.now().minusDays(8L))
: DateUtils.ldt2str(now.minusMinutes(REDUCE_MINUTES), DateUtils.YYYY_MM_DD_HH_MM_SS); : DateUtils.ldt2str(now.minusMinutes(REDUCE_MINUTES), DateUtils.YYYY_MM_DD_HH_MM_SS);
} }
context.setQueryFromTime(queryFromTime); context.setQueryFromTime(queryFromTime);
if (StringUtils.isEmpty(queryToTime)) { if (StringUtils.isEmpty(queryToTime)) {
queryToTime = asynchronous queryToTime = asynchronous
? DateUtils.endOfDate(localDate) ? DateUtils.endOfDate(LocalDate.now().minusDays(1L))
: DateUtils.ldt2str(now, DateUtils.YYYY_MM_DD_HH_MM_SS); : DateUtils.ldt2str(now, DateUtils.YYYY_MM_DD_HH_MM_SS);
} }
context.setQueryToTime(queryToTime); context.setQueryToTime(queryToTime);
@ -168,12 +170,12 @@ public abstract class SyncAccountsJobAbstract {
log.info("===================== {} strat ======================", this.getClassName()); log.info("===================== {} strat ======================", this.getClassName());
//初始化飞书信息及相关配置 //初始化飞书信息及相关配置
initLarkInfo(context); initLarkInfo(context);
if (Boolean.TRUE.equals(context.getAsynchronous())) { // if (Boolean.TRUE.equals(context.getAsynchronous())) {
Boolean deleteSuccess = handleRepeatData(now, cjt, context); // Boolean deleteSuccess = handleRepeatData(now, cjt, context);
if (!deleteSuccess){ // if (!deleteSuccess){
return; // return;
} // }
} // }
//重置ticket //重置ticket
resetTicket(context); resetTicket(context);
//执行分页同步 //执行分页同步
@ -440,6 +442,7 @@ public abstract class SyncAccountsJobAbstract {
List<String> errorKey = new ArrayList<>(); List<String> errorKey = new ArrayList<>();
//判断当前查询条件内是否存在重复数据 //判断当前查询条件内是否存在重复数据
Map<String, Integer> repeatMap = new HashMap<>(); Map<String, Integer> repeatMap = new HashMap<>();
List<AppTableRecord> waitUpdateList = new ArrayList<>();
for (List<String> row : rows) { for (List<String> row : rows) {
String uniqueKey = null; String uniqueKey = null;
try { try {
@ -472,9 +475,10 @@ public abstract class SyncAccountsJobAbstract {
} 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进行置空
addRecordRequest.setRecord(larkKey); AppTableRecord appTableRecord = new AppTableRecord();
larkTableHelper.updateTableRecord(addRecordRequest); appTableRecord.setFields(body);
addRecordRequest.setRecord(null); appTableRecord.setRecordId(larkKey);
waitUpdateList.add(appTableRecord);
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -482,12 +486,24 @@ public abstract class SyncAccountsJobAbstract {
errorKey.add(String.format("【%s,%s】", uniqueKey, e.getMessage())); errorKey.add(String.format("【%s,%s】", uniqueKey, e.getMessage()));
} }
} }
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(waitUpdateList)) {
addRecordRequest.setAppTableRecords(waitUpdateList.toArray(new AppTableRecord[0]));
updateTableRecordBatch(addRecordRequest);
}
if (!CollectionUtils.isEmpty(relationList)) { if (!CollectionUtils.isEmpty(relationList)) {
erpLarkRelationMapper.batchInsert(relationList); erpLarkRelationMapper.batchInsert(relationList);
} }
return errorKey; return errorKey;
} }
private void updateTableRecordBatch(LarkTableRequest addRecordRequest) {
try {
larkTableHelper.updateTableRecordBatch(addRecordRequest);
} catch (Exception e) {
log.error("批量更新失败");
}
}
//构建飞书行与cjt唯一键的对应关系对象 //构建飞书行与cjt唯一键的对应关系对象
private ErpLarkRelation buildErpLarkRelation(String key, String larkKey, String cjt, Boolean asynchronous) { private ErpLarkRelation buildErpLarkRelation(String key, String larkKey, String cjt, Boolean asynchronous) {
ErpLarkRelation erpLarkRelation = new ErpLarkRelation(); ErpLarkRelation erpLarkRelation = new ErpLarkRelation();

Loading…
Cancel
Save