<?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.EmsSubsystemMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsSubsystem" id="AdmEmsSubsystemResult">
        <result property="id"    column="id"    />
        <result property="systemCode"    column="system_code"    />
        <result property="systemName"    column="system_name"    />
        <result property="shortName"    column="short_name"    />
        <result property="manFacturer"    column="man_facturer"    />
        <result property="contactPerson"    column="contact_person"    />
        <result property="contactNumber"    column="contact_number"    />
        <result property="maintainerPerson"    column="maintainer_person"    />
        <result property="maintainerNumber"    column="maintainer_number"    />
        <result property="descr"    column="descr"    />
        <result property="modelCode"    column="model_code"    />
    </resultMap>

    <sql id="selectEmsSubsystemVo">
        select id, system_code, system_name, short_name, man_facturer, contact_person, contact_number, maintainer_person, maintainer_number, descr, model_code from adm_ems_subsystem
    </sql>

    <select id="selectEmsSubsystemList" parameterType="com.ruoyi.ems.domain.EmsSubsystem" resultMap="AdmEmsSubsystemResult">
        <include refid="selectEmsSubsystemVo"/>
        <where>  
            <if test="systemCode != null  and systemCode != ''"> and system_code = #{systemCode}</if>
            <if test="systemName != null  and systemName != ''"> and system_name like concat('%', #{systemName}, '%')</if>
            <if test="shortName != null  and shortName != ''"> and short_name like concat('%', #{shortName}, '%')</if>
        </where>
    </select>
    
    <select id="selectEmsSubsystemById" parameterType="Long" resultMap="AdmEmsSubsystemResult">
        <include refid="selectEmsSubsystemVo"/>
        where id = #{id}
    </select>

    <select id="selectEmsSubsystemByCode" parameterType="String" resultMap="AdmEmsSubsystemResult">
        <include refid="selectEmsSubsystemVo"/>
        where system_code = #{systemCode}
    </select>

    <insert id="insertEmsSubsystem" parameterType="com.ruoyi.ems.domain.EmsSubsystem" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_subsystem
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="systemCode != null and systemCode != ''">system_code,</if>
            <if test="systemName != null and systemName != ''">system_name,</if>
            <if test="shortName != null">short_name,</if>
            <if test="manFacturer != null">man_facturer,</if>
            <if test="contactPerson != null">contact_person,</if>
            <if test="contactNumber != null">contact_number,</if>
            <if test="maintainerPerson != null">maintainer_person,</if>
            <if test="maintainerNumber != null">maintainer_number,</if>
            <if test="descr != null">descr,</if>
            <if test="modelCode != null">model_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="systemCode != null and systemCode != ''">#{systemCode},</if>
            <if test="systemName != null and systemName != ''">#{systemName},</if>
            <if test="shortName != null">#{shortName},</if>
            <if test="manFacturer != null">#{manFacturer},</if>
            <if test="contactPerson != null">#{contactPerson},</if>
            <if test="contactNumber != null">#{contactNumber},</if>
            <if test="maintainerPerson != null">#{maintainerPerson},</if>
            <if test="maintainerNumber != null">#{maintainerNumber},</if>
            <if test="descr != null">#{descr},</if>
            <if test="modelCode != null">#{modelCode},</if>
         </trim>
    </insert>

    <update id="updateEmsSubsystem" parameterType="com.ruoyi.ems.domain.EmsSubsystem">
        update adm_ems_subsystem
        <trim prefix="SET" suffixOverrides=",">
            <if test="systemCode != null and systemCode != ''">system_code = #{systemCode},</if>
            <if test="systemName != null and systemName != ''">system_name = #{systemName},</if>
            <if test="shortName != null">short_name = #{shortName},</if>
            <if test="manFacturer != null">man_facturer = #{manFacturer},</if>
            <if test="contactPerson != null">contact_person = #{contactPerson},</if>
            <if test="contactNumber != null">contact_number = #{contactNumber},</if>
            <if test="maintainerPerson != null">maintainer_person = #{maintainerPerson},</if>
            <if test="maintainerNumber != null">maintainer_number = #{maintainerNumber},</if>
            <if test="descr != null">descr = #{descr},</if>
            <if test="modelCode != null">model_code = #{modelCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsSubsystemById" parameterType="Long">
        delete from adm_ems_subsystem where id = #{id}
    </delete>

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