<?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.zongzhi.mapper.TcDataSourceMapper">
    
    <resultMap type="TcDataSource" id="TcDataSourceResult">
        <result property="id"    column="id"    />
        <result property="areaId"    column="area_id"    />
        <result property="type"    column="type"    />
        <result property="assetName"    column="asset_name"    />
        <result property="affUnit"    column="aff_unit"    />
        <result property="affGroups"    column="aff_groups"    />
        <result property="systeamName"    column="systeam_name"    />
        <result property="url"    column="url"    />
        <result property="ipAddress"    column="ip_address"    />
        <result property="os"    column="os"    />
        <result property="versions"    column="versions"    />
        <result property="isFocus"    column="is_focus"    />
        <result property="level"    column="level"    />
        <result property="createId"    column="create_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateId"    column="update_id"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="isStatus"    column="is_status"    />
    </resultMap>

    <sql id="selectTcDataSourceVo">
        select id, area_id, type,is_status, asset_name, aff_unit, aff_groups, systeam_name, url, ip_address, os, versions, is_focus, level, create_id, create_by, create_time, update_id, update_by, update_time, remark from tc_data_source
    </sql>

    <select id="selectTcDataSourceList" parameterType="TcDataSource" resultMap="TcDataSourceResult">
        <include refid="selectTcDataSourceVo"/>
        <where>
            <if test="areaId != null ">and area_id = #{areaId}</if>
            <if test="notTypeList != null and notTypeList.size() > 0">
                and type NOT IN
                <foreach item="item" collection="notTypeList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="type != null ">and type = #{type}</if>
            <if test="assetName != null  and assetName != ''">and asset_name like concat('%', #{assetName}, '%')</if>
            <if test="affUnit != null  and affUnit != ''">and aff_unit = #{affUnit}</if>
            <if test="affGroups != null  and affGroups != ''">and aff_groups = #{affGroups}</if>
            <if test="systeamName != null  and systeamName != ''">and systeam_name like concat('%', #{systeamName},
                '%')
            </if>
            <if test="url != null  and url != ''">and url = #{url}</if>
            <if test="ipAddress != null  and ipAddress != ''">and ip_address = #{ipAddress}</if>
            <if test="os != null ">and os = #{os}</if>
            <if test="versions != null  and versions != ''">and versions = #{versions}</if>
            <if test="isFocus != null ">and is_focus = #{isFocus}</if>
            <if test="level != null ">and level = #{level}</if>
            <if test="createId != null ">and create_id = #{createId}</if>
            <if test="updateId != null ">and update_id = #{updateId}</if>
            <if test="isStatus != null "> and is_status = #{isStatus}</if>
        </where>
    </select>
    
    <select id="selectTcDataSourceById" parameterType="Long" resultMap="TcDataSourceResult">
        <include refid="selectTcDataSourceVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTcDataSource" parameterType="TcDataSource" useGeneratedKeys="true" keyProperty="id">
        insert into tc_data_source
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaId != null">area_id,</if>
            <if test="type != null">type,</if>
            <if test="assetName != null">asset_name,</if>
            <if test="affUnit != null">aff_unit,</if>
            <if test="affGroups != null">aff_groups,</if>
            <if test="systeamName != null">systeam_name,</if>
            <if test="url != null">url,</if>
            <if test="ipAddress != null">ip_address,</if>
            <if test="os != null">os,</if>
            <if test="versions != null">versions,</if>
            <if test="isFocus != null">is_focus,</if>
            <if test="level != null">level,</if>
            <if test="createId != null">create_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="isStatus != null">is_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaId != null">#{areaId},</if>
            <if test="type != null">#{type},</if>
            <if test="assetName != null">#{assetName},</if>
            <if test="affUnit != null">#{affUnit},</if>
            <if test="affGroups != null">#{affGroups},</if>
            <if test="systeamName != null">#{systeamName},</if>
            <if test="url != null">#{url},</if>
            <if test="ipAddress != null">#{ipAddress},</if>
            <if test="os != null">#{os},</if>
            <if test="versions != null">#{versions},</if>
            <if test="isFocus != null">#{isFocus},</if>
            <if test="level != null">#{level},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isStatus != null">#{isStatus},</if>
         </trim>
    </insert>

    <update id="updateTcDataSource" parameterType="TcDataSource">
        update tc_data_source
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="assetName != null">asset_name = #{assetName},</if>
            <if test="affUnit != null">aff_unit = #{affUnit},</if>
            <if test="affGroups != null">aff_groups = #{affGroups},</if>
            <if test="systeamName != null">systeam_name = #{systeamName},</if>
            <if test="url != null">url = #{url},</if>
            <if test="ipAddress != null">ip_address = #{ipAddress},</if>
            <if test="os != null">os = #{os},</if>
            <if test="versions != null">versions = #{versions},</if>
            <if test="isFocus != null">is_focus = #{isFocus},</if>
            <if test="level != null">level = #{level},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateId != null">update_id = #{updateId},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isStatus != null">is_status=#{isStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTcDataSourceById" parameterType="Long">
        delete from tc_data_source where id = #{id}
    </delete>

    <delete id="deleteTcDataSourceByIds" parameterType="String">
        delete from tc_data_source where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>