无关风月
2025-02-14 8db5d3eafb1cc5352b1bdf2c281c54c7fa80db93
ManagementOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/taxi/TOrderTaxiController.java
@@ -4,6 +4,7 @@
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;
@@ -14,15 +15,13 @@
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 java.io.*;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -102,36 +101,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 +185,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";
    }
@@ -202,27 +269,29 @@
     * @param orderDetailId
     * @return
     */
    public static String URL = "https://yingyan.baidu.com/api/v3/track/gettrack?";
    public static String AK = "WQhfsluNzEeUHUxoH4jc4JiCQOXw4Mnx";
    @ResponseBody
    @RequestMapping(value = "/getOrderTrack", method = RequestMethod.POST)
    public ResultUtil getOrderTrack(String orderDetailId){
        if(ToolUtil.isNotEmpty(orderDetailId)){
            try {
                TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(orderDetailId);
                TDriver tDriver = driverService.selectById(tOrderTaxi.getDriverId());
                SearchHttpAK ta = new SearchHttpAK();
                Map params = new LinkedHashMap<String, String>();
                params.put("ak", AK);
                params.put("entity_name", tDriver.getPhone());
                params.put("service_id", "241187");
                long start = tOrderTaxi.getStartServiceTime().getTime() / 1000L;
                long end = tOrderTaxi.getEndServiceTime().getTime() / 1000L;
                params.put("start_time", start+"");
                params.put("end_time", end+"");
                String s = ta.requestGetAK(URL, params);
                List<TOrderPositionBaiDu> list = JSONArray.parseArray(s.toString(), TOrderPositionBaiDu.class);
//                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();
@@ -380,12 +449,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));
@@ -399,6 +468,7 @@
            tOrderTaxi.setSubstitute(0);
            tOrderTaxi.setOrderSource(5);
            tOrderTaxi.setIsDelete(1);
            tOrderTaxi.setPayManner(3);
            tOrderTaxiService.insert(tOrderTaxi);
            if(tOrderTaxi.getState() == 1){
                //推送司机抢单