|
@@ -1,22 +1,40 @@
|
|
|
package edu.travel.country.service.impl;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import edu.travel.cache.util.RedisKey;
|
|
|
+import edu.travel.country.entity.BaseCountryServe;
|
|
|
import edu.travel.country.entity.ShopLanguage;
|
|
|
import edu.travel.country.mapper.ShopLanguageMapper;
|
|
|
import edu.travel.country.service.ShopLanguageService;
|
|
|
import edu.travel.dto.ShopLanguageDto;
|
|
|
import edu.travel.rpc.RPCBaseResponse;
|
|
|
import edu.travel.service.SysServiceImpl;
|
|
|
+import edu.travel.vo.LanguageSortVo;
|
|
|
+import edu.travel.vo.ServiceCountryVo;
|
|
|
import edu.travel.vo.ShopLanguageVo;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@Service
|
|
|
public class ShopLanguageServiceImpl extends SysServiceImpl<ShopLanguageMapper, ShopLanguage> implements ShopLanguageService {
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
public RPCBaseResponse<IPage<ShopLanguageVo>> getLanguagePage(ShopLanguageDto shopLanguageDto) {
|
|
|
// 创建分页对象
|
|
@@ -44,4 +62,37 @@ public class ShopLanguageServiceImpl extends SysServiceImpl<ShopLanguageMapper,
|
|
|
// 封装返回结果
|
|
|
return new RPCBaseResponse<>(200, "SUCCESS", pageVoLink);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, List<LanguageSortVo>> getLanguageSort() {
|
|
|
+ //缓存获取
|
|
|
+ String s = stringRedisTemplate.opsForValue().get(RedisKey.LANGUAGE_SORT);
|
|
|
+ if(!ObjectUtil.isEmpty(s)){
|
|
|
+ JSONObject objects = JSONUtil.parseObj(s);
|
|
|
+ Map<String, List<LanguageSortVo>> result = new HashMap<>();
|
|
|
+
|
|
|
+ objects.forEach((key, value) -> {
|
|
|
+ JSONArray jsonArray = (JSONArray) value;
|
|
|
+ List<LanguageSortVo> countries = jsonArray.toList(LanguageSortVo.class);
|
|
|
+ result.put(key, countries);
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<ShopLanguage> list = list();
|
|
|
+ List<LanguageSortVo> serviceCountryVos = BeanUtil.copyToList(list, LanguageSortVo.class);
|
|
|
+ TreeMap<String, List<LanguageSortVo>> collect = serviceCountryVos.stream()
|
|
|
+ .filter(country -> country != null && !ObjectUtil.isEmpty(country))
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ country -> {
|
|
|
+ String firstChar = country.getLanguageNameEn().substring(0, 1);
|
|
|
+ return firstChar.toUpperCase();
|
|
|
+ },
|
|
|
+ TreeMap::new,
|
|
|
+ Collectors.toList()
|
|
|
+ ));
|
|
|
+ //放入缓存
|
|
|
+ String jsonStr = JSONUtil.toJsonStr(collect);
|
|
|
+ stringRedisTemplate.opsForValue().set(RedisKey.LANGUAGE_SORT,jsonStr);
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
}
|