puzhibing
2023-05-18 53562814add61acfdc02d6b25dae6324f6fd5f92
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package com.stylefeng.guns.modular.system.controller.general;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.modular.system.model.City;
import com.stylefeng.guns.modular.system.model.TOpenCityBusiness;
import com.stylefeng.guns.modular.system.model.TRegion;
import com.stylefeng.guns.modular.system.service.ICityService;
import com.stylefeng.guns.modular.system.service.ITOpenCityBusinessService;
import com.stylefeng.guns.modular.system.service.ITRegionService;
import com.stylefeng.guns.modular.system.util.GaoDeMapUtil;
import com.stylefeng.guns.modular.system.util.GoogleMap.FindPlaceFromTextVo;
import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.TOpenCity;
import com.stylefeng.guns.modular.system.service.ITOpenCityService;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 城市管理控制器
 *
 * @author fengshuonan
 * @Date 2020-06-02 11:40:31
 */
@Controller
@RequestMapping("/tOpenCity")
public class TOpenCityController extends BaseController {
 
    private String PREFIX = "/system/tOpenCity/";
 
    @Autowired
    private ITOpenCityService tOpenCityService;
 
    @Autowired
    private ITRegionService tRegionService;
 
    @Autowired
    private ITOpenCityBusinessService tOpenCityBusinessService;
 
    @Autowired
    private ICityService cityService;
 
 
 
 
    /**
     * 跳转到城市管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tOpenCity.html";
    }
 
    /**
     * 跳转到添加城市管理
     */
    @RequestMapping("/tOpenCity_add")
    public String tOpenCityAdd(Model model) {
        List<City> city = cityService.selectList(new EntityWrapper<City>().orderBy("id"));
        model.addAttribute("city", city);
        return PREFIX + "tOpenCity_add.html";
    }
 
    /**
     * 跳转到修改城市管理
     */
    @RequestMapping("/tOpenCity_update/{tOpenCityId}")
    public String tOpenCityUpdate(@PathVariable Integer tOpenCityId, Model model) {
        TOpenCity tOpenCity = tOpenCityService.selectById(tOpenCityId);
        model.addAttribute("item",tOpenCity);
        LogObjectHolder.me().set(tOpenCity);
 
        List<City> city = cityService.selectList(new EntityWrapper<City>().orderBy("id"));
        model.addAttribute("city", city);
        //经营业务
        List<Map<String,Object>> businessList = tOpenCityService.getBusinessByCityId(tOpenCityId);
        model.addAttribute("businessList",businessList);
        return PREFIX + "tOpenCity_edit.html";
    }
 
    @RequestMapping(value = "/change")
    @ResponseBody
    public Object change(@RequestParam Integer id) {
        List<TRegion> list = new ArrayList<>();
        if (SinataUtil.isNotEmpty(id)){
            list = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", id));
        }
        return list;
    }
 
    /**
     * 获取城市管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String insertTime,String condition) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(insertTime)){
            String[] timeArray = insertTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tOpenCityService.getOpenCityList(page,beginTime,endTime,condition));
        return super.packForBT(page);
    }
 
    /**
     * 新增城市管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TOpenCity tOpenCity,@RequestParam String businessTypeStr,Integer areaId,Integer cityId,Integer provinceId) {
        //获取code
        tOpenCity.setCityId(cityId);
        City city = cityService.selectById(cityId);
        FindPlaceFromTextVo textsearch = null;
        try {
            textsearch = GoogleMapUtil.textsearch(city.getEnglishName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(null == textsearch){
            return "查询地图异常";
        }
        tOpenCity.setLat(textsearch.getLat());
        tOpenCity.setLon(textsearch.getLng());
        tOpenCity.setInsertTime(new Date());
        tOpenCity.setInsertUser(ShiroKit.getUser().getId());
        tOpenCityService.insert(tOpenCity);
 
        //添加经营业务
        testJSONStrToJSONArray(businessTypeStr,tOpenCity.getId());
        return SUCCESS_TIP;
    }
 
    public void testJSONStrToJSONArray(String subArr,Integer tOpenCityId){
        JSONArray jsonArray = JSON.parseArray(subArr);
        int size = jsonArray.size();
        for (int i = 0; i < size; i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            TOpenCityBusiness business = new TOpenCityBusiness();
            if (SinataUtil.isNotEmpty(jsonObject.getInteger("busId")) && jsonObject.getInteger("busId") != 0){
                business = tOpenCityBusinessService.selectById(jsonObject.getInteger("busId"));
                business.setUpdateTime(new Date());
                business.setUpdateUser(ShiroKit.getUser().getId());
                business.setFlag("2");
            }else{
                business.setInsertTime(DateUtil.parse(jsonObject.getString("time")+" 00:00:00","yyyy-MM-dd HH:mm:ss"));
                business.setInsertUser(ShiroKit.getUser().getId());
            }
            business.setOpenCityId(tOpenCityId);
            String type = jsonObject.getString("type");
            Integer businessType = 0;
            if ("专车".equals(type)){
                businessType = 1;
            }else if ("市内小件物流".equals(type)){
                businessType = 4;
            }
            business.setBusinessType(businessType);
            business.setSort(jsonObject.getInteger("sort"));
            if (SinataUtil.isNotEmpty(jsonObject.getInteger("busId")) && jsonObject.getInteger("busId") != 0){
                tOpenCityBusinessService.updateById(business);
            }else{
                tOpenCityBusinessService.insert(business);
            }
        }
    }
 
    /**
     * 删除城市管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tOpenCityId) {
        TOpenCity tOpenCity = tOpenCityService.selectById(tOpenCityId);
        tOpenCity.setFlag("3");
        tOpenCityService.updateById(tOpenCity);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改城市管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TOpenCity tOpenCity,@RequestParam String businessTypeStr,Integer areaId,Integer cityId,Integer provinceId) {
        //获取code
        tOpenCity.setCityId(cityId);
        City city = cityService.selectById(cityId);
        FindPlaceFromTextVo textsearch = null;
        try {
            textsearch = GoogleMapUtil.textsearch(city.getEnglishName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(null == textsearch){
            return "查询地图异常";
        }
        tOpenCity.setLat(textsearch.getLat());
        tOpenCity.setLon(textsearch.getLng());
        tOpenCity.setUpdateTime(new Date());
        tOpenCity.setUpdateUser(ShiroKit.getUser().getId());
        tOpenCityService.updateById(tOpenCity);
 
        //删除经营业务
        TOpenCityBusiness business = new TOpenCityBusiness();
        business.setFlag("3");
        tOpenCityBusinessService.update(business,new EntityWrapper<TOpenCityBusiness>().eq("openCityId",tOpenCity.getId()));
        //添加经营业务
        testJSONStrToJSONArray(businessTypeStr,tOpenCity.getId());
        return SUCCESS_TIP;
    }
 
    /**
     * 城市管理详情
     */
    @RequestMapping(value = "/detail/{tOpenCityId}")
    @ResponseBody
    public Object detail(@PathVariable("tOpenCityId") Integer tOpenCityId) {
        return tOpenCityService.selectById(tOpenCityId);
    }
}