package com.hai.dao;

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

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

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

    @Select("<script>" +
            " select " +
            " a.id storeId," +
            " a.region_id regionId," +
            " a.region_name regionName," +
            " a.store_logo storeLogo," +
            " a.store_key storeKey," +
            " a.store_name storeName," +
            " a.address," +
            " b.id tyAgentOilStationId," +
            " b.organization_id organizationId, " +
            " b.organization_name organizationName, " +
            " b.ty_agent_id tyAgentId," +
            " b.ty_agent_name tyAgentName," +
            " b.ty_salesman_id tySalesmanId," +
            " b.ty_salesman_name tySalesmanName," +
            " b.oil_station_id oilStationId," +
            " b.oil_station_name oilStationName" +
            " from high_merchant_store a" +
            " LEFT JOIN high_ty_agent_oil_station b on a.id = b.oil_station_id and b.`status` = 1" +
            " where a.type = 1 and a.`status` = 1" +
            " <if test='param.regionId != null'> and a.region_id = #{param.regionId} </if>" +
            " <if test='param.regionName != null'> and a.region_name like concat('%',#{param.regionName},'%') </if>" +
            " <if test='param.storeName != null'> and a.store_name like concat('%',#{param.storeName},'%') </if>" +
            " <if test='param.isAssignOrgId != null and param.isAssignOrgId == true'> and b.organization_id is not null </if>" +
            " <if test='param.isAssignOrgId != null and param.isAssignOrgId == false'> and b.organization_id is null </if>" +
            " <if test='param.organizationId != null'> and b.organization_id = #{param.organizationId} </if>" +
            " <if test='param.organizationName != null'> and b.organization_name = #{param.organizationName} </if>" +
            " <if test='param.isAssignTyAgent != null and param.isAssignTyAgent == true'> and b.ty_agent_id is not null </if>" +
            " <if test='param.isAssignTyAgent != null and param.isAssignTyAgent == false'> and b.ty_agent_id is null </if>" +
            " <if test='param.tyAgentId != null'> and b.ty_agent_id = #{param.tyAgentId} </if>" +
            " <if test='param.tyAgentName != null'> and a.ty_agent_name like concat('%',#{param.tyAgentName},'%') </if>" +
            " <if test='param.isAssignTySalesman != null and param.isAssignTySalesman == true'> and b.ty_salesman_id is not null </if>" +
            " <if test='param.isAssignTySalesman != null and param.isAssignTySalesman == false'> and b.ty_salesman_id is null </if>" +
            " <if test='param.tySalesmanId != null'> and b.ty_salesman_id = #{param.tySalesmanId} </if>" +
            " <if test='param.tySalesmanName != null'> and a.ty_salesman_name like concat('%',#{param.tySalesmanName},'%') </if>" +
            " ORDER BY a.id desc" +
            "</script>")
    List<TyAgentOilStationModel> queryOilStationList(@Param("param") Map<String, Object> param);

    @Select("<script>" +
            " SELECT" +
            " b.mem_phone memPhone," +
            " b.order_no orderNo," +
            " a.gas_order_no gasOrderNo," +
            " 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 payType," +
            " 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.ext_1 platformPrice," +
            " a.gas_price_gun gasPriceGun," +
            " b.create_time createTime," +
            " b.pay_time payTime, " +
            " b.order_status orderStatus, " +
            " b.refund_time refundTime, " +
            " a.gas_org_name orgName, " +
            " a.gas_agent_name agentName, " +
            " a.gas_salesman_name salesmanName " +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id " +
            " AND a.goods_type = 3 " +
            " <if test='param.companyId != null'> AND a.gas_org_id in (select id from bs_organization WHERE company_id = #{param.companyId} and `status` = 1) </if>  " +
            " <if test='param.orgId != null'> AND a.gas_org_id = #{param.orgId} </if> " +
            " <if test='param.agentId != null'> AND a.gas_agent_id = #{param.agentId} </if>  " +
            " <if test='param.salesmanId != null'> AND a.gas_salesman_id = #{param.salesmanId} </if> " +
            " <if test='param.goodsName != null'> AND a.goods_name like concat('%',#{param.goodsName},'%') </if>  " +
            " <if test='param.orderNo != null'> AND b.order_no like concat('%',#{param.orderNo},'%') </if>  " +
            " <if test='param.orgName != null'> AND a.gas_org_name like concat('%',#{param.orgName},'%') </if>  " +
            " <if test='param.agentName != null'> AND a.gas_agent_name like concat('%',#{param.agentName},'%') </if>  " +
            " <if test='param.salesmanName != null'> AND a.gas_salesman_name like concat('%',#{param.salesmanName},'%') </if>  " +
            " <if test='param.memPhone != null'> AND b.mem_phone like concat('%',#{param.memPhone},'%') </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.orderStatus != null'>  AND b.order_status = #{param.orderStatus} </if> " +
            " AND a.child_orde_status IN ( 2, 3 ) " +
            " ORDER BY" +
            " b.pay_time DESC" +
            " </script>")
    List<TyOrderModel> getOrderList(@Param("param") Map<String, Object> param);
}
