Commit 30e0adc3 by zhangxingmin

push

parent 6f992ed7
package com.yd.product.api.service.impl;
import com.yd.base.feign.client.fieldvalue.ApiFieldValueFeignClient;
import com.yd.base.feign.request.fieldvalue.ApiFieldValueListRequest;
import com.yd.base.feign.response.fieldvalue.ApiFieldValueDetailResponse;
import com.yd.common.enums.CommonEnum;
import com.yd.common.result.Result;
import com.yd.common.utils.RandomStringGenerator;
......@@ -9,13 +12,13 @@ import com.yd.product.service.dto.AttributeSettingDto;
import com.yd.product.service.model.AttributeSetting;
import com.yd.product.service.service.IAttributeSettingService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
......@@ -25,6 +28,9 @@ public class ApiAttributeSettingServiceImpl implements ApiAttributeSettingServic
@Autowired
private IAttributeSettingService iAttributeSettingService;
@Autowired
private ApiFieldValueFeignClient apiFieldValueFeignClient;
/**
* 保存产品属性(参数)配置信息
* @param apiAttributeSettingDtoList
......@@ -61,12 +67,76 @@ public class ApiAttributeSettingServiceImpl implements ApiAttributeSettingServic
List<AttributeSetting> attributeSettingList = iAttributeSettingService.queryList(AttributeSettingDto.builder()
.productLaunchBizId(productLaunchBizId)
.build());
if (!CollectionUtils.isEmpty(attributeSettingList)) {
apiAttributeSettingDtoList = attributeSettingList.stream().map(dto -> {
//收集所有需要批量查询的字段值业务ID
List<String> allFieldValueBizIds = new ArrayList<>();
Map<String, List<String>> settingDtoToValueBizIdsMap = new HashMap<>();
for (int i = 0; i < attributeSettingList.size(); i++) {
AttributeSetting dto = attributeSettingList.get(i);
if (StringUtils.isNotBlank(dto.getValue())) {
if (dto.getValue().contains(";")) {
// 多选情况
List<String> fieldValueBizIdList = Arrays.asList(dto.getValue().split(";"));
allFieldValueBizIds.addAll(fieldValueBizIdList);
settingDtoToValueBizIdsMap.put(String.valueOf(i), fieldValueBizIdList);
} else {
// 单选情况,也需要查询,因为可能需要获取字段值名称
allFieldValueBizIds.add(dto.getValue());
settingDtoToValueBizIdsMap.put(String.valueOf(i), Collections.singletonList(dto.getValue()));
}
}
}
//批量查询字段值详情
Map<String, String> fieldValueBizIdToNameMap = new HashMap<>();
if (!CollectionUtils.isEmpty(allFieldValueBizIds)) {
// 去重
List<String> distinctFieldValueBizIds = allFieldValueBizIds.stream()
.distinct()
.collect(Collectors.toList());
ApiFieldValueListRequest request = new ApiFieldValueListRequest();
request.setFieldValueBizIdList(distinctFieldValueBizIds);
try {
Result<List<ApiFieldValueDetailResponse>> result = apiFieldValueFeignClient.list(request);
if (result != null && result.getCode() == 200 && !CollectionUtils.isEmpty(result.getData())) {
// 构建映射关系:字段值业务ID -> 字段值名称
fieldValueBizIdToNameMap = result.getData().stream()
.collect(Collectors.toMap(
ApiFieldValueDetailResponse::getFieldValueBizId,
ApiFieldValueDetailResponse::getValue,
(existing, replacement) -> existing
));
} else {
log.warn("查询字段值详情失败,fieldValueBizIdList: {}", distinctFieldValueBizIds);
}
} catch (Exception e) {
log.error("调用字段值服务异常", e);
}
}
//构建返回结果
for (int i = 0; i < attributeSettingList.size(); i++) {
AttributeSetting dto = attributeSettingList.get(i);
ApiAttributeSettingDto settingDto = new ApiAttributeSettingDto();
BeanUtils.copyProperties(dto,settingDto);
return settingDto;
}).collect(Collectors.toList());
BeanUtils.copyProperties(dto, settingDto);
List<String> valueBizIds = settingDtoToValueBizIdsMap.get(String.valueOf(i));
if (!CollectionUtils.isEmpty(valueBizIds)) {
// 构建字段值名称(多个值用分号分隔)
Map<String, String> finalFieldValueBizIdToNameMap = fieldValueBizIdToNameMap;
List<String> valueNames = valueBizIds.stream()
.map(fieldValueBizId ->
StringUtils.defaultIfBlank(finalFieldValueBizIdToNameMap.get(fieldValueBizId), fieldValueBizId))
.collect(Collectors.toList());
settingDto.setValueNames(StringUtils.join(valueNames, ";"));
}
apiAttributeSettingDtoList.add(settingDto);
}
}
return apiAttributeSettingDtoList;
}
......
......@@ -36,6 +36,11 @@ public class ApiAttributeSettingDto {
private String value;
/**
* 字段值名称(多个值存在的情况用分号分隔的;)
*/
private String valueNames;
/**
* 是否自定义 0-否 1-是
*/
private String isCustomize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment