<?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="cn.fateverse.query.mapper.DataAdapterMapper">

    <resultMap id="DataAdapterResult" type="cn.fateverse.query.entity.DataAdapter">
        <id column="adapter_id" property="adapterId"/>
        <result column="adapter_name" property="adapterName"/>
        <result column="type" property="type"/>
        <result column="code" property="code"/>
        <result column="source" property="source"/>
        <result column="mock_data" property="mockData"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="selectDataAdapterVo">
        select adapter_id, data_source_id, adapter_name, `type`, code, `source`, mock_data, create_by, create_time, update_by, update_time
        from data_adapter
    </sql>



    <select id="selectList" resultMap="DataAdapterResult">
        <include refid="selectDataAdapterVo"/>
        <where>
            <if test="adapterName != null  and adapterName != ''"> and adapter_name like concat('%', #{adapterName}, '%')</if>
            <if test="type != null"> and `type` = #{type}</if>
            <if test="source != null "> and `source` = #{source}</if>
        </where>
    </select>

    <select id="selectById" resultMap="DataAdapterResult">
        <include refid="selectDataAdapterVo"/>
        where adapter_id = #{adapterId}
    </select>

    <insert id="insert" >
        insert into data_adapter
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataSourceId != null">data_source_id,</if>
            <if test="adapterName != null">adapter_name,</if>
            <if test="type != null">`type`,</if>
            <if test="code != null">code,</if>
            <if test="source != null">`source`,</if>
            <if test="mockData != null">mock_data,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dataSourceId != null">#{dataSourceId},</if>
            <if test="adapterName != null">#{adapterName},</if>
            <if test="type != null">#{type},</if>
            <if test="code != null">#{code},</if>
            <if test="source != null">#{source},</if>
            <if test="mockData != null">#{mockData},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
        </trim>
    </insert>

    <update id="update">
        update data_adapter
        <set>
            <if test="dataSourceId != null">data_source_id = #{dataSourceId},</if>
            <if test="adapterName != null">adapter_name = #{adapterName},</if>
            <if test="type != null">`type` = #{type},</if>
            <if test="code != null">code = #{code},</if>
            <if test="source != null">`source` = #{source},</if>
            <if test="mockData != null">mock_data = #{mockData},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
        </set>
        where adapter_id = #{adapterId}
    </update>

    <delete id="deleteById">
        delete from data_adapter
        where adapter_id = #{adapterId}
    </delete>

    <delete id="deleteBatchByIdList" parameterType="Long">
        delete from data_adapter
        where adapter_id in
        <foreach collection="list" open="(" close=")" separator="," item="adapterId">
            #{adapterId}
        </foreach>
    </delete>

</mapper>