<?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.fs.company.mapper.CompanyConfigMapper">
    
    <resultMap type="CompanyConfig" id="CompanyConfigResult">
        <result property="configId"    column="config_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="configName"    column="config_name"    />
        <result property="configKey"    column="config_key"    />
        <result property="configValue"    column="config_value"    />
        <result property="configType"    column="config_type"    />
        <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"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectCompanyConfigVo">
        select config_id, company_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark, is_del from company_config
    </sql>

    <select id="selectCompanyConfigList" parameterType="CompanyConfig" resultMap="CompanyConfigResult">
        <include refid="selectCompanyConfigVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="configName != null  and configName != ''"> and config_name like concat('%', #{configName}, '%')</if>
            <if test="configKey != null  and configKey != ''"> and config_key = #{configKey}</if>
            <if test="configValue != null  and configValue != ''"> and config_value = #{configValue}</if>
            <if test="configType != null  and configType != ''"> and config_type = #{configType}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectCompanyConfigById" parameterType="Integer" resultMap="CompanyConfigResult">
        <include refid="selectCompanyConfigVo"/>
        where config_id = #{configId}
    </select>
        
    <insert id="insertCompanyConfig" parameterType="CompanyConfig" useGeneratedKeys="true" keyProperty="configId">
        insert into company_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="configName != null">config_name,</if>
            <if test="configKey != null">config_key,</if>
            <if test="configValue != null">config_value,</if>
            <if test="configType != null">config_type,</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>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="configName != null">#{configName},</if>
            <if test="configKey != null">#{configKey},</if>
            <if test="configValue != null">#{configValue},</if>
            <if test="configType != null">#{configType},</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>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateCompanyConfig" parameterType="CompanyConfig">
        update company_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="configName != null">config_name = #{configName},</if>
            <if test="configKey != null">config_key = #{configKey},</if>
            <if test="configValue != null">config_value = #{configValue},</if>
            <if test="configType != null">config_type = #{configType},</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>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where config_id = #{configId}
    </update>

    <delete id="deleteCompanyConfigById" parameterType="Integer">
        delete from company_config where config_id = #{configId}
    </delete>

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