<?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.brand.apply.dao.BrandApplyProductMapper">

    <resultMap id="resultMap" type="com.cftech.brand.apply.model.BrandApplyProduct">
        <id column="id" property="id"/>
        <result column="apply_id" property="applyId"/>
        <result column="cosconfig_id" property="cosconfigId"/>
        <result column="file_url" property="fileUrl"/>
        <result column="format" property="format"/>
        <result column="name" property="name"/>
        <result column="label" property="label"/>
        <result column="del_flag" property="delFlag"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="create_by" property="createBy"/>
        <result column="update_by" property="updateBy"/>
        <result column="file_prefix" property="filePrefix"/>
    </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,
                                                apply_id,
                                                cosconfig_id,
                                                file_url,
                                                format,
                                                name,
                                                label,
                                                del_flag,
                                                create_time,
                                                update_time,
                                                create_by,
                                                update_by,
                                                file_prefix

                        </sql>


    <insert id="save" parameterType="com.cftech.brand.apply.model.BrandApplyProduct" useGeneratedKeys="true"
            keyProperty="id">
        insert into t_schaeffler_brand_apply_product
        (
        <include refid="sqlColumns"/>
        )
        values
        (
        #{id, jdbcType=BIGINT},
        #{applyId, jdbcType=BIGINT},
        #{cosconfigId, jdbcType=BIGINT},
        #{fileUrl, jdbcType=VARCHAR},
        #{format,jdbcType=VARCHAR},
        #{name, jdbcType=VARCHAR},
        #{label, jdbcType=VARCHAR},
        #{delFlag, jdbcType=TINYINT},
        now(),
        now(),
        #{createBy, jdbcType=BIGINT},
        #{updateBy, jdbcType=BIGINT},
        #{filePrefix, jdbcType=VARCHAR}
        )
    </insert>

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

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

    </select>

    <update id="update" parameterType="com.cftech.brand.apply.model.BrandApplyProduct">
        update t_schaeffler_brand_apply_product
        <set>
            <if test="id != null">
                id = #{id, jdbcType=BIGINT},
            </if>
            <if test="applyId != null">
                apply_id = #{applyId, jdbcType=BIGINT},
            </if>
            <if test="cosconfigId != null">
                cosconfig_id = #{cosconfigId, jdbcType=BIGINT},
            </if>
            <if test="fileUrl != null">
                file_url = #{fileUrl, jdbcType=VARCHAR},
            </if>
            <if test="format != null">
                format = #{format, jdbcType=VARCHAR},
            </if>
            <if test="name != null">
                name = #{name, jdbcType=VARCHAR},
            </if>
            <if test="delFlag != null">
                del_flag = #{delFlag, jdbcType=TINYINT},
            </if>
            <if test="createTime != null">
                create_time = #{createTime, jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime, jdbcType=TIMESTAMP},
            </if>
            <if test="createBy != null">
                create_by = #{createBy, jdbcType=BIGINT},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy, jdbcType=BIGINT},
            </if>
            <if test="filePrefix != null">
                file_prefix = #{filePrefix, jdbcType=VARCHAR},
            </if>
        </set>
        where id=#{id,jdbcType=BIGINT}
    </update>

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

    <select id="fetchByApplyId"  parameterType="java.lang.Long" resultMap="resultMap">
        select * from t_schaeffler_brand_apply_product where apply_id=#{applyId,jdbcType=BIGINT} and del_flag=0
    </select>

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

</mapper>