<?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.plant.mapper.TMtOpextrackMapper">

    <resultMap type="TMtOpextrack" id="TMtOpextrackResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="ongoing"    column="ongoing"    />
        <result property="finished"    column="finished"    />
        <result property="totalitem"    column="totalitem"    />
        <result property="inputdate"    column="inputdate"    />
        <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="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="meetingId"    column="meeting_id"    />
        <result property="isHis"    column="is_his"    />
        <result property="year"    column="year"    />
        <result property="benefit"    column="benefit"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTMtOpextrackVo">
        select d.id, d.plant_code, d.ongoing, d.finished, d.totalitem, d.inputdate, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks, d.meeting_id, d.is_his, d.year, d.benefit ,s.dept_name from t_mt_opextrack d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMtOpextrackList" parameterType="TMtOpextrack" resultMap="TMtOpextrackResult">
        <include refid="selectTMtOpextrackVo"/>
        <where>
            <if test="year != null "> and year = #{year}</if>
            <if test="benefit != null  and benefit != ''"> and benefit = #{benefit}</if>
            <if test="meetingId != null  and meetingId != ''"> and meeting_id = #{meetingId}</if>
            <if test="meetingId == null  or meetingId == ''"> and is_his = 0</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTMtOpextrackById" parameterType="Long" resultMap="TMtOpextrackResult">
        <include refid="selectTMtOpextrackVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMtOpextrack" parameterType="TMtOpextrack">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_mt_opextrack.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_mt_opextrack
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null">plant_code,</if>
            <if test="ongoing != null">ongoing,</if>
            <if test="finished != null">finished,</if>
            <if test="totalitem != null">totalitem,</if>
            <if test="inputdate != null">inputdate,</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="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="meetingId != null">meeting_id,</if>
            <if test="isHis != null">is_his,</if>
            <if test="year != null">year,</if>
            <if test="benefit != null">benefit,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null">#{plantCode},</if>
            <if test="ongoing != null">#{ongoing},</if>
            <if test="finished != null">#{finished},</if>
            <if test="totalitem != null">#{totalitem},</if>
            <if test="inputdate != null">#{inputdate},</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="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="meetingId != null">#{meetingId},</if>
            <if test="isHis != null">#{isHis},</if>
            <if test="year != null">#{year},</if>
            <if test="benefit != null">#{benefit},</if>
         </trim>
    </insert>

    <update id="updateTMtOpextrack" parameterType="TMtOpextrack">
        update t_mt_opextrack
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="ongoing != null">ongoing = #{ongoing},</if>
            <if test="finished != null">finished = #{finished},</if>
            <if test="totalitem != null">totalitem = #{totalitem},</if>
            <if test="inputdate != null">inputdate = #{inputdate},</if>
            <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="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="meetingId != null">meeting_id = #{meetingId},</if>
            <if test="isHis != null">is_his = #{isHis},</if>
            <if test="year != null">year = #{year},</if>
            <if test="benefit != null">benefit = #{benefit},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
