<?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.video.mapper.BizLivestockMonitorMapper">

    <resultMap type="com.ruoyi.web.modules.video.domain.BizLivestockMonitor" id="BizLivestockMonitorResult">
        <id     property="id"               column="id"/>
        <result property="monitorName"      column="monitor_name"/>
        <result property="ownerType"        column="owner_type"/>
        <result property="ownerId"          column="owner_id"/>
        <result property="ownerName"        column="owner_name"/>
        <result property="installLocation"  column="install_location"/>
        <result property="ipAddress"        column="ip_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"/>
    </resultMap>

    <sql id="selectVo">
        select id, monitor_name, owner_type, owner_id, owner_name, install_location, ip_address, del_flag,
               create_by, create_time, update_by, update_time
        from biz_livestock_monitor
    </sql>

    <sql id="selectListVo">
        select id, monitor_name, owner_type, owner_id, owner_name, install_location, del_flag,
               create_by, create_time, update_by, update_time
        from biz_livestock_monitor
    </sql>

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

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

    <select id="selectBizLivestockMonitorList" parameterType="com.ruoyi.web.modules.video.domain.BizLivestockMonitor" resultMap="BizLivestockMonitorResult">
        <include refid="selectListVo"/>
        <where>
            del_flag = '0'
            <if test="monitorName != null and monitorName != ''">
                and monitor_name like concat('%', #{monitorName}, '%')
            </if>
            <if test="ownerType != null and ownerId != null">
                and owner_type = #{ownerType}
                and owner_id = #{ownerId}
            </if>
        </where>
        order by create_time desc, id desc
    </select>

    <insert id="insertBizLivestockMonitor" parameterType="com.ruoyi.web.modules.video.domain.BizLivestockMonitor" useGeneratedKeys="true" keyProperty="id">
        insert into biz_livestock_monitor (
            monitor_name, owner_type, owner_id, owner_name, install_location, ip_address, del_flag,
            create_by, create_time
        ) values (
            #{monitorName}, #{ownerType}, #{ownerId}, #{ownerName}, #{installLocation}, #{ipAddress}, #{delFlag},
            #{createBy}, sysdate()
        )
    </insert>

    <update id="updateBizLivestockMonitor" parameterType="com.ruoyi.web.modules.video.domain.BizLivestockMonitor">
        update biz_livestock_monitor set
            monitor_name = #{monitorName},
            owner_type = #{ownerType},
            owner_id = #{ownerId},
            owner_name = #{ownerName},
            install_location = #{installLocation},
            ip_address = #{ipAddress},
            update_by = #{updateBy},
            update_time = sysdate()
        where id = #{id} and del_flag = '0'
    </update>

    <update id="logicDeleteBizLivestockMonitorByIds">
        update biz_livestock_monitor 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>
