liujie
7 天以前 3a0bef313cbc6cd71bcb234d208805c022827e13
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
package com.stylefeng.guns.modular.system.controller.specialTrain;
 
import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
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.base.tips.ErrorTip;
import com.stylefeng.guns.core.beetl.ShiroExtUtil;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.SystemPriceCity;
import com.stylefeng.guns.modular.system.model.TRegion;
import com.stylefeng.guns.modular.system.model.TServerCarmodel;
import com.stylefeng.guns.modular.system.model.TSystemPrice;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.PushMinistryOfTransportUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
 
/**
 * 快车价格设置控制器
 *
 * @author fengshuonan
 * @Date 2020-08-29 10:50:13
 */
@Controller
@RequestMapping("/tSystemPrice")
public class TSystemPriceController extends BaseController {
 
    private String PREFIX = "/system/tSystemPrice/";
 
    @Autowired
    private ITSystemPriceService tSystemPriceService;
    
    @Autowired
    private ITServerCarmodelService tServerCarmodelService;
    
    @Autowired
    private PushMinistryOfTransportUtil pushMinistryOfTransportUtil;
    
    @Autowired
    private ITRegionService tRegionService;
    @Autowired
    private ShiroExtUtil shiroExtUtil;
    
    @Value("${pushMinistryOfTransport}")
    private boolean pushMinistryOfTransport;
    
    @Autowired
    private ISystemPriceCityService systemPriceCityService;
    
    
    /**
     * 跳转到列表页
     * @return
     */
    @RequestMapping("/showSystemPriceCity")
    public String showSystemPriceCity(){
        return PREFIX + "systemPriceCity.html";
    }
    
    /**
     * 跳转到添加价格
     * @return
     */
    @RequestMapping("/systemPriceCity_add")
    public String systemPriceCity_add(Model model){
        List<TServerCarmodel> tServerCarmodels = tServerCarmodelService.selectList(new EntityWrapper<TServerCarmodel>().eq("type", 1).eq("state", 1));
        model.addAttribute("serverCarModelList", tServerCarmodels);
        List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
        model.addAttribute("provinceList",provinceList);
        return PREFIX + "systemPriceCity_add.html";
    }
    
