<?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.basicData.mapper.TWarehouseWebcamMapper">

    <resultMap type="TWarehouseWebcam" id="TWarehouseWebcamResult">
        <result property="fId" column="f_id"/>
        <result property="projectId" column="project_id"/>
        <result property="deviceName" column="device_name"/>
        <result property="deviceSerial" column="device_serial"/>
        <result property="fWarehouseId" column="f_warehouse_id"/>
        <result property="fWarehouseName" column="f_warehouse_name"/>
        <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="selectTWarehouseWebcamVo">
        select f_id,
               project_id,
               device_name,
               device_serial,
               f_warehouse_id,
               f_warehouse_name,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from t_warehouse_webcam
    </sql>

    <select id="selectTWarehouseWebcamList" parameterType="TWarehouseWebcam" resultMap="TWarehouseWebcamResult">
        <include refid="selectTWarehouseWebcamVo"/>
        <where>
            <if test="projectId != null  and projectId != ''">and project_id = #{projectId}</if>
            <if test="deviceName != null  and deviceName != ''">and device_name like concat('%', #{deviceName}, '%')
            </if>
            <if test="deviceSerial != null  and deviceSerial != ''">and device_serial = #{deviceSerial}</if>
            <if test="fWarehouseId != null ">and f_warehouse_id = #{fWarehouseId}</if>
            <if test="fWarehouseName != null  and fWarehouseName != ''">and f_warehouse_name like concat('%',
                #{fWarehouseName}, '%')
            </if>
        </where>
    </select>

    <select id="selectTWarehouseWebcamById" parameterType="Long" resultMap="TWarehouseWebcamResult">
        <include refid="selectTWarehouseWebcamVo"/>
        where f_id = #{fId}
    </select>

    <select id="selectTWarehouseWebcamByDeviceSerial" parameterType="String" resultMap="TWarehouseWebcamResult">
        <include refid="selectTWarehouseWebcamVo"/>
        where device_serial = #{deviceSerial}
    </select>

    <insert id="insertTWarehouseWebcam" parameterType="TWarehouseWebcam" useGeneratedKeys="true" keyProperty="fId">
        insert into t_warehouse_webcam
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null and projectId != ''">project_id,</if>
            <if test="deviceName != null and deviceName != ''">device_name,</if>
            <if test="deviceSerial != null and deviceSerial != ''">device_serial,</if>
            <if test="fWarehouseId != null">f_warehouse_id,</if>
            <if test="fWarehouseName != null and fWarehouseName != ''">f_warehouse_name,</if>
            <if test="delFlag != null">del_flag,</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="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null and projectId != ''">#{projectId},</if>
            <if test="deviceName != null and deviceName != ''">#{deviceName},</if>
            <if test="deviceSerial != null and deviceSerial != ''">#{deviceSerial},</if>
            <if test="fWarehouseId != null">#{fWarehouseId},</if>
            <if test="fWarehouseName != null and fWarehouseName != ''">#{fWarehouseName},</if>
            <if test="delFlag != null">#{delFlag},</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="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTWarehouseWebcam" parameterType="TWarehouseWebcam">
        update t_warehouse_webcam
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null and projectId != ''">project_id = #{projectId},</if>
            <if test="deviceName != null and deviceName != ''">device_name = #{deviceName},</if>
            <if test="deviceSerial != null and deviceSerial != ''">device_serial = #{deviceSerial},</if>
            <if test="fWarehouseId != null">f_warehouse_id = #{fWarehouseId},</if>
            <if test="fWarehouseName != null and fWarehouseName != ''">f_warehouse_name = #{fWarehouseName},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <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="remark != null">remark = #{remark},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <delete id="deleteTWarehouseWebcamById" parameterType="Long">
        delete
        from t_warehouse_webcam
        where f_id = #{fId}
    </delete>

    <delete id="deleteTWarehouseWebcamByIds" parameterType="String">
        delete from t_warehouse_webcam where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>


    <select id="appGetWarehouseList" resultType="map">
        SELECT
        f_id AS fId,
        f_name AS fName
        FROM t_warehouse
        WHERE parent_id = 100
        <if test="corpId != null and corpId != ''">
            AND f_id IN (SELECT DISTINCT f_warehouseid FROM t_whgenleg WHERE f_corpid = #{corpId})
        </if>

    </select>
    <select id="selectAppTWarehouseWebcamList" resultMap="TWarehouseWebcamResult">
        <include refid="selectTWarehouseWebcamVo"/>
        <where>
            <if test="fWarehouseId != null ">and f_warehouse_id = #{fWarehouseId}</if>
            <if test="external != null and external != ''">
                and f_warehouse_id in (
                    select distinct f_warehouseid
                    from t_customer_contact t1 left join t_whgenleg t2 on t1.f_pid = t2.f_corpid
                    where f_tel = #{external})
            </if>
        </where>
    </select>
</mapper>
