<?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.TPvesselMapper">
    
    <resultMap type="TPvessel" id="TPvesselResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="serialnumber"    column="serialnumber"    />
        <result property="tagno"    column="tagno"    />
        <result property="area"    column="area"    />
        <result property="areaowner"    column="areaowner"    />
        <result property="catalogy"    column="catalogy"    />
        <result property="description"    column="description"    />
        <result property="unit"    column="unit"    />
        <result property="manufactory"    column="manufactory"    />
        <result property="sizes"    column="sizes"    />
        <result property="stuff"    column="stuff"    />
        <result property="medium"    column="medium"    />
        <result property="designpressure"    column="designpressure"    />
        <result property="operationpressure"    column="operationpressure"    />
        <result property="designtemp"    column="designtemp"    />
        <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="servicedate"    column="servicedate"    />
        <result property="risk"    column="risk"    />
        <result property="cuistatus"    column="cuistatus"    />
        <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="selectTPvesselVo">
        select d.id, d.plant_code, d.serialnumber, d.tagno, d.area, d.areaowner, d.catalogy, d.description, d.unit, d.manufactory, d.sizes, d.stuff, d.medium, d.designpressure, d.operationpressure, d.designtemp, d.material, d.operationtemp, d.coatingage, d.jacketing, d.heattracing, d.exterenv, d.insulatingmaterial, d.outsidediameter, d.servicedate, d.risk, d.cuistatus, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_pvessel d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTPvesselList" parameterType="TPvessel" resultMap="TPvesselResult">
        <include refid="selectTPvesselVo"/>
        <where>  
            <if test="tagno != null  and tagno != ''"> and tagno like concat(concat('%', #{tagno}), '%')</if>
            <if test="description != null  and description != ''"> and description like concat(concat('%', #{description}), '%')</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.serialnumber asc
    </select>
    
    <select id="selectTPvesselById" parameterType="Long" resultMap="TPvesselResult">
        <include refid="selectTPvesselVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTPvessel" parameterType="TPvessel">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_pvessel.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_pvessel
        <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="tagno != null and tagno != ''">tagno,</if>
            <if test="area != null">area,</if>
            <if test="areaowner != null">areaowner,</if>
            <if test="catalogy != null">catalogy,</if>
            <if test="description != null">description,</if>
            <if test="unit != null">unit,</if>
            <if test="manufactory != null">manufactory,</if>
            <if test="sizes != null">sizes,</if>
            <if test="stuff != null">stuff,</if>
            <if test="medium != null">medium,</if>
            <if test="designpressure != null">designpressure,</if>
            <if test="operationpressure != null">operationpressure,</if>
            <if test="designtemp != null">designtemp,</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="servicedate != null">servicedate,</if>
            <if test="risk != null">risk,</if>
            <if test="cuistatus != null">cuistatus,</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="tagno != null and tagno != ''">#{tagno},</if>
            <if test="area != null">#{area},</if>
            <if test="areaowner != null">#{areaowner},</if>
            <if test="catalogy != null">#{catalogy},</if>
            <if test="description != null">#{description},</if>
            <if test="unit != null">#{unit},</if>
            <if test="manufactory != null">#{manufactory},</if>
            <if test="sizes != null">#{sizes},</if>
            <if test="stuff != null">#{stuff},</if>
            <if test="medium != null">#{medium},</if>
            <if test="designpressure != null">#{designpressure},</if>
            <if test="operationpressure != null">#{operationpressure},</if>
            <if test="designtemp != null">#{designtemp},</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="servicedate != null">#{servicedate},</if>
            <if test="risk != null">#{risk},</if>
            <if test="cuistatus != null">#{cuistatus},</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="updateTPvessel" parameterType="TPvessel">
        update t_pvessel
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="serialnumber != null">serialnumber = #{serialnumber},</if>
            <if test="tagno != null and tagno != ''">tagno = #{tagno},</if>
            <if test="area != null">area = #{area},</if>
            <if test="areaowner != null">areaowner = #{areaowner},</if>
            <if test="catalogy != null">catalogy = #{catalogy},</if>
            <if test="description != null">description = #{description},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="manufactory != null">manufactory = #{manufactory},</if>
            <if test="sizes != null">sizes = #{sizes},</if>
            <if test="stuff != null">stuff = #{stuff},</if>
            <if test="medium != null">medium = #{medium},</if>
            <if test="designpressure != null">designpressure = #{designpressure},</if>
            <if test="operationpressure != null">operationpressure = #{operationpressure},</if>
            <if test="designtemp != null">designtemp = #{designtemp},</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="servicedate != null">servicedate = #{servicedate},</if>
            <if test="risk != null">risk = #{risk},</if>
            <if test="cuistatus != null">cuistatus = #{cuistatus},</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="deleteTPvesselById" parameterType="Long">
        update t_pvessel set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTPvesselByIds" parameterType="String">
        update t_pvessel 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_pvessel 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.cuistatus as dataName FROM t_pvessel d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY cuistatus
        order by dataName
    </select>
</mapper>