ODOO 修改product查询条件
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
bc3364c66a
commit
19364f7729
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue