|
@@ -2,9 +2,10 @@ package edu.travel.commodity.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import edu.travel.adapter.service.country.CountryAdapter;
|
|
|
import edu.travel.commodity.entity.ShopParameters;
|
|
|
import edu.travel.commodity.entity.ShopProductParameters;
|
|
|
import edu.travel.commodity.mapper.ShopParametersMapper;
|
|
@@ -15,20 +16,23 @@ import edu.travel.remote.dto.ParametersDto;
|
|
|
import edu.travel.remote.dto.ProductSpecDto;
|
|
|
import edu.travel.remote.vo.ParametersVo;
|
|
|
import edu.travel.remote.vo.ShopParametersVo;
|
|
|
+import edu.travel.rpc.RPCBaseResponse;
|
|
|
import edu.travel.service.SysServiceImpl;
|
|
|
+import edu.travel.vo.BaseCountryServeVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ShopParametersServiceImpl extends SysServiceImpl<ShopParametersMapper, ShopParameters> implements ShopParametersService {
|
|
|
@Autowired
|
|
|
private ShopProductParametersService shopProductParametersService;
|
|
|
+ @Autowired
|
|
|
+ private ShopParametersMapper shopParametersMapper;
|
|
|
+ @Autowired
|
|
|
+ private CountryAdapter countryAdapter;
|
|
|
|
|
|
@Override
|
|
|
public Page<ShopParametersVo> getShopParameters(ProductSpecDto param) {
|
|
@@ -76,5 +80,77 @@ public class ShopParametersServiceImpl extends SysServiceImpl<ShopParametersMapp
|
|
|
return getListLink(null);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public RPCBaseResponse<Page<ShopParameters>> getAllParametersPage(ParametersDto parametersDto) {
|
|
|
+ // 查询参数数据,确保并计算总记录数
|
|
|
+ List<ShopParametersVo> shopParametersVoList = shopParametersMapper.selectParametersWithCountry(parametersDto);
|
|
|
+ int total = shopParametersMapper.selectParametersCount(parametersDto);
|
|
|
+
|
|
|
+ // 将 ShopParametersVo 转换为 ShopParameters
|
|
|
+ List<ShopParameters> shopParametersList = shopParametersVoList.stream()
|
|
|
+ .map(this::convertVoToEntity) // 使用转换方法
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 提取国家服务ID
|
|
|
+ Set<Long> countryServeIds = shopParametersList.stream()
|
|
|
+ .map(ShopParameters::getCountryId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 查询国家信息
|
|
|
+ Map<String, BaseCountryServeVo> countryMap = fetchCountryData(countryServeIds);
|
|
|
+
|
|
|
+ // 将国家信息放入参数列表中
|
|
|
+ for (ShopParameters shopParameters : shopParametersList) {
|
|
|
+ if (shopParameters.getProductParametersMap() == null) {
|
|
|
+ shopParameters.setProductParametersMap(new HashMap<>());
|
|
|
+ }
|
|
|
+ if (countryMap.containsKey(shopParameters.getCountryId())) {
|
|
|
+ shopParameters.getProductParametersMap().put("country", countryMap.get(shopParameters.getCountryId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装返回结果
|
|
|
+ Page<ShopParameters> shopParametersPage = new Page<>();
|
|
|
+ shopParametersPage.setRecords(shopParametersList);
|
|
|
+ shopParametersPage.setTotal(total);
|
|
|
+ shopParametersPage.setCurrent(parametersDto.getCurrentPage());
|
|
|
+ shopParametersPage.setSize(parametersDto.getPageSize());
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", shopParametersPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将 ShopParametersVo 转换为 ShopParameters
|
|
|
+ */
|
|
|
+ private ShopParameters convertVoToEntity(ShopParametersVo parametersVo) {
|
|
|
+ ShopParameters parameters = new ShopParameters();
|
|
|
+ // 复制各个属性
|
|
|
+ parameters.setId(Long.valueOf(parametersVo.getId()));
|
|
|
+ parameters.setParametersName(parametersVo.getParametersName());
|
|
|
+ parameters.setIsNecessary(parametersVo.getIsNecessary());
|
|
|
+ parameters.setProject(parametersVo.getProject());
|
|
|
+ parameters.setCreateTime(parametersVo.getCreateTime());
|
|
|
+ parameters.setCreateUserId(parametersVo.getCreateUserId());
|
|
|
+ parameters.setUpdateTime(parametersVo.getUpdateTime());
|
|
|
+ parameters.setUpdateUserId(parametersVo.getUpdateUserId());
|
|
|
+ parameters.setDeleteFlag(parametersVo.getDeleteFlag());
|
|
|
+ parameters.setCountryId(parametersVo.getCountryId());
|
|
|
+ return parameters;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提取国家数据
|
|
|
+ */
|
|
|
+ private Map<String, BaseCountryServeVo> fetchCountryData(Set<Long> countryServeIds) {
|
|
|
+ Map<String, BaseCountryServeVo> countryMap = new HashMap<>();
|
|
|
+ if (!countryServeIds.isEmpty()) {
|
|
|
+ for (Long countryServeId : countryServeIds) {
|
|
|
+ RPCBaseResponse<BaseCountryServeVo> response = countryAdapter.getFormId(String.valueOf(countryServeId));
|
|
|
+ if (response != null && response.getData() != null) {
|
|
|
+ countryMap.put(String.valueOf(countryServeId), response.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return countryMap;
|
|
|
+ }
|
|
|
|
|
|
}
|