<?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.base.mapper.TBasePointMapper">

    <resultMap type="TBasePoint" id="TBasePointResult">
        <id property="pointId"    column="point_id"    />
        <result property="netTestValue"    column="net_test_value"    />
        <result property="leakageDegree"    column="leakage_degree"    />
        <result property="plantId"    column="plant_id"    />
        <result property="plantType"    column="plant_type"    />
        <result property="plantName"    column="plant_name"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="regionId"    column="region_id"    />
        <result property="regionName"    column="region_name"    />
        <result property="regionCode"    column="region_code"    />
        <result property="devId"    column="dev_id"    />
        <result property="devName"    column="dev_name"    />
        <result property="devCode"    column="dev_code"    />
        <result property="medium"    column="medium"    />
        <result property="mediumType"    column="medium_type"    />
        <result property="pointType"    column="point_type"    />
        <result property="layer"    column="layer"    />
        <result property="groupPosition"    column="group_position"    />
        <result property="pointPosition"    column="point_position"    />
        <result property="groupCode"    column="group_code"    />
        <result property="extendCode"    column="extend_code"    />
        <result property="subPointType"    column="sub_point_type"    />
        <result property="dia"    column="dia"    />
        <result property="unarrive"    column="unarrive"    />
        <result property="unarriveReason"    column="unarrive_reason"    />
        <result property="keepWarm"    column="keep_warm"    />
        <result property="temperature"    column="temperature"    />
        <result property="pressure"    column="pressure"    />
        <result property="runTime"    column="run_time"    />
        <result property="pidNo"    column="pid_no"    />
        <result property="pidUrl"    column="pid_url"    />
        <result property="picNo"    column="pic_no"    />
        <result property="picUrl"    column="pic_url"    />
        <result property="tocMark"    column="toc_mark"    />
        <result property="methaneMark"    column="methane_mark"    />
        <result property="vocsMark"    column="vocs_mark"    />
        <result property="remarks"    column="remarks"    />
        <result property="approveStatus"    column="approve_status"    />
        <result property="approveTime"    column="approve_time"    />
        <result property="deptId"    column="dept_id"    />
        <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="updater"    column="updater"    />
        <result property="updatedate"    column="updatedate"    />
    </resultMap>

    <sql id="selectTBasePointVo">
        select point_id, net_test_value, leakage_degree, plant_id, region_id, dev_id, medium, medium_type, point_type, layer, group_position, point_position, group_code, extend_code, sub_point_type, dia, unarrive, unarrive_reason, keep_warm, temperature, pressure, run_time, pid_no, pid_url, pic_no, pic_url, toc_mark, methane_mark, vocs_mark, remarks, approve_status, approve_time, dept_id, del_flag, creater_code, createdate, updater_code, updatedate from t_base_point
    </sql>

    <select id="selectTBasePointList" parameterType="TBasePoint" resultMap="TBasePointResult">
        select d.point_id, d.net_test_value, d.leakage_degree, d.plant_id,bp.plant_name,bp.plant_type,bp.plant_code, d.region_id,br.region_code,br.region_name, d.dev_id,bd.dev_code,bd.`dev_describe` dev_name,d.medium, d.medium_type, d.point_type, d.layer, d.group_position, d.point_position, d.group_code, d.extend_code, d.sub_point_type, d.dia, d.unarrive, d.unarrive_reason, d.keep_warm, d.temperature, d.pressure, d.run_time, d.pid_no, d.pid_url, d.pic_no, d.pic_url, d.toc_mark, d.methane_mark, d.vocs_mark, d.remarks, d.approve_status, d.approve_time, d.dept_id, d.del_flag, d.creater_code, d.createdate, su.user_name updater, d.updatedate from t_base_point d
        left join sys_user su on su.user_id = d.updater_code
        left join t_base_plant bp on bp.plant_id = d.plant_id
        left join t_base_region br on br.region_id = d.region_id
        left join t_base_device bd on bd.dev_id = d.dev_id
        <where>
            <if test="netTestValue != null "> and d.net_test_value = #{netTestValue}</if>
            <if test="leakageDegree != null  and leakageDegree != ''"> and d.leakage_degree = #{leakageDegree}</if>
            <if test="plantId != null "> and d.plant_id = #{plantId}</if>
            <if test="regionId != null "> and d.region_id = #{regionId}</if>
            <if test="devId != null "> and d.dev_id = #{devId}</if>
            <if test="medium != null  and medium != ''"> and d.medium = #{medium}</if>
            <if test="mediumType != null  and mediumType != ''"> and d.medium_type = #{mediumType}</if>
            <if test="pointType != null  and pointType != ''"> and d.point_type = #{pointType}</if>
            <if test="layer != null  and layer != ''"> and d.layer = #{layer}</if>
            <if test="groupPosition != null  and groupPosition != ''"> and d.group_position = #{groupPosition}</if>
            <if test="pointPosition != null  and pointPosition != ''"> and d.point_position = #{pointPosition}</if>
            <if test="groupCode != null  and groupCode != ''"> and d.group_code = #{groupCode}</if>
            <if test="extendCode != null  and extendCode != ''"> and d.extend_code = #{extendCode}</if>
            <if test="subPointType != null  and subPointType != ''"> and d.sub_point_type = #{subPointType}</if>
            <if test="dia != null  and dia != ''"> and d.dia = #{dia}</if>
            <if test="unarrive != null  and unarrive != ''"> and d.unarrive = #{unarrive}</if>
            <if test="unarriveReason != null  and unarriveReason != ''"> and d.unarrive_reason = #{unarriveReason}</if>
            <if test="keepWarm != null  and keepWarm != ''"> and d.keep_warm = #{keepWarm}</if>
            <if test="temperature != null  and temperature != ''"> and d.temperature = #{temperature}</if>
            <if test="pressure != null  and pressure != ''"> and d.pressure = #{pressure}</if>
            <if test="runTime != null "> and d.run_time = #{runTime}</if>
            <if test="pidNo != null  and pidNo != ''"> and d.pid_no = #{pidNo}</if>
            <if test="pidUrl != null  and pidUrl != ''"> and d.pid_url = #{pidUrl}</if>
            <if test="picNo != null  and picNo != ''"> and d.pic_no = #{picNo}</if>
            <if test="picUrl != null  and picUrl != ''"> and d.pic_url = #{picUrl}</if>
            <if test="tocMark != null  and tocMark != ''"> and d.toc_mark = #{tocMark}</if>
            <if test="methaneMark != null  and methaneMark != ''"> and d.methane_mark = #{methaneMark}</if>
            <if test="vocsMark != null  and vocsMark != ''"> and d.vocs_mark = #{vocsMark}</if>
            <if test="remarks != null  and remarks != ''"> and d.remarks = #{remarks}</if>
            <if test="approveStatus != null "> and d.approve_status = #{approveStatus}</if>
            <if test="approveTime != null "> and d.approve_time = #{approveTime}</if>
            <if test="deptId != null "> and d.dept_id = #{deptId}</if>
            <if test="createrCode != null "> and d.creater_code = #{createrCode}</if>
            <if test="createdate != null "> and d.createdate = #{createdate}</if>
            <if test="updaterCode != null "> and d.updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and d.updatedate = #{updatedate}</if>
            and d.del_flag=0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScopePlant}
    </select>

    <select id="selectTBasePointListByPlan" parameterType="TBasePoint" resultMap="TBasePointResult">
    select d.point_id, d.net_test_value, d.leakage_degree, d.plant_id,bp.plant_name,bp.plant_type,bp.plant_code, d.region_id,br.region_code,br.region_name, d.dev_id,bd.dev_code,bd.`dev_describe` dev_name,d.medium, d.medium_type, d.point_type, d.layer, d.group_position, d.point_position, d.group_code, d.extend_code, d.sub_point_type, d.dia, d.unarrive, d.unarrive_reason, d.keep_warm, d.temperature, d.pressure, d.run_time, d.pid_no, d.pid_url, d.pic_no, d.pic_url, d.toc_mark, d.methane_mark, d.vocs_mark, d.remarks, d.approve_status, d.approve_time, d.dept_id, d.del_flag, d.creater_code, d.createdate, su.user_name updater, d.updatedate
    from t_base_point d
             left join sys_user su on su.user_id = d.updater_code
             left join t_base_plant bp on bp.plant_id = d.plant_id
             left join t_base_region br on br.region_id = d.region_id
             left join t_base_device bd on bd.dev_id = d.dev_id
        <where>
            and point_id in (select point_id
            from t_check_checkpoints
            where plan_id = #{planId})
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScopePlant}
    </select>

    <select id="selectTBasePointListNotInPlan" parameterType="TBasePoint" resultMap="TBasePointResult">
        select d.point_id, d.net_test_value, d.leakage_degree, d.plant_id,bp.plant_name,bp.plant_type,bp.plant_code, d.region_id,br.region_code,br.region_name, d.dev_id,bd.dev_code,bd.`dev_describe` dev_name,d.medium, d.medium_type, d.point_type, d.layer, d.group_position, d.point_position, d.group_code, d.extend_code, d.sub_point_type, d.dia, d.unarrive, d.unarrive_reason, d.keep_warm, d.temperature, d.pressure, d.run_time, d.pid_no, d.pid_url, d.pic_no, d.pic_url, d.toc_mark, d.methane_mark, d.vocs_mark, d.remarks, d.approve_status, d.approve_time, d.dept_id, d.del_flag, d.creater_code, d.createdate, su.user_name updater, d.updatedate
        from t_base_point d
                 left join sys_user su on su.user_id = d.updater_code
                 left join t_base_plant bp on bp.plant_id = d.plant_id
                 left join t_base_region br on br.region_id = d.region_id
                 left join t_base_device bd on bd.dev_id = d.dev_id
        where point_id not in (select point_id
                           from t_check_checkpoints
                           where plan_id = #{planId}) and d.del_flag=0 and d.plant_id= #{plantId}
    </select>

    <select id="selectTBasePointById" parameterType="Long" resultMap="TBasePointResult">
        <include refid="selectTBasePointVo"/>
        where point_id = #{pointId}
    </select>

    <select id="selectTBasePointByGroupCodeAndExtendCode" parameterType="TBasePoint" resultMap="TBasePointResult">
        <include refid="selectTBasePointVo"/>
        <where>
            <if test="pointId != null "> and point_id != #{pointId}</if>
            <if test="plantId != null "> and plant_id = #{plantId}</if>
            <if test="regionId != null "> and region_id = #{regionId}</if>
            <if test="devId != null "> and dev_id = #{devId}</if>
            <if test="groupCode != null  and groupCode != ''"> and group_code = #{groupCode}</if>
            <if test="extendCode != null  and extendCode != ''"> and extend_code = #{extendCode}</if>
            and del_flag=0
        </where>
    </select>

    <insert id="insertTBasePoint" parameterType="TBasePoint" useGeneratedKeys="true" keyProperty="pointId">
        insert into t_base_point
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="netTestValue != null">net_test_value,</if>
            <if test="leakageDegree != null">leakage_degree,</if>
            <if test="plantId != null">plant_id,</if>
            <if test="regionId != null">region_id,</if>
            <if test="devId != null">dev_id,</if>
            <if test="medium != null">medium,</if>
            <if test="mediumType != null">medium_type,</if>
            <if test="pointType != null">point_type,</if>
            <if test="layer != null">layer,</if>
            <if test="groupPosition != null">group_position,</if>
            <if test="pointPosition != null">point_position,</if>
            <if test="groupCode != null">group_code,</if>
            <if test="extendCode != null">extend_code,</if>
            <if test="subPointType != null">sub_point_type,</if>
            <if test="dia != null">dia,</if>
            <if test="unarrive != null">unarrive,</if>
            <if test="unarriveReason != null">unarrive_reason,</if>
            <if test="keepWarm != null">keep_warm,</if>
            <if test="temperature != null">temperature,</if>
            <if test="pressure != null">pressure,</if>
            <if test="runTime != null">run_time,</if>
            <if test="pidNo != null">pid_no,</if>
            <if test="pidUrl != null">pid_url,</if>
            <if test="picNo != null">pic_no,</if>
            <if test="picUrl != null">pic_url,</if>
            <if test="tocMark != null">toc_mark,</if>
            <if test="methaneMark != null">methane_mark,</if>
            <if test="vocsMark != null">vocs_mark,</if>
            <if test="remarks != null">remarks,</if>
            <if test="approveStatus != null">approve_status,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            createdate,
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="netTestValue != null">#{netTestValue},</if>
            <if test="leakageDegree != null">#{leakageDegree},</if>
            <if test="plantId != null">#{plantId},</if>
            <if test="regionId != null">#{regionId},</if>
            <if test="devId != null">#{devId},</if>
            <if test="medium != null">#{medium},</if>
            <if test="mediumType != null">#{mediumType},</if>
            <if test="pointType != null">#{pointType},</if>
            <if test="layer != null">#{layer},</if>
            <if test="groupPosition != null">#{groupPosition},</if>
            <if test="pointPosition != null">#{pointPosition},</if>
            <if test="groupCode != null">#{groupCode},</if>
            <if test="extendCode != null">#{extendCode},</if>
            <if test="subPointType != null">#{subPointType},</if>
            <if test="dia != null">#{dia},</if>
            <if test="unarrive != null">#{unarrive},</if>
            <if test="unarriveReason != null">#{unarriveReason},</if>
            <if test="keepWarm != null">#{keepWarm},</if>
            <if test="temperature != null">#{temperature},</if>
            <if test="pressure != null">#{pressure},</if>
            <if test="runTime != null">#{runTime},</if>
            <if test="pidNo != null">#{pidNo},</if>
            <if test="pidUrl != null">#{pidUrl},</if>
            <if test="picNo != null">#{picNo},</if>
            <if test="picUrl != null">#{picUrl},</if>
            <if test="tocMark != null">#{tocMark},</if>
            <if test="methaneMark != null">#{methaneMark},</if>
            <if test="vocsMark != null">#{vocsMark},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="approveStatus != null">#{approveStatus},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            sysdate(),
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
         </trim>
    </insert>

    <update id="updateTBasePoint" parameterType="TBasePoint">
        update t_base_point
        <trim prefix="SET" suffixOverrides=",">
            <if test="netTestValue != null">net_test_value = #{netTestValue},</if>
            <if test="leakageDegree != null">leakage_degree = #{leakageDegree},</if>
            <if test="plantId != null">plant_id = #{plantId},</if>
            <if test="regionId != null">region_id = #{regionId},</if>
            <if test="devId != null">dev_id = #{devId},</if>
            <if test="medium != null">medium = #{medium},</if>
            <if test="mediumType != null">medium_type = #{mediumType},</if>
            <if test="pointType != null">point_type = #{pointType},</if>
            <if test="layer != null">layer = #{layer},</if>
            <if test="groupPosition != null">group_position = #{groupPosition},</if>
            <if test="pointPosition != null">point_position = #{pointPosition},</if>
            <if test="groupCode != null">group_code = #{groupCode},</if>
            <if test="extendCode != null">extend_code = #{extendCode},</if>
            <if test="subPointType != null">sub_point_type = #{subPointType},</if>
            <if test="dia != null">dia = #{dia},</if>
            <if test="unarrive != null">unarrive = #{unarrive},</if>
            <if test="unarriveReason != null">unarrive_reason = #{unarriveReason},</if>
            <if test="keepWarm != null">keep_warm = #{keepWarm},</if>
            <if test="temperature != null">temperature = #{temperature},</if>
            <if test="pressure != null">pressure = #{pressure},</if>
            <if test="runTime != null">run_time = #{runTime},</if>
            <if test="pidNo != null">pid_no = #{pidNo},</if>
            <if test="pidUrl != null">pid_url = #{pidUrl},</if>
            <if test="picNo != null">pic_no = #{picNo},</if>
            <if test="picUrl != null">pic_url = #{picUrl},</if>
            <if test="tocMark != null">toc_mark = #{tocMark},</if>
            <if test="methaneMark != null">methane_mark = #{methaneMark},</if>
            <if test="vocsMark != null">vocs_mark = #{vocsMark},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="approveStatus != null">approve_status = #{approveStatus},</if>
            <if test="approveTime != null">approve_time = #{approveTime},</if>
            <if test="deptId != null">dept_id = #{deptId},</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>
        </trim>
        where point_id = #{pointId}
    </update>

    <delete id="deleteTBasePointById" parameterType="Long">
        update t_base_point set del_flag=1 where point_id = #{pointId}
    </delete>

    <delete id="deleteTBasePointByIds" parameterType="String">
        update t_base_point set del_flag=1 where point_id in
        <foreach item="pointId" collection="array" open="(" separator="," close=")">
            #{pointId}
        </foreach>
    </delete>

    <update id="updateTBasePointByPointIds" parameterType="TBaseRegion">
        update t_base_point set approve_status=#{approveStatus},approve_time=#{approveTime}
        <where>
            point_id in
            <foreach item="pointId" collection="pointIds" open="(" separator="," close=")">
                #{pointId}
            </foreach>
            <if test="approveStatus ==1">
                and approve_status=0
            </if>
            <if test="approveStatus ==2">
                and approve_status=1
            </if>
        </where>
    </update>

    <update id="updateTBasePointByUploadFile" parameterType="TBaseRegion">
        update t_base_point
        <trim prefix="SET" suffixOverrides=",">
            <if test="pidUrl != null">pid_url = #{pidUrl},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="picUrl != null">pic_url = #{picUrl},</if>
        </trim>
        <where>
            <if test="pidFlag != null and pidFlag==1"> and pid_no = #{fileName}</if>
            <if test="pidFlag != null and pidFlag==0"> and pic_no = #{fileName}</if>
        </where>
    </update>

</mapper>
