xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
package com.stylefeng.guns.modular.system.controller.taxi;
 
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.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.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.TDriver;
import com.stylefeng.guns.modular.system.model.TOrderPosition;
import com.stylefeng.guns.modular.system.model.TUser;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.HttpRequestUtil;
import com.stylefeng.guns.modular.system.util.PushURL;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.TOrderTaxi;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;
 
/**
 * 出租车订单控制器
 *
 * @author fengshuonan
 * @Date 2020-06-08 10:25:55
 */
@Controller
@RequestMapping("/tOrderTaxi")
public class TOrderTaxiController extends BaseController {
 
    private String PREFIX = "/system/tOrderTaxi/";
 
    @Autowired
    private ITOrderTaxiService tOrderTaxiService;
 
    @Autowired
    private ITOrderPrivateCarService tOrderPrivateCarService;
 
    @Autowired
    private ITOrderPositionService tOrderPositionService;
 
    @Autowired
    private ITDriverService tDriverService;
 
    @Autowired
    private ITUserService userService;
 
    @Value("${filePath}")
    private String filePath;
 
    /**
     * 跳转到出租车订单首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tOrderTaxi.html";
    }
 
    /**
     * 跳转到添加出租车订单
     */
    @RequestMapping("/tOrderTaxi_add")
    public String tOrderTaxiAdd() {
        return PREFIX + "tOrderTaxi_add.html";
    }
 
    /**
     * 跳转到修改出租车订单
     */
    @RequestMapping("/tOrderTaxi_update/{tOrderTaxiId}")
    public String tOrderTaxiUpdate(@PathVariable Integer tOrderTaxiId, Model model) {
        Map<String, Object> tOrderTaxi = tOrderTaxiService.getTaxiOrderDetailById(tOrderTaxiId);
 
        if (ToolUtil.isNotEmpty(tOrderTaxi)){
            List<Map<String, Object>> surchargeList = new ArrayList<>();
            List<Map<String, Object>> mapList = tOrderPrivateCarService.getSurcharge(tOrderTaxi.get("id"),2);
            if (CollectionUtils.isNotEmpty(mapList)) {
                tOrderTaxi.put("roadTollMoney", String.format(String.format("%.2f", mapList.get(0).get("amount"))));
                for (int i = 0; i < mapList.size(); i++) {
                    if (i > 0) {
                        mapList.get(i).put("amount",String.format("%.2f", Double.valueOf(Double.valueOf(mapList.get(i).get("amount").toString()))));
                        surchargeList.add(mapList.get(i));
                    }
                }
                tOrderTaxi.put("surchargeList", surchargeList);
            }
        }
        model.addAttribute("item", tOrderTaxi);
        LogObjectHolder.me().set(tOrderTaxi);
 
        model.addAttribute("item", tOrderTaxi);
        LogObjectHolder.me().set(tOrderTaxi);
        return PREFIX + "tOrderTaxi_edit.html";
    }
 
