<?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.AdmEmsIndexRangeMapper">

    <resultMap type="com.ruoyi.ems.domain.AdmEmsIndexRange" id="AdmEmsIndexRangeResult">
        <result property="id" column="id"/>
        <result property="objCode" column="obj_code"/>
        <result property="objType" column="obj_type"/>
        <result property="indexName" column="index_name"/>
        <result property="indexDesc" column="index_desc"/>
        <result property="indexUpperLimit" column="index_upper_limit"/>
        <result property="indexLowerLimit" column="index_lower_limit"/>
    </resultMap>

    <sql id="selectAdmEmsIndexRangeVo">
        select id, obj_code, obj_type, index_name, index_desc, index_upper_limit, index_lower_limit
        from adm_ems_index_range
    </sql>

    <select id="selectAdmEmsIndexRangeList" parameterType="com.ruoyi.ems.domain.AdmEmsIndexRange"
            resultMap="AdmEmsIndexRangeResult">
        <include refid="selectAdmEmsIndexRangeVo"/>
        <where>
            <if test="objType != null ">and obj_type = #{objType}</if>
            <if test="indexName != null  and indexName != ''">and index_name like concat('%', #{indexName}, '%')</if>
            <if test="indexDesc != null  and indexDesc != ''">and index_desc = #{indexDesc}</if>
        </where>
    </select>

    <select id="selectAdmEmsIndexRangeById" parameterType="Long" resultMap="AdmEmsIndexRangeResult">
        <include refid="selectAdmEmsIndexRangeVo"/>
        where id = #{id}
    </select>

    <insert id="insertAdmEmsIndexRange" parameterType="com.ruoyi.ems.domain.AdmEmsIndexRange" useGeneratedKeys="true"
            keyProperty="id">
        insert into adm_ems_index_range
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objCode != null and objCode != ''">obj_code,</if>
            <if test="objType != null">obj_type,</if>
            <if test="indexName != null and indexName != ''">index_name,</if>
            <if test="indexDesc != null">index_desc,</if>
            <if test="indexUpperLimit != null">index_upper_limit,</if>
            <if test="indexLowerLimit != null">index_lower_limit,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objCode != null and objCode != ''">#{objCode},</if>
            <if test="objType != null">#{objType},</if>
            <if test="indexName != null and indexName != ''">#{indexName},</if>
            <if test="indexDesc != null">#{indexDesc},</if>
            <if test="indexUpperLimit != null">#{indexUpperLimit},</if>
            <if test="indexLowerLimit != null">#{indexLowerLimit},</if>
        </trim>
    </insert>

    <update id="updateAdmEmsIndexRange" parameterType="com.ruoyi.ems.domain.AdmEmsIndexRange">
        update adm_ems_index_range
        <trim prefix="SET" suffixOverrides=",">
            <if test="objCode != null and objCode != ''">obj_code = #{objCode},</if>
            <if test="objType != null">obj_type = #{objType},</if>
            <if test="indexName != null and indexName != ''">index_name = #{indexName},</if>
            <if test="indexDesc != null">index_desc = #{indexDesc},</if>
            <if test="indexUpperLimit != null">index_upper_limit = #{indexUpperLimit},</if>
            <if test="indexLowerLimit != null">index_lower_limit = #{indexLowerLimit},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAdmEmsIndexRangeById" parameterType="Long">
        delete
        from adm_ems_index_range
        where id = #{id}
    </delete>

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

    <select id="selectAdmEmsIndexRange" resultType="Map">
        select indexRange.id,
               obj_code objCode,
               obj_type objType,
               index_name indexName,
               index_desc indexDesc,
               index_upper_limit indexUpperLimit,
               index_lower_limit indexLowerLimit,
               facs.facs_category facsCategory,
               facs.facs_name facsName
        FROM adm_ems_index_range indexRange
                 LEFT JOIN adm_ems_facs facs ON indexRange.obj_code = facs.facs_code
            AND indexRange.obj_type = 1
    </select>

</mapper>
