<?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.ebts.generator.dao.UniQueryDao">

    <resultMap type="com.ebts.generator.entity.UniQuery" id="UniQueryResult">
        <result property="id"    column="id"    />
        <result property="uqName"    column="uq_name"    />
        <result property="uqSql"    column="uq_sql"    />
        <result property="uqDescribe"    column="uq_describe"    />
        <result property="isRelease"    column="is_release"    />
        <result property="topJson"    column="top_json"    />
        <result property="type"    column="type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>


    <sql id="selectUniQueryVo">
        select id, uq_name, uq_sql, uq_describe, type, is_release, create_by, create_time, update_by, update_time from gen_uni_query
    </sql>

    <select id="selectUniQueryList" parameterType="UniQuery" resultMap="UniQueryResult">
        select id, uq_name, uq_describe, type, is_release, create_by, create_time, update_by, update_time from gen_uni_query
        <where>
            <if test="uqName != null  and uqName != ''"> and uq_name like concat('%', #{uqName}, '%')</if>
            <if test="uqDescribe != null  and uqDescribe != ''"> and uq_describe like concat('%', #{uqDescribe}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type} </if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
        </where>
    </select>

    <select id="selectUniQueryById" parameterType="Long" resultMap="UniQueryResult">
        select id, uq_name, uq_describe, top_json, type, is_release, create_by, create_time, update_by, update_time from gen_uni_query
        where id = #{id} and is_release = 2
    </select>
    <select id="selectUniQueryReleaseByIds" resultType="java.lang.Integer">
        select count(1) from gen_uni_query where is_release = 1 and id in
        <foreach collection="ids" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </select>

    <insert id="insertUniQuery" parameterType="UniQuery" useGeneratedKeys="true" keyProperty="id">
        insert into gen_uni_query
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uqName != null and uqName != ''">uq_name,</if>
            <if test="uqSql != null">uq_sql,</if>
            <if test="uqDescribe != null and uqDescribe != ''">uq_describe,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="topJson != null and topJson != ''">top_json,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uqName != null and uqName != ''">#{uqName},</if>
            <if test="uqSql != null">#{uqSql},</if>
            <if test="uqDescribe != null and uqDescribe != ''">#{uqDescribe},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="topJson != null and topJson != ''">#{topJson},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateUniQuery" parameterType="UniQuery">
        update gen_uni_query
        <trim prefix="SET" suffixOverrides=",">
            <if test="uqName != null and uqName != ''">uq_name = #{uqName},</if>
            <if test="uqSql != null">uq_sql = #{uqSql},</if>
            <if test="isPreview != null">is_preview = #{isPreview},</if>
            <if test="uqDescribe != null and uqDescribe != ''">uq_describe = #{uqDescribe},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="topJson != null and topJson != ''">top_json = #{topJson},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id} and is_release = 2
    </update>

    <delete id="deleteUniQueryById" parameterType="Long">
        delete from gen_uni_query where id = #{id}
    </delete>
    
    <delete id="deleteUniQueryByUqId" parameterType="Long">
        delete from gen_uni_con where uq_id in #{id}
    </delete>

    <delete id="deleteUniQueryByUqIds" parameterType="Long">
        delete from gen_uni_con where uq_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

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