<?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.TWasteWaterMapper">
    
    <resultMap type="TWasteWater" id="TWasteWaterResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="flow"    column="flow"    />
        <result property="waterName"    column="water_name"    />
        <result property="origin"    column="origin"    />
        <result property="wwtp"    column="wwtp"    />
        <result property="dischargeTo"    column="discharge_to"    />
        <result property="severity"    column="severity"    />
        <result property="probability"    column="probability"    />
        <result property="risk"    column="risk"    />
        <result property="residualRisk"    column="residual_risk"    />
        <result property="existsMeasures"    column="exists_measures"    />
        <result property="furtherMeasures"    column="further_measures"    />
        <result property="owner"    column="owner"    />
        <result property="deadline"    column="deadline"    />
        <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="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTWasteWaterVo">
        select d.id, d.plant_code, d.flow, d.water_name, d.origin, d.wwtp, d.discharge_to, d.severity, d.probability, d.risk, d.residual_risk, d.exists_measures, d.further_measures, d.owner, d.deadline, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_waste_water d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTWasteWaterList" parameterType="TWasteWater" resultMap="TWasteWaterResult">
        <include refid="selectTWasteWaterVo"/>
        <where>  
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="flow != null  and flow != ''"> and flow like concat(concat('%', #{flow}), '%')</if>
            <if test="waterName != null  and waterName != ''"> and water_name like concat(concat('%', #{waterName}), '%')</if>
            <if test="origin != null  and origin != ''"> and origin like concat(concat('%', #{origin}), '%')</if>
            <if test="wwtp != null  and wwtp != ''"> and wwtp like concat(concat('%', #{wwtp}), '%')</if>
            <if test="dischargeTo != null  and dischargeTo != ''"> and discharge_to like concat(concat('%', #{dischargeTo}), '%')</if>
            <if test="severity != null  and severity != ''"> and severity like concat(concat('%', #{severity}), '%')</if>
            <if test="probability != null  and probability != ''"> and probability like concat(concat('%', #{probability}), '%')</if>
            <if test="risk != null  and risk != ''"> and risk like concat(concat('%', #{risk}), '%')</if>
            <if test="residualRisk != null  and residualRisk != ''"> and residual_risk like concat(concat('%', #{residualRisk}), '%')</if>
            <if test="existsMeasures != null  and existsMeasures != ''"> and exists_measures like concat(concat('%', #{existsMeasures}), '%')</if>
            <if test="furtherMeasures != null  and furtherMeasures != ''"> and further_measures like concat(concat('%', #{furtherMeasures}), '%')</if>
            <if test="owner != null  and owner != ''"> and owner like concat(concat('%', #{owner}), '%')</if>
            <if test="deadline != null "> and deadline = #{deadline}</if>
            <if test="remarks != null  and remarks != ''"> and remarks like concat(concat('%', #{remarks}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTWasteWaterById" parameterType="Long" resultMap="TWasteWaterResult">
        <include refid="selectTWasteWaterVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTWasteWater" parameterType="TWasteWater">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_waste_water.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_waste_water
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="flow != null">flow,</if>
            <if test="waterName != null">water_name,</if>
            <if test="origin != null">origin,</if>
            <if test="wwtp != null">wwtp,</if>
            <if test="dischargeTo != null">discharge_to,</if>
            <if test="severity != null">severity,</if>
            <if test="probability != null">probability,</if>
            <if test="risk != null">risk,</if>
            <if test="residualRisk != null">residual_risk,</if>
            <if test="existsMeasures != null">exists_measures,</if>
            <if test="furtherMeasures != null">further_measures,</if>
            <if test="owner != null">owner,</if>
            <if test="deadline != null">deadline,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="flow != null">#{flow},</if>
            <if test="waterName != null">#{waterName},</if>
            <if test="origin != null">#{origin},</if>
            <if test="wwtp != null">#{wwtp},</if>
            <if test="dischargeTo != null">#{dischargeTo},</if>
            <if test="severity != null">#{severity},</if>
            <if test="probability != null">#{probability},</if>
            <if test="risk != null">#{risk},</if>
            <if test="residualRisk != null">#{residualRisk},</if>
            <if test="existsMeasures != null">#{existsMeasures},</if>
            <if test="furtherMeasures != null">#{furtherMeasures},</if>
            <if test="owner != null">#{owner},</if>
            <if test="deadline != null">#{deadline},</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>
         </trim>
    </insert>

    <update id="updateTWasteWater" parameterType="TWasteWater">
        update t_waste_water
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="flow != null">flow = #{flow},</if>
            <if test="waterName != null">water_name = #{waterName},</if>
            <if test="origin != null">origin = #{origin},</if>
            <if test="wwtp != null">wwtp = #{wwtp},</if>
            <if test="dischargeTo != null">discharge_to = #{dischargeTo},</if>
            <if test="severity != null">severity = #{severity},</if>
            <if test="probability != null">probability = #{probability},</if>
            <if test="risk != null">risk = #{risk},</if>
            <if test="residualRisk != null">residual_risk = #{residualRisk},</if>
            <if test="existsMeasures != null">exists_measures = #{existsMeasures},</if>
            <if test="furtherMeasures != null">further_measures = #{furtherMeasures},</if>
            <if test="owner != null">owner = #{owner},</if>
            <if test="deadline != null">deadline = #{deadline},</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>
        </trim>
        where id = #{id}
    </update>

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

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