<?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.shkj.system.mapper.SysParameterMapper">
    
    <resultMap type="com.shkj.system.domain.SysParameter" id="SysParameterResult">
    	<id     property="id"      column="id"      />
        <result property="paraCode"    column="para_code"    />
        <result property="paraName"     column="para_name"     />
        <result property="paraValue"   column="para_value"   />
        <result property="paraType"    column="para_type"    />
        <result property="branchId"    column="branch_id"    />
        <result property="createBy"      column="create_by"      />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"      column="update_by"      />
        <result property="updateTime"    column="update_time"    />
    </resultMap>
    
    <sql id="selectConfigVo">
        select *
		from sys_parameter
    </sql>
    
    <!-- 查询条件 -->
	<sql id="sqlwhereSearch">
		<where>
			<if test="id !=null">
				and id = #{id}
			</if>
            <if test="branchId != null">
                and branch_id = #{branchId}
            </if>
			<if test="paraCode !=null and paraCode != ''">
				and para_code = #{paraCode}
			</if>
		</where>
	</sql>
    
    <select id="selectConfig" parameterType="SysParameter" resultMap="SysParameterResult">
        <include refid="selectConfigVo"/>
        <include refid="sqlwhereSearch"/>
    </select>
    
    <select id="selectConfigList" parameterType="SysParameter" resultMap="SysParameterResult">
        <include refid="selectConfigVo"/>
        <where>
            <if test="branchId != null">
                and branch_id = #{branchId}
            </if>
			<if test="paraName != null and paraName != ''">
				AND para_name like concat('%', #{paraName}, '%')
			</if>
			<if test="paraType != null and paraType != ''">
				AND para_type = #{paraType}
			</if>
			<if test="paraCode != null and paraCode != ''">
				AND para_code like concat('%', #{paraCode}, '%')
			</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="checkConfigKeyUnique"  resultMap="SysParameterResult">
        <include refid="selectConfigVo"/>
        where para_code = #{paraCode} and branch_id = #{branchId} limit 1
    </select>
    
    <insert id="insertConfig" parameterType="SysParameter">
        insert into sys_parameter (
			<if test="paraName != null and paraName != '' ">para_name,</if>
			<if test="branchId != null">branch_id,</if>
			<if test="paraCode != null and paraCode != '' ">para_code,</if>
			<if test="paraValue != null and paraValue != '' ">para_value,</if>
			<if test="paraType != null and paraType != '' ">para_type,</if>
			<if test="createBy != null and createBy != ''">create_by,</if>
			<if test="remark != null and remark != ''">remark,</if>
 			create_time
        )values(
			<if test="paraName != null and paraName != ''">#{paraName},</if>
            <if test="branchId != null">#{branchId},</if>
			<if test="paraCode != null and paraCode != ''">#{paraCode},</if>
			<if test="paraValue != null and paraValue != ''">#{paraValue},</if>
			<if test="paraType != null and paraType != ''">#{paraType},</if>
			<if test="createBy != null and createBy != ''">#{createBy},</if>
			<if test="remark != null and remark != ''">#{remark},</if>
 			sysdate()
		)
    </insert>
	 
    <update id="updateConfig" parameterType="SysParameter">
        update sys_parameter 
        <set>
            <if test="paraName != null and paraName != ''">para_name = #{paraName},</if>
            <if test="paraCode != null and paraCode != ''">para_code = #{paraCode},</if>
            <if test="paraValue != null and paraValue != ''">para_value = #{paraValue},</if>
            <if test="paraType != null and paraType != ''">para_type = #{paraType},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
 			update_time = sysdate()
        </set>
        where id = #{id}
    </update>
	
    <delete id="deleteConfigById" parameterType="Long">
        delete from sys_parameter where id = #{id}
    </delete>
    
    <delete id="deleteConfigByIds" parameterType="Long">
        delete from sys_parameter where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
        	#{id}
        </foreach>
    </delete>
    
</mapper>