package com.yc.ship.module.trade.service.orderjzdetail;

import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.IdUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.util.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.ship.framework.common.exception.ErrorCode;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.framework.security.core.LoginUser;
import com.yc.ship.framework.tenant.core.aop.TenantIgnore;
import com.yc.ship.module.trade.controller.admin.orderjzdetail.vo.OrderJzDetailPageReqVO;
import com.yc.ship.module.trade.controller.admin.orderjzdetail.vo.OrderJzDetailSaveReqVO;
import com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO;
import com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO;
import com.yc.ship.module.trade.dal.dataobject.orderjz.OrderJzDO;
import com.yc.ship.module.trade.dal.dataobject.orderjzdetail.OrderJzDetailDO;
import com.yc.ship.module.trade.dal.mysql.order.TradeOrderMapper;
import com.yc.ship.module.trade.dal.mysql.order.TradeVisitorMapper;
import com.yc.ship.module.trade.dal.mysql.orderjz.OrderJzMapper;
import com.yc.ship.module.trade.dal.mysql.orderjzdetail.OrderJzDetailMapper;
import com.yc.ship.module.trade.framework.common.Base64Util;
import com.yc.ship.module.trade.framework.common.ota.DesUtil;
import com.yc.ship.module.trade.utils.MD5Utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.yc.ship.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;

