<?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.ehs.mapper.TEnvironapprcontMapper">
    
    <resultMap type="TEnvironapprcont" id="TEnvironapprcontResult">
        <result property="id"    column="id"    />
        <result property="emissionname"    column="emissionname"    />
        <result property="category"    column="category"    />
        <result property="year"    column="year"    />
        <result property="emissions"    column="emissions"    />
        <result property="contents"    column="contents"    />
        <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="pid"    column="pid"    />
        <result property="deptName" column="dept_name" />
        <result property="pname" column="approvalname" />
    </resultMap>

    <sql id="selectTEnvironapprcontVo">
        select d.id, d.emissionname, d.category, d.year, d.emissions, d.contents, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks, d.pid ,s.dept_name, t.approvalname from t_environapprcont d
      left join sys_dept s on s.dept_id = d.dept_id
      left join t_environapproval t on t.id = d.pid
    </sql>

    <select id="selectTEnvironapprcontList" parameterType="TEnvironapprcont" resultMap="TEnvironapprcontResult">
        <include refid="selectTEnvironapprcontVo"/>
        <where>  
            <if test="emissionname != null  and emissionname != ''"> and emissionname like concat(concat('%', #{emissionname}), '%')</if>
            <if test="category != null  and category != ''"> and category = #{category}</if>
            <if test="year != null "> and year = #{year}</if>
            <if test="emissions != null "> and emissions like concat(concat('%', #{emissions}), '%')</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="pid != null  and pid != ''"> and pid = #{pid}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTEnvironapprcontById" parameterType="Long" resultMap="TEnvironapprcontResult">
        <include refid="selectTEnvironapprcontVo"/>
        where d.id = #{id}
    </select>
        
    <insert id="insertTEnvironapprcont" parameterType="TEnvironapprcont">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_environapprcont.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_environapprcont
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="emissionname != null">emissionname,</if>
            <if test="category != null">category,</if>
            <if test="year != null">year,</if>
            <if test="emissions != null">emissions,</if>
            <if test="contents != null">contents,</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="pid != null">pid,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="emissionname != null">#{emissionname},</if>
            <if test="category != null">#{category},</if>
            <if test="year != null">#{year},</if>
            <if test="emissions != null">#{emissions},</if>
            <if test="contents != null">#{contents},</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="pid != null">#{pid},</if>
         </trim>
    </insert>

    <update id="updateTEnvironapprcont" parameterType="TEnvironapprcont">
        update t_environapprcont
        <trim prefix="SET" suffixOverrides=",">
            <if test="emissionname != null">emissionname = #{emissionname},</if>
            <if test="category != null">category = #{category},</if>
            <if test="year != null">year = #{year},</if>
            <if test="emissions != null">emissions = #{emissions},</if>
            <if test="contents != null">contents = #{contents},</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="pid != null">pid = #{pid},</if>
        </trim>
        where d.id = #{id}
    </update>

    <update id="deleteTEnvironapprcontById" parameterType="Long">
        update t_environapprcont set del_flag = 2 where d.id = #{id}
    </update>

    <update id="deleteTEnvironapprcontByIds" parameterType="String">
        update t_environapprcont set del_flag = 2 where d.id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>