    /**
     * 跳转到修改价格城市
     * @return
     */
    @RequestMapping("/systemPriceCity_update")
    public String systemPriceCity_update(Integer id, Model model){
        SystemPriceCity systemPriceCity = systemPriceCityService.selectById(id);
        model.addAttribute("item", systemPriceCity);
        //省
        List<TRegion> provinceList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", 0));
        model.addAttribute("provinceList",provinceList);
        //市
        TRegion code = tRegionService.selectOne(new EntityWrapper<TRegion>().eq("code", systemPriceCity.getAreaCode()));
        List<TRegion> cityList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", code.getId()));
        model.addAttribute("cityList",cityList);
        //区
        model.addAttribute("areaList", null);
        if(ToolUtil.isNotEmpty(systemPriceCity.getProvinceCode())){
            code = tRegionService.selectOne(new EntityWrapper<TRegion>().eq("code", systemPriceCity.getCityCode()));
            List<TRegion> areaList = tRegionService.selectList(new EntityWrapper<TRegion>().eq("parent_id", code.getId()));
            model.addAttribute("areaList",areaList);
        }
        List<TServerCarmodel> tServerCarmodels = tServerCarmodelService.selectList(new EntityWrapper<TServerCarmodel>().eq("type", 1).eq("state", 1));
        List<TSystemPrice> tSystemPrices = tSystemPriceService.selectList(new EntityWrapper<TSystemPrice>().eq("systemPriceCityId", id).eq("state", 1).eq("type", 1));
        tServerCarmodels.forEach(s->{
            Optional<TSystemPrice> first = tSystemPrices.stream().filter(p -> p.getServerCarModelId().equals(s.getId())).findFirst();
            if(first.isPresent()){
                TSystemPrice tSystemPrice = first.get();
                s.setObject(Base64.encode(JSON.toJSONString(tSystemPrice)));
            }
        });
        model.addAttribute("serverCarModelList", tServerCarmodels);
        TSystemPrice systemPrice = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("systemPriceCityId", id).eq("state", 1).eq("type", 2));
        model.addAttribute("zcPrice", Base64.encode(systemPrice.getContent()));
        return PREFIX + "systemPriceCity_edit.html";
    }
    
    
    /**
     * 跳转到快车价格设置首页
     */
    @RequestMapping("/special")
    public String index(Integer id) {
        return PREFIX + "tSystemPrice.html";
    }
 
    /**
     * 跳转到小件物流价格设置首页
     */
    @RequestMapping("/small")
    public String small(Model model) {
        //跨城小件物流
        TSystemPrice one = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("type", 5).eq("companyId", shiroExtUtil.getUser().getObjectId()).eq("state", 1));
        if (SinataUtil.isNotEmpty(one)){
            JSONObject json1 = JSONObject.fromObject(one.getContent());
            model.addAttribute("json1",json1);
        }
        //同城小件物流
        TSystemPrice two = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("type", 4).eq("companyId", shiroExtUtil.getUser().getObjectId()).eq("state", 1));
        if (SinataUtil.isNotEmpty(two)){
            JSONObject json2 = JSONObject.fromObject(two.getContent());
            model.addAttribute("json2",json2);
        }
        return PREFIX + "small.html";
    }
 
 
 
     @RequestMapping("/taxi")
    public String taxi(String price, Model model) {
         if(ToolUtil.isNotEmpty(price)){
             price = Base64.decodeStr(price);
             JSONObject json1 = JSONObject.fromObject(price);
             model.addAttribute("json", json1);
         }
         return PREFIX + "taxiSet.html";
     }
    /**
     * 跳转到添加快车价格设置
     */
    @RequestMapping("/tSystemPrice_add")
    public String tSystemPriceAdd(Integer id, String price, Model model) {
        model.addAttribute("item", null);
        model.addAttribute("content", null);
        model.addAttribute("contentPutOne", null);
        model.addAttribute("contentNotOne", null);
        model.addAttribute("contentPutTwo", null);
        model.addAttribute("contentNotTwo", null);
        model.addAttribute("contentPutThree", null);
        model.addAttribute("contentNotThree", null);
        model.addAttribute("contentExclusive", null);
        model.addAttribute("contentPrice", null);
        if(ToolUtil.isNotEmpty(price)){
            String s = Base64.decodeStr(price);
            TSystemPrice tSystemPrice = JSON.parseObject(s, TSystemPrice.class);
            model.addAttribute("item",tSystemPrice);
            LogObjectHolder.me().set(tSystemPrice);
    
            JSONObject json = JSONObject.fromObject(tSystemPrice.getContent());
            model.addAttribute("content",json);
    
            model.addAttribute("contentPutOne", JSONObject.fromObject(tSystemPrice.getContentPutOne()));
            model.addAttribute("contentNotOne", JSONObject.fromObject(tSystemPrice.getContentNotOne()));
            model.addAttribute("contentPutTwo", JSONObject.fromObject(tSystemPrice.getContentPutTwo()));
            model.addAttribute("contentNotTwo", JSONObject.fromObject(tSystemPrice.getContentNotTwo()));
            model.addAttribute("contentPutThree", JSONObject.fromObject(tSystemPrice.getContentPutThree()));
            model.addAttribute("contentNotThree", JSONObject.fromObject(tSystemPrice.getContentNotThree()));
            model.addAttribute("contentExclusive", JSONObject.fromObject(tSystemPrice.getContentExclusive()));
            model.addAttribute("contentPrice", JSONObject.fromObject(tSystemPrice.getContentPrice()));
        }
        
        TServerCarmodel tServerCarmodel = tServerCarmodelService.selectById(id);
        model.addAttribute("modelList", tServerCarmodel);
        return PREFIX + "tSystemPrice_edit.html";
    }
 
    /**
     * 跳转到修改快车价格设置
     */
    @RequestMapping("/tSystemPrice_update/{tSystemPriceId}")
    public String tSystemPriceUpdate(@PathVariable Integer tSystemPriceId, Model model) {
        TSystemPrice tSystemPrice = tSystemPriceService.selectById(tSystemPriceId);
        model.addAttribute("item",tSystemPrice);
        LogObjectHolder.me().set(tSystemPrice);
 
        JSONObject json = JSONObject.fromObject(tSystemPrice.getContent());
        model.addAttribute("content",json);
    
        model.addAttribute("contentPutOne", JSONObject.fromObject(tSystemPrice.getContentPutOne()));
        model.addAttribute("contentNotOne", JSONObject.fromObject(tSystemPrice.getContentNotOne()));
        model.addAttribute("contentPutTwo", JSONObject.fromObject(tSystemPrice.getContentPutTwo()));
        model.addAttribute("contentNotTwo", JSONObject.fromObject(tSystemPrice.getContentNotTwo()));
        model.addAttribute("contentPutThree", JSONObject.fromObject(tSystemPrice.getContentPutThree()));
        model.addAttribute("contentNotThree", JSONObject.fromObject(tSystemPrice.getContentNotThree()));
        model.addAttribute("contentExclusive", JSONObject.fromObject(tSystemPrice.getContentExclusive()));
        model.addAttribute("contentPrice", JSONObject.fromObject(tSystemPrice.getContentPrice()));
    
        //查询所有快车车型
        List<TSystemPrice> tSystemPrices = tSystemPriceService.selectList(new EntityWrapper<TSystemPrice>().eq("type", 1).eq("companyId", shiroExtUtil.getUser().getObjectId()).ne("state", 3));
        List<TServerCarmodel> modelList = tServerCarmodelService.selectList(new EntityWrapper<TServerCarmodel>().eq("type", 1).eq("state", 1)
                .notIn("id", tSystemPrices.stream().map(TSystemPrice::getServerCarModelId).collect(Collectors.toList())));
        List<TServerCarmodel> serverCarmodels = new ArrayList<>();
    
        modelList.add(tServerCarmodelService.selectById(tSystemPrice.getServerCarModelId()));
//            boolean b = true;
//            for(TSystemPrice tsp : tSystemPrices){
//                if(tsc.getId() == tsp.getServerCarModelId()){
//                    b = false;
//                    break;
//                }
//            }
//            if(b){
//                serverCarmodels.add(tsc);
//            }
        model.addAttribute("modelList",modelList);
 
        return PREFIX + "tSystemPrice_edit.html";
    }
    
    
    /**
     * 获取价格列表设置
     * @param name
     * @param time
     * @return
     */
    @RequestMapping(value = "/queryList")
    @ResponseBody
    public Object queryList(String condition, String insertTime){
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(systemPriceCityService.queryList(page, condition, insertTime));
        return super.packForBT(page);
        
    }
    
    
    
    /**
     * 获取快车价格设置列表
     */
    @RequestMapping(value = "/listSpecial")
    @ResponseBody
    public Object list(String name,Integer state) {
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tSystemPriceService.getSpecialPriceList(page, shiroExtUtil.getUser().getObjectId(), name, state));
        return super.packForBT(page);
    }
 
    /**
     * 新增快车价格设置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SystemPriceCity systemPriceCity, String zcPrice, String czcPrice) {
        if(ToolUtil.isNotEmpty(systemPriceCity.getProvinceCode())){
            TRegion tRegion = tRegionService.selectById(systemPriceCity.getProvinceCode());
            systemPriceCity.setProvinceCode(tRegion.getCode());
        }
        if(ToolUtil.isNotEmpty(systemPriceCity.getCityCode())){
            TRegion tRegion = tRegionService.selectById(systemPriceCity.getCityCode());
            systemPriceCity.setCityCode(tRegion.getCode());
        }
        if(ToolUtil.isNotEmpty(systemPriceCity.getAreaCode())){
            TRegion tRegion = tRegionService.selectById(systemPriceCity.getAreaCode());
            systemPriceCity.setAreaCode(tRegion.getCode());
        }
        
        
        SystemPriceCity one = null;
        if(null != systemPriceCity.getProvinceCode()){
            one = systemPriceCityService.selectOne(new EntityWrapper<SystemPriceCity>().eq("areaCode", systemPriceCity.getAreaCode())
                    .eq("cityCode", systemPriceCity.getCityCode()).eq("provinceCode", systemPriceCity.getProvinceCode()).ne("flag", 3));
        }
        if(null == one){
            one = systemPriceCityService.selectOne(new EntityWrapper<SystemPriceCity>().eq("areaCode", systemPriceCity.getAreaCode())
                    .eq("cityCode", systemPriceCity.getCityCode()).isNull("provinceCode").ne("flag", 3));
            if(null == one){
                one = systemPriceCityService.selectOne(new EntityWrapper<SystemPriceCity>().eq("areaCode", systemPriceCity.getAreaCode())
                        .isNull("cityCode").isNull("provinceCode").ne("flag", 3));
                if(null != one){
                    return new ErrorTip(500, "不能重复添加城市");
                }
            }else{
                return new ErrorTip(500, "不能重复添加城市");
            }
        }else{
            return new ErrorTip(500, "不能重复添加城市");
        }
        systemPriceCityService.insert(systemPriceCity);
        //解析专车的价格配置
        JSONArray jsonArray = JSON.parseArray(zcPrice);
        for (int i = 0; i < jsonArray.size(); i++) {
            TSystemPrice tSystemPrice = jsonArray.getObject(i, TSystemPrice.class);
            tSystemPrice.setSystemPriceCityId(systemPriceCity.getId());
            tSystemPrice.setType(1);
            tSystemPrice.setState(1);
            tSystemPriceService.insert(tSystemPrice);
        }
        //解析出出租车价格设置
        TSystemPrice tSystemPrice = new TSystemPrice();
        tSystemPrice.setContent(czcPrice);
        tSystemPrice.setSystemPriceCityId(systemPriceCity.getId());
        tSystemPrice.setType(2);
        tSystemPrice.setState(1);
        tSystemPriceService.insert(tSystemPrice);
        return SUCCESS_TIP;
    }
 
    @RequestMapping(value = "/taxiSet")
    @ResponseBody
    public Object taxiSet(String content) {
        Integer id = shiroExtUtil.getUser().getId();
        TSystemPrice tSystemPrice1 = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("type", 2).eq("companyId", id));
        if (tSystemPrice1 == null) {
            TSystemPrice tSystemPrice = new TSystemPrice();
            tSystemPrice.setContent(content);
            tSystemPrice.setType(2);
            tSystemPriceService.insert(tSystemPrice);
        } else {
            tSystemPrice1.setContent(content);
            tSystemPriceService.updateById(tSystemPrice1);
        }
        System.err.println("========"+content);
        return ResultUtil.success();
    }
 
    /**
     * 修改快车价格设置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SystemPriceCity systemPriceCity, String zcPrice, String czcPrice) {
        if(ToolUtil.isNotEmpty(systemPriceCity.getProvinceCode())){
            TRegion tRegion = tRegionService.selectById(systemPriceCity.getProvinceCode());
            systemPriceCity.setProvinceCode(tRegion.getCode());
        }
        if(ToolUtil.isNotEmpty(systemPriceCity.getCityCode())){
            TRegion tRegion = tRegionService.selectById(systemPriceCity.getCityCode());
            systemPriceCity.setCityCode(tRegion.getCode());
        }
        if(ToolUtil.isNotEmpty(systemPriceCity.getAreaCode())){
            TRegion tRegion = tRegionService.selectById(systemPriceCity.getAreaCode());
            systemPriceCity.setAreaCode(tRegion.getCode());
        }
    
    
        SystemPriceCity one = null;
        if(null != systemPriceCity.getProvinceCode()){
            one = systemPriceCityService.selectOne(new EntityWrapper<SystemPriceCity>().eq("areaCode", systemPriceCity.getAreaCode())
                    .eq("cityCode", systemPriceCity.getCityCode()).eq("provinceCode", systemPriceCity.getProvinceCode()).ne("flag", 3));
        }
        if(null == one){
            one = systemPriceCityService.selectOne(new EntityWrapper<SystemPriceCity>().eq("areaCode", systemPriceCity.getAreaCode())
                    .eq("cityCode", systemPriceCity.getCityCode()).isNull("provinceCode").ne("flag", 3));
            if(null == one){
                one = systemPriceCityService.selectOne(new EntityWrapper<SystemPriceCity>().eq("areaCode", systemPriceCity.getAreaCode())
                        .isNull("cityCode").isNull("provinceCode").ne("flag", 3));
                if(null != one && !systemPriceCity.getId().equals(one.getId())){
                    return new ErrorTip(500, "不能重复添加城市");
                }
            }else if(!systemPriceCity.getId().equals(one.getId())){
                return new ErrorTip(500, "不能重复添加城市");
            }
        }else if(!systemPriceCity.getId().equals(one.getId())){
            return new ErrorTip(500, "不能重复添加城市");
        }
        systemPriceCityService.updateById(systemPriceCity);
        //删除历史数据
        tSystemPriceService.delete(new EntityWrapper<TSystemPrice>().eq("systemPriceCityId", systemPriceCity.getId()));
        //解析专车的价格配置
        JSONArray jsonArray = JSON.parseArray(zcPrice);
        for (int i = 0; i < jsonArray.size(); i++) {
            TSystemPrice tSystemPrice = jsonArray.getObject(i, TSystemPrice.class);
            tSystemPrice.setSystemPriceCityId(systemPriceCity.getId());
            tSystemPrice.setType(1);
            tSystemPrice.setState(1);
            tSystemPriceService.insert(tSystemPrice);
        }
        //解析出出租车价格设置
        TSystemPrice tSystemPrice = new TSystemPrice();
        tSystemPrice.setContent(czcPrice);
        tSystemPrice.setSystemPriceCityId(systemPriceCity.getId());
        tSystemPrice.setType(2);
        tSystemPrice.setState(1);
        tSystemPriceService.insert(tSystemPrice);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改状态
     */
    @RequestMapping(value = "/opt")
    @ResponseBody
    public Object opt(Integer id) {
        SystemPriceCity systemPriceCity = systemPriceCityService.selectById(id);
        systemPriceCity.setFlag(3);
        systemPriceCityService.updateById(systemPriceCity);
        return SUCCESS_TIP;
    }
 
    /**
     * 小件物流价格设置
     */
    @RequestMapping(value = "/smallSubmit")
    @ResponseBody
    public Object smallSubmit(String json1,String json2) {
        //跨城小件物流
        TSystemPrice one = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("type", 5).eq("companyId", shiroExtUtil.getUser().getObjectId()));
        if (SinataUtil.isNotEmpty(one)){
            one.setContent(json1);
            tSystemPriceService.updateById(one);
        }else {
            one = new TSystemPrice();
            one.setState(1);
            one.setType(5);
            one.setContent(json1);
            tSystemPriceService.insert(one);
        }
        //同城小件物流
        TSystemPrice two = tSystemPriceService.selectOne(new EntityWrapper<TSystemPrice>().eq("type", 4).eq("companyId", shiroExtUtil.getUser().getObjectId()));
        if (SinataUtil.isNotEmpty(two)){
            two.setContent(json2);
            tSystemPriceService.updateById(two);
        }else {
            two = new TSystemPrice();
            two.setState(1);
            two.setType(4);
            two.setContent(json2);
            tSystemPriceService.insert(two);
        }
        return SUCCESS_TIP;
    }
 
}