<?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.EmsObjModelMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsObjModel" id="objModelResult">
        <result property="id"    column="id"    />
        <result property="modelCode"    column="model_code"    />
        <result property="modelName"    column="model_name"    />
        <result property="objType"    column="obj_type"    />
    </resultMap>

    <sql id="selectObjModelVo">
        select id, model_code, model_name, obj_type from adm_ems_obj_model
    </sql>

    <select id="selectObjModelList" parameterType="com.ruoyi.ems.domain.EmsObjModel" resultMap="objModelResult">
        <include refid="selectObjModelVo"/>
        <where>  
            <if test="modelCode != null  and modelCode != ''"> and model_code = #{modelCode}</if>
            <if test="modelName != null  and modelName != ''"> and model_name like concat('%', #{modelName}, '%')</if>
            <if test="objType != null "> and obj_type = #{objType}</if>
        </where>
    </select>
    
    <select id="selectObjModelById" parameterType="Long" resultMap="objModelResult">
        <include refid="selectObjModelVo"/>
        where id = #{id}
    </select>

    <select id="selectByModelCode" parameterType="String" resultMap="objModelResult">
        <include refid="selectObjModelVo"/>
        where model_code = #{code}
    </select>
        
    <insert id="insertObjModel" parameterType="com.ruoyi.ems.domain.EmsObjModel" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_obj_model
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="modelCode != null and modelCode != ''">model_code,</if>
            <if test="modelName != null and modelName != ''">model_name,</if>
            <if test="objType != null">obj_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="modelCode != null and modelCode != ''">#{modelCode},</if>
            <if test="modelName != null and modelName != ''">#{modelName},</if>
            <if test="objType != null">#{objType},</if>
         </trim>
    </insert>

    <update id="updateObjModel" parameterType="com.ruoyi.ems.domain.EmsObjModel">
        update adm_ems_obj_model
        <trim prefix="SET" suffixOverrides=",">
            <if test="modelCode != null and modelCode != ''">model_code = #{modelCode},</if>
            <if test="modelName != null and modelName != ''">model_name = #{modelName},</if>
            <if test="objType != null">obj_type = #{objType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteObjModelById" parameterType="Long">
        delete from adm_ems_obj_model where id = #{id}
    </delete>

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