Pu Zhibing
2025-04-20 fcd3abef1eda1db95831359c1710381ebdd8f754
ManagementOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/taxi/TOrderTaxiController.java
@@ -4,9 +4,12 @@
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.google.gson.Gson;
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.ExcelExportUtil;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.*;
@@ -14,15 +17,15 @@
import com.stylefeng.guns.modular.system.util.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
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 java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -102,36 +105,72 @@
     * 跳转到修改出租车订单
     */
    @RequestMapping("/tOrderTaxi_update/{tOrderTaxiId}")
    public String tOrderTaxiUpdate(@PathVariable Integer tOrderTaxiId, Model model) {
    public String tOrderTaxiUpdate(@PathVariable Integer tOrderTaxiId, Model model) throws IOException {
        Map<String, Object> tOrderTaxi = tOrderTaxiService.getTaxiOrderDetailById(tOrderTaxiId);
        model.addAttribute("item",tOrderTaxi);
        // 查询司机扣款
        TPubTransactionDetails tPubTransactionDetails = pubTransactionDetailsService.selectOne(new EntityWrapper<TPubTransactionDetails>()
        List<TPubTransactionDetails> tPubTransactionDetails = pubTransactionDetailsService.selectList(new EntityWrapper<TPubTransactionDetails>()
                .eq("userId", tOrderTaxi.get("driverId"))
                .eq("state", 2)
                .eq("orderId", tOrderTaxi.get("id"))
                .eq("type", 1)
                .eq("userType", 6)
                .eq("payState", 2)
                .last("LIMIT 1"));
        if (tPubTransactionDetails==null){
                .eq("userType", 2));
        if(CollectionUtils.isEmpty(tPubTransactionDetails)){
            model.addAttribute("companyMoney","");
            model.addAttribute("driverMoney","");
        }else{
            model.addAttribute("companyMoney",tPubTransactionDetails.getMoney());
            model.addAttribute("driverMoney",new BigDecimal(tOrderTaxi.get("payMoney").toString()).subtract(tPubTransactionDetails.getMoney()));
        }
        if (tOrderTaxi.get("payManner")!=null){
            if(tOrderTaxi.get("payManner").equals("1")){
                model.addAttribute("payMannerStr","线上收款");
        }else {
            TPubTransactionDetails pubTransactionDetailCompany = tPubTransactionDetails.stream().filter(e -> e.getOrderType().equals(6)).findFirst().orElse(null);
            if(Objects.nonNull(pubTransactionDetailCompany)){
                model.addAttribute("companyMoney",pubTransactionDetailCompany.getMoney());
            }else {
                model.addAttribute("payMannerStr","计费打表");
                model.addAttribute("companyMoney","");
            }
            TPubTransactionDetails pubTransactionDetailDriver = tPubTransactionDetails.stream().filter(e -> e.getOrderType().equals(2)).findFirst().orElse(null);
            if(Objects.nonNull(pubTransactionDetailDriver)){
                model.addAttribute("driverMoney",pubTransactionDetailDriver.getMoney());
            }else {
                model.addAttribute("driverMoney","");
            }
        }
        if(tOrderTaxi.get("payManner")!=null && tOrderTaxi.get("payManner").equals("1")){
            model.addAttribute("payMannerStr","线上收款");
        }else {
            model.addAttribute("payMannerStr","计费打表");
        }
        LogObjectHolder.me().set(tOrderTaxi);
        try{
            //将数据存储到文件中
            File file = new File(filePath + tOrderTaxiId + "_2.txt");
            //读取文件(字符流)
            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);
            List<Map> maps = new ArrayList<>();
            for (TOrderPosition tOrderPosition : list) {
                Map<String, String> map = new HashMap<>();
                map.put("lon",tOrderPosition.getLon());
                map.put("lat",tOrderPosition.getLat());
                maps.add(map);
            }
//        resultUtil = ResultUtil.success(list);
            // 将maps转化为jsonArray字符串
            // 使用 Gson 转换为 JSON 字符串
//        Gson gson = new Gson();
//        String jsonString = gson.toJson(maps);
//        System.out.println(jsonString);
            model.addAttribute("guiji",maps);
        }catch (Exception e){
            e.printStackTrace();
            resultUtil = ResultUtil.runErr();
            model.addAttribute("guiji","");
        }
        return PREFIX + "tOrderTaxi_edit.html";
    }
@@ -150,8 +189,40 @@
     * 跳转到出租车订单轨迹页面
     */
    @RequestMapping("/tOrderTaxi_trajectory/{tOrderTaxiId}")
    public String tOrderTaxi_trajectory(@PathVariable Integer tOrderTaxiId, Model model) {
    public String tOrderTaxi_trajectory(@PathVariable Integer tOrderTaxiId, Model model) throws IOException {
        model.addAttribute("tOrderTaxiId",tOrderTaxiId);
        try{
            //将数据存储到文件中
            File file = new File(filePath + tOrderTaxiId + "_2.txt");
            //读取文件(字符流)
            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);
            List<Map> maps = new ArrayList<>();
            for (TOrderPosition tOrderPosition : list) {
                Map<String, String> map = new HashMap<>();
                map.put("lon",tOrderPosition.getLon());
                map.put("lat",tOrderPosition.getLat());
                maps.add(map);
            }
//        resultUtil = ResultUtil.success(list);
            // 将maps转化为jsonArray字符串
            // 使用 Gson 转换为 JSON 字符串
//        Gson gson = new Gson();
//        String jsonString = gson.toJson(maps);
//        System.out.println(jsonString);
            model.addAttribute("guiji",maps);
        }catch (Exception e){
            e.printStackTrace();
            resultUtil = ResultUtil.runErr();
            model.addAttribute("guiji","");
        }
        return PREFIX + "tOrderTaxi_trajectory.html";
    }
@@ -180,7 +251,225 @@
        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);
    }
    /**
     * 导出订单
     * @param insertTime
     * @param orderNum
     * @param orderSource
     * @param userName
     * @param userPhone
     * @param passengers
     * @param passengersPhone
     * @param driver
     * @param state
     * @param request
     * @param response
     */
    @GetMapping("/export")
    public void export(String insertTime,
                       String orderNum,
                       Integer orderSource,
                       String userName,
                       String userPhone,
                       String passengers,
                       String passengersPhone,
                       String driver,
                       Integer state, HttpServletRequest request, HttpServletResponse response){
        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 Page(1, 99999);
        List<Map<String, Object>> taxiOrderList = tOrderTaxiService.getTaxiOrderList(page, beginTime, endTime, ShiroKit.getUser().getRoleType(), ShiroKit.getUser().getObjectId(), orderNum, orderSource, userName, userPhone, passengers, passengersPhone, driver, state);
        // 表格数据【封装】
        List<List<String>> dataList = new ArrayList<>();
        // 列【封装】
        List<String> shellList = new ArrayList<String>();
        shellList.add("下单时间");
        shellList.add("订单编号");
        shellList.add("订单来源");
        shellList.add("乘车时间");
        shellList.add("下单用户昵称");
        shellList.add("下单用户手机");
        shellList.add("乘车用户姓名");
        shellList.add("乘车用户手机");
        shellList.add("起点");
        shellList.add("终点");
        shellList.add("接单司机");
        shellList.add("司机手机号");
        shellList.add("车辆所属机构");
        shellList.add("接单车辆");
        shellList.add("订单金额");
        shellList.add("司机抽成");
        shellList.add("状态");
        dataList.add(shellList);
        for (Map<String,Object> object : taxiOrderList){
            // 详细数据列【封装】
            shellList = new ArrayList<String>();
            if(SinataUtil.isNotEmpty(object.get("insertTime"))){
                shellList.add(DateUtil.formatDate(DateUtil.parse(object.get("insertTime").toString(),"YYYY-MM-dd HH:mm:ss.S"), "YYYY-MM-dd HH:mm"));
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("orderNum"))){
                shellList.add(object.get("orderNum").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("orderSource"))){
                switch (object.get("orderSource").toString()){
                    case "1":
                        shellList.add("APP下单");
                        break;
                    case "2":
                        shellList.add("扫码下单");
                        break;
                    case "3":
                        shellList.add("小程序下单");
                        break;
                    case "4":
                        shellList.add("司机下单");
                        break;
                    case "5":
                        shellList.add("调度下单");
                        break;
                    case "6":
                        shellList.add("电话下单");
                        break;
                    case "7":
                        shellList.add("95128电召");
                        break;
                }
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("travelTime"))){
                shellList.add(DateUtil.formatDate(DateUtil.parse(object.get("travelTime").toString(),"YYYY-MM-dd HH:mm:ss.S"), "YYYY-MM-dd HH:mm"));
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("userName"))){
                shellList.add(object.get("userName").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("userPhone"))){
                shellList.add(object.get("userPhone").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("passengers"))){
                shellList.add(object.get("passengers").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("passengersPhone"))){
                shellList.add(object.get("passengersPhone").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("startAddress"))){
                shellList.add(object.get("startAddress").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("endAddress"))){
                shellList.add(object.get("endAddress").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("driver"))){
                shellList.add(object.get("driver").toString().split("-")[0]);
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("driver"))){
                shellList.add(object.get("driver").toString().split("-")[1]);
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("company"))){
                shellList.add(object.get("company").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("car"))){
                shellList.add(object.get("car").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("payMoney"))){
                shellList.add(object.get("payMoney").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("commission"))){
                shellList.add(object.get("commission").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("state"))){
                switch (object.get("state").toString()){
                    case "1":
                        shellList.add("待接单");
                        break;
                    case "2":
                        shellList.add("待出发");
                        break;
                    case "3":
                        shellList.add("待到达预约地点");
                        break;
                    case "4":
                        shellList.add("待乘客上车");
                        break;
                    case "5":
                        shellList.add("服务中");
                        break;
                    case "6":
                        shellList.add("完成服务");
                        break;
                    case "7":
                        shellList.add("待支付");
                        break;
                    case "8":
                        shellList.add("待评价");
                        break;
                    case "9":
                        shellList.add("已完成");
                        break;
                    case "10":
                        shellList.add("已取消");
                        break;
                    case "11":
                        shellList.add("改派中");
                        break;
                    case "12":
                        shellList.add("取消待支付");
                        break;
                }
            }else{
                shellList.add("-");
            }
            dataList.add(shellList);
        }
        try {
            // 调用工具类进行导出
            ExcelExportUtil.easySheet("出租车订单"+DateUtil.formatDate(new Date(), "YYYYMMddHHmmss"), "出租车订单", dataList,request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 选择司机列表
     */
@@ -382,12 +671,12 @@
            tOrderTaxi.setUserId(tUser.getId());
            tOrderTaxi.setOrderNum(this.getOrderNum());
            tOrderTaxi.setPlacementAddress(tOrderTaxi.getStartAddress());
            tOrderTaxi.setPlacementLon(Double.valueOf(s.get(0).split(",")[0]));
            tOrderTaxi.setPlacementLat(Double.valueOf(s.get(0).split(",")[1]));
            tOrderTaxi.setStartLon(Double.valueOf(s.get(0).split(",")[0]));
            tOrderTaxi.setStartLat(Double.valueOf(s.get(0).split(",")[1]));
            tOrderTaxi.setEndLon(Double.valueOf(e.get(0).split(",")[0]));
            tOrderTaxi.setEndLat(Double.valueOf(e.get(0).split(",")[1]));
            tOrderTaxi.setPlacementLon(Double.valueOf(s.get(0).split(",")[1]));
            tOrderTaxi.setPlacementLat(Double.valueOf(s.get(0).split(",")[0]));
            tOrderTaxi.setStartLon(Double.valueOf(s.get(0).split(",")[1]));
            tOrderTaxi.setStartLat(Double.valueOf(s.get(0).split(",")[0]));
            tOrderTaxi.setEndLon(Double.valueOf(e.get(0).split(",")[1]));
            tOrderTaxi.setEndLat(Double.valueOf(e.get(0).split(",")[0]));
            tOrderTaxi.setMileage(0D);
            tOrderTaxi.setOrderMoney(new BigDecimal(0));
            tOrderTaxi.setTravelMoney(new BigDecimal(0));
@@ -401,6 +690,7 @@
            tOrderTaxi.setSubstitute(0);
            tOrderTaxi.setOrderSource(5);
            tOrderTaxi.setIsDelete(1);
            tOrderTaxi.setPayManner(3);
            tOrderTaxiService.insert(tOrderTaxi);
            if(tOrderTaxi.getState() == 1){
                //推送司机抢单