yanghb
2023-04-21 0481353111afb43a2322e18530dde26f1d841ead
ManagementTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/taxi/TOrderTaxiController.java
@@ -6,17 +6,13 @@
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 com.stylefeng.guns.modular.system.service.ITDriverService;
import com.stylefeng.guns.modular.system.service.ITOrderPositionService;
import com.stylefeng.guns.modular.system.util.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@@ -24,12 +20,16 @@
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.TOrderTaxi;
import com.stylefeng.guns.modular.system.service.ITOrderTaxiService;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 出租车订单控制器
@@ -47,16 +47,10 @@
    private ITOrderTaxiService tOrderTaxiService;
    @Autowired
    private ITOrderPrivateCarService tOrderPrivateCarService;
    @Autowired
    private ITOrderPositionService tOrderPositionService;
    @Autowired
    private ITDriverService tDriverService;
    @Autowired
    private ITUserService userService;
    @Value("${filePath}")
    private String filePath;
@@ -83,25 +77,8 @@
    @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);
        tOrderTaxi.put("userPhone", null != tOrderTaxi.get("userPhone") ? AESUtil.decrypt(tOrderTaxi.get("userPhone").toString()) : "");
        model.addAttribute("item",tOrderTaxi);
        LogObjectHolder.me().set(tOrderTaxi);
        return PREFIX + "tOrderTaxi_edit.html";
    }
@@ -112,7 +89,7 @@
    @RequestMapping("/tOrderTaxi_changeOrder/{tOrderTaxiId}")
    public String tOrderTaxi_changeOrder(@PathVariable Integer tOrderTaxiId, Model model) {
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId);
        model.addAttribute("item", tOrderTaxi);
        model.addAttribute("item",tOrderTaxi);
        LogObjectHolder.me().set(tOrderTaxi);
        return PREFIX + "tOrderTaxi_changeOrder.html";
    }
@@ -122,7 +99,7 @@
     */
    @RequestMapping("/tOrderTaxi_trajectory/{tOrderTaxiId}")
    public String tOrderTaxi_trajectory(@PathVariable Integer tOrderTaxiId, Model model) {
        model.addAttribute("tOrderTaxiId", tOrderTaxiId);
        model.addAttribute("tOrderTaxiId",tOrderTaxiId);
        return PREFIX + "tOrderTaxi_trajectory.html";
    }
@@ -142,13 +119,13 @@
                       Integer state) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(insertTime)) {
        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));
        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);
    }
@@ -162,7 +139,7 @@
                               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));
        page.setRecords(tOrderTaxiService.getCanSelectTaxiDriverList(page,tOrderTaxi.getCompanyId(),name,phone));
        return super.packForBT(page);
    }
@@ -170,14 +147,13 @@
    /**
     * 获取订单轨迹
     *
     * @param orderDetailId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getOrderTrack", method = RequestMethod.POST)
    public ResultUtil getOrderTrack(String orderDetailId) {
        if (ToolUtil.isNotEmpty(orderDetailId)) {
    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){
@@ -185,11 +161,11 @@
                }*/
                //将数据存储到文件中
                File file = new File(filePath + orderDetailId + "_2.txt");
                if (!file.exists()) {
                if(!file.exists()){
                    return ResultUtil.success(new ArrayList<>());
                }
                //读取文件(字符流)
                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
                //循环取出数据
                String str = null;
                StringBuffer sb = new StringBuffer();
@@ -198,11 +174,11 @@
                }
                List<TOrderPosition> list = JSONArray.parseArray(sb.toString(), TOrderPosition.class);
                resultUtil = ResultUtil.success(list);
            } catch (Exception e) {
            }catch (Exception e){
                e.printStackTrace();
                resultUtil = ResultUtil.runErr();
            }
        } else {
        }else {
            resultUtil = ResultUtil.paranErr();
        }
        return resultUtil;
@@ -225,10 +201,10 @@
     */
    @RequestMapping(value = "/selectDriver")
    @ResponseBody
    public Object selectDriver(@RequestParam Integer orderId, @RequestParam Integer driverId) {
    public Object selectDriver(@RequestParam Integer orderId,@RequestParam Integer driverId) {
        //修改订单
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(orderId);
        //修改之前司机状态 -- 空闲
        TDriver oldDriver = tDriverService.selectById(tOrderTaxi.getDriverId());
        oldDriver.setState(2);
@@ -246,11 +222,11 @@
        tOrderTaxiService.updateById(tOrderTaxi);
        //增加推送
        Map<String, String> map = new HashMap<>();
        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);
        System.out.println("出租车改派:【orderId="+tOrderTaxi.getId().toString()+"】,调用接口:"+result);
        return SUCCESS_TIP;
    }
@@ -262,88 +238,21 @@
    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);
        }
        //修改之前司机状态 -- 空闲
        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<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);
        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(5);
            tOrderTaxi.setType(1);
            tOrderTaxi.setIsReassign(1);
            tOrderTaxi.setReassignNotice(0);
            tOrderTaxi.setSubstitute(0);
            tOrderTaxi.setBoardingLon(tOrderTaxi.getStartLon());
            tOrderTaxi.setBoardingLat(tOrderTaxi.getStartLat());
            tOrderTaxi.setPlacementAddress(tOrderTaxi.getStartAddress());
            ///   判断是否为预约单
            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(5);
            tOrderTaxi.setType(1);
            tOrderTaxi.setIsReassign(1);
            tOrderTaxi.setReassignNotice(0);
            tOrderTaxi.setSubstitute(0);
            tOrderTaxi.setBoardingLon(tOrderTaxi.getStartLon());
            tOrderTaxi.setBoardingLat(tOrderTaxi.getStartLat());
            tOrderTaxi.setPlacementAddress(tOrderTaxi.getStartAddress());
            ///   判断是否为预约单
            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);
        }
        return SUCCESS_TIP;
    }