<?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.yanzhu.jh.video.mapper.DevAiProjectConfigMapper">
    
    <resultMap type="DevAiProjectConfig" id="DevAiProjectConfigResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="projectName"    column="projectName"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="ipcName"    column="ipc_name"    />
        <result property="deviceName"    column="device_name"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="manufacturer"    column="manufacturer"    />
        <result property="isDel"    column="is_del"    />
        <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>

    <resultMap id="DevAiProjectConfigDevAiProjectConfigPassageResult" type="DevAiProjectConfig" extends="DevAiProjectConfigResult">
        <collection property="devAiProjectConfigPassageList" notNullColumn="sub_id" javaType="java.util.List" resultMap="DevAiProjectConfigPassageResult" />
    </resultMap>

    <resultMap type="DevAiProjectConfigPassage" id="DevAiProjectConfigPassageResult">
        <result property="id"    column="sub_id"    />
        <result property="passageValue"    column="sub_passage_value"    />
        <result property="aiboxId"    column="sub_aibox_id"    />
        <result property="channelId"    column="sub_channel_id"    />
        <result property="channelName"    column="sub_channel_name"    />
        <result property="isImportance"    column="sub_is_importance"    />
        <result property="passageType"    column="sub_passage_type"    />
        <result property="isDel"    column="sub_is_del"    />
    </resultMap>

    <sql id="selectDevAiProjectConfigVo">
        select dapc.id, dapc.project_id, sp.projectName, dapc.dept_id, sd.dept_name, dapc.ipc_name, dapc.device_name, dapc.serial_number, dapc.manufacturer, dapc.is_del, dapc.create_by, dapc.create_time, dapc.update_by, dapc.update_time, dapc.remark from dev_ai_project_config dapc
        left join sur_project sp on sp.id=dapc.project_id
        left join sys_dept sd on sd.dept_id=dapc.dept_id
    </sql>

    <select id="selectDevAiProjectConfigList" parameterType="DevAiProjectConfig" resultMap="DevAiProjectConfigResult">
        <include refid="selectDevAiProjectConfigVo"/>
        <where>  
            <if test="projectId != null "> and dapc.project_id like concat('%', #{projectId}, '%')</if>
            <if test="projectName != null  and projectName != ''"> and sp.projectName like concat('%', #{projectName}, '%')</if>
            <if test="deptId != null "> and dapc.dept_id like concat('%', #{deptId}, '%')</if>
            <if test="deptName != null  and deptName != ''"> and sd.dept_name like concat('%', #{deptName}, '%')</if>
            <if test="ipcName != null  and ipcName != ''"> and dapc.ipc_name like concat('%', #{ipcName}, '%')</if>
            <if test="deviceName != null  and deviceName != ''"> and (dapc.device_name like concat('%', #{deviceName}, '%') or dapc.serial_number like concat('%', #{deviceName}, '%'))</if>
            <if test="serialNumber != null  and serialNumber != ''"> and dapc.serial_number = #{serialNumber}</if>
            <if test="manufacturer != null  and manufacturer != ''"> and dapc.manufacturer like concat('%', #{manufacturer}, '%')</if>
            <if test="isDel != null  and isDel != ''"> and dapc.is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectDevAiProjectConfigById" parameterType="Long" resultMap="DevAiProjectConfigDevAiProjectConfigPassageResult">
        select a.id, a.project_id, sp.projectName, a.dept_id, sd.dept_name, a.ipc_name, a.device_name, a.serial_number, a.manufacturer, a.is_del, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
 b.id as sub_id, spvp.passage_value as sub_passage_value, b.aibox_id as sub_aibox_id, b.channel_id as sub_channel_id, b.channel_name as sub_channel_name, b.is_importance as sub_is_importance, b.passage_type as sub_passage_type, b.is_del as sub_is_del
        from dev_ai_project_config a
        left join sur_project sp on sp.id=a.project_id
        left join sys_dept sd on sd.dept_id=a.dept_id
        left join dev_ai_project_config_passage b on b.aibox_id = a.id
        left join sur_project_video_passage spvp on b.video_passage_id = spvp.id
        where a.id = #{id}
    </select>
        
    <insert id="insertDevAiProjectConfig" parameterType="DevAiProjectConfig" useGeneratedKeys="true" keyProperty="id">
        insert into dev_ai_project_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="ipcName != null">ipc_name,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="serialNumber != null">serial_number,</if>
            <if test="manufacturer != null">manufacturer,</if>
            <if test="isDel != null">is_del,</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">#{projectId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="ipcName != null">#{ipcName},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="serialNumber != null">#{serialNumber},</if>
            <if test="manufacturer != null">#{manufacturer},</if>
            <if test="isDel != null">#{isDel},</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="updateDevAiProjectConfig" parameterType="DevAiProjectConfig">
        update dev_ai_project_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="ipcName != null">ipc_name = #{ipcName},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="serialNumber != null">serial_number = #{serialNumber},</if>
            <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="isDel != null">is_del = #{isDel},</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 id = #{id}
    </update>

    <delete id="deleteDevAiProjectConfigById" parameterType="Long">
        delete from dev_ai_project_config where id = #{id}
    </delete>

    <delete id="deleteDevAiProjectConfigByIds" parameterType="String">
        delete from dev_ai_project_config where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
    <delete id="deleteDevAiProjectConfigPassageByAiboxIds" parameterType="String">
        delete from dev_ai_project_config_passage where aibox_id in 
        <foreach item="aiboxId" collection="array" open="(" separator="," close=")">
            #{aiboxId}
        </foreach>
    </delete>

    <delete id="deleteDevAiProjectConfigPassageByAiboxId" parameterType="Long">
        delete from dev_ai_project_config_passage where aibox_id = #{aiboxId}
    </delete>

    <insert id="batchDevAiProjectConfigPassage">
        insert into dev_ai_project_config_passage( id, video_passage_id, aibox_id, channel_id, channel_name, is_importance, passage_type, is_del) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.id}, #{item.videoPassageId}, #{item.aiboxId}, #{item.channelId}, #{item.channelName}, #{item.isImportance}, #{item.passageType}, #{item.isDel})
        </foreach>
    </insert>
</mapper>