<?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.hw.ems.base.mapper.SysDatasourceMapper">

    <resultMap type="SysDatasource" id="SysDatasourceResult">
        <result property="id"    column="id"    />
        <result property="url"    column="url"    />
        <result property="userName"    column="user_name"    />
        <result property="password"    column="password"    />
        <result property="driveClassName"    column="drive_class_name"    />
        <result property="poolName"    column="pool_name"    />
        <result property="status"    column="status"    />
        <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"    />
        <result property="cbsParkCode"    column="cbs_park_code"    />
        <result property="cbsParkName"    column="cbs_park_name"    />
    </resultMap>

    <sql id="selectSysDatasourceVo">
        select id, url, user_name, password, drive_class_name, pool_name, status, del_flag, create_by, create_time, update_by, update_time, remark, cbs_park_code, cbs_park_name from sys_datasource
    </sql>

    <select id="selectSysDatasourceList" parameterType="SysDatasource" resultMap="SysDatasourceResult">
        <include refid="selectSysDatasourceVo"/>
        <where>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="driveClassName != null  and driveClassName != ''"> and drive_class_name like concat('%', #{driveClassName}, '%')</if>
            <if test="poolName != null  and poolName != ''"> and pool_name like concat('%', #{poolName}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="cbsParkCode != null  and cbsParkCode != ''"> and cbs_park_code = #{cbsParkCode}</if>
        </where>
    </select>

    <select id="selectSysDatasourceById" parameterType="String" resultMap="SysDatasourceResult">
        <include refid="selectSysDatasourceVo"/>
        where id = #{id}
    </select>
    <select id="selectSysDatasourceByPoolName" resultType="com.hw.ems.base.domain.SysDatasource">
        select id, url, user_name, password, drive_class_name,
               pool_name, status, del_flag, create_by, create_time,
               update_by, update_time, remark, cbs_park_code, cbs_park_name
        from sys_datasource
        where pool_name = #{poolName}
    </select>
    <select id="selectSysDatasourceByCbsParkCode" resultMap="SysDatasourceResult">
        select id, url, user_name, password, drive_class_name,
               pool_name, status, del_flag, create_by, create_time,
               update_by, update_time, remark, cbs_park_code, cbs_park_name
        from sys_datasource
        where cbs_park_code = #{cbsParkCode}
    </select>
    <select id="selectSysDatasource" resultType="SysDatasource">
        SELECT
			id,
			url,
			user_name AS userName,
			password,
			drive_class_name AS driveClassName,
			pool_name AS poolName,
			park_name AS parkName,
			status,
			del_flag AS delFlag,
			create_by AS createBy,
			create_time AS createTime,
			update_by AS updateBy,
			update_time AS updateTime,
			remark,
            cbs_park_code AS cbsParkCode,
            cbs_park_name AS cbsParkName
		FROM sys_datasource
		where del_flag = '0' and status = 0
    </select>

    <insert id="insertSysDatasource" parameterType="SysDatasource">
        insert into sys_datasource
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="url != null and url != ''">url,</if>
            <if test="userName != null and userName != ''">user_name,</if>
            <if test="password != null and password != ''">password,</if>
            <if test="driveClassName != null and driveClassName != ''">drive_class_name,</if>
            <if test="poolName != null and poolName != ''">pool_name,</if>
            <if test="status != null">status,</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>
            <if test="cbsParkCode != null and cbsParkCode != ''">cbs_park_code,</if>
            <if test="cbsParkName != null and cbsParkName != ''">cbs_park_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="url != null and url != ''">#{url},</if>
            <if test="userName != null and userName != ''">#{userName},</if>
            <if test="password != null and password != ''">#{password},</if>
            <if test="driveClassName != null and driveClassName != ''">#{driveClassName},</if>
            <if test="poolName != null and poolName != ''">#{poolName},</if>
            <if test="status != null">#{status},</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>
            <if test="cbsParkCode != null and cbsParkCode != ''">#{cbsParkCode},</if>
            <if test="cbsParkName != null and cbsParkName != ''">#{cbsParkName},</if>
         </trim>
    </insert>

    <update id="updateSysDatasource" parameterType="SysDatasource">
        update sys_datasource
        <trim prefix="SET" suffixOverrides=",">
            <if test="url != null and url != ''">url = #{url},</if>
            <if test="userName != null and userName != ''">user_name = #{userName},</if>
            <if test="password != null and password != ''">password = #{password},</if>
            <if test="driveClassName != null and driveClassName != ''">drive_class_name = #{driveClassName},</if>
            <if test="poolName != null and poolName != ''">pool_name = #{poolName},</if>
            <if test="status != null">status = #{status},</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>
            <if test="cbsParkCode != null and cbsParkCode != ''">cbs_park_code = #{cbsParkCode},</if>
            <if test="cbsParkName != null and cbsParkName != ''">cbs_park_name = #{cbsParkName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysDatasourceById" parameterType="String">
        delete from sys_datasource where id = #{id}
    </delete>

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