<?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.simuwang.base.mapper.system.SysConfigMapper">
    
    <resultMap type="com.simuwang.base.pojo.dos.SysConfigDO" id="SysConfigResult">
    	<id     property="configId"      column="configId"      />
        <result property="configName"    column="configName"    />
        <result property="configKey"     column="configKey"     />
        <result property="configValue"   column="configNalue"   />
        <result property="configType"    column="configType"    />
        <result property="creatorId"     column="creatorid"      />
        <result property="createTime"    column="createtime"    />
        <result property="updaterId"     column="updaterid"      />
        <result property="updateTime"    column="updatetime"    />
        <result property="isvalid"       column="isvalid"    />
    </resultMap>
    
    <sql id="selectConfigDo">
        select config_id, config_name, config_key, config_value, config_type, creatorid, createtime, updaterid, updatetime, remark,isvalid
		from PPW_EMAIL.sys_config
    </sql>
    
    <!-- 查询条件 -->
	<sql id="sqlwhereSearch">
		<where>
			<if test="configId !=null">
				and config_id = #{configId}
			</if>
			<if test="configKey !=null and configKey != ''">
				and config_key = #{configKey}
			</if>
		</where>
	</sql>
    
    <select id="selectConfig" parameterType="com.simuwang.base.pojo.dos.SysConfigDO" resultMap="SysConfigResult">
        <include refid="selectConfigDo"/>
        <include refid="sqlwhereSearch"/>
    </select>
    
    <select id="selectConfigList" parameterType="com.simuwang.base.pojo.dos.SysConfigDO" resultMap="SysConfigResult">
        <include refid="selectConfigDo"/>
        <where>
			<if test="configName != null and configName != ''">
				AND config_name like concat('%', #{configName}, '%')
			</if>
			<if test="configType != null and configType != ''">
				AND config_type = #{configType}
			</if>
			<if test="configKey != null and configKey != ''">
				AND config_key like concat('%', #{configKey}, '%')
			</if>
			<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
				and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
			</if>
			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
				and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
			</if>
		</where>
    </select>
    
    <select id="selectConfigById" parameterType="Long" resultMap="SysConfigResult">
        <include refid="selectConfigDo"/>
        where config_id = #{configId} and isvalid =1
    </select>
	
    <select id="checkConfigKeyUnique" parameterType="String" resultMap="SysConfigResult">
        <include refid="selectConfigDo"/>
        where config_key = #{configKey}  and isvalid =1 limit 1
    </select>
    <select id="selectConfigByKey" resultType="java.lang.String">

    </select>

    <insert id="insertConfig" parameterType="com.simuwang.base.pojo.dos.SysConfigDO">
        insert into sys_config (
			<if test="configName != null and configName != '' ">config_name,</if>
			<if test="configKey != null and configKey != '' ">config_key,</if>
			<if test="configValue != null and configValue != '' ">config_value,</if>
			<if test="configType != null and configType != '' ">config_type,</if>
			<if test="creatorId != null and creatorId != ''">creatorid,</if>
            <if test="updaterId != null and updaterId != ''">updaterid,</if>
			<if test="remark != null and remark != ''">remark,</if>
            isvalid,
 			createtime,
            updatetime,
        )values(
			<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="creatorId != null and creatorId != ''">#{creatorId},</if>
            <if test="updaterId != null and updaterId != ''">#{updaterId},</if>
			<if test="remark != null and remark != ''">#{remark},</if>
            1,
 			sysdate(),
            sysdate()
		)
    </insert>
	 
    <update id="updateConfig" parameterType="com.simuwang.base.pojo.dos.SysConfigDO">
        update sys_config 
        <set>
            <if test="configName != null and configName != ''">config_name = #{configName},</if>
            <if test="configKey != null and configKey != ''">config_key = #{configKey},</if>
            <if test="configValue != null and configValue != ''">config_value = #{configValue},</if>
            <if test="configType != null and configType != ''">config_type = #{configType},</if>
            <if test="updaterId != null and updaterId != ''">updaterid = #{updaterId},</if>
            <if test="remark != null">remark = #{remark},</if>
 			updatetime = sysdate()
        </set>
        where config_id = #{configId} and isvalid=1
    </update>
	
    <delete id="deleteConfigById" parameterType="Long">
        UPDATE sys_config SET isvalid=0  where config_id = #{configId}
    </delete>
    
    <delete id="deleteConfigByIds" parameterType="Long">
        UPDATE sys_config SET isvalid=0 where config_id in
        <foreach item="configId" collection="configIds" open="(" separator="," close=")">
        	#{configId}
        </foreach>
    </delete>
    
</mapper>