|
@@ -278,7 +278,7 @@ public class JdApiServiceImpl implements JdApiService {
|
|
|
/**
|
|
|
* 初始化租户字典表
|
|
|
*/
|
|
|
-// @PostConstruct
|
|
|
+ @Async
|
|
|
public void initTenantDict(){
|
|
|
JdClient jdClient = jdClientFactory.getJdClient();
|
|
|
handleDeliveryCenter(jdClient);
|
|
@@ -402,7 +402,6 @@ public class JdApiServiceImpl implements JdApiService {
|
|
|
|
|
|
DictTenantType dictTenantType = handleDictType(InitDictConstant.DELIVERY_CENTER, InitDictConstant.DELIVERY_CENTER_LABEL);
|
|
|
//处理字典数据表
|
|
|
- //删除全部数据
|
|
|
List<WarehouseDto> warehouseList = response.getJosWarehouseResultDto().getWarehouseList();
|
|
|
List<CommonDictData> commonDictDataList = new ArrayList<>();
|
|
|
for (WarehouseDto warehouseDto : warehouseList) {
|
|
@@ -417,20 +416,31 @@ public class JdApiServiceImpl implements JdApiService {
|
|
|
}
|
|
|
|
|
|
private void handleDictData(List<CommonDictData> commonDictDataList, DictTenantType dictTenantType) {
|
|
|
- dictTenantDataService.lambdaUpdate().eq(DictTenantData::getDictCode, dictTenantType.getCode()).remove();
|
|
|
+ //查出原来的字典
|
|
|
+ List<DictTenantData> list = dictTenantDataService.lambdaQuery().eq(DictTenantData::getDictCode, dictTenantType.getCode()).orderByAsc(DictTenantData::getSort).list();
|
|
|
+ Map<String, DictTenantData> dictDataMap = new HashMap<>();
|
|
|
int sort = 10;
|
|
|
+ if(CollectionUtil.isNotEmpty(list)) {
|
|
|
+ dictDataMap = list.stream().collect(Collectors.toMap(DictTenantData::getDictKey, o -> o, (v1, v2) ->v2));
|
|
|
+ sort = list.get(list.size()-1).getSort() + 10;
|
|
|
+ }
|
|
|
List<DictTenantData> dataList = new ArrayList<>();
|
|
|
for (CommonDictData commonDictData : commonDictDataList) {
|
|
|
DictTenantDataDto dictTenantDataDto = new DictTenantDataDto();
|
|
|
- dictTenantDataDto.setDictCode(dictTenantType.getCode());
|
|
|
- dictTenantDataDto.setDictKey(StrUtil.toString(commonDictData.getKey()));
|
|
|
+ DictTenantData dictTenantData = dictDataMap.get(commonDictData.getKey());
|
|
|
+ if(ObjectUtil.isNotNull(dictTenantData)){
|
|
|
+ BeanUtil.copyProperties(dictTenantData, dictTenantDataDto);
|
|
|
+ }else{
|
|
|
+ dictTenantDataDto.setDictCode(dictTenantType.getCode());
|
|
|
+ dictTenantDataDto.setDictKey(StrUtil.toString(commonDictData.getKey()));
|
|
|
+ dictTenantDataDto.setTenantId(tenantId);
|
|
|
+ dictTenantDataDto.setSort(sort);
|
|
|
+ sort = sort + 10;
|
|
|
+ }
|
|
|
dictTenantDataDto.setDictValue(commonDictData.getValue());
|
|
|
- dictTenantDataDto.setTenantId(tenantId);
|
|
|
- dictTenantDataDto.setSort(sort);
|
|
|
- sort = sort + 10;
|
|
|
dataList.add(dictTenantDataDto);
|
|
|
}
|
|
|
- dictTenantDataService.saveBatch(dataList);
|
|
|
+ dictTenantDataService.saveOrUpdateBatch(dataList);
|
|
|
}
|
|
|
|
|
|
/**
|