ODOO 修改product查询条件
continuous-integration/drone/push Build is passing Details

沃森川job同步飞书
YXY 1 year ago
parent bc3364c66a
commit 19364f7729

@ -24,7 +24,9 @@ public enum TableRelationTypeEnum {
SYNC_CJT_SALE_ORDER("SYNC_CJT_SALE_ORDER", "同步畅捷通销售订单"), SYNC_CJT_SALE_ORDER("SYNC_CJT_SALE_ORDER", "同步畅捷通销售订单"),
SYNC_CJT_SALE_DISPATCH("SYNC_CJT_SALE_DISPATCH", "同步畅捷通销售出库单"), SYNC_CJT_SALE_DISPATCH("SYNC_CJT_SALE_DISPATCH", "同步畅捷通销售出库单"),
SYNC_ODOO_ACCOUNT_MOVE_LINE("SYNC_ODOO_ACCOUNT_MOVE_LINE", "每天晚上7点后更新"), SYNC_ODOO_ACCOUNT_MOVE_LINE("SYNC_ODOO_ACCOUNT_MOVE_LINE", "每天晚上7点后更新"),
SYNC_ODOO_PRODUCT_PRODUCT("SYNC_ODOO_PRODUCT_PRODUCT", "周日一更"), SYNC_ODOO_PRODUCT_PRODUCT_ONE("SYNC_ODOO_PRODUCT_PRODUCT_ONE", "仓库id=1"),
SYNC_ODOO_PRODUCT_PRODUCT_SIX("SYNC_ODOO_PRODUCT_PRODUCT_SIX", "仓库id=6"),
SYNC_ODOO_PRODUCT_PRODUCT_EIGHT("SYNC_ODOO_PRODUCT_PRODUCT_EIGHT", "仓库id=8"),
SYNC_ODOO_PRODUCT_PACKING("SYNC_ODOO_PRODUCT_PACKING", "周日一更"), SYNC_ODOO_PRODUCT_PACKING("SYNC_ODOO_PRODUCT_PACKING", "周日一更"),
SYNC_ODOO_PRODUCT_SHUKIKU("SYNC_ODOO_PRODUCT_SHUKIKU", "周日一更"), SYNC_ODOO_PRODUCT_SHUKIKU("SYNC_ODOO_PRODUCT_SHUKIKU", "周日一更"),
SYNC_ODOO_STOCK_QUANT("SYNC_ODOO_STOCK_QUANT", "每天晚上7点后更新"); SYNC_ODOO_STOCK_QUANT("SYNC_ODOO_STOCK_QUANT", "每天晚上7点后更新");

@ -17,6 +17,7 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class OdooContext implements Serializable { public class OdooContext implements Serializable {
private Integer warehouseId;
private XmlRpcClient models; private XmlRpcClient models;
private Integer uid; private Integer uid;

@ -32,8 +32,8 @@ public class AccountMoveLineJob extends OdooAbstrackob {
} }
@Override @Override
public void execute() { public void execute(Integer warehouseId) {
super.execute(); super.execute(warehouseId);
} }
@Override @Override
@ -41,13 +41,13 @@ public class AccountMoveLineJob extends OdooAbstrackob {
String date = DateUtils.ldt2str(LocalDateTime.now(), DateUtils.YYYY_MM_DD); String date = DateUtils.ldt2str(LocalDateTime.now(), DateUtils.YYYY_MM_DD);
return Arrays.asList(Arrays.asList( return Arrays.asList(Arrays.asList(
Arrays.asList("parent_state", "=", "posted") Arrays.asList("parent_state", "=", "posted")
, Arrays.asList("account_id", "=", 1018) , Arrays.asList("account_id", "in","1018,107,1189")
// ,Arrays.asList("Date", ">", 2023-07-27) ,Arrays.asList("create_date", ">=", date)
)); ));
} }
@Override @Override
protected Map<String, List<String>> getQueryFieldMap() { protected Map<String, List<String>> getQueryFieldMap(Integer warehouseId) {
// return new HashMap() {{ // return new HashMap() {{
// put("fields", Arrays.asList("id","partner_id.name", "date", "product_id.default_code" // put("fields", Arrays.asList("id","partner_id.name", "date", "product_id.default_code"
// , "quantity", "unit_price", "company_id.display_name","product_id.categ_id.name")); // , "quantity", "unit_price", "company_id.display_name","product_id.categ_id.name"));
@ -78,7 +78,7 @@ public class AccountMoveLineJob extends OdooAbstrackob {
@Override @Override
protected TableRelationTypeEnum syncLarkType() { protected TableRelationTypeEnum syncLarkType(Integer warehouseId) {
return TableRelationTypeEnum.SYNC_ODOO_ACCOUNT_MOVE_LINE; return TableRelationTypeEnum.SYNC_ODOO_ACCOUNT_MOVE_LINE;
} }
} }

@ -0,0 +1,197 @@
package com.ruoyi.quartz.task.odoo;
import com.lark.oapi.service.bitable.v1.enums.AppTableCreateHeaderTypeEnum;
import com.lark.oapi.service.bitable.v1.model.AppTableCreateHeader;
import com.lark.oapi.service.bitable.v1.model.AppTableFieldProperty;
import com.lark.oapi.service.bitable.v1.model.CreateAppTableRespBody;
import com.ruoyi.common.enums.AppType;
import com.ruoyi.common.enums.CjtAccountEnum;
import com.ruoyi.common.enums.FlagStatus;
import com.ruoyi.common.enums.TableRelationTypeEnum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper;
import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper;
import com.ruoyi.flyingbook.domain.LarkCompanyRelation;
import com.ruoyi.flyingbook.domain.LarkTableRelation;
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
import com.ruoyi.flyingbook.mapper.LarkCompanyRelationMapper;
import com.ruoyi.flyingbook.mapper.LarkTableRelationMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.*;
/**
* odoo
*
* @author yuxiangyong
* @create 2023-07-17 21:21
*/
@Slf4j
@Component("CJTOdooLarkTableJob")
public class CJTOdooLarkTableJob {
@Autowired
private LarkCompanyRelationMapper larkCompanyRelationMapper;
@Autowired
private LarkTableRelationMapper larkTableRelationMapper;
@Autowired
private LarkTableHelper larkTableHelper;
@Autowired
private LarkRobotHelper larkRobotHelper;
@Value("${lark.robot.group}")
private String ROBOT_GROUP;
private static final List<Integer> enableExecuteMonth = Arrays.asList(1,4,7,10);
public void execute() {
Map<AppType, TableRelationTypeEnum> waitCreatMap = getWaitCreateMap();
Map<TableRelationTypeEnum, String> tableNameMap = getTableNameMap();
LocalDateTime now = LocalDateTime.now();
if (!enableExecuteMonth.contains(now.getMonthValue())){
return;
}
List<String> errorList = new ArrayList<>();
for (Map.Entry<AppType, TableRelationTypeEnum> entry : waitCreatMap.entrySet()) {
AppType appType = entry.getKey();
TableRelationTypeEnum tableRelationType = entry.getValue();
try {
LarkCompanyRelation companyRelation = this.getCompanyRelation(appType);
LarkTableRelation tableRelation = this.getTableRelation(companyRelation.getId(), tableRelationType);
String tableName = buileTableName(tableNameMap.get(tableRelationType), now);
AppTableCreateHeader[] larkHeader = getLarkHeader(tableRelationType);
LarkTableRequest request = new LarkTableRequest(companyRelation.getAppId(), companyRelation.getSecret(), tableRelation.getToAppToken(), tableName, tableName, larkHeader);
CreateAppTableRespBody dataTable = larkTableHelper.createDataTable(request);
tableRelation.setToTableId(dataTable.getTableId());
larkTableRelationMapper.updateLarkTableRelation(tableRelation);
} catch (Exception e) {
log.error("{} 创建多维表格失败", e);
errorList.add(String.format("【%s:%s】", tableRelationType.getCode(), e.getMessage()));
}
}
if (CollectionUtils.isNotEmpty(errorList)) {
larkRobotHelper.sendMessageByBot(ROBOT_GROUP, String.join(";", errorList));
}
}
private String buileTableName(String tableRelationName,LocalDateTime now){
StringBuilder sb = new StringBuilder();
sb.append(now.getYear());
int monthValue = now.getMonthValue();
switch (monthValue){
case 1:
sb.append("Q1");
break;
case 4:
sb.append("Q2");
break;
case 7:
sb.append("Q3");
break;
case 10:
sb.append("Q4");
break;
default:
break;
}
sb.append(tableRelationName);
return sb.toString();
}
private Map<AppType, TableRelationTypeEnum> getWaitCreateMap() {
Map<AppType, TableRelationTypeEnum> map = new HashMap<>();
map.put(AppType.SYNC_ODOO_DATA_TO_MULTI_TABLE, TableRelationTypeEnum.SYNC_ODOO_ACCOUNT_MOVE_LINE);
map.put(AppType.SYNC_ODOO_DATA_TO_MULTI_TABLE, TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT_ONE);
map.put(AppType.SYNC_ODOO_DATA_TO_MULTI_TABLE, TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT_SIX);
map.put(AppType.SYNC_ODOO_DATA_TO_MULTI_TABLE, TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT_EIGHT);
return map;
}
private Map<TableRelationTypeEnum, String> getTableNameMap() {
Map<TableRelationTypeEnum, String> map = new HashMap<>();
map.put(TableRelationTypeEnum.SYNC_ODOO_ACCOUNT_MOVE_LINE, "account");
map.put(TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT_ONE, "product_1");
map.put(TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT_SIX, "product_6");
map.put(TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT_EIGHT, "product_8");
return map;
}
private AppTableCreateHeader[] getLarkHeader(TableRelationTypeEnum appType) {
switch (appType) {
case SYNC_ODOO_ACCOUNT_MOVE_LINE:
return new AppTableCreateHeader[]{
buildHeader("id", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("date", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("quantity", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("partner_id", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("product_id", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("price_unit", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("company_id", AppTableCreateHeaderTypeEnum.TEXT)
};
case SYNC_ODOO_PRODUCT_PRODUCT_ONE:
case SYNC_ODOO_PRODUCT_PRODUCT_SIX:
case SYNC_ODOO_PRODUCT_PRODUCT_EIGHT:
return new AppTableCreateHeader[]{
buildHeader("id", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("default_code", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("name", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("description_purchase", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("qty_available", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("incoming_qty", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("packaging_ids", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("standard_price", AppTableCreateHeaderTypeEnum.TEXT),
buildHeader("categ_id", AppTableCreateHeaderTypeEnum.TEXT)
};
default:
return null;
}
}
private AppTableFieldProperty buildProperty(String formatter) {
AppTableFieldProperty.Builder property = AppTableFieldProperty.newBuilder();
if (DateUtils.YYYY_MM_DD_SECOND.equals(formatter)) {
property.autoFill(Boolean.FALSE);
property.dateFormatter(formatter);
} else {
property.formatter(formatter);
}
return property.build();
}
private AppTableCreateHeader buildHeader(String fieldName, AppTableCreateHeaderTypeEnum type) {
AppTableCreateHeader.Builder builder = new AppTableCreateHeader.Builder();
builder.fieldName(fieldName)
.type(type);
return new AppTableCreateHeader(builder);
}
private AppTableCreateHeader buildPropertyHeader(String fieldName, AppTableCreateHeaderTypeEnum type, AppTableFieldProperty property) {
AppTableCreateHeader.Builder builder = new AppTableCreateHeader.Builder();
builder.fieldName(fieldName)
.type(type)
.property(property);
return new AppTableCreateHeader(builder);
}
private LarkCompanyRelation getCompanyRelation(AppType appType) {
LarkCompanyRelation companyRelationQuery = new LarkCompanyRelation();
companyRelationQuery.setAppType(appType.getCode());
companyRelationQuery.setFlag(FlagStatus.OK.getCode());
List<LarkCompanyRelation> larkCompanyRelations = larkCompanyRelationMapper.selectLarkCompanyRelationList(companyRelationQuery);
return larkCompanyRelations.get(0);
}
private LarkTableRelation getTableRelation(Long companyRelationId, TableRelationTypeEnum relationType) {
LarkTableRelation tableRelationQuery = new LarkTableRelation();
tableRelationQuery.setLarkCompanyRelationId(companyRelationId);
tableRelationQuery.setFlag(FlagStatus.OK.getCode());
tableRelationQuery.setRelationType(relationType.getCode());
List<LarkTableRelation> larkTableRelations = larkTableRelationMapper.selectLarkTableRelationList(tableRelationQuery);
return larkTableRelations.get(0);
}
}

@ -55,11 +55,6 @@ public abstract class OdooAbstrackob {
@Value("${lark.robot.group}") @Value("${lark.robot.group}")
private String ROBOT_GROUP; private String ROBOT_GROUP;
public static final String ACCOUNT_MOVE_LINE_MODEL_NAME = "account.move.line";
public static final String PRODUCT_PRODUCT_MODEL_NAME = "product.product";
public static final String PRODUCT_PACKING_MODEL_NAME = "product_packaging";
public static final String PRODUCT_PRODUCT_SHUKIKU_MODEL_NAME = "product.product.shukiku";
public static final String STOCK_QUANT_MODEL_NAME = "stock_quant";
private static final String GET_DATA_DB = "Fortune_test0716"; private static final String GET_DATA_DB = "Fortune_test0716";
private static final String GET_DATA_NAME = "test"; private static final String GET_DATA_NAME = "test";
@ -72,11 +67,11 @@ public abstract class OdooAbstrackob {
private static final String PAGE_LIMIT_KEY = "limit"; private static final String PAGE_LIMIT_KEY = "limit";
private static final Integer PAGE_SIZE = 20; private static final Integer PAGE_SIZE = 20;
public void execute() { public void execute(Integer warehouseId) {
try { try {
log.info("===================== {} strat ======================", this.getClassName()); log.info("===================== {} strat ======================", this.getClassName());
//初始化调用对象 //初始化调用对象
OdooContext context = initContext(); OdooContext context = initContext(warehouseId);
//初始化飞书信息 //初始化飞书信息
initLarkInfo(context); initLarkInfo(context);
//分页调用接口批量更新 //分页调用接口批量更新
@ -112,14 +107,14 @@ public abstract class OdooAbstrackob {
//待创建关联关系 //待创建关联关系
do { do {
List<ErpLarkRelation> waitCreateRelation = new ArrayList<>(); List<ErpLarkRelation> waitCreateRelation = new ArrayList<>();
dateList = getDate(context, pageMap, errorList); dateList = getDate(context, pageMap, errorList,context.getWarehouseId());
List<JSONObject> midDateList = dateList.stream().map(r -> { List<JSONObject> midDateList = dateList.stream().map(r -> {
return (JSONObject)JSONObject.toJSON(r); return (JSONObject)JSONObject.toJSON(r);
}).collect(Collectors.toList()); }).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(midDateList)){ if (CollectionUtils.isNotEmpty(midDateList)){
Map<String, String> relationMap = getLarkRelation(midDateList); Map<String, String> relationMap = getLarkRelation(midDateList,context.getWarehouseId());
for (JSONObject jsonObject : midDateList) { for (JSONObject jsonObject : midDateList) {
sync(jsonObject, errorList, relationMap, larkRequest,waitCreateRelation); sync(jsonObject, errorList, relationMap, larkRequest,waitCreateRelation,context.getWarehouseId());
} }
} }
if (CollectionUtils.isNotEmpty(waitCreateRelation)){ if (CollectionUtils.isNotEmpty(waitCreateRelation)){
@ -136,19 +131,22 @@ public abstract class OdooAbstrackob {
private void sync(JSONObject jsonObject, List<String> errorList private void sync(JSONObject jsonObject, List<String> errorList
, Map<String, String> relationMap, LarkTableRequest larkRequest , Map<String, String> relationMap, LarkTableRequest larkRequest
, List<ErpLarkRelation> waitCreateRelation) { , List<ErpLarkRelation> waitCreateRelation,Integer warehouseId) {
String uniqueKey = null; String uniqueKey = null;
try { try {
Map<String, Object> larkBodyMap = this.buildLarkBodyMap(jsonObject); Map<String, Object> larkBodyMap = this.buildLarkBodyMap(jsonObject);
larkRequest.setBody(larkBodyMap); larkRequest.setBody(larkBodyMap);
uniqueKey = buildUniqueKey(jsonObject); uniqueKey = buildUniqueKey(jsonObject);
String larkRecord = relationMap.get(uniqueKey); String larkRecord = relationMap.get(uniqueKey);
TableRelationTypeEnum tableRelationTypeEnum = this.syncLarkType(warehouseId);
if (StringUtils.isNotBlank(larkRecord)) { if (StringUtils.isNotBlank(larkRecord)) {
larkRequest.setRecord(larkRecord); if (!tableRelationTypeEnum.equals(TableRelationTypeEnum.SYNC_ODOO_ACCOUNT_MOVE_LINE)) {
larkTableHelper.updateTableRecord(larkRequest); larkRequest.setRecord(larkRecord);
larkTableHelper.updateTableRecord(larkRequest);
}
} else { } else {
CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(larkRequest); CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(larkRequest);
waitCreateRelation.add(buildErpLarkRelation(uniqueKey,respBody.getRecord().getRecordId())); waitCreateRelation.add(buildErpLarkRelation(uniqueKey,respBody.getRecord().getRecordId(),warehouseId));
} }
} catch (Exception e) { } catch (Exception e) {
log.error("{} addOrUpdate exception {}", this.getClassName(),uniqueKey, e); log.error("{} addOrUpdate exception {}", this.getClassName(),uniqueKey, e);
@ -157,11 +155,11 @@ public abstract class OdooAbstrackob {
} }
//构建飞书行与cjt唯一键的对应关系对象 //构建飞书行与cjt唯一键的对应关系对象
private ErpLarkRelation buildErpLarkRelation(String key, String larkKey) { private ErpLarkRelation buildErpLarkRelation(String key, String larkKey,Integer warehouseId) {
ErpLarkRelation erpLarkRelation = new ErpLarkRelation(); ErpLarkRelation erpLarkRelation = new ErpLarkRelation();
erpLarkRelation.setKey(key); erpLarkRelation.setKey(key);
erpLarkRelation.setLarkKey(larkKey); erpLarkRelation.setLarkKey(larkKey);
erpLarkRelation.setMethod(syncLarkType().getCode()); erpLarkRelation.setMethod(syncLarkType(warehouseId).getCode());
erpLarkRelation.setFlag(FlagStatus.OK.getCode()); erpLarkRelation.setFlag(FlagStatus.OK.getCode());
erpLarkRelation.setCreateBy("SYSTEM"); erpLarkRelation.setCreateBy("SYSTEM");
erpLarkRelation.setCreateTime(new Date()); erpLarkRelation.setCreateTime(new Date());
@ -175,14 +173,14 @@ public abstract class OdooAbstrackob {
return jsonObject.toJSONString(); return jsonObject.toJSONString();
} }
private Map<String, String> getLarkRelation(List<JSONObject> dateList) { private Map<String, String> getLarkRelation(List<JSONObject> dateList,Integer warehouseId) {
List<String> uniqueKeyList = dateList.stream().map(r -> { List<String> uniqueKeyList = dateList.stream().map(r -> {
return buildUniqueKey(r); return buildUniqueKey(r);
}).distinct().collect(Collectors.toList()); }).distinct().collect(Collectors.toList());
if (CollectionUtils.isEmpty(uniqueKeyList)) { if (CollectionUtils.isEmpty(uniqueKeyList)) {
return new HashMap<>(); return new HashMap<>();
} }
return erpLarkRelationMapper.queryListByKeyList(uniqueKeyList, syncLarkType().getCode()) return erpLarkRelationMapper.queryListByKeyList(uniqueKeyList, syncLarkType(warehouseId).getCode())
.stream().collect(Collectors.toMap(ErpLarkRelation::getKey, ErpLarkRelation::getLarkKey, (k1, k2) -> k1)); .stream().collect(Collectors.toMap(ErpLarkRelation::getKey, ErpLarkRelation::getLarkKey, (k1, k2) -> k1));
} }
@ -199,7 +197,7 @@ public abstract class OdooAbstrackob {
LarkTableRelation tableRelationQuery = new LarkTableRelation(); LarkTableRelation tableRelationQuery = new LarkTableRelation();
tableRelationQuery.setLarkCompanyRelationId(companyRelation.getId()); tableRelationQuery.setLarkCompanyRelationId(companyRelation.getId());
tableRelationQuery.setFlag(FlagStatus.OK.getCode()); tableRelationQuery.setFlag(FlagStatus.OK.getCode());
tableRelationQuery.setRelationType(syncLarkType().getCode()); tableRelationQuery.setRelationType(syncLarkType(context.getWarehouseId()).getCode());
List<LarkTableRelation> larkTableRelations = larkTableRelationMapper.selectLarkTableRelationList(tableRelationQuery); List<LarkTableRelation> larkTableRelations = larkTableRelationMapper.selectLarkTableRelationList(tableRelationQuery);
LarkTableRelation tableRelation = larkTableRelations.get(0); LarkTableRelation tableRelation = larkTableRelations.get(0);
context.setTableRelation(tableRelation); context.setTableRelation(tableRelation);
@ -219,13 +217,13 @@ public abstract class OdooAbstrackob {
protected abstract List getQueryConditionList(); protected abstract List getQueryConditionList();
//获取查询字段信息 //获取查询字段信息
protected abstract Map<String, List<String>> getQueryFieldMap(); protected abstract Map<String, List<String>> getQueryFieldMap(Integer warehouseId);
//构建飞书请求体信息 //构建飞书请求体信息
protected abstract Map<String, Object> buildLarkBodyMap(JSONObject date); protected abstract Map<String, Object> buildLarkBodyMap(JSONObject date);
//获取待同步飞书表格信息 //获取待同步飞书表格信息
protected abstract TableRelationTypeEnum syncLarkType(); protected abstract TableRelationTypeEnum syncLarkType(Integer warehouseId);
protected JSONArray parseJsonArray(String value, int count){ protected JSONArray parseJsonArray(String value, int count){
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
@ -242,7 +240,7 @@ public abstract class OdooAbstrackob {
return jsonArray; return jsonArray;
} }
public List<Object> getDate(OdooContext odooContext, Map<String, Integer> pageMap, List<String> errorList) { public List<Object> getDate(OdooContext odooContext, Map<String, Integer> pageMap, List<String> errorList,Integer warehouseId) {
try { try {
XmlRpcClient models = odooContext.getModels(); XmlRpcClient models = odooContext.getModels();
Integer uid = getUserId(); Integer uid = getUserId();
@ -258,7 +256,7 @@ public abstract class OdooAbstrackob {
GET_DATA_DB, uid, GET_DATA_PASSWORD, GET_DATA_DB, uid, GET_DATA_PASSWORD,
modelName, "read", modelName, "read",
asList(ids), asList(ids),
getQueryFieldMap() getQueryFieldMap(warehouseId)
))); )));
} catch (Exception e) { } catch (Exception e) {
log.error("{} 获取数据失败", this.getClassName(), e); log.error("{} 获取数据失败", this.getClassName(), e);
@ -267,8 +265,9 @@ public abstract class OdooAbstrackob {
return null; return null;
} }
public OdooContext initContext() { public OdooContext initContext(Integer warehouseId) {
OdooContext context = new OdooContext(); OdooContext context = new OdooContext();
context.setWarehouseId(warehouseId);
try { try {
final XmlRpcClient models = new XmlRpcClient() {{ final XmlRpcClient models = new XmlRpcClient() {{
setConfig(new XmlRpcClientConfigImpl() {{ setConfig(new XmlRpcClientConfigImpl() {{
@ -289,7 +288,6 @@ public abstract class OdooAbstrackob {
XmlRpcClient client = new XmlRpcClient(); XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl common_config = new XmlRpcClientConfigImpl(); XmlRpcClientConfigImpl common_config = new XmlRpcClientConfigImpl();
common_config.setServerURL(new URL(String.format("%s/xmlrpc/2/common", INIT_URL))); common_config.setServerURL(new URL(String.format("%s/xmlrpc/2/common", INIT_URL)));
Object version = client.execute(common_config, "version", emptyList());
return (int) client.execute(common_config, "authenticate", asList(GET_DATA_DB, GET_DATA_NAME, GET_DATA_PASSWORD, emptyMap())); return (int) client.execute(common_config, "authenticate", asList(GET_DATA_DB, GET_DATA_NAME, GET_DATA_PASSWORD, emptyMap()));
} }

@ -29,8 +29,8 @@ public class ProductPackingJob extends OdooAbstrackob {
} }
@Override @Override
public void execute() { public void execute(Integer warehouseId) {
super.execute(); super.execute(warehouseId);
} }
@Override @Override
@ -43,7 +43,7 @@ public class ProductPackingJob extends OdooAbstrackob {
} }
@Override @Override
protected Map<String, List<String>> getQueryFieldMap() { protected Map<String, List<String>> getQueryFieldMap(Integer warehouseId) {
return new HashMap() {{ return new HashMap() {{
put("fields", Arrays.asList("id", "name", "qty")); put("fields", Arrays.asList("id", "name", "qty"));
}}; }};
@ -59,7 +59,7 @@ public class ProductPackingJob extends OdooAbstrackob {
} }
@Override @Override
protected TableRelationTypeEnum syncLarkType() { protected TableRelationTypeEnum syncLarkType(Integer warehouseId) {
return TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PACKING; return TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PACKING;
} }
} }

@ -1,5 +1,6 @@
package com.ruoyi.quartz.task.odoo; package com.ruoyi.quartz.task.odoo;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.enums.TableRelationTypeEnum; import com.ruoyi.common.enums.TableRelationTypeEnum;
@ -30,8 +31,8 @@ public class ProductProductJob extends OdooAbstrackob {
} }
@Override @Override
public void execute() { public void execute(Integer warehouseId) {
super.execute(); super.execute(warehouseId);
} }
@Override @Override
@ -44,7 +45,7 @@ public class ProductProductJob extends OdooAbstrackob {
} }
@Override @Override
protected Map<String, List<String>> getQueryFieldMap() { protected Map<String, List<String>> getQueryFieldMap(Integer warehouseId) {
// return new HashMap() {{ // return new HashMap() {{
// put("fields", Arrays.asList("id","default_code", "name", "description_purchase" // put("fields", Arrays.asList("id","default_code", "name", "description_purchase"
// , "qty_available", "incoming_qty","cost","categ_id.name", "packaging_ids")); // , "qty_available", "incoming_qty","cost","categ_id.name", "packaging_ids"));
@ -52,6 +53,7 @@ public class ProductProductJob extends OdooAbstrackob {
return new HashMap() {{ return new HashMap() {{
put("fields", Arrays.asList("id","default_code", "name", "description_purchase" put("fields", Arrays.asList("id","default_code", "name", "description_purchase"
, "qty_available", "incoming_qty", "packaging_ids", "standard_price", "categ_id")); , "qty_available", "incoming_qty", "packaging_ids", "standard_price", "categ_id"));
put("context", MapUtil.of("warehouse",String.valueOf(warehouseId)));
}}; }};
} }
@ -74,7 +76,18 @@ public class ProductProductJob extends OdooAbstrackob {
} }
@Override @Override
protected TableRelationTypeEnum syncLarkType() { protected TableRelationTypeEnum syncLarkType(Integer warehouseId) {
return TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT; if (warehouseId == null){
return null;
}
if (warehouseId.equals(1)){
return TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT_ONE;
}else if (warehouseId.equals(6)){
return TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT_SIX;
}else if (warehouseId.equals(8)){
return TableRelationTypeEnum.SYNC_ODOO_PRODUCT_PRODUCT_EIGHT;
}else {
return null;
}
} }
} }

@ -29,8 +29,8 @@ public class ProductShukikuJob extends OdooAbstrackob {
} }
@Override @Override
public void execute() { public void execute(Integer warehouseId) {
super.execute(); super.execute(warehouseId);
} }
@Override @Override
@ -46,7 +46,7 @@ public class ProductShukikuJob extends OdooAbstrackob {
} }
@Override @Override
protected Map<String, List<String>> getQueryFieldMap() { protected Map<String, List<String>> getQueryFieldMap(Integer warehouseId) {
return new HashMap() {{ return new HashMap() {{
put("fields", Arrays.asList("id","default_code", "name", "description_purchase" put("fields", Arrays.asList("id","default_code", "name", "description_purchase"
, "qty_available", "incoming_qty","cost","categ_id.name", "packaging_ids")); , "qty_available", "incoming_qty","cost","categ_id.name", "packaging_ids"));
@ -69,7 +69,7 @@ public class ProductShukikuJob extends OdooAbstrackob {
} }
@Override @Override
protected TableRelationTypeEnum syncLarkType() { protected TableRelationTypeEnum syncLarkType(Integer warehouseId) {
return TableRelationTypeEnum.SYNC_ODOO_PRODUCT_SHUKIKU; return TableRelationTypeEnum.SYNC_ODOO_PRODUCT_SHUKIKU;
} }
} }

@ -29,8 +29,8 @@ public class StockQuantJob extends OdooAbstrackob {
} }
@Override @Override
public void execute() { public void execute(Integer warehouseId) {
super.execute(); super.execute(warehouseId);
} }
@Override @Override
@ -44,7 +44,7 @@ public class StockQuantJob extends OdooAbstrackob {
} }
@Override @Override
protected Map<String, List<String>> getQueryFieldMap() { protected Map<String, List<String>> getQueryFieldMap(Integer warehouseId) {
return new HashMap() {{ return new HashMap() {{
put("fields", Arrays.asList("free_qty","incoming_qty","virtual_available", "company_id", "id")); put("fields", Arrays.asList("free_qty","incoming_qty","virtual_available", "company_id", "id"));
}}; }};
@ -62,7 +62,7 @@ public class StockQuantJob extends OdooAbstrackob {
} }
@Override @Override
protected TableRelationTypeEnum syncLarkType() { protected TableRelationTypeEnum syncLarkType(Integer warehouseId) {
return TableRelationTypeEnum.SYNC_ODOO_STOCK_QUANT; return TableRelationTypeEnum.SYNC_ODOO_STOCK_QUANT;
} }
} }

Loading…
Cancel
Save