|
@@ -10,6 +10,7 @@ import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
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.adapter.service.upload.UploadAdapter;
|
|
@@ -21,18 +22,20 @@ import edu.travel.commodity.service.ShopCategoryService;
|
|
|
import edu.travel.commodity.utils.FIleUtil;
|
|
|
import edu.travel.commodity.utils.RedisUtil;
|
|
|
import edu.travel.remote.dto.BaseDto;
|
|
|
+import edu.travel.remote.dto.ShopCategoryDto;
|
|
|
import edu.travel.remote.dto.ShopTypeDto;
|
|
|
+import edu.travel.remote.feign.mode.vo.banner.BannerVo;
|
|
|
import edu.travel.remote.upload.dto.EduFileDTO;
|
|
|
+import edu.travel.remote.vo.ShopCategoryVo;
|
|
|
import edu.travel.remote.vo.ShopTypeVo;
|
|
|
import edu.travel.rpc.RPCBaseResponse;
|
|
|
+import edu.travel.vo.BaseCountryServeVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.View;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -47,6 +50,63 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
|
|
|
private UploadAdapter uploadAdapter;
|
|
|
@Autowired
|
|
|
private CountryAdapter countryAdapter;
|
|
|
+ @Autowired
|
|
|
+ private ShopCategoryMapper shopCategoryMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RPCBaseResponse<Page<ShopCategoryVo>> getCategoryPage(ShopCategoryDto shopCategoryDto) {
|
|
|
+ // 查询商品类型数据,确保返回数据正确
|
|
|
+ List<ShopCategoryVo> categoryVos = shopCategoryMapper.selectCategoryWithCountry(shopCategoryDto);
|
|
|
+ int total = shopCategoryMapper.countAll(shopCategoryDto);
|
|
|
+
|
|
|
+ // 提取 CountryID
|
|
|
+ Set<String> countryIds = categoryVos.stream()
|
|
|
+ .map(ShopCategoryVo::getCountryId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 查询国家信息
|
|
|
+ Map<String, ShopCategoryVo> countryMap = fetchCountryData(countryIds);
|
|
|
+
|
|
|
+ // 遍历并设置国家信息
|
|
|
+ for (ShopCategoryVo shopCategoryVo : categoryVos) {
|
|
|
+ if (shopCategoryVo.getMap() == null) {
|
|
|
+ shopCategoryVo.setMap(new HashMap<>());
|
|
|
+ }
|
|
|
+ // 设置国家信息到 map 中
|
|
|
+ if (countryMap.containsKey(shopCategoryVo.getCountryId())) {
|
|
|
+ shopCategoryVo.getMap().put("countryServe", countryMap.get(shopCategoryVo.getCountryId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装返回结果
|
|
|
+ Page<ShopCategoryVo> pageVoLink = new Page<>();
|
|
|
+ pageVoLink.setRecords(categoryVos);
|
|
|
+ pageVoLink.setTotal(total);
|
|
|
+ pageVoLink.setCurrent(shopCategoryDto.getCurrentPage());
|
|
|
+ pageVoLink.setSize(shopCategoryDto.getPageSize());
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", pageVoLink);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询国家信息
|
|
|
+ private Map<String, ShopCategoryVo> fetchCountryData(Set<String> countryIds) {
|
|
|
+ Map<String, ShopCategoryVo> countryMap = new HashMap<>();
|
|
|
+ for (String countryId : countryIds) {
|
|
|
+ // 假设 countryAdapter.getFormId(countryId) 返回 RPCBaseResponse<BaseCountryServeVo>
|
|
|
+ BaseCountryServeVo countryServeVo = countryAdapter.getFormId(countryId).getData();
|
|
|
+ if (countryServeVo != null) {
|
|
|
+ ShopCategoryVo countryVo = new ShopCategoryVo(); // 使用 ShopCategoryVo 来存储国家信息
|
|
|
+ countryVo.setCountryId(countryId);
|
|
|
+ countryVo.setMap(new HashMap<>());
|
|
|
+ countryVo.getMap().put("countryNameZh", countryServeVo.getCountryNameZh());
|
|
|
+ countryVo.getMap().put("countryNameEn", countryServeVo.getCountryNameEn());
|
|
|
+ countryVo.getMap().put("countryNameLocal", countryServeVo.getCountryNameLocal());
|
|
|
+
|
|
|
+ // 将国家信息放入 countryMap
|
|
|
+ countryMap.put(countryId, countryVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return countryMap;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public List<ShopTypeVo> getShopType(ShopTypeDto shopTypeDto) {
|