<?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.flossom.common.core.mapper.WxSystemSettingMapper">

    <resultMap type="WxSystemSetting" id="WxSystemSettingResult">
        <result property="id"    column="id"    />
        <result property="key"    column="key"    />
        <result property="value"    column="value"    />
        <result property="instructions"    column="instructions"    />
        <result property="pictureUrl"    column="picture_url"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectWxSystemSettingVo">
        select id, `key`, `value`, instructions, picture_url, status, create_by, create_time, update_by, update_time, remark from wx_system_setting
    </sql>

    <select id="selectWxSystemSettingList" parameterType="WxSystemSetting" resultMap="WxSystemSettingResult">
        <include refid="selectWxSystemSettingVo"/>
        <where>
            <if test="key != null  and key != ''"> and `key` = #{key}</if>
            <if test="value != null  and value != ''"> and `value` = #{value}</if>
            <if test="instructions != null  and instructions != ''"> and instructions = #{instructions}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectWxSystemSettingById" parameterType="Long" resultMap="WxSystemSettingResult">
        <include refid="selectWxSystemSettingVo"/>
        where id = #{id}
    </select>

    <insert id="insertWxSystemSetting" parameterType="WxSystemSetting" useGeneratedKeys="true" keyProperty="id">
        insert into wx_system_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="key != null">`key`,</if>
            <if test="value != null">`value`,</if>
            <if test="instructions != null">instructions,</if>
            <if test="pictureUrl != null">picture_url,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="key != null">#{key},</if>
            <if test="value != null">#{value},</if>
            <if test="instructions != null">#{instructions},</if>
            <if test="pictureUrl != null">#{pictureUrl},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateWxSystemSetting" parameterType="WxSystemSetting">
        update wx_system_setting
        <trim prefix="SET" suffixOverrides=",">
            <if test="key != null">`key` = #{key},</if>
            <if test="value != null">`value` = #{value},</if>
            <if test="instructions != null">instructions = #{instructions},</if>
            <if test="pictureUrl != null">picture_url = #{pictureUrl},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxSystemSettingById" parameterType="Long">
        delete from wx_system_setting where id = #{id}
    </delete>

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

    <select id="getSystemSettingByKey" parameterType="String" resultMap="WxSystemSettingResult">
        <include refid="selectWxSystemSettingVo"/>
        <where>
            <if test="key !=null">
                and `key` = #{key}
            </if>
        </where>
        order by update_time desc
        limit 1
    </select>
</mapper>
