package com.hai.dao;

import com.hai.model.OilCardOrderModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * mapper扩展类
 */
public interface HighFleetOilCardMapperExt {

    @Select("<script>" +
            " SELECT" +
            " (select org_name from high_oil_card oc where oc.card_no = b.mem_card_no) orgName," +
            " b.mem_phone merPhone," +
            " a.gas_car_license_plate carLicensePlate," +
            " b.order_no orderNo," +
            " a.gas_order_no gasOrderNo," +
            " b.pay_type payType," +
            " CASE" +
            " b.pay_type " +
            " WHEN 1 THEN '支付' " +
            " WHEN 2 THEN '微信'" +
            " WHEN 3 THEN '金币'" +
            " WHEN 4 THEN '汇联通'" +
            " WHEN 5 THEN '银联'" +
            " WHEN 6 THEN '银联分期'" +
            " WHEN 7 THEN '嗨森逛油卡'" +
            " ELSE '未知' " +
            " END payTypeName," +
            " b.mem_card_no memCardNo," +
            " b.total_price totalPrice," +
            " b.deduction_price deductionPrice," +
            " b.pay_real_price payRealPrice," +
            " a.goods_name goodsName," +
            " a.gas_oil_no gasOilNo," +
            " a.gas_gun_no gasGunNo," +
            " a.gas_price_gun gasPriceGun," +
            " a.ext_1 platformPriceGun," +
            " b.order_status status," +
            " CASE" +
            " b.order_status " +
            " WHEN 1 THEN '待支付' " +
            " WHEN 2 THEN '已支付'" +
            " WHEN 3 THEN '已完成'" +
            " WHEN 4 THEN '已退款'" +
            " WHEN 5 THEN '已取消'" +
            " WHEN 6 THEN '退款中'" +
            " WHEN 6 THEN '退款失败'" +
            " ELSE '未知' " +
            " END statusName," +
            " b.create_time createTime," +
            " b.pay_time payTime," +
            " b.refund_time refundTime" +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id " +
            " AND a.goods_type = 3 " +
            " AND b.order_status in (2,3,4,6,7) " +
            " <if test='param.memPhone != null'> AND b.mem_phone like concat('%',#{param.memPhone},'%') </if>" +
            " <if test='param.carLicensePlate != null'> AND a.gas_car_license_plate like concat('%',#{param.carLicensePlate},'%') </if>" +
            " <if test='param.cardNo != null'> AND b.mem_card_no like concat('%',#{param.cardNo},'%') </if>" +
            " <if test='param.goodsName != null'> AND b.goods_name like concat('%',#{param.goodsName},'%') </if>" +
            " <if test='param.payTimeS != null'> <![CDATA[ AND b.pay_time >= #{param.payTimeS} ]]> </if> " +
            " <if test='param.payTimeE != null'> <![CDATA[ AND b.pay_time <= #{param.payTimeE} ]]> </if> " +
            " <if test='param.status != null'> and b.order_status = #{param.status} </if> " +
            " AND EXISTS (select 1 from high_fleet_oil_card c where c.company_id = #{param.companyId} " +
            " <if test='param.orgId != null'> and c.org_id = #{param.orgId} </if> " +
            " and b.mem_card_no = c.card_no)" +
            " ORDER BY" +
            " b.pay_time DESC" +
            "</script>")
    List<OilCardOrderModel> selectOilCardOrderList(@Param(value = "param") Map<String, Object> param);
}