    /**
     * 跳转到改派出租车订单
     */
    @RequestMapping("/tOrderTaxi_changeOrder/{tOrderTaxiId}")
    public String tOrderTaxi_changeOrder(@PathVariable Integer tOrderTaxiId, Model model) {
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId);
        model.addAttribute("item", tOrderTaxi);
        LogObjectHolder.me().set(tOrderTaxi);
        return PREFIX + "tOrderTaxi_changeOrder.html";
    }
 
    /**
     * 跳转到出租车订单轨迹页面
     */
    @RequestMapping("/tOrderTaxi_trajectory/{tOrderTaxiId}")
    public String tOrderTaxi_trajectory(@PathVariable Integer tOrderTaxiId, Model model) {
        model.addAttribute("tOrderTaxiId", tOrderTaxiId);
        return PREFIX + "tOrderTaxi_trajectory.html";
    }
 
    /**
     * 获取出租车订单列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String insertTime,
                       String orderNum,
                       Integer orderSource,
                       String userName,
                       String userPhone,
                       String passengers,
                       String passengersPhone,
                       String driver,
                       Integer state) {
        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(tOrderTaxiService.getTaxiOrderList(page, beginTime, endTime, ShiroKit.getUser().getRoleType(), ShiroKit.getUser().getObjectId(), orderNum, orderSource, userName, userPhone, passengers, passengersPhone, driver, state));
        return super.packForBT(page);
    }
 
    /**
     * 选择司机列表
     */
    @RequestMapping(value = "/selectDriver/{orderId}")
    @ResponseBody
    public Object selectDriver(@PathVariable Integer orderId,
                               String name,
                               String phone) {
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(orderId);
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tOrderTaxiService.getCanSelectTaxiDriverList(page, tOrderTaxi.getCompanyId(), name, phone));
        return super.packForBT(page);
    }
 
    private ResultUtil resultUtil;
 
    /**
     * 获取订单轨迹
     *
     * @param orderDetailId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getOrderTrack", method = RequestMethod.POST)
    public ResultUtil getOrderTrack(String orderDetailId) {
        if (ToolUtil.isNotEmpty(orderDetailId)) {
            try {
//                List<TOrderPosition> list = tOrderPositionService.selectList(new EntityWrapper<TOrderPosition>().eq("orderType", 2).eq("orderId", orderDetailId).orderBy("insertTime"));
                /*if(list.size() == 0){
                    return ResultUtil.error("该订单没有运行轨迹");
                }*/
                //将数据存储到文件中
                File file = new File(filePath + orderDetailId + "_2.txt");
                if (!file.exists()) {
                    return ResultUtil.success(new ArrayList<>());
                }
                //读取文件(字符流)
                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
                //循环取出数据
                String str = null;
                StringBuffer sb = new StringBuffer();
                while ((str = in.readLine()) != null) {
                    sb.append(str);
                }
                List<TOrderPosition> list = JSONArray.parseArray(sb.toString(), TOrderPosition.class);
                resultUtil = ResultUtil.success(list);
            } catch (Exception e) {
                e.printStackTrace();
                resultUtil = ResultUtil.runErr();
            }
        } else {
            resultUtil = ResultUtil.paranErr();
        }
        return resultUtil;
    }
 
    /**
     * 删除出租车订单
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tOrderTaxiId) {
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId);
        tOrderTaxi.setIsDelete(2);
        tOrderTaxiService.updateById(tOrderTaxi);
        return SUCCESS_TIP;
    }
 
    /**
     * 出租车订单改派司机
     */
    @RequestMapping(value = "/selectDriver")
    @ResponseBody
    public Object selectDriver(@RequestParam Integer orderId, @RequestParam Integer driverId) {
        //修改订单
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(orderId);
 
        //修改之前司机状态 -- 空闲
        TDriver oldDriver = tDriverService.selectById(tOrderTaxi.getDriverId());
        oldDriver.setState(2);
        tDriverService.updateById(oldDriver);
 
        //查找司机对象
        TDriver nowDriver = tDriverService.selectById(driverId);
        nowDriver.setState(3);
        tDriverService.updateById(nowDriver);
 
        //修改出租车订单
        tOrderTaxi.setState(tOrderTaxi.getOldState());
        tOrderTaxi.setDriverId(driverId);
        tOrderTaxi.setCarId(nowDriver.getCarId());
        tOrderTaxiService.updateById(tOrderTaxi);
 
        //增加推送
        Map<String, String> map = new HashMap<>();
        map.put("orderId", tOrderTaxi.getId().toString());
        map.put("orderType", "2");
        String result = HttpRequestUtil.postRequest(PushURL.order_push_url, map);
        System.out.println("出租车改派:【orderId=" + tOrderTaxi.getId().toString() + "】,调用接口:" + result);
        return SUCCESS_TIP;
    }
 
    /**
     * 取消出租车订单
     */
    @RequestMapping(value = "/cancel")
    @ResponseBody
    public Object cancel(@RequestParam Integer tOrderTaxiId) {
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId);
 
        if (SinataUtil.isNotEmpty(tOrderTaxi.getDriverId())) {
            //修改之前司机状态 -- 空闲
            TDriver driver = tDriverService.selectById(tOrderTaxi.getDriverId());
            driver.setState(2);
            tDriverService.updateById(driver);
        }
 
        tOrderTaxi.setState(10);
        tOrderTaxiService.updateById(tOrderTaxi);
 
        //增加推送
        Map<String, String> map = new HashMap<>();
        map.put("id", tOrderTaxi.getId().toString());
        map.put("orderType", "2");
        String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map);
        System.out.println("出租车取消:【orderId=" + tOrderTaxi.getId().toString() + "】,调用接口:" + result);
 
        return SUCCESS_TIP;
    }
 
    /**
     * 修改出租车订单
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TOrderTaxi tOrderTaxi) {
        TUser user = userService.selectOne(new EntityWrapper<TUser>().eq("phone", tOrderTaxi.getPassengersPhone()));
        if (ToolUtil.isNotEmpty(user)) {///  用户是平台用户
            tOrderTaxi.setOrderNum("TAXI" + String.valueOf(1000000 + tOrderTaxiService.selectList(null).size() + 1).substring(1));
            tOrderTaxi.setUserId(user.getId());
            tOrderTaxi.setState(1);
            tOrderTaxi.setInsertTime(DateUtil.parseTime(DateUtil.getTime()));
            tOrderTaxi.setOrderType(1);
            tOrderTaxi.setType(1);
            tOrderTaxi.setIsReassign(1);
            tOrderTaxi.setReassignNotice(0);
            tOrderTaxi.setSubstitute(0);
            tOrderTaxi.setPlacementAddress(tOrderTaxi.getStartAddress());
            tOrderTaxi.setPlacementLat(tOrderTaxi.getStartLat());
            tOrderTaxi.setPlacementLon(tOrderTaxi.getStartLon());
            tOrderTaxi.setStartLat(tOrderTaxi.getStartLat());
            tOrderTaxi.setStartLon(tOrderTaxi.getStartLon());
            tOrderTaxi.setOrderSource(5);
            tOrderTaxi.setEndAddress(tOrderTaxi.getEndAddress().replaceAll("& #40;","(").replaceAll("& #41;",")"));
 
            ///   判断是否为预约单
            long travelTime = tOrderTaxi.getTravelTime().getTime();
            long momengtTime = new Date().getTime();
            if ((travelTime - momengtTime) > 10 * 60 * 1000) {
                tOrderTaxi.setOrderType(2);
            } else {
                tOrderTaxi.setOrderType(1);
            }
            tOrderTaxiService.insert(tOrderTaxi);
        } else {///  用户不是平台用户时
            TUser tUser = new TUser();
            tUser.setInsertTime(DateUtil.parseTime(DateUtil.getTime()));
            tUser.setPhone(tOrderTaxi.getPassengersPhone());
            tUser.setName(tOrderTaxi.getPassengers());
            tUser.setNickName("JYX" + String.valueOf(1000000 + userService.selectList(null).size() + 1).substring(1));
            userService.insert(tUser);
 
            ///  存入订单信息
            tOrderTaxi.setOrderNum("TAXI" + String.valueOf(1000000 + tOrderTaxiService.selectList(null).size() + 1).substring(1));
            tOrderTaxi.setUserId(tUser.getId());
            tOrderTaxi.setState(1);
            tOrderTaxi.setInsertTime(DateUtil.parseTime(DateUtil.getTime()));
            tOrderTaxi.setOrderType(1);
            tOrderTaxi.setType(1);
            tOrderTaxi.setIsReassign(1);
            tOrderTaxi.setReassignNotice(0);
            tOrderTaxi.setSubstitute(0);
            tOrderTaxi.setPlacementAddress(tOrderTaxi.getStartAddress());
            tOrderTaxi.setPlacementLat(tOrderTaxi.getStartLat());
            tOrderTaxi.setPlacementLon(tOrderTaxi.getStartLon());
            tOrderTaxi.setStartLat(tOrderTaxi.getStartLat());
            tOrderTaxi.setStartLon(tOrderTaxi.getStartLon());
            tOrderTaxi.setOrderSource(5);
 
            ///   判断是否为预约单
            long travelTime = tOrderTaxi.getTravelTime().getTime();
            long momengtTime = new Date().getTime();
            if ((travelTime - momengtTime) > 10 * 60 * 1000) {
                tOrderTaxi.setOrderType(2);
            } else {
                tOrderTaxi.setOrderType(1);
            }
            tOrderTaxiService.insert(tOrderTaxi);
        }
        //增加推送
        Map<String, String> map = new HashMap<>();
        map.put("orderId", tOrderTaxi.getId().toString());
        map.put("orderType", "2");
        String result = HttpRequestUtil.postRequest(PushURL.push_order, map);
        System.out.println("添加订单推单调用结果:" + result);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改出租车订单
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TOrderTaxi tOrderTaxi) {
        tOrderTaxiService.updateById(tOrderTaxi);
        return SUCCESS_TIP;
    }
 
    /**
     * 出租车订单详情
     */
    @RequestMapping(value = "/detail/{tOrderTaxiId}")
    @ResponseBody
    public Object detail(@PathVariable("tOrderTaxiId") Integer tOrderTaxiId) {
        return tOrderTaxiService.selectById(tOrderTaxiId);
    }
}