<?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.ruoyi.ems.mapper.EmsFacsAbilityMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsFacsAbility" id="AbilityResult">
        <result property="id"    column="id"    />
        <result property="facsCode"    column="facs_code"    />
        <result property="abilityName"    column="ability_name"    />
        <result property="abilityDesc"    column="ability_desc"    />
        <result property="abilityParam"    column="ability_param"    />
    </resultMap>

    <sql id="selectEmsFacsAbilityVo">
        select id, facs_code, ability_name, ability_desc, ability_param from adm_ems_facs_ability
    </sql>

    <select id="selectEmsFacsAbilityList" parameterType="com.ruoyi.ems.domain.EmsFacsAbility" resultMap="AbilityResult">
        <include refid="selectEmsFacsAbilityVo"/>
        <where>  
            <if test="facsCode != null  and facsCode != ''"> and facs_code = #{facsCode}</if>
            <if test="abilityName != null  and abilityName != ''"> and ability_name like concat('%', #{abilityName}, '%')</if>
            <if test="abilityDesc != null  and abilityDesc != ''"> and ability_desc = #{abilityDesc}</if>
            <if test="abilityParam != null  and abilityParam != ''"> and ability_param = #{abilityParam}</if>
        </where>
    </select>
    
    <select id="selectEmsFacsAbilityById" parameterType="Long" resultMap="AbilityResult">
        <include refid="selectEmsFacsAbilityVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertEmsFacsAbility" parameterType="com.ruoyi.ems.domain.EmsFacsAbility" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_facs_ability
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="facsCode != null and facsCode != ''">facs_code,</if>
            <if test="abilityName != null and abilityName != ''">ability_name,</if>
            <if test="abilityDesc != null">ability_desc,</if>
            <if test="abilityParam != null">ability_param,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="facsCode != null and facsCode != ''">#{facsCode},</if>
            <if test="abilityName != null and abilityName != ''">#{abilityName},</if>
            <if test="abilityDesc != null">#{abilityDesc},</if>
            <if test="abilityParam != null">#{abilityParam},</if>
         </trim>
    </insert>

    <insert id="insertEmsFacsAbilityBatch" parameterType="java.util.List">
        insert into adm_ems_facs_ability (facs_code, ability_name, ability_desc, ability_param) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.facsCode},#{item.abilityName},#{item.abilityDesc},#{item.abilityParam})
        </foreach>
    </insert>

    <update id="updateEmsFacsAbility" parameterType="com.ruoyi.ems.domain.EmsFacsAbility">
        update adm_ems_facs_ability
        <trim prefix="SET" suffixOverrides=",">
            <if test="facsCode != null and facsCode != ''">facs_code = #{facsCode},</if>
            <if test="abilityName != null and abilityName != ''">ability_name = #{abilityName},</if>
            <if test="abilityDesc != null">ability_desc = #{abilityDesc},</if>
            <if test="abilityParam != null">ability_param = #{abilityParam},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsFacsAbilityById" parameterType="Long">
        delete from adm_ems_facs_ability where id = #{id}
    </delete>

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

    <delete id="deleteEmsFacsAbilityFacsCode" parameterType="String">
        delete from adm_ems_facs_ability where facs_code = #{facsCode}
    </delete>
</mapper>