<?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.zhyc.module.app.mapper.AppSettingsMapper">
    
    <resultMap type="com.zhyc.module.app.domain.AppSettings" id="AppSettingsResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="settingKey"    column="setting_key"    />
        <result property="settingValue"    column="setting_value"    />
        <result property="settingType"    column="setting_type"    />
        <result property="settingGroup"    column="setting_group"    />
        <result property="settingDesc"    column="setting_desc"    />
        <result property="platform"    column="platform"    />
        <result property="versionRange"    column="version_range"    />
        <result property="status"    column="status"    />
        <result property="logical"    column="logical"    />
        <result property="customData"    column="custom_data"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAppSettingsVo">
        select id, user_id, setting_key, setting_value, setting_type, setting_group, setting_desc, platform, version_range, status, logical, custom_data, create_time, update_time from app_settings
    </sql>

    <select id="selectAppSettingsList" parameterType="AppSettings" resultMap="AppSettingsResult">
        <include refid="selectAppSettingsVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="settingKey != null  and settingKey != ''"> and setting_key = #{settingKey}</if>
            <if test="settingValue != null  and settingValue != ''"> and setting_value = #{settingValue}</if>
            <if test="settingType != null  and settingType != ''"> and setting_type = #{settingType}</if>
            <if test="settingGroup != null  and settingGroup != ''"> and setting_group = #{settingGroup}</if>
            <if test="settingDesc != null  and settingDesc != ''"> and setting_desc = #{settingDesc}</if>
            <if test="platform != null  and platform != ''"> and platform = #{platform}</if>
            <if test="versionRange != null  and versionRange != ''"> and version_range = #{versionRange}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="logical != null "> and logical = #{logical}</if>
            <if test="customData != null  and customData != ''"> and custom_data = #{customData}</if>
        </where>
    </select>
    
    <select id="selectAppSettingsById" parameterType="Long" resultMap="AppSettingsResult">
        <include refid="selectAppSettingsVo"/>
        where id = #{id}
    </select>

    <insert id="insertAppSettings" parameterType="AppSettings" useGeneratedKeys="true" keyProperty="id">
        insert into app_settings
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="settingKey != null and settingKey != ''">setting_key,</if>
            <if test="settingValue != null">setting_value,</if>
            <if test="settingType != null">setting_type,</if>
            <if test="settingGroup != null">setting_group,</if>
            <if test="settingDesc != null">setting_desc,</if>
            <if test="platform != null">platform,</if>
            <if test="versionRange != null">version_range,</if>
            <if test="status != null">status,</if>
            <if test="logical != null">logical,</if>
            <if test="customData != null">custom_data,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="settingKey != null and settingKey != ''">#{settingKey},</if>
            <if test="settingValue != null">#{settingValue},</if>
            <if test="settingType != null">#{settingType},</if>
            <if test="settingGroup != null">#{settingGroup},</if>
            <if test="settingDesc != null">#{settingDesc},</if>
            <if test="platform != null">#{platform},</if>
            <if test="versionRange != null">#{versionRange},</if>
            <if test="status != null">#{status},</if>
            <if test="logical != null">#{logical},</if>
            <if test="customData != null">#{customData},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateAppSettings" parameterType="AppSettings">
        update app_settings
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="settingKey != null and settingKey != ''">setting_key = #{settingKey},</if>
            <if test="settingValue != null">setting_value = #{settingValue},</if>
            <if test="settingType != null">setting_type = #{settingType},</if>
            <if test="settingGroup != null">setting_group = #{settingGroup},</if>
            <if test="settingDesc != null">setting_desc = #{settingDesc},</if>
            <if test="platform != null">platform = #{platform},</if>
            <if test="versionRange != null">version_range = #{versionRange},</if>
            <if test="status != null">status = #{status},</if>
            <if test="logical != null">logical = #{logical},</if>
            <if test="customData != null">custom_data = #{customData},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppSettingsById" parameterType="Long">
        delete from app_settings where id = #{id}
    </delete>

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