From c1937dbb0b30d7d9882070605f8e61c9f99caf55 Mon Sep 17 00:00:00 2001
From: guyue <1721849008@qq.com>
Date: 星期三, 30 七月 2025 20:23:13 +0800
Subject: [PATCH] 我的订单

---
 UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java |  284 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 283 insertions(+), 1 deletions(-)

diff --git a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java
index ce1ca75..a6f588b 100644
--- a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java
+++ b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java
@@ -13,9 +13,12 @@
 import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
 import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
 import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
+import com.stylefeng.guns.modular.system.dao.CarMapper;
 import com.stylefeng.guns.modular.system.dao.SystemPriceMapper;
 import com.stylefeng.guns.modular.system.model.*;
+import com.stylefeng.guns.modular.system.model.vo.TripOrderVo;
 import com.stylefeng.guns.modular.system.model.vo.UnPayOrderVO;
+import com.stylefeng.guns.modular.system.pdf.TripSheetGenerator;
 import com.stylefeng.guns.modular.system.service.*;
 import com.stylefeng.guns.modular.system.util.*;
 import com.stylefeng.guns.modular.system.util.qianyuntong.model.QYTPaymentCallback;
@@ -39,7 +42,9 @@
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.io.PrintWriter;
+import java.io.Serializable;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -129,6 +134,18 @@
     private IUserCouponRecordService userCouponRecordService;
     @Value("${pushMinistryOfTransport}")
     private boolean pushMinistryOfTransport;
+
+
+    @Value("${trip.sheet.filePath}")
+    private  String filePath;
+    @Autowired
+    private EmailUtil emailUtil;
+    @Autowired
+    private  TripSheetGenerator tripSheetGenerator;
+    @Autowired
+    private IServerCarModelService serverCarModelService;
+
+
     
     @Resource
     private SystemPriceMapper systemPriceMapper;
@@ -138,7 +155,8 @@
     
     @Resource
     private ISystemPriceCityService systemPriceCityService;
-    
+
+
     
     /**
      * 获取正在进行中的订单
@@ -458,6 +476,16 @@
                     map = orderCrossCityService.queryOrderInfo(orderId);
                     break;
             }
+
+            if(map.get("companyId") != null){
+                Company companyId = companyService.selectById(map.get("companyId").toString());
+                map.put("companyName", companyId.getName());
+            }else {
+                String string = map.get("driverId").toString();
+                Driver driver = driverService.selectById(string);
+                Company company = companyService.selectById(driver.getCompanyId());
+                map.put("companyName", company.getName());
+            }
             if(map.get("telX") != null){
                 map.put("driverPhone", map.get("telX"));
             }
@@ -590,6 +618,41 @@
                 orderInfoWarpper.setTime(arriveTime.substring(11,arriveTime.length()-3));
             }
             return ResultUtil.success(orderInfoWarpper);
+        }catch (Exception e){
+            e.printStackTrace();
+            return ResultUtil.runErr();
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/api/order/addAppeal")
+    @ApiOperation(value = "发起申诉", tags = {"用户端-服务中"}, notes = "",response = OrderInfoWarpper.class)
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=城际)", name = "orderType", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "申诉描述", name = "abnormalIntro", required = true, dataType = "String"),
+            @ApiImplicitParam(value = "申诉图片", name = "abnormalImg", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResultUtil<OrderInfoWarpper> addAppeal(Integer orderId, Integer orderType,String abnormalIntro, String abnormalImg, HttpServletRequest request){
+        try {
+            Integer uid = userInfoService.getUserIdFormRedis(request);
+            if(null == uid){
+                return ResultUtil.tokenErr();
+            }
+            switch (orderType){
+                case 1://专车
+                     orderPrivateCarService.addAppeal(uid, orderId,abnormalIntro,abnormalImg);
+                    break;
+                case 2://出租车
+                    orderTaxiService.addAppeal(uid,orderId,abnormalIntro,abnormalImg);
+                    break;
+                case 3://跨城
+                     orderCrossCityService.addAppeal(uid,orderId,abnormalIntro,abnormalImg);
+                    break;
+            }
+            return ResultUtil.success();
         }catch (Exception e){
             e.printStackTrace();
             return ResultUtil.runErr();
@@ -2046,6 +2109,30 @@
     }
 
 
+
+    /**
+     * 推广订单支付成功回调
+     *
+     * @param orderId
+     * @return
+     */
+    private void promotion(Integer orderType,Integer orderId){
+        switch (orderType){
+            case 1:
+                orderPrivateCarService.promotion(orderId);
+                break;
+            case 2:
+                orderTaxiService.promotion(orderId);
+                break;
+            case 3:
+                orderCrossCityService.promotion(orderId);
+                break;
+            default:
+                    break;
+        }
+    }
+
+
     @ResponseBody
     @PostMapping("/api/get/unPayOrder")
     @ApiOperation(value = "获取未支付订单", tags = {"用户端-首页"}, notes = "")
