<?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.web.modules.hub.mapper.BizDataSendRecordMapper">

    <resultMap type="com.ruoyi.web.modules.hub.domain.BizDataSendRecord" id="BizDataSendRecordResult">
        <id     property="id"               column="id"/>
        <result property="sendTime"         column="send_time"/>
        <result property="sendContent"      column="send_content"/>
        <result property="receiverName"     column="receiver_name"/>
        <result property="receiverAddress"  column="receiver_address"/>
        <result property="delFlag"          column="del_flag"/>
        <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="remark"           column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select id, send_time, send_content, receiver_name, receiver_address, del_flag,
               create_by, create_time, update_by, update_time, remark
        from biz_data_send_record
    </sql>

    <select id="selectBizDataSendRecordById" parameterType="long" resultMap="BizDataSendRecordResult">
        <include refid="selectVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="selectBizDataSendRecordByIdAny" parameterType="long" resultMap="BizDataSendRecordResult">
        <include refid="selectVo"/>
        where id = #{id}
    </select>

    <select id="selectBizDataSendRecordList" parameterType="com.ruoyi.web.modules.hub.domain.BizDataSendRecord" resultMap="BizDataSendRecordResult">
        <include refid="selectVo"/>
        <where>
            del_flag = '0'
            <if test="startDate != null and startDate != ''">
                and date(send_time) &gt;= #{startDate}
            </if>
            <if test="endDate != null and endDate != ''">
                and date(send_time) &lt;= #{endDate}
            </if>
            <if test="receiverName != null and receiverName != ''">
                and lower(receiver_name) = lower(#{receiverName})
            </if>
        </where>
        order by send_time desc, id desc
    </select>

    <insert id="insertBizDataSendRecord" parameterType="com.ruoyi.web.modules.hub.domain.BizDataSendRecord" useGeneratedKeys="true" keyProperty="id">
        insert into biz_data_send_record (
            send_time, send_content, receiver_name, receiver_address, del_flag,
            create_by, create_time, remark
        ) values (
            #{sendTime}, #{sendContent}, #{receiverName}, #{receiverAddress}, #{delFlag},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizDataSendRecord" parameterType="com.ruoyi.web.modules.hub.domain.BizDataSendRecord">
        update biz_data_send_record set
            send_time = #{sendTime},
            send_content = #{sendContent},
            receiver_name = #{receiverName},
            receiver_address = #{receiverAddress},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id} and del_flag = '0'
    </update>

    <update id="logicDeleteBizDataSendRecordByIds">
        update biz_data_send_record set del_flag = '2', update_by = #{updateBy}, update_time = sysdate()
        where del_flag = '0' and id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
