|
@@ -1,23 +1,41 @@
|
|
|
package edu.travel.country.web;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.extra.pinyin.PinyinUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import edu.travel.cache.util.RedisKey;
|
|
|
import edu.travel.country.entity.BaseCountryServe;
|
|
|
import edu.travel.country.service.BaseCountryServeService;
|
|
|
import edu.travel.country.service.BaseCountryService;
|
|
|
import edu.travel.dto.BaseCountryServeDto;
|
|
|
import edu.travel.dto.BaseCountryServeStatusDto;
|
|
|
+import edu.travel.entity.EduTenantPO;
|
|
|
import edu.travel.remote.BaseCountryServeRemoteController;
|
|
|
import edu.travel.rpc.RPCBaseResponse;
|
|
|
import edu.travel.vo.BaseCountryServeStatusVo;
|
|
|
import edu.travel.vo.BaseCountryServeVo;
|
|
|
+import edu.travel.vo.ServiceCountryVo;
|
|
|
import edu.travel.web.BaseController;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static edu.travel.rpc.RPCBaseResponse.error;
|
|
|
+import static edu.travel.rpc.RPCBaseResponse.success;
|
|
|
|
|
|
|
|
|
* 服务国家表(base_country_serve)表控制层
|
|
@@ -35,6 +53,8 @@ public class BaseCountryServeController extends BaseController<BaseCountryServe>
|
|
|
private BaseCountryServeService baseCountryServeService;
|
|
|
@Autowired
|
|
|
private BaseCountryService baseCountryService;
|
|
|
+ @Autowired
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
|
|
|
* 分页连表
|
|
@@ -150,4 +170,53 @@ public class BaseCountryServeController extends BaseController<BaseCountryServe>
|
|
|
BeanUtils.copyProperties(listRPCBaseResponse, baseCountryServeVoRPCBaseResponse);
|
|
|
return baseCountryServeVoRPCBaseResponse;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * 选择服务国家
|
|
|
+ */
|
|
|
+ @PostMapping("/selection")
|
|
|
+ public RPCBaseResponse<Void> selection(@RequestBody String countryId) {
|
|
|
+ EduTenantPO principal = (EduTenantPO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
|
+ String userId = principal.getId().toString();
|
|
|
+ BaseCountryServe byId = baseCountryServeService.getById(countryId);
|
|
|
+ if(byId==null){
|
|
|
+ return error("国家不存在");
|
|
|
+ }
|
|
|
+ String key = RedisKey.USER_COUNTRY + userId;
|
|
|
+ stringRedisTemplate.opsForValue().set(key,byId.getTimeZone());
|
|
|
+ return success();
|
|
|
+ }
|
|
|
+ @GetMapping("/grouped")
|
|
|
+ public RPCBaseResponse<Map<String, List<ServiceCountryVo>>> grouped() {
|
|
|
+
|
|
|
+ String s = stringRedisTemplate.opsForValue().get(RedisKey.COUNTRY_SORT);
|
|
|
+ if(!ObjectUtil.isEmpty(s)){
|
|
|
+ JSONObject objects = JSONUtil.parseObj(s);
|
|
|
+ Map<String, List<ServiceCountryVo>> result = new HashMap<>();
|
|
|
+
|
|
|
+ objects.forEach((key, value) -> {
|
|
|
+ JSONArray jsonArray = (JSONArray) value;
|
|
|
+ List<ServiceCountryVo> countries = jsonArray.toList(ServiceCountryVo.class);
|
|
|
+ result.put(key, countries);
|
|
|
+ });
|
|
|
+ return success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BaseCountryServe> list = baseCountryServeService.list();
|
|
|
+ List<ServiceCountryVo> serviceCountryVos = BeanUtil.copyToList(list, ServiceCountryVo.class);
|
|
|
+ TreeMap<String, List<ServiceCountryVo>> collect = serviceCountryVos.stream()
|
|
|
+ .filter(country -> country != null && !ObjectUtil.isEmpty(country))
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ country -> {
|
|
|
+ String firstChar = country.getCountryNameEn().substring(0, 1);
|
|
|
+ return firstChar.toUpperCase();
|
|
|
+ },
|
|
|
+ TreeMap::new,
|
|
|
+ Collectors.toList()
|
|
|
+ ));
|
|
|
+
|
|
|
+ String jsonStr = JSONUtil.toJsonStr(collect);
|
|
|
+ stringRedisTemplate.opsForValue().set(RedisKey.COUNTRY_SORT,jsonStr);
|
|
|
+ return success(collect);
|
|
|
+ }
|
|
|
}
|