mitao
2024-04-29 151d70eba459a86218a18c679adafa0a865d3a98
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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);
    }
 
}