<?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.ruoyi.frequency.highendauth.mapper.HighendAuthMapper">

    <resultMap type="com.ruoyi.frequency.highendauth.entity.HighendAuth" id="HighendAuthResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="amount"    column="amount"    />
        <result property="status"    column="status"    />
        <result property="storeId"    column="store_id"    />
        <result property="isPay"    column="is_pay"    />
        <result property="payOrderNo"    column="pay_order_no"    />
        <result property="idFront"    column="id_front"    />
        <result property="idBack"    column="id_back"    />
        <result property="idHandHand"    column="id_hand_hand"    />
        <result property="name"    column="name"    />
        <result property="idcardNo"    column="idcard_no"    />
        <result property="images"    column="images"    />
        <result property="processTime"    column="process_time"    />
        <result property="wecomQrcode"    column="wecom_qrcode"    />
        <result property="branchWork"    column="branch_work"    />
    </resultMap>

    <sql id="selectHighendAuthVo">
        SELECT
            t.id,
            t.branch_work,
            t.create_by,
            t.create_time,
            t.update_by,
            t.update_time,
            t.del_flag,
            t.amount,
            t.`status`,
            t.store_id,
            t.is_pay,
            t.pay_order_no,
            t.id_front,
            t.id_back,
            t.id_hand_hand,
            t.`name`,
            t.idcard_no,
            t.images,
            t.remark,
            t.pay_status,
            t.pay_type,
            t.ali_business_id,
            t.bank,
            t.subbranch,
            t.bank_card,
            t.speciality_area,
            t.process_time,
            s.wecom_qrcode
        FROM
            t_highend_auth AS t
                LEFT JOIN t_store AS s ON s.id = t.store_id
    </sql>

    <select id="selectHighendAuthList" parameterType="com.ruoyi.frequency.highendauth.entity.HighendAuth" resultMap="HighendAuthResult">
        <include refid="selectHighendAuthVo"/>
        <where> and t.del_flag != 2
            <if test="amount != null "> and t.amount = #{amount}</if>
            <if test="status != null "> and t.status = #{status}</if>
            <if test="storeId != null "> and t.store_id = #{storeId}</if>
            <if test="isPay != null "> and t.is_pay = #{isPay}</if>
            <if test="payOrderNo != null  and payOrderNo != ''"> and t.pay_order_no = #{payOrderNo}</if>
            <if test="idFront != null  and idFront != ''"> and t.id_front = #{idFront}</if>
            <if test="idBack != null  and idBack != ''"> and t.id_back = #{idBack}</if>
            <if test="idHandHand != null  and idHandHand != ''"> and t.id_hand_hand = #{idHandHand}</if>
            <if test="name != null  and name != ''"> and t.name like concat('%', #{name}, '%')</if>
            <if test="idcardNo != null  and idcardNo != ''"> and t.idcard_no like concat('%', #{idcardNo}, '%')</if>
            <if test="images != null  and images != ''"> and t.images = #{images}</if>
            <if test="userInfo != null and userInfo.nickname != null  and userInfo.nickname != '' ">
                and s.nickname like concat('%', #{userInfo.nickname}, '%')
            </if>
            <if test="userInfo != null and  userInfo.mobile != null and  userInfo.mobile != '' ">
                and s.mobile like concat('%', #{userInfo.mobile}, '%')
            </if>
            <if test="beginTime != null ">
                and  t.create_time >= #{beginTime}

            </if>
            <if test="endTime != null ">
                and  t.create_time &lt; #{endTime}
            </if>
        </where>
        order by t.create_time desc
    </select>


    <select id="statistics" parameterType="com.ruoyi.frequency.highendauth.entity.HighendAuth" resultType="com.ruoyi.frequency.highendauth.model.result.HighendAuthCount">
        SELECT (SELECT
        count(1)
        FROM
        t_highend_auth AS t
        LEFT JOIN t_store AS s ON s.id = t.store_id
        where
        t.id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
        ) number ,
        (SELECT
        count(1)
        FROM
        t_highend_auth AS t
        LEFT JOIN t_store AS s ON s.id = t.store_id
        where
        t.id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
        and t.status >=3
        ) passNumber,
        (SELECT
        count(1)
        FROM
        t_highend_auth AS t
        LEFT JOIN t_store AS s ON s.id = t.store_id
        where
        t.id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
        and t.status &lt;=2
        ) noPassNumber,
        (SELECT
        count(1)
        FROM
        t_highend_auth AS t
        where
        t.id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
        and t.status &lt;=2) auditNumber
    </select>

    <select id="selectHighendAuthById" parameterType="Long" resultMap="HighendAuthResult">
        <include refid="selectHighendAuthVo"/>
        where t.id = #{id}
    </select>

    <insert id="insertHighendAuth" parameterType="com.ruoyi.frequency.highendauth.entity.HighendAuth">
        insert into t_highend_auth
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="amount != null">amount,</if>
            <if test="status != null">status,</if>
            <if test="storeId != null">store_id,</if>
            <if test="isPay != null">is_pay,</if>
            <if test="payOrderNo != null">pay_order_no,</if>
            <if test="idFront != null">id_front,</if>
            <if test="idBack != null">id_back,</if>
            <if test="idHandHand != null">id_hand_hand,</if>
            <if test="name != null">name,</if>
            <if test="idcardNo != null">idcard_no,</if>
            <if test="images != null">images,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="amount != null">#{amount},</if>
            <if test="status != null">#{status},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="isPay != null">#{isPay},</if>
            <if test="payOrderNo != null">#{payOrderNo},</if>
            <if test="idFront != null">#{idFront},</if>
            <if test="idBack != null">#{idBack},</if>
            <if test="idHandHand != null">#{idHandHand},</if>
            <if test="name != null">#{name},</if>
            <if test="idcardNo != null">#{idcardNo},</if>
            <if test="images != null">#{images},</if>
         </trim>
    </insert>

    <update id="updateHighendAuth" parameterType="com.ruoyi.frequency.highendauth.entity.HighendAuth">
        update t_highend_auth
        <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="status != null">status = #{status},</if>
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="isPay != null">is_pay = #{isPay},</if>
            <if test="payOrderNo != null">pay_order_no = #{payOrderNo},</if>
            <if test="idFront != null">id_front = #{idFront},</if>
            <if test="idBack != null">id_back = #{idBack},</if>
            <if test="idHandHand != null">id_hand_hand = #{idHandHand},</if>
            <if test="name != null">name = #{name},</if>
            <if test="idcardNo != null">idcard_no = #{idcardNo},</if>
            <if test="images != null">images = #{images},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteHighendAuthById" parameterType="Long">
        delete from t_highend_auth where id = #{id}
    </delete>

    <delete id="deleteHighendAuthByIds" parameterType="String">
        delete from t_highend_auth where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