/**
 * 订单接站人员名单 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
@Slf4j
public class OrderJzDetailServiceImpl implements OrderJzDetailService {

    @Resource
    private TradeOrderMapper tradeOrderMapper;

    @Resource
    private OrderJzMapper orderJzMapper;

    @Resource
    private OrderJzDetailMapper orderJzDetailMapper;

    @Resource
    private TradeVisitorMapper tradeVisitorMapper;

    @Override
    public Long createOrderJzDetail(OrderJzDetailSaveReqVO createReqVO) {
        // 插入
        OrderJzDetailDO orderJzDetail = BeanUtils.toBean(createReqVO, OrderJzDetailDO.class);
        orderJzDetail.setTenantId(1L);
        orderJzDetail.setIdCard(createReqVO.getIdCard());
        orderJzDetailMapper.insert(orderJzDetail);
        // 返回
        return orderJzDetail.getId();
    }


    @Override
    @TenantIgnore
    public void validateAndFillVisitorId(List<OrderJzDetailSaveReqVO> createReqVOList) {
        if (createReqVOList == null || createReqVOList.isEmpty()) {
            return;
        }
        String oid = createReqVOList.get(0).getOid();
        if (oid == null || oid.isEmpty()) {
            throw exception(new ErrorCode(10006, "未查询到相关订单"));
        }
        // 查询订单下所有游客信息
        List<TradeVisitorDO> visitorList = tradeVisitorMapper.selectListByOrderId(Long.valueOf(oid));
        if (visitorList == null || visitorList.isEmpty()) {
            throw exception(new ErrorCode(10005, "未查询到该订单的游客信息"));
        }
        // 遍历传入的接站明细，按姓名匹配游客，校验身份证号
        for (OrderJzDetailSaveReqVO reqVO : createReqVOList) {
            if (reqVO.getIdCard() == null || reqVO.getName() == null) {
                continue;
            }
            // 按姓名匹配游客
            TradeVisitorDO matchedVisitor = visitorList.stream()
                    .filter(v -> reqVO.getName().equals(v.getName()))
                    .findFirst().orElse(null);
            if (matchedVisitor == null) {
                throw exception(new ErrorCode(10007, "未找到匹配的游客"));
                //continue;
            }
            // 校验身份证号是否一致（匹配到游客时）
            if (matchedVisitor.getCredentialNo() != null
                    && !matchedVisitor.getCredentialNo().trim().equalsIgnoreCase(reqVO.getIdCard().trim())) {
                throw exception(new ErrorCode(10003, "游客【" + reqVO.getName() + "】身份证效验不通过"));
            }
            // 校验通过，填充 visitorId
            reqVO.setVisitorId(matchedVisitor.getId());
        }
    }

    @Override
    @TenantIgnore
    public Long createOrderJzDetail(List<OrderJzDetailSaveReqVO> createReqVOList) {
        if (createReqVOList == null || createReqVOList.isEmpty()) {
            return 0L;
        }
        String oid = createReqVOList.get(0).getOid();
        if (oid == null || oid.isEmpty()) {
            throw new RuntimeException("未查询到相关订单");
        }
        TradeOrderDO orderDo = tradeOrderMapper.selectOne(new LambdaQueryWrapper<TradeOrderDO>().eq(TradeOrderDO::getId, oid));
        if (orderDo == null) {
            throw new RuntimeException("未查询到相关订单");
        }
        // 根据订单编号查询jz编号
        OrderJzDO orderJzDO = orderJzMapper.selectOne(new LambdaQueryWrapper<OrderJzDO>().eq(OrderJzDO::getOrderId, oid));
        if (orderJzDO == null) {
            orderJzDO = new OrderJzDO();
            orderJzDO.setId(IdUtil.getSnowflake(0, 0).nextId());
            orderJzDO.setIsJz(1);
            orderJzDO.setJzAddress("");
            orderJzDO.setJzLinkName("");
            orderJzDO.setJzLinkPhone("");
            orderJzDO.setOrderId(orderDo.getId());
            orderJzDO.setCreateTime(LocalDateTime.now());
            orderJzDO.setTenantId(orderDo.getTenantId());
            orderJzDO.setDeleted(false);
            orderJzMapper.insert(orderJzDO);
        }
        long count = 0;
        String batchNo = IdUtil.getSnowflake(0, 0).nextIdStr();
        // 先删除当前传入游客的历史接站数据
        for (OrderJzDetailSaveReqVO orderJzDetailSaveReqVO : createReqVOList) {
            orderJzDetailMapper.delete(new LambdaQueryWrapper<OrderJzDetailDO>().eq(OrderJzDetailDO::getVisitorId, orderJzDetailSaveReqVO.getVisitorId()));
        }
        //处理三方系统退票
        for (OrderJzDetailSaveReqVO orderJzDetailSaveReqVO : createReqVOList) {
            orderJzDetailSaveReqVO.setBatchNo(batchNo);
            orderJzDetailSaveReqVO.setJzId(orderJzDO.getId());
            createOrderJzDetail(orderJzDetailSaveReqVO);
            count++;
        }

        return count;
    }


    @Override
    public void sendJz(List<Map<String, Object>> list, Long jzId) {
        try {
            List<Long> visitorIds = list.stream().map(item -> MapUtils.getLong(item, "visitorId")).collect(Collectors.toList());
            cancelSupplierJz(visitorIds, jzId);
            //处理三方系统出票 二期接站
            String supplierOrderId = createSupplierJz(list);
            paySupplierJz(supplierOrderId, jzId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private String createSupplierJz(List<Map<String, Object>> createReqVOList) throws Exception {
        Long id = null;
        String productId = "2034198456717037761";
        String method = "createOrder";
        String createOrderUrl = "http://10.3.10.50/app-api/travelhub-ops-trade/trade/ota/zshl/212/" + method;
        String userId = "67fd6a5e6a2a453a98f288b08d571234";
        String userKey = "TFD9BEOK";
        String bookname = "";
        String mobile = "";
        String idcard = "";
        String useDate = "";
        for (Map<String, Object> orderJzDetailSaveReqVO : createReqVOList) {
            id = MapUtils.getLong(orderJzDetailSaveReqVO, "jz_id");
            mobile = MapUtils.getString(orderJzDetailSaveReqVO, "phone");
            idcard = MapUtils.getString(orderJzDetailSaveReqVO, "id_card");
            useDate = MapUtils.getString(orderJzDetailSaveReqVO, "use_date");
        }
        JSONObject rep_body = new JSONObject();
        rep_body.put("orderId", id);
        rep_body.put("travelDate", useDate);
        rep_body.put("travelTime", "");
        rep_body.put("quantity", createReqVOList.size());
        rep_body.put("productId", productId);
        rep_body.put("bookName", bookname);
        rep_body.put("bookMobile", mobile);
        rep_body.put("idCard", idcard);

        JSONArray vistorList = new JSONArray();
        for (Map<String, Object> tradeVisitorDO : createReqVOList) {
            JSONObject vistor = new JSONObject();
            vistor.put("name", MapUtils.getString(tradeVisitorDO, "name"));
            vistor.put("mobile", MapUtils.getString(tradeVisitorDO, "phone"));
            String idCard = MapUtils.getString(tradeVisitorDO, "id_card");
            vistor.put("idCard", idCard);
            if (idCard.length() != 18) {
                vistor.put("idType", "1");
            }

            vistor.put("face", "");
            vistorList.add(vistor);
        }
        rep_body.put("visitPersons", vistorList);
        String bodyStr = DesUtil.encrypt(rep_body.toString(), userKey);
        Long timestamp = System.currentTimeMillis() / 1000;
        String signStr = userId + method + timestamp + bodyStr + userKey;
        log.info("三峡二期系统预下单开始,signStr:{}", signStr);
        String sign = MD5Utils.getMD5(signStr.getBytes(StandardCharsets.UTF_8));

        JSONObject rep_head = new JSONObject();
        rep_head.put("user_id", userId);
        rep_head.put("method", method);
        rep_head.put("timestamp", timestamp);
        rep_head.put("sign", sign);

        JSONObject req = new JSONObject();
        req.put("requestHead", rep_head);
        req.put("requestBody", bodyStr);
        Map<String, String> headMap = new HashMap<>();
        headMap.put("Content-type", "application/x-www-form-urlencoded");
        log.info("二期预下单开始,请求地址:{},请求参数:{}", createOrderUrl, req.toString());
        String res = HttpUtil.createPost(createOrderUrl).contentType("application/json")
                .body(Base64Util.encode(req.toString()))
                .headerMap(headMap, false)
                .timeout(100000)
                .execute().body();
        log.info("二期系统预下单完成,响应参数:{}", res);
        // base64解密
        String result = Base64Decoder.decodeStr(res);
        log.info("二期系统预下单完成,响应response参数:{}", result);
        JSONObject jsonObj = JSONUtil.parseObj(result);
        JSONObject responseHead = jsonObj.getJSONObject("responseHead");
        if (StringUtils.equals("1000", responseHead.getStr("res_code"))) {
            String response = jsonObj.getStr("responseBody");
            String body = "";
            try {
                body = DesUtil.decrypt(response, userKey);
            } catch (Exception e) {
                log.info(e.toString());
            }
            log.error("二期下单完成,响应body参数:{}", body);
            JSONObject responseBody = JSONUtil.parseObj(body);
            return responseBody.getStr("orderId");
        } else {
            log.error("二期下单失败,响应response参数:{}", res);
        }
        return null;
    }


    private void paySupplierJz(String supplierOrderId, Long jzId) throws Exception {
        String method = "payOrder";
        String createOrderUrl = "http://10.3.10.50/app-api/travelhub-ops-trade/trade/ota/zshl/212/" + method;
        String userId = "67fd6a5e6a2a453a98f288b08d571234";
        String userKey = "TFD9BEOK";
        JSONObject rep_body = new JSONObject();
        rep_body.put("orderId", supplierOrderId);
        rep_body.put("partnerOrderId", jzId);

        String bodyStr = DesUtil.encrypt(rep_body.toString(), userKey);
        Long timestamp = System.currentTimeMillis() / 1000;
        String signStr = userId + method + timestamp + bodyStr + userKey;
        log.info("二期订单支付开始,signStr:{}", signStr);
        String sign = MD5Utils.getMD5(signStr.getBytes("UTF-8"));

        JSONObject rep_head = new JSONObject();
        rep_head.put("user_id", userId);
        rep_head.put("method", method);
        rep_head.put("timestamp", timestamp);
        rep_head.put("sign", sign);

        JSONObject req = new JSONObject();
        req.put("requestHead", rep_head);
        req.put("requestBody", bodyStr);
        Map<String, String> headMap = new HashMap<>();
        headMap.put("Content-type", "application/x-www-form-urlencoded");
        log.info("二期预支付开始,请求地址:{},请求参数:{}", createOrderUrl, req.toString());
        String res = HttpUtil.createPost(createOrderUrl).contentType("application/json")
                .body(Base64Util.encode(req.toString()))
                .headerMap(headMap, false)
                .timeout(100000)
                .execute().body();
        log.info("二期系统支付完成,响应参数:{}", res);
        // base64解密
        String json = new String(org.apache.commons.codec.binary.Base64.decodeBase64(res.getBytes("UTF-8")));
        log.info("二期系统支付完成,响应response参数:{}", json);
        JSONObject jsonObj = JSONUtil.parseObj(json);
        JSONObject responseHead = jsonObj.getJSONObject("responseHead");
        if (StringUtils.equals("1000", responseHead.getStr("res_code"))) {
            String response = jsonObj.getStr("responseBody");
            String body = "";
            try {
                body = DesUtil.decrypt(response, userKey);
            } catch (Exception e) {
                log.info(e.toString());
            }
            log.error("二期支付完成,响应body参数:{}", body);
            JSONObject responseBody = JSONUtil.parseObj(body);
            JSONArray vistors = responseBody.getJSONArray("visitPersons");
            for (int i = 0; i < vistors.size(); i++) {
                JSONObject vistor = vistors.getJSONObject(i);
                String idCard = vistor.getStr("idCard");
                String ticketId = vistor.getStr("ticketId");
                orderJzDetailMapper.update(new UpdateWrapper<OrderJzDetailDO>().set("extend_order_no", supplierOrderId).set("extend_ticket_no", ticketId).eq("jz_id", jzId).eq("id_card", idCard));
            }
        } else {
            log.error("二期支付失败,响应response参数:{}", json);
        }
    }

    private void cancelSupplierJz(List<Long> visitorIds, Long jzId) {
        String method = "cancelTicket";
        String createOrderUrl = "http://10.3.10.50/app-api/travelhub-ops-trade/trade/ota/zshl/212/" + method;
        String userId = "67fd6a5e6a2a453a98f288b08d571234";
        String userKey = "TFD9BEOK";
        List<OrderJzDetailDO> jzDetailList = orderJzDetailMapper.selectList(new QueryWrapper<OrderJzDetailDO>().in("visitor_id", visitorIds));
        Map<String, List<OrderJzDetailDO>> groupList = jzDetailList.stream().filter(item -> StringUtils.isNotBlank(item.getExtendOrderNo())).collect(Collectors.groupingBy(OrderJzDetailDO::getExtendOrderNo));
        if (groupList.isEmpty()) {
            log.error("无可退二期票信息" + jzId);
            return;
        }
        groupList.forEach((supplierOrderId, list) -> {
            try {
                JSONObject rep_body = new JSONObject();
                rep_body.put("orderId", supplierOrderId);
                rep_body.put("partnerOrderId", jzId);
                List<String> ticketIds = new ArrayList<>();
                for (OrderJzDetailDO item : list) {
                    ticketIds.add(item.getExtendTicketNo());
                }
                rep_body.set("refundDetailIds", ticketIds);
                String bodyStr = DesUtil.encrypt(rep_body.toString(), userKey);
                Long timestamp = System.currentTimeMillis() / 1000;
                String signStr = userId + method + timestamp + bodyStr + userKey;
                log.info("二期系统退票开始,signStr:{}", signStr);
                String sign = MD5Utils.getMD5(signStr.getBytes("UTF-8"));

                JSONObject rep_head = new JSONObject();
                rep_head.put("user_id", userId);
                rep_head.put("method", method);
                rep_head.put("timestamp", timestamp);
                rep_head.put("sign", sign);

                JSONObject req = new JSONObject();
                req.put("requestHead", rep_head);
                req.put("requestBody", bodyStr);
                Map<String, String> headMap = new HashMap<>();
                headMap.put("Content-type", "application/x-www-form-urlencoded");
                log.info("二期系统退票开始,请求地址:{},请求参数:{}", createOrderUrl, req.toString());
                String res = HttpUtil.createPost(createOrderUrl).contentType("application/json")
                        .body(Base64Util.encode(req.toString()))
                        .headerMap(headMap, false)
                        .timeout(100000)
                        .execute().body();
                log.info("二期系统退票完成,响应参数:{}", res);
                // base64解密
                String json = new String(org.apache.commons.codec.binary.Base64.decodeBase64(res.getBytes("UTF-8")));
                log.info("二期系统退票完成,响应response参数:{}", json);
                JSONObject jsonObj = JSONUtil.parseObj(json);
                JSONObject responseHead = jsonObj.getJSONObject("responseHead");
                if (StringUtils.equals("1000", responseHead.getStr("res_code"))) {
                    String response = jsonObj.getStr("responseBody");
                    String body = "";
                    try {
                        body = DesUtil.decrypt(response, userKey);
                    } catch (Exception e) {
                        log.info(e.toString());
                    }
                    log.error("二期系统退票完成,响应body参数:{}", body);
                } else {
                    log.error("二期系统退票失败,响应response参数:{}", json);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });


    }


    @Override
    public void updateOrderJzDetail(OrderJzDetailSaveReqVO updateReqVO) {
        // 校验存在
        validateOrderJzDetailExists(updateReqVO.getId());
        // 更新
        OrderJzDetailDO updateObj = BeanUtils.toBean(updateReqVO, OrderJzDetailDO.class);
        orderJzDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteOrderJzDetail(Long id) {
        // 校验存在
        validateOrderJzDetailExists(id);
        // 删除
        orderJzDetailMapper.deleteById(id);
    }

    private void validateOrderJzDetailExists(Long id) {
        if (orderJzDetailMapper.selectById(id) == null) {
            throw exception(500, "不存在");
        }
    }

    @Override
    public OrderJzDetailDO getOrderJzDetail(Long id) {
        return orderJzDetailMapper.selectById(id);
    }

    @Override
    public PageResult<OrderJzDetailDO> getOrderJzDetailPage(OrderJzDetailPageReqVO pageReqVO) {
        return orderJzDetailMapper.selectPage(pageReqVO);
    }

    @Override
    public List<OrderJzDetailDO> selectPageByVoyageId(String voyageId) {
        return orderJzDetailMapper.selectPageByVoyageId(voyageId);
    }

    @Override
    public List<OrderJzDetailDO> getOrderJzDetailList(OrderJzDetailPageReqVO pageReqVO) {
        String oid = pageReqVO.getOid();
        // 根据订单编号查询jz编号
        OrderJzDO orderJzDO = orderJzMapper.selectOne(new LambdaQueryWrapper<OrderJzDO>().eq(OrderJzDO::getOrderId, oid));
        if (orderJzDO == null) {
            return new ArrayList<>();
        }
        pageReqVO.setJzId(orderJzDO.getId());
        return orderJzDetailMapper.selectList(pageReqVO);
    }

    @Override
    public Long cleanOrderJzDetail(String id) {
        return orderJzDetailMapper.cleanSign(id);
    }

    @Override
    public Long signOrderJzDetail(OrderJzDetailSaveReqVO createReqVO) {
        OrderJzDetailDO detail = getOrderJzDetail(createReqVO.getId());
        // 如果ID为空，则为补登游客，按订单来查询
        if (detail == null) {
            // 查询是否有接站头表
            List<OrderJzDO> orderJzDOList = orderJzMapper.selectList(new LambdaQueryWrapper<OrderJzDO>().eq(OrderJzDO::getOrderId, createReqVO.getOid()));
            OrderJzDO orderJzDO = null;
            if (orderJzDOList == null || orderJzDOList.size() == 0) { // 创建一条
                TradeOrderDO orderDo = tradeOrderMapper.selectById(createReqVO.getOid());
                if (orderDo == null) {
                    throw new RuntimeException("未查询到相关订单");
                }
                orderJzDO = new OrderJzDO();
                orderJzDO.setId(IdUtil.getSnowflake(0, 0).nextId());
                orderJzDO.setIsJz(1);
                orderJzDO.setJzAddress("");
                orderJzDO.setJzLinkName("");
                orderJzDO.setJzLinkPhone("");
                orderJzDO.setOrderId(Long.valueOf(createReqVO.getOid()));
                orderJzMapper.insert(orderJzDO);
            } else {
                orderJzDO = orderJzDOList.get(0);
            }
            detail = new OrderJzDetailDO();
            detail.setJzId(orderJzDO.getId());
            detail.setBatchNo(IdUtil.getSnowflake(0, 0).nextIdStr());
            detail.setArriveTime(createReqVO.getArriveTime());
            detail.setAddress(createReqVO.getAddress());
            detail.setName(createReqVO.getName());
            detail.setIdCard(createReqVO.getIdCard());
            detail.setPhone(createReqVO.getPhone());
            detail.setRemark("接站补登");
            detail.setStatus(1);
        }
        detail.setSignTime(DateUtils.format(new Date(), DatePattern.NORM_DATETIME_PATTERN));
        // 当前登录人
        LoginUser loginUser = getLoginUser();
        detail.setSignMan(MapUtils.getString(loginUser.getInfo(), LoginUser.INFO_KEY_NICKNAME));
        detail.setSignRemark(createReqVO.getSignRemark());
        detail.setSignImage(createReqVO.getSignImage());

        if (detail.getId() == null) {
            orderJzDetailMapper.insert(detail);
        } else {
            orderJzDetailMapper.updateById(detail);
        }
        return detail.getId();
    }

    @Override
    public int batchSignOrderJzDetail(List<Long> ids, String signRemark) {
        if (ids == null || ids.isEmpty()) {
            return 0;
        }
        // 批量查询
        List<OrderJzDetailDO> detailList = orderJzDetailMapper.selectBatchIds(ids);
        if (detailList == null || detailList.isEmpty()) {
            return 0;
        }

        // 检查已核销的人员，收集名称用于提示
        List<String> alreadySignedNames = detailList.stream()
                .filter(d -> StringUtils.isNotBlank(d.getSignTime()))
                .map(OrderJzDetailDO::getName)
                .collect(Collectors.toList());
        if (!alreadySignedNames.isEmpty()) {
            throw new RuntimeException("以下游客已核销，请勿重复核销：" + String.join("、", alreadySignedNames));
        }

        // 获取当前登录人信息
        LoginUser loginUser = getLoginUser();
        String signMan = MapUtils.getString(loginUser.getInfo(), LoginUser.INFO_KEY_NICKNAME);
        String signTime = DateUtils.format(new Date(), DatePattern.NORM_DATETIME_PATTERN);

        int count = 0;
        for (OrderJzDetailDO detail : detailList) {
            detail.setSignTime(signTime);
            detail.setSignMan(signMan);
            detail.setSignRemark(signRemark);
            orderJzDetailMapper.updateById(detail);
            count++;
        }
        return count;
    }

    @Override
    public PageResult<OrderJzDetailDO> getOrderJzDetailPage2(OrderJzDetailPageReqVO pageReqVO) {
        IPage<OrderJzDetailDO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
        IPage<OrderJzDetailDO> iPage = orderJzDetailMapper.selectPage2(page, pageReqVO);
        return new PageResult<>(iPage.getRecords(), iPage.getTotal());
    }


    @Override
    public PageResult<?> getOrderJzDetailPage3(OrderJzDetailPageReqVO pageReqVO) {
        IPage<Map> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
        IPage<?> iPage = orderJzDetailMapper.selectPage3(page, pageReqVO);
        return new PageResult<>(iPage.getRecords(), iPage.getTotal());
    }

    @Override
    public List<OrderJzDetailDO> getVisitorExportList(OrderJzDetailPageReqVO pageReqVO) {
        return orderJzDetailMapper.selectVisitorExportList(pageReqVO);
    }

    // ==================== 赠送行程接站相关 ====================

    @Override
    public PageResult<OrderJzDetailDO> getGiftPage(OrderJzDetailPageReqVO pageReqVO) {
        IPage<OrderJzDetailDO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
        IPage<OrderJzDetailDO> iPage = orderJzDetailMapper.selectGiftPage(page, pageReqVO);
        return new PageResult<>(iPage.getRecords(), iPage.getTotal());
    }

    @Override
    public List<OrderJzDetailDO> getGiftExportList(OrderJzDetailPageReqVO pageReqVO) {
        return orderJzDetailMapper.selectGiftExportList(pageReqVO);
    }

    @Override
    public PageResult<?> getGiftOrderPage(OrderJzDetailPageReqVO pageReqVO) {
        IPage<Map> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
        IPage<?> iPage = orderJzDetailMapper.selectGiftOrderPage(page, pageReqVO);
        return new PageResult<>(iPage.getRecords(), iPage.getTotal());
    }


}