<?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.sems.his.mapper.TSpechiDtMapper">

    <resultMap type="TSpechiDt" id="TSpechiDtResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="unit"    column="unit"    />
        <result property="devname"    column="devname"    />
        <result property="devno"    column="devno"    />
        <result property="createdate"    column="createdate"    />
        <result property="submitdate"    column="submitdate"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createrDate"    column="creater_date"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updaterDate"    column="updater_date"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="approveStatus"    column="approve_status"    />
        <result property="regno"    column="regno"    />
        <result property="useno"    column="useno"    />
        <result property="warnDate"    column="warn_date"    />
        <result property="warnCycle"    column="warn_cycle"    />
        <result property="nextWarnDate"    column="next_warn_date"    />
        <result property="warnFlag"    column="warn_flag"    />
        <result property="model"    column="model"    />
        <result property="capacity"    column="capacity"    />
        <result property="floor"    column="floor"    />
        <result property="createUnit"    column="create_unit"    />
        <result property="maintContractor"    column="maint_contractor"    />
        <result property="location"    column="location"    />
        <result property="checkStrategy"    column="check_strategy"    />
        <result property="firstWarnDate"    column="first_warn_date"    />
        <result property="checkUnit"    column="check_unit"    />
        <result property="docno"    column="docno"    />
        <result property="approveTime"    column="approve_time"    />
        <result property="changeTime"    column="change_time"    />
        <result property="reportNo"    column="report_no"    />
        <result property="devId"    column="dev_id"    />
        <result property="hiType"    column="hi_type"    />
        <result property="deptName" column="dept_name" />
        <result property="useDept"    column="use_dept"    />
        <result property="plantMaint"    column="plant_maint"    />
    </resultMap>

    <sql id="selectTSpechiDtVo">
        select d.id, d.plant_code, d.plant_maint,d.use_dept,d.unit, d.devname, d.devno, d.createdate, d.submitdate, d.status, d.del_flag, d.creater_code, d.creater_date, d.updater_code, d.updater_date, d.dept_id, d.remarks, d.approve_status, d.regno, d.useno, d.warn_date, d.warn_cycle, d.next_warn_date, d.warn_flag, d.model, d.capacity, d.floor, d.create_unit, d.maint_contractor, d.location, d.check_strategy, d.first_warn_date, d.check_unit, d.docno, d.approve_time, d.change_time, d.report_no, d.dev_id, d.hi_type ,s.dept_name from t_spechi_dt d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTSpechiDtList" parameterType="TSpechiDt" resultMap="TSpechiDtResult">
        <include refid="selectTSpechiDtVo"/>
        <where>
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="devname != null  and devname != ''"> and devname like concat(concat('%', #{devname}), '%')</if>
            <if test="devno != null  and devno != ''"> and devno = #{devno}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="submitdate != null "> and submitdate = #{submitdate}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createrDate != null "> and creater_date = #{createrDate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updaterDate != null "> and updater_date = #{updaterDate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="approveStatus != null "> and approve_status = #{approveStatus}</if>
            <if test="regno != null  and regno != ''"> and regno = #{regno}</if>
            <if test="useno != null  and useno != ''"> and useno = #{useno}</if>
            <if test="warnDate != null "> and warn_date = #{warnDate}</if>
            <if test="warnCycle != null "> and warn_cycle = #{warnCycle}</if>
            <if test="nextWarnDate != null "> and next_warn_date = #{nextWarnDate}</if>
            <if test="warnFlag != null "> and warn_flag = #{warnFlag}</if>
            <if test="model != null  and model != ''"> and model = #{model}</if>
            <if test="capacity != null  and capacity != ''"> and capacity = #{capacity}</if>
            <if test="floor != null  and floor != ''"> and floor = #{floor}</if>
            <if test="createUnit != null  and createUnit != ''"> and create_unit = #{createUnit}</if>
            <if test="maintContractor != null  and maintContractor != ''"> and maint_contractor = #{maintContractor}</if>
            <if test="location != null  and location != ''"> and location = #{location}</if>
            <if test="checkStrategy != null  and checkStrategy != ''"> and check_strategy = #{checkStrategy}</if>
            <if test="firstWarnDate != null "> and first_warn_date = #{firstWarnDate}</if>
            <if test="checkUnit != null  and checkUnit != ''"> and check_unit = #{checkUnit}</if>
            <if test="docno != null  and docno != ''"> and docno = #{docno}</if>
            <if test="approveTime != null "> and approve_time = #{approveTime}</if>
            <if test="changeTime != null "> and change_time = #{changeTime}</if>
            <if test="reportNo != null  and reportNo != ''"> and report_no = #{reportNo}</if>
            <if test="devId != null "> and dev_id = #{devId}</if>
            <if test="hiType != null "> and hi_type = #{hiType}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTSpechiDtById" parameterType="Long" resultMap="TSpechiDtResult">
        <include refid="selectTSpechiDtVo"/>
        where d.dev_id = #{id}
        and d.hi_type = 1
        and d.del_flag = 0
    </select>

    <select id="selectTSpechiDtByReform" parameterType="Long" resultMap="TSpechiDtResult">
        <include refid="selectTSpechiDtVo"/>
        where d.dev_id = #{devId}
        and d.hi_type = 0
        and d.del_flag = 0
    </select>


    <insert id="insertTSpechiDt" parameterType="TSpechiDt">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_spechi_dt.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_spechi_dt
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="unit != null">unit,</if>
            <if test="devname != null">devname,</if>
            <if test="devno != null">devno,</if>
            <if test="createdate != null">createdate,</if>
            <if test="submitdate != null">submitdate,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createrDate != null">creater_date,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updaterDate != null">updater_date,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="approveStatus != null">approve_status,</if>
            <if test="regno != null">regno,</if>
            <if test="useno != null">useno,</if>
            <if test="warnDate != null">warn_date,</if>
            <if test="warnCycle != null">warn_cycle,</if>
            <if test="nextWarnDate != null">next_warn_date,</if>
            <if test="warnFlag != null">warn_flag,</if>
            <if test="model != null">model,</if>
            <if test="capacity != null">capacity,</if>
            <if test="floor != null">floor,</if>
            <if test="createUnit != null">create_unit,</if>
            <if test="maintContractor != null">maint_contractor,</if>
            <if test="location != null">location,</if>
            <if test="checkStrategy != null">check_strategy,</if>
            <if test="firstWarnDate != null">first_warn_date,</if>
            <if test="checkUnit != null">check_unit,</if>
            <if test="docno != null">docno,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="changeTime != null">change_time,</if>
            <if test="reportNo != null">report_no,</if>
            <if test="devId != null">dev_id,</if>
            <if test="hiType != null">hi_type,</if>
            <if test="plantMaint != null">plant_maint,</if>
            <if test="useDept != null">use_dept,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="unit != null">#{unit},</if>
            <if test="devname != null">#{devname},</if>
            <if test="devno != null">#{devno},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="submitdate != null">#{submitdate},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createrDate != null">#{createrDate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updaterDate != null">#{updaterDate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="approveStatus != null">#{approveStatus},</if>
            <if test="regno != null">#{regno},</if>
            <if test="useno != null">#{useno},</if>
            <if test="warnDate != null">#{warnDate},</if>
            <if test="warnCycle != null">#{warnCycle},</if>
            <if test="nextWarnDate != null">#{nextWarnDate},</if>
            <if test="warnFlag != null">#{warnFlag},</if>
            <if test="model != null">#{model},</if>
            <if test="capacity != null">#{capacity},</if>
            <if test="floor != null">#{floor},</if>
            <if test="createUnit != null">#{createUnit},</if>
            <if test="maintContractor != null">#{maintContractor},</if>
            <if test="location != null">#{location},</if>
            <if test="checkStrategy != null">#{checkStrategy},</if>
            <if test="firstWarnDate != null">#{firstWarnDate},</if>
            <if test="checkUnit != null">#{checkUnit},</if>
            <if test="docno != null">#{docno},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="changeTime != null">#{changeTime},</if>
            <if test="reportNo != null">#{reportNo},</if>
            <if test="devId != null">#{devId},</if>
            <if test="hiType != null">#{hiType},</if>
            <if test="plantMaint != null">#{plantMaint},</if>
            <if test="useDept != null">#{useDept},</if>
         </trim>
    </insert>

    <insert id="insertTSpechiDtByDev" parameterType="com.ruoyi.project.sems.domain.TSpecdevDt">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_spechi_dt.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_spechi_dt
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="unit != null">unit,</if>
            <if test="devname != null">devname,</if>
            <if test="devno != null">devno,</if>
            <if test="createdate != null">createdate,</if>
            <if test="submitdate != null">submitdate,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createrDate != null">creater_date,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updaterDate != null">updater_date,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="approveStatus != null">approve_status,</if>
            <if test="regno != null">regno,</if>
            <if test="useno != null">useno,</if>
            <if test="warnDate != null">warn_date,</if>
            <if test="warnCycle != null">warn_cycle,</if>
            <if test="nextWarnDate != null">next_warn_date,</if>
            <if test="warnFlag != null">warn_flag,</if>
            <if test="model != null">model,</if>
            <if test="capacity != null">capacity,</if>
            <if test="floor != null">floor,</if>
            <if test="createUnit != null">create_unit,</if>
            <if test="maintContractor != null">maint_contractor,</if>
            <if test="location != null">location,</if>
            <if test="checkStrategy != null">check_strategy,</if>
            <if test="firstWarnDate != null">first_warn_date,</if>
            <if test="checkUnit != null">check_unit,</if>
            <if test="docno != null">docno,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="changeTime != null">change_time,</if>
            <if test="reportNo != null">report_no,</if>
            <if test="devId != null">dev_id,</if>
            <if test="hiType != null">hi_type,</if>
            <if test="plantMaint != null">plant_maint,</if>
            <if test="useDept != null">use_dept,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="unit != null">#{unit},</if>
            <if test="devname != null">#{devname},</if>
            <if test="devno != null">#{devno},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="submitdate != null">#{submitdate},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createrDate != null">#{createrDate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updaterDate != null">#{updaterDate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="approveStatus != null">#{approveStatus},</if>
            <if test="regno != null">#{regno},</if>
            <if test="useno != null">#{useno},</if>
            <if test="warnDate != null">#{warnDate},</if>
            <if test="warnCycle != null">#{warnCycle},</if>
            <if test="nextWarnDate != null">#{nextWarnDate},</if>
            <if test="warnFlag != null">#{warnFlag},</if>
            <if test="model != null">#{model},</if>
            <if test="capacity != null">#{capacity},</if>
            <if test="floor != null">#{floor},</if>
            <if test="createUnit != null">#{createUnit},</if>
            <if test="maintContractor != null">#{maintContractor},</if>
            <if test="location != null">#{location},</if>
            <if test="checkStrategy != null">#{checkStrategy},</if>
            <if test="firstWarnDate != null">#{firstWarnDate},</if>
            <if test="checkUnit != null">#{checkUnit},</if>
            <if test="docno != null">#{docno},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="changeTime != null">#{changeTime},</if>
            <if test="reportNo != null">#{reportNo},</if>
            <if test="devId != null">#{devId},</if>
            <if test="hiType != null">#{hiType},</if>
            <if test="plantMaint != null">#{plantMaint},</if>
            <if test="useDept != null">#{useDept},</if>
        </trim>
    </insert>

    <update id="updateTSpechiDt" parameterType="TSpechiDt">
        update t_spechi_dt
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="devname != null">devname = #{devname},</if>
            <if test="devno != null">devno = #{devno},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="submitdate != null">submitdate = #{submitdate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createrDate != null">creater_date = #{createrDate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updaterDate != null">updater_date = #{updaterDate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="approveStatus != null">approve_status = #{approveStatus},</if>
            <if test="regno != null">regno = #{regno},</if>
            <if test="useno != null">useno = #{useno},</if>
            <if test="warnDate != null">warn_date = #{warnDate},</if>
            <if test="warnCycle != null">warn_cycle = #{warnCycle},</if>
            <if test="nextWarnDate != null">next_warn_date = #{nextWarnDate},</if>
            <if test="warnFlag != null">warn_flag = #{warnFlag},</if>
            <if test="model != null">model = #{model},</if>
            <if test="capacity != null">capacity = #{capacity},</if>
            <if test="floor != null">floor = #{floor},</if>
            <if test="createUnit != null">create_unit = #{createUnit},</if>
            <if test="maintContractor != null">maint_contractor = #{maintContractor},</if>
            <if test="location != null">location = #{location},</if>
            <if test="checkStrategy != null">check_strategy = #{checkStrategy},</if>
            <if test="firstWarnDate != null">first_warn_date = #{firstWarnDate},</if>
            <if test="checkUnit != null">check_unit = #{checkUnit},</if>
            <if test="docno != null">docno = #{docno},</if>
            <if test="approveTime != null">approve_time = #{approveTime},</if>
            <if test="changeTime != null">change_time = #{changeTime},</if>
            <if test="reportNo != null">report_no = #{reportNo},</if>
            <if test="devId != null">dev_id = #{devId},</if>
            <if test="hiType != null">hi_type = #{hiType},</if>
            <if test="plantMaint != null">plant_maint = #{plantMaint},</if>
            <if test="useDept != null">use_dept = #{useDept},</if>
        </trim>
        where id = #{id}
    </update>

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

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

    <update id="deleteTSpechiDtByDevId" parameterType="Long">
        update t_spechi_dt set del_flag = 2 where dev_id = #{devId} and hi_type = 1
    </update>
</mapper>
