<?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.check.mapper.TCheckRepairpointsMapper">

    <resultMap type="TCheckRepairpoints" id="TCheckRepairpointsResult">
        <result property="checkId"    column="check_id"    />
        <result property="pointId"    column="point_id"    />
        <result property="repairId"    column="repair_id"    />
        <result property="netTestValue"    column="net_test_value"    />
        <result property="repairFunc"    column="repair_func"    />
        <result property="repairType"    column="repair_type"    />
        <result property="repairCount"    column="repair_count"    />
        <result property="plantName"    column="plant_name"    />
        <result property="regionName"    column="region_name"    />
        <result property="layer"    column="layer"    />
        <result property="devName"    column="dev_name"    />
        <result property="devCode"    column="dev_code"    />
        <result property="groupCode"    column="group_code"    />
        <result property="extendCode"    column="extend_code"    />
        <result property="pointType"    column="point_type"    />
        <result property="instrumentCode"    column="instrument_code"    />
        <result property="leakagePosition"    column="leakage_position"    />
        <result property="repairer"    column="repairer"    />
        <result property="repairDate"    column="repair_date"    />
        <result property="leakageDegree"    column="leakage_degree"    />
        <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="updatedate"    column="updatedate"    />
        <result property="plantId"    column="plant_id"    />
        <result property="regionId"    column="region_id"    />
        <result property="devId"    column="dev_id"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="plantType"    column="plant_type"    />
        <result property="mediumType"    column="medium_type"    />
    </resultMap>

    <sql id="selectTCheckRepairpointsVo">
        select check_id, point_id, repair_id, net_test_value, repair_func, repair_type, repair_count, plant_name, region_name, layer, dev_name, dev_code, group_code, extend_code, point_type, instrument_code, leakage_position, repairer, repair_date, leakage_degree, remarks, approve_status, approve_time, dept_id, del_flag, creater_code, createdate, updater_code, updatedate, plant_id, region_id, dev_id, instrument_id, plant_type, medium_type from t_check_repairpoints
    </sql>

    <select id="selectTCheckRepairpointsList" parameterType="TCheckRepairpoints" resultMap="TCheckRepairpointsResult">
        <include refid="selectTCheckRepairpointsVo"/>
        <where>
            <if test="pointId != null "> and point_id = #{pointId}</if>
            <if test="repairId != null "> and repair_id = #{repairId}</if>
            <if test="netTestValue != null  and netTestValue != ''"> and net_test_value = #{netTestValue}</if>
            <if test="repairFunc != null  and repairFunc != ''"> and repair_func = #{repairFunc}</if>
            <if test="repairType != null  and repairType != ''"> and repair_type = #{repairType}</if>
            <if test="repairCount != null  and repairCount != ''"> and repair_count = #{repairCount}</if>
            <if test="plantName != null  and plantName != ''"> and plant_name like concat('%', #{plantName}, '%')</if>
            <if test="regionName != null  and regionName != ''"> and region_name like concat('%', #{regionName}, '%')</if>
            <if test="layer != null  and layer != ''"> and layer = #{layer}</if>
            <if test="devName != null  and devName != ''"> and dev_name like concat('%', #{devName}, '%')</if>
            <if test="devCode != null  and devCode != ''"> and dev_code = #{devCode}</if>
            <if test="groupCode != null  and groupCode != ''"> and group_code = #{groupCode}</if>
            <if test="extendCode != null  and extendCode != ''"> and extend_code = #{extendCode}</if>
            <if test="pointType != null  and pointType != ''"> and point_type = #{pointType}</if>
            <if test="instrumentCode != null  and instrumentCode != ''"> and instrument_code = #{instrumentCode}</if>
            <if test="leakagePosition != null  and leakagePosition != ''"> and leakage_position = #{leakagePosition}</if>
            <if test="repairer != null  and repairer != ''"> and repairer = #{repairer}</if>
            <if test="repairDate != null "> and repair_date = #{repairDate}</if>
            <if test="leakageDegree != null  and leakageDegree != ''"> and leakage_degree = #{leakageDegree}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="approveStatus != null "> and approve_status = #{approveStatus}</if>
            <if test="approveTime != null "> and approve_time = #{approveTime}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</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="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="plantType != null  and plantType != ''"> and plant_type = #{plantType}</if>
            <if test="mediumType != null  and mediumType != ''"> and medium_type = #{mediumType}</if>
            <if test="choose != null "> and repair_id is null</if>
        and del_flag = 0
        </where>
    </select>

    <select id="selectTCheckRepairpointsByCheckId" parameterType="Long" resultMap="TCheckRepairpointsResult">
        <include refid="selectTCheckRepairpointsVo"/>
        where check_id = #{checkId}
    </select>

    <select id="selectRepairpointsByInspectionId" parameterType="Long" resultMap="TCheckRepairpointsResult">
        <include refid="selectTCheckRepairpointsVo"/>
        where check_id in (select repair_id from t_check_checkpoints where inspection_id=#{inspectionId})
    </select>

    <select id="selectTCheckRepairpointsByIds" parameterType="Long" resultMap="TCheckRepairpointsResult">
        <include refid="selectTCheckRepairpointsVo"/> where check_id in
        <foreach item="checkId" collection="array" open="(" separator="," close=")">
            #{checkId}
        </foreach>
        and approve_status=2
    </select>

    <insert id="insertTCheckRepairpoints" parameterType="TCheckRepairpoints" useGeneratedKeys="true" keyProperty="checkId">
        insert into t_check_repairpoints
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pointId != null">point_id,</if>
            <if test="repairId != null">repair_id,</if>
            <if test="netTestValue != null">net_test_value,</if>
            <if test="repairFunc != null">repair_func,</if>
            <if test="repairType != null">repair_type,</if>
            <if test="repairCount != null">repair_count,</if>
            <if test="plantName != null">plant_name,</if>
            <if test="regionName != null">region_name,</if>
            <if test="layer != null">layer,</if>
            <if test="devName != null">dev_name,</if>
            <if test="devCode != null">dev_code,</if>
            <if test="groupCode != null">group_code,</if>
            <if test="extendCode != null">extend_code,</if>
            <if test="pointType != null">point_type,</if>
            <if test="instrumentCode != null">instrument_code,</if>
            <if test="leakagePosition != null">leakage_position,</if>
            <if test="repairer != null">repairer,</if>
            <if test="repairDate != null">repair_date,</if>
            <if test="leakageDegree != null">leakage_degree,</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>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="plantId != null">plant_id,</if>
            <if test="regionId != null">region_id,</if>
            <if test="devId != null">dev_id,</if>
            <if test="instrumentId != null">instrument_id,</if>
            <if test="plantType != null">plant_type,</if>
            <if test="mediumType != null">medium_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pointId != null">#{pointId},</if>
            <if test="repairId != null">#{repairId},</if>
            <if test="netTestValue != null">#{netTestValue},</if>
            <if test="repairFunc != null">#{repairFunc},</if>
            <if test="repairType != null">#{repairType},</if>
            <if test="repairCount != null">#{repairCount},</if>
            <if test="plantName != null">#{plantName},</if>
            <if test="regionName != null">#{regionName},</if>
            <if test="layer != null">#{layer},</if>
            <if test="devName != null">#{devName},</if>
            <if test="devCode != null">#{devCode},</if>
            <if test="groupCode != null">#{groupCode},</if>
            <if test="extendCode != null">#{extendCode},</if>
            <if test="pointType != null">#{pointType},</if>
            <if test="instrumentCode != null">#{instrumentCode},</if>
            <if test="leakagePosition != null">#{leakagePosition},</if>
            <if test="repairer != null">#{repairer},</if>
            <if test="repairDate != null">#{repairDate},</if>
            <if test="leakageDegree != null">#{leakageDegree},</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>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="plantId != null">#{plantId},</if>
            <if test="regionId != null">#{regionId},</if>
            <if test="devId != null">#{devId},</if>
            <if test="instrumentId != null">#{instrumentId},</if>
            <if test="plantType != null">#{plantType},</if>
            <if test="mediumType != null">#{mediumType},</if>
         </trim>
    </insert>

    <insert id="insertTCheckRepairpointsByList" parameterType="TCheckRepairpoints">
        insert into t_check_repairpoints
        <trim prefix="(" suffix=")" suffixOverrides=",">
            point_id,
            net_test_value,
            plant_name,
            region_name,
            layer,
            dev_name,
            dev_code,
            group_code,
            extend_code,
            point_type,
            instrument_code,
            leakage_position,
            leakage_degree,
            approve_status,
            creater_code,
            createdate,
            updater_code,
            updatedate,
            plant_id,
            region_id,
            dev_id,
            instrument_id,
            plant_type,
            medium_type,
         </trim>
        values
        <foreach collection="list" index="index" separator="," item="item">
            <trim prefix="(" suffix=")" suffixOverrides=",">
                #{item.pointId},
                #{item.netTestValue},
                #{item.plantName},
                #{item.regionName},
                #{item.layer},
                #{item.devName},
                #{item.devCode},
                #{item.groupCode},
                #{item.extendCode},
                #{item.pointType},
                #{item.instrumentCode},
                #{item.leakagePosition},
                #{item.leakageDegree},
                #{item.approveStatus},
                #{item.createrCode},
                #{item.createdate},
                #{item.updaterCode},
                #{item.updatedate},
                #{item.plantId},
                #{item.regionId},
                #{item.devId},
                #{item.instrumentId},
                #{item.plantType},
                #{item.mediumType},
            </trim>
        </foreach>
    </insert>

    <update id="updateTCheckRepairpoints" parameterType="TCheckRepairpoints">
        update t_check_repairpoints
        <trim prefix="SET" suffixOverrides=",">
            <if test="pointId != null">point_id = #{pointId},</if>
            <if test="repairId != null">repair_id = #{repairId},</if>
            <if test="netTestValue != null">net_test_value = #{netTestValue},</if>
            <if test="repairFunc != null">repair_func = #{repairFunc},</if>
            <if test="repairType != null">repair_type = #{repairType},</if>
            <if test="repairCount != null">repair_count = #{repairCount},</if>
            <if test="plantName != null">plant_name = #{plantName},</if>
            <if test="regionName != null">region_name = #{regionName},</if>
            <if test="layer != null">layer = #{layer},</if>
            <if test="devName != null">dev_name = #{devName},</if>
            <if test="devCode != null">dev_code = #{devCode},</if>
            <if test="groupCode != null">group_code = #{groupCode},</if>
            <if test="extendCode != null">extend_code = #{extendCode},</if>
            <if test="pointType != null">point_type = #{pointType},</if>
            <if test="instrumentCode != null">instrument_code = #{instrumentCode},</if>
            <if test="leakagePosition != null">leakage_position = #{leakagePosition},</if>
            <if test="repairer != null">repairer = #{repairer},</if>
            <if test="repairDate != null">repair_date = #{repairDate},</if>
            <if test="leakageDegree != null">leakage_degree = #{leakageDegree},</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>
            <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="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="plantType != null">plant_type = #{plantType},</if>
            <if test="mediumType != null">medium_type = #{mediumType},</if>
        </trim>
        where check_id = #{checkId}
    </update>

    <update id="updateTCheckRepairpointsByUpload" parameterType="TCheckRepairpoints">
        update t_check_repairpoints
        <trim prefix="SET" suffixOverrides=",">
            <if test="repairer != null">repairer = #{repairer},</if>
            <if test="repairDate != null">repair_date = #{repairDate},</if>
            <if test="repairFunc != null">repair_func = #{repairFunc},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="approveStatus != null">approve_status = #{approveStatus},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where plant_name=#{plantName} and group_code=#{groupCode} and extend_code=#{extendCode} and repair_id=#{repairId} and (approve_status is null or approve_status=0)
    </update>

    <update id="updateApproveStatusByIds" parameterType="TCheckCheckpoints">
        update t_check_repairpoints
        <trim prefix="SET" suffixOverrides=",">
            <if test="approveStatus != null">approve_status = #{approveStatus},</if>
            <if test="repairCount != null">repair_count = #{repairCount},</if>
        </trim>
        <where>
            check_id in
            <foreach item="checkId" collection="checkIds" open="(" separator="," close=")">
                #{checkId}
            </foreach>
            <if test="approveStatus ==1">
                and approve_status=0
            </if>
            <if test="approveStatus ==2">
                and approve_status=1
            </if>
            and repair_date is not null
        </where>
    </update>


    <delete id="deleteTCheckRepairpointsByCheckId" parameterType="Long">
        update t_check_repairpoints set del_flag=1 where check_id = #{checkId}
    </delete>

    <delete id="deleteTCheckRepairpointsByCheckIds" parameterType="String">
        update t_check_repairpoints set del_flag=1 where check_id in
        <foreach item="checkId" collection="array" open="(" separator="," close=")">
            #{checkId}
        </foreach>
    </delete>

    <update id="updateTCheckRepairpointsByCheckIds" parameterType="TCheckRepairpoints">
        <if test="choose == 1">
            update t_check_repairpoints set repair_id=#{repairId} where check_id in
            <foreach item="checkId" collection="checkIds" open="(" separator="," close=")">
                #{checkId}
            </foreach>
        </if>
        <if test="choose == 2">
            update t_check_repairpoints set repair_id = null where check_id in
            <foreach item="checkId" collection="checkIds" open="(" separator="," close=")">
                #{checkId}
            </foreach>
        </if>
        <if test="choose == 3">
            update t_check_repairpoints set repair_id = #{repairId} where check_id in
            (select t.check_id from (select check_id from t_check_repairpoints d
            <where>
                <if test="plantId != null  and plantId != ''">and d.plant_id = #{plantId}</if>
                <if test="regionId != null  and regionId != ''">and d.region_id= #{regionId}</if>
                <if test="devId != null  and devId != ''">and d.dev_id = #{devId}</if>
                and d.repair_id is null
            </where>
            ) t)
        </if>
        <if test="choose == 4">
            update t_check_repairpoints set repair_id = null where repair_id =#{repairId}
        </if>
    </update>
</mapper>
