<?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.meas.system.mapper.MeasStatusMapper">

    <resultMap type="MeasStatus" id="MeasStatusResult">
            <result property="id" column="id"/>
            <result property="status" column="status"/>
            <result property="index" column="index"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectMeasStatusVo">
        select id, status, `index`, create_by, create_time, update_by, update_time
        from meas_status
    </sql>

    <select id="selectMeasStatusList" parameterType="MeasStatus" resultMap="MeasStatusResult">
        <include refid="selectMeasStatusVo"/>
        <where>
                        <if test="status != null  and status != ''">
                            and status = #{status}
                        </if>
                        <if test="index != null ">
                            and `index` = #{index}
                        </if>
        </where>
        order by `index` asc
    </select>

    <select id="selectMeasStatusById" parameterType="Long"
            resultMap="MeasStatusResult">
            <include refid="selectMeasStatusVo"/>
            where id = #{id}
    </select>

    <insert id="insertMeasStatus" parameterType="MeasStatus" useGeneratedKeys="true" keyProperty="id">
        insert into meas_status
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="status != null and status != ''">status,
                    </if>
                    <if test="index != null">`index`,
                    </if>
                    <if test="createBy != null">create_by,
                    </if>
                    <if test="createTime != null">create_time,
                    </if>
                    <if test="updateBy != null">update_by,
                    </if>
                    <if test="updateTime != null">update_time,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="status != null and status != ''">#{status},
                    </if>
                    <if test="index != null">#{index},
                    </if>
                    <if test="createBy != null">#{createBy},
                    </if>
                    <if test="createTime != null">#{createTime},
                    </if>
                    <if test="updateBy != null">#{updateBy},
                    </if>
                    <if test="updateTime != null">#{updateTime},
                    </if>
        </trim>
    </insert>

    <update id="updateMeasStatus" parameterType="MeasStatus">
        update meas_status
        <trim prefix="SET" suffixOverrides=",">
                    <if test="status != null and status != ''">status =
                        #{status},
                    </if>
                    <if test="index != null">`index` =
                        #{index},
                    </if>
                    <if test="createBy != null">create_by =
                        #{createBy},
                    </if>
                    <if test="createTime != null">create_time =
                        #{createTime},
                    </if>
                    <if test="updateBy != null">update_by =
                        #{updateBy},
                    </if>
                    <if test="updateTime != null">update_time =
                        #{updateTime},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMeasStatusById" parameterType="Long">
        delete
        from meas_status where id = #{id}
    </delete>

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

    <select id="getOption" resultType="String">
        select status from meas_status order by `index` asc
    </select>
</mapper>