<?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.cui.mapper.TPipeMapper">
    
    <resultMap type="TPipe" id="TPipeResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="serialnumber"    column="serialnumber"    />
        <result property="pipeno"    column="pipeno"    />
        <result property="pipename"    column="pipename"    />
        <result property="unit"    column="unit"    />
        <result property="servicedate"    column="servicedate"    />
        <result property="pipelength"    column="pipelength"    />
        <result property="starting"    column="starting"    />
        <result property="ending"    column="ending"    />
        <result property="medium"    column="medium"    />
        <result property="material"    column="material"    />
        <result property="operationtemp"    column="operationtemp"    />
        <result property="coatingage"    column="coatingage"    />
        <result property="jacketing"    column="jacketing"    />
        <result property="heattracing"    column="heattracing"    />
        <result property="exterenv"    column="exterenv"    />
        <result property="insulatingmaterial"    column="insulatingmaterial"    />
        <result property="outsidediameter"    column="outsidediameter"    />
        <result property="risk"    column="risk"    />
        <result property="fieldwalkdown"    column="fieldwalkdown"    />
        <result property="inspector"    column="inspector"    />
        <result property="inspectingdate"    column="inspectingdate"    />
        <result property="nextinspectdate"    column="nextinspectdate"    />
        <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="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTPipeVo">
        select d.id, d.plant_code, d.serialnumber, d.pipeno, d.pipename, d.unit, d.servicedate, d.pipelength, d.starting, d.ending, d.medium, d.material, d.operationtemp, d.coatingage, d.jacketing, d.heattracing, d.exterenv, d.insulatingmaterial, d.outsidediameter, d.risk, d.fieldwalkdown, d.inspector, d.inspectingdate, d.nextinspectdate, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_pipe d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTPipeList" parameterType="TPipe" resultMap="TPipeResult">
        <include refid="selectTPipeVo"/>
        <where>  
            <if test="pipeno != null  and pipeno != ''"> and pipeno like concat(concat('%', #{pipeno}), '%')</if>
            <if test="pipename != null  and pipename != ''"> and pipename like concat(concat('%', #{pipename}), '%')</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="material != null  and material != ''"> and material like concat(concat('%', #{material}), '%')</if>
            <if test="risk != null  and risk != ''"> and risk like concat(concat('%', #{risk}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.unit asc, d.serialnumber asc
    </select>

    <select id="selectList" parameterType="TPipe" resultMap="TPipeResult">
        <include refid="selectTPipeVo"/>
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.unit asc, d.serialnumber asc
    </select>
    
    <select id="selectTPipeById" parameterType="Long" resultMap="TPipeResult">
        <include refid="selectTPipeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTPipe" parameterType="TPipe">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_pipe.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_pipe
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="serialnumber != null">serialnumber,</if>
            <if test="pipeno != null and pipeno != ''">pipeno,</if>
            <if test="pipename != null">pipename,</if>
            <if test="unit != null">unit,</if>
            <if test="servicedate != null">servicedate,</if>
            <if test="pipelength != null">pipelength,</if>
            <if test="starting != null">starting,</if>
            <if test="ending != null">ending,</if>
            <if test="medium != null">medium,</if>
            <if test="material != null">material,</if>
            <if test="operationtemp != null">operationtemp,</if>
            <if test="coatingage != null">coatingage,</if>
            <if test="jacketing != null">jacketing,</if>
            <if test="heattracing != null">heattracing,</if>
            <if test="exterenv != null">exterenv,</if>
            <if test="insulatingmaterial != null">insulatingmaterial,</if>
            <if test="outsidediameter != null">outsidediameter,</if>
            <if test="risk != null">risk,</if>
            <if test="fieldwalkdown != null">fieldwalkdown,</if>
            <if test="inspector != null">inspector,</if>
            <if test="inspectingdate != null">inspectingdate,</if>
            <if test="nextinspectdate != null">nextinspectdate,</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="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="serialnumber != null">#{serialnumber},</if>
            <if test="pipeno != null and pipeno != ''">#{pipeno},</if>
            <if test="pipename != null">#{pipename},</if>
            <if test="unit != null">#{unit},</if>
            <if test="servicedate != null">#{servicedate},</if>
            <if test="pipelength != null">#{pipelength},</if>
            <if test="starting != null">#{starting},</if>
            <if test="ending != null">#{ending},</if>
            <if test="medium != null">#{medium},</if>
            <if test="material != null">#{material},</if>
            <if test="operationtemp != null">#{operationtemp},</if>
            <if test="coatingage != null">#{coatingage},</if>
            <if test="jacketing != null">#{jacketing},</if>
            <if test="heattracing != null">#{heattracing},</if>
            <if test="exterenv != null">#{exterenv},</if>
            <if test="insulatingmaterial != null">#{insulatingmaterial},</if>
            <if test="outsidediameter != null">#{outsidediameter},</if>
            <if test="risk != null">#{risk},</if>
            <if test="fieldwalkdown != null">#{fieldwalkdown},</if>
            <if test="inspector != null">#{inspector},</if>
            <if test="inspectingdate != null">#{inspectingdate},</if>
            <if test="nextinspectdate != null">#{nextinspectdate},</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="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTPipe" parameterType="TPipe">
        update t_pipe
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="serialnumber != null">serialnumber = #{serialnumber},</if>
            <if test="pipeno != null and pipeno != ''">pipeno = #{pipeno},</if>
            <if test="pipename != null">pipename = #{pipename},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="servicedate != null">servicedate = #{servicedate},</if>
            <if test="pipelength != null">pipelength = #{pipelength},</if>
            <if test="starting != null">starting = #{starting},</if>
            <if test="ending != null">ending = #{ending},</if>
            <if test="medium != null">medium = #{medium},</if>
            <if test="material != null">material = #{material},</if>
            <if test="operationtemp != null">operationtemp = #{operationtemp},</if>
            <if test="coatingage != null">coatingage = #{coatingage},</if>
            <if test="jacketing != null">jacketing = #{jacketing},</if>
            <if test="heattracing != null">heattracing = #{heattracing},</if>
            <if test="exterenv != null">exterenv = #{exterenv},</if>
            <if test="insulatingmaterial != null">insulatingmaterial = #{insulatingmaterial},</if>
            <if test="outsidediameter != null">outsidediameter = #{outsidediameter},</if>
            <if test="risk != null">risk = #{risk},</if>
            <if test="fieldwalkdown != null">fieldwalkdown = #{fieldwalkdown},</if>
            <if test="inspector != null">inspector = #{inspector},</if>
            <if test="inspectingdate != null">inspectingdate = #{inspectingdate},</if>
            <if test="nextinspectdate != null">nextinspectdate = #{nextinspectdate},</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="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

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

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


    <select id="selectRiskData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum,d.risk as dataName FROM t_pipe d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY risk
        order by dataName
    </select>

    <select id="selectStatusData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum,d.fieldwalkdown as dataName FROM t_pipe d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY fieldwalkdown
        order by dataName
    </select>
</mapper>