<?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="org.jeecg.modules.system.app.mapper.InsureOrderInfoMapper">
    <update id="updateBatch">
        update   nm_insure_order_info a
        INNER  join  nm_order b  on a.order_id =b.id and b.pay_time is not null
        INNER  join  nm_family_members c on  a.family_members_id = c.id
        SET a.is_enter_system =#{findInsureOrderPageRequestDTO.updateIsEnterSystem}
        where 1=1
        <if test="findInsureOrderPageRequestDTO.id != null and findInsureOrderPageRequestDTO.id  != ''">
            AND a.id = #{findInsureOrderPageRequestDTO.id}
        </if>
        <if test="findInsureOrderPageRequestDTO.bdOrderNo != null and findInsureOrderPageRequestDTO.bdOrderNo != ''">
            AND a.bd_order_no = #{findInsureOrderPageRequestDTO.bdOrderNo}
        </if>
        <if test="findInsureOrderPageRequestDTO.insureName != null and findInsureOrderPageRequestDTO.insureName != ''">
            AND a.insure_name = #{findInsureOrderPageRequestDTO.insureName}
        </if>
        <if test="findInsureOrderPageRequestDTO.fullName != null and findInsureOrderPageRequestDTO.fullName != ''">
            AND c.full_name = #{findInsureOrderPageRequestDTO.fullName}
        </if>
        <if test="findInsureOrderPageRequestDTO.identityCard != null and findInsureOrderPageRequestDTO.identityCard != ''">
            AND c.identity_card = #{findInsureOrderPageRequestDTO.identityCard}
        </if>
        <if test="findInsureOrderPageRequestDTO.phone != null and findInsureOrderPageRequestDTO.phone != ''">
            AND c.phone = #{findInsureOrderPageRequestDTO.phone}
        </if>
        <if test="findInsureOrderPageRequestDTO.isEnterSystem != null">
            AND a.is_enter_system = #{findInsureOrderPageRequestDTO.isEnterSystem}
        </if>

        <if test="findInsureOrderPageRequestDTO.endTime!=null  and findInsureOrderPageRequestDTO.endTime!=''">
            <![CDATA[   AND DATE_FORMAT(b.pay_time, '%Y-%m-%d')<=  DATE_FORMAT(#{findInsureOrderPageRequestDTO.endTime}, '%Y-%m-%d') ]]>
        </if>
        <if test="findInsureOrderPageRequestDTO.startTime!=null  and findInsureOrderPageRequestDTO.startTime!=''">
            <![CDATA[   AND DATE_FORMAT(b.pay_time, '%Y-%m-%d')>=  DATE_FORMAT(#{findInsureOrderPageRequestDTO.startTime}, '%Y-%m-%d') ]]>
        </if>
    </update>


    <select id="findPage"
            resultType="org.jeecg.modules.system.app.dto.insureOrder.FindInsureOrderPageResponseDTO">
        select  a.id,a.bd_order_no,a.insure_name,a.insure_company,a.is_enter_system ,
                a.assert_start_time,a.assert_end_time,c.full_name,c.identity_card,c.phone,b.pay_time
        from
        nm_insure_order_info a
        left join  nm_order b  on a.order_id =b.id and b.pay_time is not null
        left join  nm_family_members c on  a.family_members_id = c.id
        where 1=1
        <if test="findInsureOrderPageRequestDTO.bdOrderNo != null and findInsureOrderPageRequestDTO.bdOrderNo != ''">
            AND a.bd_order_no = #{findInsureOrderPageRequestDTO.bdOrderNo}
        </if>
        <if test="findInsureOrderPageRequestDTO.insureName != null and findInsureOrderPageRequestDTO.insureName != ''">
            AND a.insure_name = #{findInsureOrderPageRequestDTO.insureName}
        </if>
        <if test="findInsureOrderPageRequestDTO.fullName != null and findInsureOrderPageRequestDTO.fullName != ''">
            AND c.full_name = #{findInsureOrderPageRequestDTO.fullName}
        </if>
        <if test="findInsureOrderPageRequestDTO.identityCard != null and findInsureOrderPageRequestDTO.identityCard != ''">
            AND c.identity_card = #{findInsureOrderPageRequestDTO.identityCard}
        </if>
        <if test="findInsureOrderPageRequestDTO.phone != null and findInsureOrderPageRequestDTO.phone != ''">
            AND c.phone = #{findInsureOrderPageRequestDTO.phone}
        </if>
        <if test="findInsureOrderPageRequestDTO.isEnterSystem != null">
            AND a.is_enter_system = #{findInsureOrderPageRequestDTO.isEnterSystem}
        </if>

        <if test="findInsureOrderPageRequestDTO.endTime!=null  and findInsureOrderPageRequestDTO.endTime!=''">
            <![CDATA[   AND DATE_FORMAT(b.pay_time, '%Y-%m-%d')<=  DATE_FORMAT(#{findInsureOrderPageRequestDTO.endTime}, '%Y-%m-%d') ]]>
        </if>
        <if test="findInsureOrderPageRequestDTO.startTime!=null  and findInsureOrderPageRequestDTO.startTime!=''">
            <![CDATA[   AND DATE_FORMAT(b.pay_time, '%Y-%m-%d')>=  DATE_FORMAT(#{findInsureOrderPageRequestDTO.startTime}, '%Y-%m-%d') ]]>
        </if>
        order by b.pay_time desc
    </select>
    <select id="findByList"
            resultType="org.jeecg.modules.system.app.dto.insureOrder.FindInsureOrderPageResponseDTO">
        select  a.id,a.bd_order_no,a.insure_name,a.insure_company,a.is_enter_system ,
        a.assert_start_time,a.assert_end_time,c.full_name,c.identity_card,c.phone,b.pay_time
        from
        nm_insure_order_info a
        left join  nm_order b  on a.order_id =b.id and b.pay_time is not null
        left join  nm_family_members c on  a.family_members_id = c.id
        where 1=1
        <if test="findInsureOrderPageRequestDTO.bdOrderNo != null and findInsureOrderPageRequestDTO.bdOrderNo != ''">
            AND a.bd_order_no = #{findInsureOrderPageRequestDTO.bdOrderNo}
        </if>
        <if test="findInsureOrderPageRequestDTO.id != null and findInsureOrderPageRequestDTO.id != ''">
            AND a.id = #{findInsureOrderPageRequestDTO.id}
        </if>
        <if test="findInsureOrderPageRequestDTO.insureName != null and findInsureOrderPageRequestDTO.insureName != ''">
            AND a.insure_name = #{findInsureOrderPageRequestDTO.insureName}
        </if>
        <if test="findInsureOrderPageRequestDTO.fullName != null and findInsureOrderPageRequestDTO.fullName != ''">
            AND c.full_name = #{findInsureOrderPageRequestDTO.fullName}
        </if>
        <if test="findInsureOrderPageRequestDTO.identityCard != null and findInsureOrderPageRequestDTO.identityCard != ''">
            AND c.identity_card = #{findInsureOrderPageRequestDTO.identityCard}
        </if>
        <if test="findInsureOrderPageRequestDTO.phone != null and findInsureOrderPageRequestDTO.phone != ''">
            AND c.phone = #{findInsureOrderPageRequestDTO.phone}
        </if>
        <if test="findInsureOrderPageRequestDTO.isEnterSystem != null">
            AND a.is_enter_system = #{findInsureOrderPageRequestDTO.isEnterSystem}
        </if>

        <if test="findInsureOrderPageRequestDTO.endTime!=null  and findInsureOrderPageRequestDTO.endTime!=''">
            <![CDATA[   AND DATE_FORMAT(b.pay_time, '%Y-%m-%d')<=  DATE_FORMAT(#{findInsureOrderPageRequestDTO.endTime}, '%Y-%m-%d') ]]>
        </if>
        <if test="findInsureOrderPageRequestDTO.startTime!=null  and findInsureOrderPageRequestDTO.startTime!=''">
            <![CDATA[   AND DATE_FORMAT(b.pay_time, '%Y-%m-%d')>=  DATE_FORMAT(#{findInsureOrderPageRequestDTO.startTime}, '%Y-%m-%d') ]]>
        </if>
    </select>
</mapper>