@@ -2102,4 +2189,199 @@
         }
     }
 
+    @PostMapping("/api/order/queryMyTripList")
+    @ApiOperation(value = "获取我的行程列表", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=跨城出行)", name = "type", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "页码(首页1)", name = "pageNum", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"),
+            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResultUtil<List<TripOrderVo>> queryMyTripList(Integer type, Integer pageNum, Integer size, HttpServletRequest request){
+        try {
+            Integer uid = userInfoService.getUserIdFormRedis(request);
+            if(null == uid){
+                return ResultUtil.tokenErr();
+            }
+//            List<Map<String, Object>> list = null;
+//            switch (type){
+//                case 1:
+//                    list = orderPrivateCarService.queryMyTripList(uid, pageNum, size);
+//                    break;
+//                case 2:
+//                    list = orderTaxiService.queryMyTripList(uid, pageNum, size);
+//                    break;
+//                case 3:
+//                    list = orderCrossCityService.queryMyTripList(uid, pageNum, size);
+//                    break;
+//
+//            }
+//
+//            // 将经纬度转换为城市并设置到数据中
+//            if (list != null && !list.isEmpty()) {
+//                for (Map<String, Object> orderMap : list) {
+//                    // 获取经纬度(根据实际字段名调整)
+//                    Object lonObj = orderMap.get("boardingLon");
+//                    Object latObj = orderMap.get("boardingLat");
+//                    //获取公司id
+//                    Object companyId = orderMap.get("companyId");
+//
+//                    Object serverCarModelId =null;
+//                    ServerCarModel serverCarModel = null;
+//                    if (type == 1 || type == 3){
+//                        //获取车型id
+//                         serverCarModelId = orderMap.get("serverCarModelId");
+//                         serverCarModel = serverCarModelService.selectById((Serializable) serverCarModelId);
+//                    }
+//
+//                    if (lonObj != null && latObj != null) {
+//                        String lon = lonObj.toString();
+//                        String lat = latObj.toString();
+//                        Company company = companyService.selectById((Serializable) companyId);
+//
+//                        try {
+//                            // 调用逆地理编码接口获取城市信息
+//                            Map<String, String> geoInfo = gdMapGeocodingUtil.geocode(lon, lat);
+//                            // 将城市信息存入map,供后续转换VO使用
+//                            orderMap.put("city", geoInfo.getOrDefault("city", ""));
+//                            orderMap.put("companyName", company.getName());
+//                            if (serverCarModel != null) {
+//                                orderMap.put("serverCarModel", serverCarModel.getName());
+//                            }
+//                        } catch (Exception e) {
+//                            // 记录转换失败日志,不中断流程
+//                            System.err.println("经纬度转城市失败: " + lon + "," + lat + ",错误: " + e.getMessage());
+//                            orderMap.put("city", ""); // 转换失败时设为空
+//                        }
+//                    } else {
+//                        orderMap.put("city", ""); // 经纬度为空时设为空
+//                    }
+//                }
+//            }
+            List<Map<String,Object>> raw = fetchTrips(uid, type, pageNum, size);
+            return ResultUtil.success(TripOrderVo.getTripOrderVo(raw));
+//            return ResultUtil.success(TripOrderVo.getTripOrderVo(list));
+        }catch (Exception e){
+            e.printStackTrace();
+            return ResultUtil.runErr();
+        }
+    }
+    /**
+     * 私有:拉取指定 type 的行程列表。
+     * type=0 → 全部类型;1/2/3 → 对应三种服务;pageNum/size 负责分页。
+     * 对于 type==1 或 3,内部额外加载 serverCarModel 信息。
+     */
+    private List<Map<String,Object>> fetchTrips(
+            Integer uid, Integer type, Integer pageNum, Integer size) throws Exception {
+
+        List<Map<String, Object>> list = new ArrayList<>();
+        if (type == null || type == 0) {
+            list.addAll(orderPrivateCarService.queryMyTripListAll(uid));
+            list.addAll(orderTaxiService.queryMyTripListAll(uid));
+            list.addAll(orderCrossCityService.queryMyTripListAll(uid));
+        } else {
+            switch (type) {
+                case 1:
+                    list = orderPrivateCarService.queryMyTripList(uid, pageNum, size);
+                    break;
+                case 2:
+                    list = orderTaxiService.queryMyTripList(uid, pageNum, size);
+                    break;
+                case 3:
+                    list = orderCrossCityService.queryMyTripList(uid, pageNum, size);
+                    break;
+                default:
+                    throw new IllegalArgumentException("无效的订单类型:" + type);
+            }
+        }
+        // 排序
+        list.sort((a, b) -> {
+            Date da = (Date) a.get("boardingTime");
+            Date db = (Date) b.get("boardingTime");
+            if (da == null && db == null) return 0;
+            if (da == null) return 1;   // a 在后面
+            if (db == null) return -1;  // b 在后面
+            return db.compareTo(da);    // 都不为空,再按时间倒序
+        });
+        // 将经纬度转换为城市并设置到数据中
+        if (list != null && !list.isEmpty()) {
+            for (Map<String, Object> orderMap : list) {
+                // 获取经纬度(根据实际字段名调整)
+                Object lonObj = orderMap.get("boardingLon");
+                Object latObj = orderMap.get("boardingLat");
+                //获取公司id
+                Object companyId = orderMap.get("companyId");
+
+                Object serverCarModelId =null;
+                ServerCarModel serverCarModel = null;
+                if (orderMap.get("serverCarModelId") != null ){
+                    //获取车型id
+                    serverCarModelId = orderMap.get("serverCarModelId");
+                    serverCarModel = serverCarModelService.selectById((Serializable) serverCarModelId);
+                }
+
+                if (lonObj != null && latObj != null) {
+                    String lon = lonObj.toString();
+                    String lat = latObj.toString();
+                    Company company = companyService.selectById((Serializable) companyId);
+
+                    try {
+                        // 调用逆地理编码接口获取城市信息
+                        Map<String, String> geoInfo = gdMapGeocodingUtil.geocode(lon, lat);
+                        // 将城市信息存入map,供后续转换VO使用
+                        orderMap.put("city", geoInfo.getOrDefault("city", ""));
+                        orderMap.put("companyName", company.getName());
+                        if (serverCarModel != null) {
+                            orderMap.put("serverCarModel", serverCarModel.getName());
+                        }
+                    } catch (Exception e) {
+                        // 记录转换失败日志,不中断流程
+                        System.err.println("经纬度转城市失败: " + lon + "," + lat + ",错误: " + e.getMessage());
+                        orderMap.put("city", ""); // 转换失败时设为空
+                    }
+                } else {
+                    orderMap.put("city", ""); // 经纬度为空时设为空
+                }
+            }
+        }
+        return list;
+    }
+    @PostMapping("/api/user/sendTripSheetEmail")
+    @ApiOperation(value = "发送行程单邮件", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "订单列表", name = "orders", required = false, dataType = "List<OrderWarpper>"),
+            @ApiImplicitParam(value = "收件人邮箱", name = "recipientEmail", required = false, dataType = "String"),
+            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResultUtil sendTripSheetEmail( @RequestParam boolean allOrders,
+                                          @RequestBody(required = false) List<TripOrderVo> orders,
+                                          @RequestParam String recipientEmail,
+                                          HttpServletRequest  request) {
+        try {
+            // 从Redis中获取当前用户ID
+            Integer uid = userInfoService.getUserIdFormRedis(request);
+            if (null == uid) {
+                return ResultUtil.tokenErr();
+            }
+            if (allOrders) {
+                // 这里复用 queryMyTripList 逻辑,不分页,type=0 表示全部
+                List<Map<String, Object>> rawList = fetchTrips(uid, 0, null, null);
+                orders = TripOrderVo.getTripOrderVo(rawList);
+            } else {
+                // allOrders=false,需要前端传 orders
+                if (orders == null || orders.isEmpty()) {
+                    return ResultUtil.error("请传入 orders 或者选择全部订单");
+                }
+            }
+            String filePath = tripSheetGenerator.generatePdf(orders);
+            File attachment = new File(filePath);
+            emailUtil.sendEmailWithAttachment(recipientEmail, "行程单", "请查收您的行程单", attachment);
+            attachment.delete(); // 发送成功后删除临时文件
+            return ResultUtil.success("邮件发送成功");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResultUtil.error("邮件发送失败");
+        }
+    }
+
 }

--
Gitblit v1.7.1