<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.xxfc.platform.order.mapper.OrderPersonInsuranceMapper">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xxfc.platform.order.entity.OrderPersonInsurance" id="orderPersonInsuranceMap">
        <result property="id" column="id"/>
        <result property="orderId" column="order_id"/>
        <result property="name" column="name"/>
        <result property="idCard" column="id_card"/>
        <result property="orderDay" column="order_day"/>
        <result property="insuranceDay" column="insurance_day"/>
        <result property="amount" column="amount"/>
        <result property="status" column="status"/>
        <result property="crtTime" column="crt_time"/>
        <result property="crtUser" column="crt_user"/>
        <result property="updTime" column="upd_time"/>
        <result property="updUser" column="upd_user"/>
    </resultMap>

    <select id="selectOrderInfo" resultType="com.xxfc.platform.order.pojo.personinsurance.BgPageVO">
        select distinct bo.no, bo.insure_pic

        <include refid="commonFromWhere"></include>

        order by
            bo.no desc
    </select>

    <select id="selectInsuranceInfo" resultType="com.xxfc.platform.order.entity.OrderPersonInsurance">
        select opi.*

        <include refid="commonFromWhere"></include>

        order by
            bo.no desc
    </select>

    <sql id="commonFromWhere">
        from order_person_insurance opi
        left join base_order bo on opi.order_id = bo.id
        <where>
            and bo.has_pay = 1
            <if test="keyWord != null">
                and (
                opi.id_card like concat('%',#{keyWord},'%') or opi.name like concat('%',#{keyWord},'%')
                )
            </if>
            <if test="price != null">
                and opi.amount = #{price}
            </if>
            <if test="status != null">
                and opi.status = #{status}
            </if>
            <if test="orderStartTime != null">
                and opi.pay_time &gt;= #{orderStartTime}
            </if>
            <if test="orderEndTime != null">
                and bo.pay_time &lt;= #{orderEndTime}
            </if>
            <if test="refundStartTime != null">
                and opi.refund_time &gt;= #{refundStartTime}
            </if>
            <if test="refundEndTime != null">
                and bo.refund_time &lt;= #{refundEndTime}
            </if>
        </where>
    </sql>

</mapper>