<?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.cftech.cos.config.cosconfig.dao.CosconfigMapper">

    <resultMap id="resultMap" type="com.cftech.cos.config.cosconfig.model.Cosconfig">
        <id column="id" property="id"/>
        <result column="app_id" property="appId"/>
        <result column="cos_type" property="cosType"/>
        <result column="key_id" property="keyId"/>
        <result column="key_secret" property="keySecret"/>
        <result column="bucket" property="bucket"/>
        <result column="endpoint" property="endpoint"/>
        <result column="region" property="region"/>
        <result column="url" property="url"/>
        <result column="del_flag" property="delFlag"/>
        <result column="status" property="status"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="description" property="description"/>
        <result column="create_by" property="createBy"/>
        <result column="update_by" property="updateBy"/>
    </resultMap>

    <sql id="sqlWhere">
        <if test="conds!=null">
            <trim prefix="WHERE" prefixOverrides="AND|OR">
                <foreach collection="conds.conds" index="index" item="cond">
                    ${cond.linkType}
                    <if test="cond.condType == 'EQUAL'">${cond.param} = #{cond.value}</if>
                    <if test="cond.condType == 'NOTEQUAL'">${cond.param} &lt;&gt; #{cond.value}</if>
                    <if test="cond.condType == 'GREATEQUAL'">${cond.param} &gt;= #{cond.value}</if>
                    <if test="cond.condType == 'GREATTHAN'">${cond.param} &gt; #{cond.value}</if>
                    <if test="cond.condType == 'LESSEQUAL'">${cond.param} &lt;= #{cond.value}</if>
                    <if test="cond.condType == 'LESSTHAN'">${cond.param} &lt; #{cond.value}</if>
                    <if test="cond.condType == 'BETWEEN'">${cond.param} BETWEEN #{cond.startValue} AND
                        #{cond.endValue}
                    </if>
                    <if test="cond.condType == 'ISNULL'">${cond.param} IS NULL</if>
                    <if test="cond.condType == 'NOTNULL'">${cond.param} IS NOT NULL</if>
                    <if test="cond.condType == 'LIKE'">${cond.param} LIKE #{cond.value}</if>
                    <if test="cond.condType == 'IN'">${cond.param} IN
                        <foreach item="item" index="index" collection="cond.value" open="(" separator="," close=")">
                            #{item}
                        </foreach>
                    </if>
                </foreach>
            </trim>
        </if>
    </sql>

    <sql id="sqlColumns">
      id,
      app_id,
      cos_type,
      key_id,
      key_secret,
      bucket,
      endpoint,
      region,
      url,
      del_flag,
      status,
      create_time,
      update_time,
      description,
      create_by,
      update_by
    </sql>


    <insert id="save" parameterType="com.cftech.cos.config.cosconfig.model.Cosconfig" useGeneratedKeys="true"
            keyProperty="id">
        insert into t_cos_config
        (
        <include refid="sqlColumns"/>
        )
        values
        (
        #{id, jdbcType=BIGINT},
        #{appId, jdbcType=BIGINT},
        #{cosType, jdbcType=VARCHAR},
        #{keyId, jdbcType=VARCHAR},
        #{keySecret, jdbcType=VARCHAR},
        #{bucket, jdbcType=VARCHAR},
        #{endpoint, jdbcType=VARCHAR},
        #{region, jdbcType=VARCHAR},
        #{url, jdbcType=VARCHAR},
        #{delFlag, jdbcType=TINYINT},
        #{status, jdbcType=VARCHAR},
        now(),
        now(),
        #{description, jdbcType=VARCHAR},
        #{createBy, jdbcType=BIGINT},
        #{updateBy, jdbcType=BIGINT}
        )
    </insert>

    <select id="fetchById" parameterType="java.lang.Long" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>
        FROM t_cos_config t
        WHERE t.id=#{id}
    </select>

    <select id="count" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT COUNT(1) FROM t_cos_config
        <include refid="sqlWhere"/>

    </select>

    <select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>
        FROM t_cos_config
        <include refid="sqlWhere"/>
        <if test="sort!=null">ORDER BY ${sort.param} ${sort.type}</if>
        <if test="limit>0">limit #{offset},#{limit}</if>
    </select>

    <update id="update" parameterType="com.cftech.cos.config.cosconfig.model.Cosconfig">
        update t_cos_config
        <set>
            <if test="id != null">
                id = #{id, jdbcType=BIGINT},
            </if>
            <if test="appId != null">
                app_id = #{appId, jdbcType=BIGINT},
            </if>
            <if test="cosType != null">
                cos_type = #{cosType, jdbcType=VARCHAR},
            </if>
            <if test="keyId != null">
                key_id = #{keyId, jdbcType=VARCHAR},
            </if>
            <if test="keySecret != null">
                key_secret = #{keySecret, jdbcType=VARCHAR},
            </if>
            <if test="bucket != null">
                bucket = #{bucket, jdbcType=VARCHAR},
            </if>
            <if test="endpoint != null">
                endpoint = #{endpoint, jdbcType=VARCHAR},
            </if>
            <if test="region != null">
                region = #{region, jdbcType=VARCHAR},
            </if>
            <if test="url != null">
                url = #{url, jdbcType=VARCHAR},
            </if>
            <if test="delFlag != null">
                del_flag = #{delFlag, jdbcType=TINYINT},
            </if>
            <if test="status != null">
                status = #{status, jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime, jdbcType=TIMESTAMP},
            </if>
            <if test="description != null">
                description = #{description, jdbcType=VARCHAR},
            </if>
            <if test="createBy != null">
                create_by = #{createBy, jdbcType=BIGINT},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy, jdbcType=BIGINT},
            </if>
        </set>
        where id=#{id,jdbcType=BIGINT}
    </update>

    <update id="delete" parameterType="java.lang.Long">
        update t_cos_config set del_flag=1 where id=#{id,jdbcType=BIGINT}
    </update>
</mapper>