<?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.EmsFacsSubtypeMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsFacsSubtype" id="EmsFacsSubtypeResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="parentCode"    column="parent_code"    />
        <result property="desc"    column="desc"    />
        <result property="version"    column="version"    />
    </resultMap>

    <sql id="selectFacsSubtypeVo">
        select `id`, `code`, `name`, `parent_code`, `desc`, `version` from dim_ems_facs_subtype
    </sql>

    <select id="selectFacsSubtypeList" parameterType="com.ruoyi.ems.domain.EmsFacsSubtype" resultMap="EmsFacsSubtypeResult">
        <include refid="selectFacsSubtypeVo"/>
        <where>  
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="parentCode != null  and parentCode != ''"> and parent_code = #{parentCode}</if>
            <if test="desc != null  and desc != ''"> and desc = #{desc}</if>
            <if test="version != null  and version != ''"> and version = #{version}</if>
        </where>
    </select>
    
    <select id="selectFacsSubtypeById" parameterType="Long" resultMap="EmsFacsSubtypeResult">
        <include refid="selectFacsSubtypeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFacsSubtype" parameterType="com.ruoyi.ems.domain.EmsFacsSubtype" useGeneratedKeys="true" keyProperty="id">
        insert into dim_ems_facs_subtype
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="code != null and code != ''">code,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="parentCode != null and parentCode != ''">parent_code,</if>
            <if test="desc != null">desc,</if>
            <if test="version != null">version,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="code != null and code != ''">#{code},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="parentCode != null and parentCode != ''">#{parentCode},</if>
            <if test="desc != null">#{desc},</if>
            <if test="version != null">#{version},</if>
         </trim>
    </insert>

    <insert id="insertFacsSubtypeBatch" parameterType="java.util.List">
        insert into dim_ems_facs_subtype (code, name, parent_code, desc, version) values
        <foreach collection="emsFacsSubtypes" item="subtype" index="index" separator=",">
            (#{subtype.code},#{subtype.name},#{subtype.parent_code},#{subtype.desc},#{subtype.version})
        </foreach>
    </insert>

    <update id="updateFacsSubtype" parameterType="com.ruoyi.ems.domain.EmsFacsSubtype">
        update dim_ems_facs_subtype
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="parentCode != null and parentCode != ''">parent_code = #{parentCode},</if>
            <if test="desc != null">desc = #{desc},</if>
            <if test="version != null">version = #{version},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFacsSubtypeById" parameterType="Long">
        delete from dim_ems_facs_subtype where id = #{id}
    </delete>

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

    <delete id="deleteFacsSubtypeByParentCode" parameterType="String">
        delete from dim_ems_facs_subtype where parent_code = #{code}
    </delete>
</mapper>