<?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.yunfeiyun.agmp.common.web.system.mapper.SysConfigMapper">
    
    <resultMap type="SysConfig" id="SysConfigResult">
    	<id     property="configId"      column="configId"      />
        <result property="configName"    column="configName"    />
        <result property="configKey"     column="configKey"     />
        <result property="configValue"   column="configValue"   />
        <result property="configType"    column="configType"    />
        <result property="configCreator"      column="configCreator"      />
        <result property="configCreateddate"    column="configCreateddate"    />
        <result property="configModifier"      column="configModifier"      />
        <result property="configModifieddate"    column="configModifieddate"    />
        <result property="configRemark"    column="configRemark"    />
    </resultMap>
    
    <sql id="selectConfigVo">
        select configId, configName, configKey, configValue, configType, configCreator, configCreateddate, configModifier, configModifieddate, configRemark
		from SysConfig
    </sql>
    
    <!-- 查询条件 -->
	<sql id="sqlwhereSearch">
		<where>
			<if test="configId !=null">
				and configId = #{configId}
			</if>
			<if test="configKey !=null and configKey != ''">
				and configKey = #{configKey}
			</if>
		</where>
	</sql>
    
    <select id="selectConfig" parameterType="SysConfig" resultMap="SysConfigResult">
        <include refid="selectConfigVo"/>
        <include refid="sqlwhereSearch"/>
    </select>
    
    <select id="selectConfigList" parameterType="SysConfig" resultMap="SysConfigResult">
        <include refid="selectConfigVo"/>
        <where>
			<if test="configName != null and configName != ''">
				AND configName like concat('%', #{configName}, '%')
			</if>
			<if test="configType != null and configType != ''">
				AND configType = #{configType}
			</if>
			<if test="configKey != null and configKey != ''">
				AND configKey like concat('%', #{configKey}, '%')
			</if>
			<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
				and date_format(configCreateddate,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
			</if>
			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
				and date_format(configCreateddate,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
			</if>
		</where>
    </select>
    
    <select id="selectConfigById" parameterType="String" resultMap="SysConfigResult">
        <include refid="selectConfigVo"/>
        where configId = #{configId}
    </select>
	
    <select id="checkConfigKeyUnique" parameterType="String" resultMap="SysConfigResult">
        <include refid="selectConfigVo"/>
        where configKey = #{configKey} limit 1
    </select>
    
    <insert id="insertConfig" parameterType="SysConfig">
        insert into SysConfig (
            <if test="configId != null and configId != '' ">configId,</if>
			<if test="configName != null and configName != '' ">configName,</if>
			<if test="configKey != null and configKey != '' ">configKey,</if>
			<if test="configValue != null and configValue != '' ">configValue,</if>
			<if test="configType != null and configType != '' ">configType,</if>
			<if test="configCreator != null and configCreator != ''">configCreator,</if>
			<if test="configRemark != null and configRemark != ''">configRemark,</if>
        configCreateddate
        )values(
            <if test="configId != null and configId != '' ">#{configId},</if>
			<if test="configName != null and configName != ''">#{configName},</if>
			<if test="configKey != null and configKey != ''">#{configKey},</if>
			<if test="configValue != null and configValue != ''">#{configValue},</if>
			<if test="configType != null and configType != ''">#{configType},</if>
			<if test="configCreator != null and configCreator != ''">#{configCreator},</if>
			<if test="configRemark != null and configRemark != ''">#{configRemark},</if>
 			date_format(sysdate(),'%Y-%m-%d %H:%i:%s')
		)
    </insert>
	 
    <update id="updateConfig" parameterType="SysConfig">
        update SysConfig
        <set>
            <if test="configName != null and configName != ''">configName = #{configName},</if>
            <if test="configKey != null and configKey != ''">configKey = #{configKey},</if>
            <if test="configValue != null and configValue != ''">configValue = #{configValue},</if>
            <if test="configType != null and configType != ''">configType = #{configType},</if>
            <if test="configModifier != null and configModifier != ''">configModifier = #{configModifier},</if>
            <if test="configRemark != null">configRemark = #{configRemark},</if>
            configModifieddate = date_format(sysdate(),'%Y-%m-%d %H:%i:%s')
        </set>
        where configId = #{configId}
    </update>
	
    <delete id="deleteConfigById" parameterType="String">
        delete from SysConfig where configId = #{configId}
    </delete>
    
    <delete id="deleteConfigByIds" parameterType="String">
        delete from SysConfig where configId in
        <foreach item="configId" collection="array" open="(" separator="," close=")">
        	#{configId}
        </foreach>
    </delete>
    
</mapper>