<?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.project.sems.mapper.TMeasureRecordMapper">

    <resultMap type="TMeasureRecord" id="TMeasureRecordResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="measureId"    column="measure_id"    />
        <result property="measureValue"    column="measure_value"    />
        <result property="measureDate"    column="measure_date"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTMeasureRecordVo">
        select d.id, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.measure_id, d.measure_value, d.measure_date  from t_measure_record d
    </sql>

    <select id="selectTMeasureRecordList" parameterType="TMeasureRecord" resultMap="TMeasureRecordResult">
        <include refid="selectTMeasureRecordVo"/>
        <where>
            <if test="measureId != null  and measureId != ''"> and measure_id = #{measureId}</if>
            <if test="measureValue != null "> and measure_value = #{measureValue}</if>
            <if test="measureDate != null "> and measure_date = #{measureDate}</if>
            and d.del_flag = 0
        </where>
        order by measure_date desc
    </select>

    <select id="selectTMeasureRecordById" parameterType="Long" resultMap="TMeasureRecordResult">
        <include refid="selectTMeasureRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMeasureRecord" parameterType="TMeasureRecord">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_measure_record.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_measure_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="measureId != null">measure_id,</if>
            <if test="measureValue != null">measure_value,</if>
            <if test="measureDate != null">measure_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="measureId != null">#{measureId},</if>
            <if test="measureValue != null">#{measureValue},</if>
            <if test="measureDate != null">#{measureDate},</if>
         </trim>
    </insert>

    <update id="updateTMeasureRecord" parameterType="TMeasureRecord">
        update t_measure_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="measureId != null">measure_id = #{measureId},</if>
            <if test="measureValue != null">measure_value = #{measureValue},</if>
            <if test="measureDate != null">measure_date = #{measureDate},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTMeasureRecordById" parameterType="Long">
        update t_measure_record set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTMeasureRecordByIds" parameterType="String">
        update t_measure_record set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <update id="deleteTMeasureRecordByDate"  parameterType="TMeasureRecord">
        update t_measure_record set del_flag = 2
        <where>
            <if test="measureId != null  and measureId != ''"> and measure_id = #{measureId}</if>
            <if test="measureDate != null "> and measure_date = #{measureDate}</if>
        </where>

    </update>



</mapper>
