Pu Zhibing
6 天以前 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.stylefeng.guns.modular.api;
 
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.model.City;
import com.stylefeng.guns.modular.system.model.CityCopy;
import com.stylefeng.guns.modular.system.service.ICityCopyService;
import com.stylefeng.guns.modular.system.service.IOpenCityBusinessService;
import com.stylefeng.guns.modular.system.service.IOpenCityService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 开通城市控制器
 */
@Api
@RestController
@RequestMapping("/base/openCity")
public class OpenCityController {
 
    @Autowired
    private IOpenCityService openCityService;
 
    @Autowired
    private IOpenCityBusinessService openCityBusinessService;
 
    @Autowired
    private IUserInfoService userInfoService;
    
    @Resource
    private ICityCopyService cityCopyService;
 
 
 
 
 
    /**
     * 获取开通城市列表
     * @return
     */
    @ResponseBody
    @PostMapping("/queryOpenCity")
    @ApiOperation(value = "获取开通城市列表【1.0】", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "语言(1=中文,2=英文,3=法语)", name = "language", required = false, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = false, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<BaseWarpper>> queryOpenCity(Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            List<BaseWarpper> list = openCityService.queryOpenCity(uid, language);
            return ResultUtil.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    /**
     * 根据当前定位获取对应的业务类型
     * @return
     */
    @ResponseBody
    @PostMapping("/queryBusiness")
    @ApiOperation(value = "根据当前定位获取业务类型【1.0】", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "double"),
            @ApiImplicitParam(value = "经度", name = "lnt", required = true, dataType = "double"),
            @ApiImplicitParam(value = "语言类型(1=简体中文,2=英语,3=法语)", name = "language", required = false, dataType = "int"),
    })
    public ResultUtil<List<BaseWarpper>> queryBusiness(Double lat, Double lnt, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            List<BaseWarpper> list = openCityBusinessService.queryBusiness(uid, lat, lnt, language);
            return ResultUtil.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 根据开通城市id获取业务类型
     * @param id
     * @return
     */
    @ResponseBody
    @PostMapping("/queryBusinessById")
    @ApiOperation(value = "选择开通城市获取业务类型", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "开通城市id", name = "id", required = true, dataType = "int"),
            @ApiImplicitParam(value = "语言类型(1=简体中文,2=英语,3=法语)", name = "language", required = false, dataType = "int"),
    })
    public ResultUtil<List<BaseWarpper>> queryBusinessById(Integer id, Integer language){
        try {
            List<BaseWarpper> list = openCityBusinessService.queryBusinessById(id, language);
            return ResultUtil.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
    /**
     * 判断开通城市
     * @return
     */
    @ResponseBody
    @PostMapping("/openCity")
    @ApiOperation(value = "判断当前是否是开通城市【1.0】", tags = {"用户端-首页"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "String"),
            @ApiImplicitParam(value = "经度", name = "lnt", required = true, dataType = "String")
    })
    public ResultUtil openCity(Double lat, Double lnt, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            City city = openCityService.openCity(uid, lat, lnt, language);
            if(null == city){
                return ResultUtil.error("");
            }
            Map<String, Object> map = new HashMap<>();
            map.put("name", language == 1 ? city.getChineseName() : language == 2 ? city.getEnglishName() : city.getFrenchName());
            map.put("content", language == 1 ? city.getCountryChineseName() : language == 2 ? city.getCountryEnglishName() : city.getCountryFrenchName());
            return ResultUtil.success(map);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    
    
    
    @ResponseBody
    @PostMapping("/getCity")
    @ApiOperation(value = "获取省市联动【1.0】", tags = {"用户端-首页"})
    public ResultUtil<List<CityCopy>> getCity(Integer pid){
        List<CityCopy> pid1 = cityCopyService.selectList(new EntityWrapper<CityCopy>().eq("pid", pid));
        return ResultUtil.success(pid1);
    }
}