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

    <resultMap type="TMtdItem" id="TMtdItemResult">
        <result property="id"    column="id"    />
        <result property="dailyId"    column="daily_id"    />
        <result property="item"    column="item"    />
        <result property="itemType"    column="item_type"    />
        <result property="description"    column="description"    />
        <result property="actionby"    column="actionby"    />
        <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="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTMtdItemVo">
        select d.id, d.daily_id, d.item, d.description, d.actionby, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id ,s.dept_name from t_mtd_item d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMtdItemList" parameterType="TMtdItem" resultMap="TMtdItemResult">
        <include refid="selectTMtdItemVo"/>
        <where>
            <if test="dailyId != null "> and daily_id = #{dailyId}</if>
            <if test="item != null  and item != ''"> and item = #{item}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="actionby != null  and actionby != ''"> and actionby = #{actionby}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="itemType != null "> and item_type = #{itemType}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTMtdItemById" parameterType="Long" resultMap="TMtdItemResult">
        <include refid="selectTMtdItemVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMtdItem" parameterType="TMtdItem">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_mtd_item.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_mtd_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="dailyId != null">daily_id,</if>
            <if test="item != null">item,</if>
            <if test="description != null">description,</if>
            <if test="actionby != null">actionby,</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="itemType != null">item_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="dailyId != null">#{dailyId},</if>
            <if test="item != null">#{item},</if>
            <if test="description != null">#{description},</if>
            <if test="actionby != null">#{actionby},</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="itemType != null">#{itemType},</if>
         </trim>
    </insert>

    <update id="updateTMtdItem" parameterType="TMtdItem">
        update t_mtd_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="dailyId != null">daily_id = #{dailyId},</if>
            <if test="item != null">item = #{item},</if>
            <if test="description != null">description = #{description},</if>
            <if test="actionby != null">actionby = #{actionby},</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>
        </trim>
        where id = #{id}
    </update>

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


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

    <delete id="deleteTMtdItemByDailyId" parameterType="Long">
        delete from t_mtd_item where daily_id = #{dailyId}
    </delete>



</mapper>
