puzhibing
2023-06-13 7860e5cb6db60aeb82c640651998f8294635df5b
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package com.dsh.guns.modular.system.controller.general;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.course.entity.City;
import com.dsh.course.mapper.CityMapper;
import com.dsh.course.util.GoogleMap.GoogleMapUtil;
import com.dsh.course.util.GoogleMap.ReverseGeocodeVo;
import com.dsh.guns.config.UserExt;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.core.log.LogObjectHolder;
import com.dsh.guns.core.util.SinataUtil;
import com.dsh.guns.modular.system.model.TbHotAddress;
import com.dsh.guns.modular.system.service.ITbHotAddressService;
import com.dsh.guns.modular.system.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2022-06-17 14:43:39
 */
@Controller
@RequestMapping("/THotAddress")
public class THotAddressController extends BaseController {
 
    private String PREFIX = "/system/tHotAddress/";
 
    @Autowired
    private ITbHotAddressService tbHotAddressService;
 
    @Autowired
    private CityMapper cityMapper;
 
    @Autowired
    private GoogleMapUtil googleMapUtil;
 
    @RequestMapping(value = "/change")
    @ResponseBody
    public Object change(@RequestParam Integer id) {
        List<City> list = new ArrayList<>();
        if (SinataUtil.isNotEmpty(id)){
            list = cityMapper.selectList(new QueryWrapper<City>().eq("pid", id));
        }
        if(UserExt.getLanguage()==2){
            for (City city : list) {
                city.setChineseName(city.getEnglishName());
            }
        }
        if(UserExt.getLanguage()==3){
            for (City city : list) {
                city.setChineseName(city.getIndonesianName());
            }
        }
        return list;
    }
 
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index(Model model) {
        model.addAttribute("language", UserExt.getLanguage());
        return PREFIX + "tbHotAddress.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tbHotAddress_add")
    public String tbHotAddressAdd(Model model) {
        List<City> pid = cityMapper.selectList(new QueryWrapper<City>().eq("pid", 0));
        if(UserExt.getLanguage()==2){
            for (City city : pid) {
                city.setChineseName(city.getEnglishName());
            }
        }else if(UserExt.getLanguage()==3){
            for (City city : pid) {
                city.setChineseName(city.getIndonesianName());
            }
        }
        model.addAttribute("item",pid);
        model.addAttribute("language",UserExt.getLanguage());
        return PREFIX + "tbHotAddress_add.html";
    }
 
    /**
     * 跳转到修改
     */
    @RequestMapping("/tbHotAddress_update/{tbHotAddressId}")
    public String tbHotAddressUpdate(@PathVariable Integer tbHotAddressId, Model model) {
        TbHotAddress tbHotAddress = tbHotAddressService.getById(tbHotAddressId);
        model.addAttribute("item",tbHotAddress);
        List<City> pid = cityMapper.selectList(new QueryWrapper<City>().eq("pid", 0));
        if(UserExt.getLanguage()==2){
            for (City city : pid) {
                city.setChineseName(city.getEnglishName());
            }
        }else if(UserExt.getLanguage()==3){
            for (City city : pid) {
                city.setChineseName(city.getIndonesianName());
            }
        }
 
        List<City> pid1 = cityMapper.selectList(new QueryWrapper<City>().eq("pid", tbHotAddress.getAreaId()));
        if(UserExt.getLanguage()==2){
            for (City city : pid1) {
                city.setChineseName(city.getEnglishName());
            }
        }
        if(UserExt.getLanguage()==3){
            for (City city : pid1) {
                city.setChineseName(city.getIndonesianName());
            }
        }
        model.addAttribute("cityList",pid1);
        model.addAttribute("item1",pid);
        model.addAttribute("language",UserExt.getLanguage());
        LogObjectHolder.me().set(tbHotAddress);
        return PREFIX + "tbHotAddress_edit.html";
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String time,String name) {
        List<TbHotAddress> list = tbHotAddressService.getList(time,name);
        return list;
    }
 
    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Integer cityId,String address,Double lon,Double lat,String name,Integer sort,Integer cityId1) {
            TbHotAddress tbHotAddress = new TbHotAddress();
        tbHotAddress.setAddress(address);
        tbHotAddress.setHide(0);
        tbHotAddress.setCityId(cityId1);
        tbHotAddress.setCreateTime(new Date());
        tbHotAddress.setLat(lat);
        tbHotAddress.setAreaId(cityId);
        tbHotAddress.setLon(lon);
        tbHotAddress.setName(name);
        tbHotAddress.setSort(sort);
        tbHotAddressService.save(tbHotAddress);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer THotAddressId) {
        TbHotAddress byId = tbHotAddressService.getById(THotAddressId);
        byId.setHide(1);
        tbHotAddressService.updateById(byId);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TbHotAddress tbHotAddress,Integer cityId1) {
        tbHotAddress.setAreaId(tbHotAddress.getCityId());
        tbHotAddress.setCityId(cityId1);
        tbHotAddressService.updateById(tbHotAddress);
        return SUCCESS_TIP;
    }
 
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{tbHotAddressId}")
    @ResponseBody
    public Object detail(@PathVariable("tbHotAddressId") Integer tbHotAddressId) {
        return tbHotAddressService.getById(tbHotAddressId);
    }
 
 
 
    @ResponseBody
    @RequestMapping(value = "/queryPlaceInfo", produces = "application/json;charset=utf-8")
    public ResultUtil queryPlaceInfo(Double lat, Double lng){
        try {
            ReverseGeocodeVo reverseGeocode = googleMapUtil.getReverseGeocode(lat, lng);
            if(null != reverseGeocode){
                return ResultUtil.success(reverseGeocode.getAddress());
            }
            return ResultUtil.error("定位失败");
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
}