package com.sinata.rest.modular.member.controller;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.sinata.common.enums.EnumIsDelete;
|
import com.sinata.common.util.PingYinUtil;
|
import com.sinata.rest.common.ApiUtils;
|
import com.sinata.rest.modular.member.controller.common.vo.OpenCityVo;
|
import com.sinata.rest.modular.member.model.MemMerchant;
|
import com.sinata.rest.modular.member.service.IMemMerchantService;
|
import com.sinata.rest.modular.system.controller.AuthController;
|
import com.sinata.rest.modular.system.model.AreaCity;
|
import com.sinata.rest.modular.system.service.IAreaCityService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.*;
|
|
@Slf4j
|
@RestController
|
@RequestMapping("/cityArea")
|
@Api(tags = "城市区域相关接口", description = "医生相关接口")
|
public class CityAreaController extends AuthController {
|
@Autowired
|
IAreaCityService areaCityService;
|
@Autowired
|
IMemMerchantService merchantService;
|
|
@GetMapping(value = "/getCityList")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "level", value = "层级 1 省 2 市 3 区", dataType = "Int", paramType = "query", required = true),
|
@ApiImplicitParam(name = "cityCode", value = "城市code", dataType = "String", paramType = "query", required = true)
|
})
|
@ApiOperation(value = "获取城市信息", response = AreaCity.class)
|
public Object getCityList(Integer level,String cityCode,Integer current, Integer size) {
|
Page<AreaCity> page = new Page<AreaCity>(current, size);
|
LambdaQueryWrapper<AreaCity> queryWrapper = new LambdaQueryWrapper<>();
|
if(Objects.nonNull(level) && StrUtil.isNotEmpty(cityCode)){
|
if(level == 1){
|
queryWrapper.groupBy(AreaCity::getProvinceCode);
|
}else if(level == 2){
|
queryWrapper.eq(AreaCity::getProvinceCode,cityCode);
|
queryWrapper.groupBy(AreaCity::getCityCode);
|
}else{
|
queryWrapper.eq(AreaCity::getCityCode,cityCode);
|
queryWrapper.groupBy(AreaCity::getCountyCode);
|
}
|
}
|
List<AreaCity> cityList = areaCityService.list(queryWrapper);
|
Page<MemMerchant> page2 = new Page<MemMerchant>(1, 999999);
|
cityList.parallelStream().forEach(city->{
|
city.setMerchantNum(merchantService.queryMerchantList(level,cityCode,page2).size());
|
});
|
return ApiUtils.returnOK(cityList);
|
}
|
|
@GetMapping(value = "/getOpenCityList")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "level", value = "层级 1 省 2 市 3 区", dataType = "Int", paramType = "query", required = true)
|
})
|
@ApiOperation(value = "获取开通城市列表", response = OpenCityVo.class)
|
public Object getOpenCityList(Integer level,Integer current, Integer size) {
|
Page<AreaCity> page = new Page<AreaCity>(current, size);
|
LambdaQueryWrapper<AreaCity> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(AreaCity::getIsOpen, 1);
|
queryWrapper.eq(AreaCity::getIsDelete, EnumIsDelete.EXISTED.index);
|
if(Objects.nonNull(level)){
|
if(level == 1){
|
queryWrapper.groupBy(AreaCity::getProvinceCode);
|
}else if(level == 2){
|
queryWrapper.groupBy(AreaCity::getCityCode);
|
}else{
|
queryWrapper.groupBy(AreaCity::getCountyCode);
|
}
|
}
|
List<AreaCity> cityList = areaCityService.list(queryWrapper);
|
Map<String, List<AreaCity>> mapList = new HashMap<>();
|
cityList.stream().forEach(areaCity ->{
|
String cityCode = "";
|
if(level == 1){
|
cityCode = PingYinUtil.getPinYinHeadChar(areaCity.getProvinceName());
|
}else if(level == 2){
|
cityCode = PingYinUtil.getPinYinHeadChar(areaCity.getCityName());
|
}else{
|
cityCode = PingYinUtil.getPinYinHeadChar(areaCity.getCountyName());
|
}
|
List<AreaCity> list = mapList.get(cityCode);
|
if(Objects.isNull(list)){
|
list = new ArrayList<>();
|
}
|
list.add(areaCity);
|
mapList.put(cityCode,list);
|
});
|
List<OpenCityVo> openCityVoList = new ArrayList<>();
|
for (String key:mapList.keySet()) {
|
OpenCityVo cityVo = new OpenCityVo();
|
cityVo.setIndex(key);
|
cityVo.setList(mapList.get(key));
|
openCityVoList.add(cityVo);
|
}
|
return ApiUtils.returnOK(openCityVoList);
|
}
|
|
}
|