<?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.DevcTypeMapper">
    
    <resultMap type="com.ruoyi.ems.domain.DevcType" id="devcTypeResult">
        <result property="id"    column="id"    />
        <result property="typeCode"    column="type_code"    />
        <result property="typeName"    column="type_name"    />
    </resultMap>

    <sql id="selectDevcTypeVo">
        select id, type_code, type_name from dim_devc_type
    </sql>

    <select id="selectDevcTypeList" parameterType="com.ruoyi.ems.domain.DevcType" resultMap="devcTypeResult">
        <include refid="selectDevcTypeVo"/>
        <where>  
            <if test="typeCode != null "> and type_code = #{typeCode}</if>
            <if test="typeName != null  and typeName != ''"> and type_name like concat('%', #{typeName}, '%')</if>
        </where>
    </select>
    
    <select id="selectDevcTypeById" parameterType="Long" resultMap="devcTypeResult">
        <include refid="selectDevcTypeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertDevcType" parameterType="com.ruoyi.ems.domain.DevcType" useGeneratedKeys="true" keyProperty="id">
        insert into dim_devc_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeCode != null">type_code,</if>
            <if test="typeName != null and typeName != ''">type_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeCode != null">#{typeCode},</if>
            <if test="typeName != null and typeName != ''">#{typeName},</if>
         </trim>
    </insert>

    <update id="updateDevcType" parameterType="com.ruoyi.ems.domain.DevcType">
        update dim_devc_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="typeCode != null">type_code = #{typeCode},</if>
            <if test="typeName != null and typeName != ''">type_name = #{typeName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDevcTypeById" parameterType="Long">
        delete from dim_devc_type where id = #{id}
    </delete>

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