<?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.boman.web.core.mapper.IpTimesMapper">

    <delete id="delete">
        delete from ip_times where id = #{id}
    </delete>

    <select id="list" resultType="com.alibaba.fastjson.JSONObject">
         select id,app_id as appId,ip, table_name as tableName,times ,column_names as columnNames,app_key as appKey,app_secret as appSecret,is_strong as isStrong from ip_times
        <where>
        <if test="ip != null and ip != ''">
            and ip like concat('%', #{ip},'%')
        </if>
        <if test="times != null">
            and times = #{times}
        </if>
        </where>
    </select>

    <select id="getById" resultType="com.alibaba.fastjson.JSONObject">
        select id,app_id as appId,ip, table_name as tableName,times ,column_names as columnNames,app_key as appKey,app_secret as appSecret,is_strong as isStrong from ip_times where id = #{id}
    </select>
    <select id="getByIp" resultType="com.alibaba.fastjson.JSONObject">
        select id,app_id as appId,ip, table_name as tableName,times ,column_names as columnNames,app_key as appKey,app_secret as appSecret,is_strong as isStrong from ip_times where ip = #{ip} limit 1;
    </select>

    <select id="getByAppId" resultType="com.alibaba.fastjson.JSONObject">
        select app_key,app_secret,is_strong,ip,times,column_names from ip_times where app_id = #{appId} limit 1;
    </select>
    <select id="getAllColumns" resultType="com.alibaba.fastjson.JSONObject">
        show full columns from czrk;
    </select>

    <select id="countByUsername" resultType="com.alibaba.fastjson.JSONObject">
        select id,app_id as appId,ip, table_name as tableName,times ,column_names as columnNames,app_key as appKey,app_secret as appSecret,is_strong as isStrong from ip_times where app_key = #{appKey} and app_secret = #{appSecret};
    </select>

    <insert id="save">
        insert into ip_times
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ip != null">ip,</if>
            <if test="appId != null">app_id,</if>
            <if test="tableName != null">table_name,</if>
            <if test="times != null">times,</if>
            <if test="columnNames != null">column_names,</if>
            <if test="appKey != null">app_key,</if>
            <if test="appSecret != null">app_secret,</if>
            <if test="isStrong != null">is_strong,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ip != null">#{ip},</if>
            <if test="appId != null">#{appId},</if>
            <if test="tableName != null">#{tableName},</if>
            <if test="times != null">#{times},</if>
            <if test="columnNames != null">#{columnNames},</if>
            <if test="appKey != null">#{appKey},</if>
            <if test="appSecret != null">#{appSecret},</if>
            <if test="isStrong != null">#{isStrong},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            sysdate()
        </trim>
    </insert>

    <update id="update">
        update ip_times
        <trim prefix="SET" suffixOverrides=",">
            <if test="ip != null">ip = #{ip},</if>
            <if test="appId != null">app_id = #{appId},</if>
            <if test="times != null">times = #{times},</if>
            <if test="tableName != null">table_name = #{tableName},</if>
            <if test="columnNames != null">column_names = #{columnNames},</if>
            <if test="appKey != null and appKey != ''">app_key = #{appKey},</if>
            <if test="appSecret != null and appSecret != ''">app_secret = #{appSecret},</if>
            <if test="isStrong != null and isStrong !=''">is_strong = #{isStrong},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null and updateTime != ''">update_time = SYSDATE()</if>
        </trim>
        where id = #{id}
    </update>
</mapper>