<?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.sf.system.deployment.mapper.DeploymentWhitelistInfoMapper">
    
    <resultMap type="DeploymentWhitelistInfo" id="DeploymentWhitelistInfoResult">
        <result property="id"    column="id"    />
        <result property="appId"    column="app_id"    />
        <result property="appCode"    column="app_code"    />
        <result property="whitelistName"    column="whitelist_name"    />
        <result property="whitelistType"    column="whitelist_type"    />
        <result property="whitelistMode"    column="whitelist_mode"    />
        <result property="status"    column="status"    />
        <result property="remarks"    column="remarks"    />
        <result property="orderNum"    column="order_num"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="created"    column="created"    />
        <result property="modified"    column="modified"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <resultMap id="DeploymentWhitelistInfoDeploymentWhitelistListResult" type="DeploymentWhitelistInfo" extends="DeploymentWhitelistInfoResult">
        <collection property="deploymentWhitelistListList" notNullColumn="sub_id" javaType="java.util.List" resultMap="DeploymentWhitelistListResult" />
    </resultMap>

    <resultMap type="DeploymentWhitelistList" id="DeploymentWhitelistListResult">
        <result property="id"    column="sub_id"    />
        <result property="whitelistId"    column="sub_whitelist_id"    />
        <result property="appId"    column="sub_app_id"    />
        <result property="appCode"    column="sub_app_code"    />
        <result property="user"    column="sub_user_id"    />
        <result property="remarks"    column="sub_remarks"    />
        <result property="orderNum"    column="sub_order_num"    />
        <result property="isDelete"    column="sub_is_delete"    />
        <result property="created"    column="sub_created"    />
        <result property="modified"    column="sub_modified"    />
        <result property="createTime"    column="sub_create_time"    />
        <result property="updateTime"    column="sub_update_time"    />
    </resultMap>

    <sql id="selectDeploymentWhitelistInfoVo">
        select id, app_id, app_code, whitelist_name, whitelist_type, whitelist_mode, status, remarks, order_num, is_delete, created, modified, create_time, update_time from DEPLOYMENT_WHITELIST_INFO
    </sql>

    <select id="selectDeploymentWhitelistInfoList" parameterType="DeploymentWhitelistInfo" resultMap="DeploymentWhitelistInfoResult">
        <include refid="selectDeploymentWhitelistInfoVo"/>
        <where>  
            <if test="appCode != null  and appCode != ''"> and app_code = #{appCode}</if>
            <if test="whitelistName != null  and whitelistName != ''"> and whitelist_name like concat('%', #{whitelistName}, '%')</if>
            <if test="whitelistType != null "> and whitelist_type = #{whitelistType}</if>
            <if test="whitelistMode != null "> and whitelist_mode = #{whitelistMode}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="beginTime != null">and create_time <![CDATA[>]]> #{beginTime}</if>
            <if test="endTime != null">and create_time <![CDATA[<]]> #{endTime}</if>
        </where>
    </select>
    
    <select id="selectDeploymentWhitelistInfoById" parameterType="Long" resultMap="DeploymentWhitelistInfoDeploymentWhitelistListResult">
        select a.id, a.app_id, a.app_code, a.whitelist_name, a.whitelist_type, a.whitelist_mode, a.status, a.remarks, a.order_num, a.is_delete, a.created, a.modified, a.create_time, a.update_time,
 b.id as sub_id, b.whitelist_id as sub_whitelist_id, b.app_id as sub_app_id, b.app_code as sub_app_code, b.user as sub_user, b.remarks as sub_remarks, b.order_num as sub_order_num, b.is_delete as sub_is_delete, b.created as sub_created, b.modified as sub_modified, b.create_time as sub_create_time, b.update_time as sub_update_time
        from DEPLOYMENT_WHITELIST_INFO a
        left join DEPLOYMENT_WHITELIST_LIST b on b.whitelist_id = a.id
        where a.id = #{id}
    </select>
        
    <insert id="insertDeploymentWhitelistInfo" parameterType="DeploymentWhitelistInfo" useGeneratedKeys="true" keyProperty="id">
        insert into DEPLOYMENT_WHITELIST_INFO
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appId != null">app_id,</if>
            <if test="appCode != null">app_code,</if>
            <if test="whitelistName != null and whitelistName != ''">whitelist_name,</if>
            <if test="whitelistType != null">whitelist_type,</if>
            <if test="whitelistMode != null">whitelist_mode,</if>
            <if test="status != null">status,</if>
            <if test="remarks != null">remarks,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="created != null">created,</if>
            <if test="modified != null">modified,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appId != null">#{appId},</if>
            <if test="appCode != null">#{appCode},</if>
            <if test="whitelistName != null and whitelistName != ''">#{whitelistName},</if>
            <if test="whitelistType != null">#{whitelistType},</if>
            <if test="whitelistMode != null">#{whitelistMode},</if>
            <if test="status != null">#{status},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="created != null">#{created},</if>
            <if test="modified != null">#{modified},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>


    <update id="updateDeploymentWhitelistInfo" parameterType="DeploymentWhitelistInfo">
        update DEPLOYMENT_WHITELIST_INFO
        <trim prefix="SET" suffixOverrides=",">
            <if test="appId != null">app_id = #{appId},</if>
            <if test="appCode != null">app_code = #{appCode},</if>
            <if test="whitelistName != null and whitelistName != ''">whitelist_name = #{whitelistName},</if>
            <if test="whitelistType != null">whitelist_type = #{whitelistType},</if>
            <if test="whitelistMode != null">whitelist_mode = #{whitelistMode},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="created != null">created = #{created},</if>
            <if test="modified != null">modified = #{modified},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDeploymentWhitelistInfoById" parameterType="Long">
        delete from DEPLOYMENT_WHITELIST_INFO where id = #{id}
    </delete>

    <delete id="deleteDeploymentWhitelistInfoByIds" parameterType="String">
        delete from DEPLOYMENT_WHITELIST_INFO where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
    <delete id="deleteDeploymentWhitelistListByWhitelistIds" parameterType="String">
        delete from DEPLOYMENT_WHITELIST_LIST where whitelist_id in 
        <foreach item="whitelistId" collection="array" open="(" separator="," close=")">
            #{whitelistId}
        </foreach>
    </delete>

    <delete id="deleteDeploymentWhitelistListByWhitelistId" parameterType="Long">
        delete from DEPLOYMENT_WHITELIST_LIST where whitelist_id = #{whitelistId}
    </delete>

    <insert id="batchDeploymentWhitelistList">
        insert into DEPLOYMENT_WHITELIST_LIST( id, whitelist_id, app_id, app_code, user, remarks, order_num, is_delete, created, modified, create_time, update_time) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.id}, #{item.whitelistId}, #{item.appId}, #{item.appCode}, #{item.user}, #{item.remarks}, #{item.orderNum}, #{item.isDelete}, #{item.created}, #{item.modified}, #{item.createTime}, #{item.updateTime})
        </foreach>
    </insert>
</mapper>