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

    <resultMap type="TSpecdevGl" id="TSpecdevGlResult">
        <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="submitdate"    column="submitdate"    />
        <result property="status"    column="status"    />
        <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="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="createUnit"    column="create_unit"    />
        <result property="burnMode"    column="burn_mode"    />
        <result property="burnKind"    column="burn_kind"    />
        <result property="ratedPower"    column="rated_power"    />
        <result property="desPressure"    column="des_pressure"    />
        <result property="desTemp"    column="des_temp"    />
        <result property="optPressure"    column="opt_pressure"    />
        <result property="optTemp"    column="opt_temp"    />
        <result property="checkUnit"    column="check_unit"    />
        <result property="checkConclusion"    column="check_conclusion"    />
        <result property="model"    column="model"    />
        <result property="waterMode"    column="water_mode"    />
        <result property="reportNo"    column="report_no"    />
        <result property="approveTime"    column="approve_time"    />
        <result property="changeTime"    column="change_time"    />
        <result property="plantMaint"    column="plant_maint"    />
        <result property="outWarnDate"    column="out_warn_date"    />
        <result property="outNextWarnDate"    column="out_next_warn_date"    />
        <result property="outCheckConclusion"    column="out_check_conclusion"    />
        <result property="outReportNo"    column="out_report_no"    />
        <result property="engineer"    column="engineer"    />
        <result property="hiFlag" column="hiFlag" />
        <result property="isRepeat" column="is_repeat"/>
        <result property="containerNo" column="container_no"/>
        <result property="filedSituation" column="filed_situation"/>
        <result property="internalInspection" column="internal_inspection"/>
        <result property="externalInspection" column="external_inspection"/>
        <result property="pressureTest" column="pressure_test"/>
        <result property="energyEfficiencyTest" column="energy_efficiency_test"/>
        <result property="factoryInfo" column="factory_info"/>
        <result property="factoryNo" column="factory_no"/>
        <result property="medium" column="medium"/>
        <result property="designUnit" column="design_unit"/>
    </resultMap>

    <sql id="selectTSpecdevGlVo">
        select d.id, d.plant_code, d.unit, d.devname, d.devno, d.submitdate, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, 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.create_unit, d.burn_mode, d.burn_kind, d.rated_power, d.des_pressure, d.des_temp, d.opt_pressure, d.opt_temp, d.check_unit, d.check_conclusion, d.model, d.water_mode, d.report_no, d.approve_time, d.change_time, d.plant_maint, d.out_warn_date, d.out_next_warn_date, d.out_check_conclusion, d.out_report_no, d.engineer ,s.dept_name,
        d.is_repeat,d.container_no,
               d.filed_situation,
               d.internal_inspection,
               d.external_inspection,
               d.pressure_test,
               d.energy_efficiency_test,
               d.factory_info,
               d.factory_no,
               d.medium,
               d.design_unit
        from t_specdev_gl d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTSpecdevGlList" parameterType="TSpecdevGl" resultMap="TSpecdevGlResult">
        <include refid="selectTSpecdevGlVo"/>
        <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="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="nextWarnDate != null "> and next_warn_date = #{nextWarnDate}</if>
            <if test="warnFlag != null "> and warn_flag = #{warnFlag}</if>
            <if test="createUnit != null  and createUnit != ''"> and create_unit = #{createUnit}</if>
            <if test="burnMode != null  and burnMode != ''"> and burn_mode = #{burnMode}</if>
            <if test="burnKind != null  and burnKind != ''"> and burn_kind = #{burnKind}</if>
            <if test="ratedPower != null  and ratedPower != ''"> and rated_power = #{ratedPower}</if>
            <if test="desPressure != null  and desPressure != ''"> and des_pressure = #{desPressure}</if>
            <if test="desTemp != null  and desTemp != ''"> and des_temp = #{desTemp}</if>
            <if test="optPressure != null  and optPressure != ''"> and opt_pressure = #{optPressure}</if>
            <if test="optTemp != null  and optTemp != ''"> and opt_temp = #{optTemp}</if>
            <if test="checkUnit != null  and checkUnit != ''"> and check_unit = #{checkUnit}</if>
            <if test="checkConclusion != null  and checkConclusion != ''"> and check_conclusion = #{checkConclusion}</if>
            <if test="model != null  and model != ''"> and model = #{model}</if>
            <if test="waterMode != null  and waterMode != ''"> and water_mode = #{waterMode}</if>
            <if test="reportNo != null  and reportNo != ''"> and report_no = #{reportNo}</if>
            <if test="approveTime != null "> and approve_time = #{approveTime}</if>
            <if test="changeTime != null "> and change_time = #{changeTime}</if>
            <if test="plantMaint != null  and plantMaint != ''"> and plant_maint = #{plantMaint}</if>
            <if test="status != null "> and d.status = #{status}</if>
            <if test="approveStatus != null ">and approve_status = #{approveStatus}</if>
            <if test="warnFlag != null ">and warn_Flag = #{warnFlag}</if>
            <if test="containerNo != null "> and `container_no` = #{containerNo}</if>
            <if test="filedSituation != null "> and `filed_situation` = #{filedSituation}</if>
            <if test="internalInspection != null "> and `internal_inspection` = #{internalInspection}</if>
            <if test="externalInspection != null "> and `external_inspection` = #{externalInspection}</if>
            <if test="pressureTest != null "> and `pressure_test` = #{pressureTest}</if>
            <if test="energyEfficiencyTest != null "> and `energy_efficiency_test` = #{energyEfficiencyTest}</if>
            <if test="factoryInfo != null "> and `factory_info` = #{factoryInfo}</if>
            <if test="factoryNo != null "> and `factory_no` = #{factoryNo}</if>
            <if test="medium != null "> and `medium` = #{medium}</if>
            <if test="designUnit != null "> and `design_unit` = #{designUnit}</if>
            <if test="fuzzy != null and  fuzzy!=''"> and (plant_code like concat('%',#{fuzzy},'%')
                or unit like concat('%',#{fuzzy},'%')
                or devname like concat('%',#{fuzzy},'%')
                or devno like concat('%',#{fuzzy},'%')
                or regno like concat('%',#{fuzzy},'%')
                or useno like concat('%',#{fuzzy},'%')
                or warn_date like concat('%',#{fuzzy},'%')
                or next_warn_date like concat('%',#{fuzzy},'%')
                or warn_flag like concat('%',#{fuzzy},'%')
                or create_unit like concat('%',#{fuzzy},'%')
                or burn_mode like concat('%',#{fuzzy},'%')
                or burn_kind like concat('%',#{fuzzy},'%')
                or rated_power like concat('%',#{fuzzy},'%')
                or des_pressure like concat('%',#{fuzzy},'%')
                or des_temp like concat('%',#{fuzzy},'%')
                or opt_pressure like concat('%',#{fuzzy},'%')
                or opt_temp like concat('%',#{fuzzy},'%')
                or check_unit like concat('%',#{fuzzy},'%')
                or check_conclusion like concat('%',#{fuzzy},'%')
                or model like concat('%',#{fuzzy},'%')
                or water_mode like concat('%',#{fuzzy},'%')
                or report_no like concat('%',#{fuzzy},'%')
                or plant_maint like concat('%',#{fuzzy},'%')
                or `container_no` like concat('%',#{fuzzy},'%')
                or `filed_situation` like concat('%',#{fuzzy},'%')
                or `internal_inspection` like concat('%',#{fuzzy},'%')
                or `external_inspection` like concat('%',#{fuzzy},'%')
                or `pressure_test` like concat('%',#{fuzzy},'%')
                or `energy_efficiency_test` like concat('%',#{fuzzy},'%')
                or `factory_info` like concat('%',#{fuzzy},'%')
                or `factory_no` like concat('%',#{fuzzy},'%')
                or `medium` like concat('%',#{fuzzy},'%')
                or `design_unit` like concat('%',#{fuzzy},'%'))</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScopePlant}
        order by d.is_repeat desc, d.plant_code, d.unit, d.id
    </select>

    <select id="selectTSpecdevGlListByYear" parameterType="TSpecdevGl" resultMap="TSpecdevGlResult">
        <include refid="selectTSpecdevGlVo"/>
        <where>
            <if test="status != null ">and d.status = #{status}</if>
            <if test="hiType == 1 ">and date_format(NEXT_WARN_DATE,'%Y') = #{checkYear}</if>
            <if test="hiType == 2 ">and date_format(out_next_warn_date,'%Y') = #{checkYear}</if>
            <if test="plantIds != null  and plantIds != ''">
                and
                d.plant_code in
                <foreach collection="plantIds.split(',')" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <!--<if test="unitIds != null  and unitIds != ''">
                and
                (
                d.unit in
                <foreach collection="unitIds.split(',')" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
                )
            </if>-->
            and d.del_flag = 0
        </where>
    </select>


    <select id="selectTSpecdevGlById" parameterType="Long" resultMap="TSpecdevGlResult">
        <include refid="selectTSpecdevGlVo"/>
        where id = #{id}
    </select>

    <insert id="insertTSpecdevGl" parameterType="TSpecdevGl">

        insert into t_specdev_gl
        <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="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="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</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="createUnit != null">create_unit,</if>
            <if test="burnMode != null">burn_mode,</if>
            <if test="burnKind != null">burn_kind,</if>
            <if test="ratedPower != null">rated_power,</if>
            <if test="desPressure != null">des_pressure,</if>
            <if test="desTemp != null">des_temp,</if>
            <if test="optPressure != null">opt_pressure,</if>
            <if test="optTemp != null">opt_temp,</if>
            <if test="checkUnit != null">check_unit,</if>
            <if test="checkConclusion != null">check_conclusion,</if>
            <if test="model != null">model,</if>
            <if test="waterMode != null">water_mode,</if>
            <if test="reportNo != null">report_no,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="changeTime != null">change_time,</if>
            <if test="plantMaint != null">plant_maint,</if>
            <if test="outWarnDate != null">out_warn_date,</if>
            <if test="outNextWarnDate != null">out_next_warn_date,</if>
            <if test="outCheckConclusion != null">out_check_conclusion,</if>
            <if test="outReportNo != null">out_report_no,</if>
            <if test="engineer != null">engineer,</if>
            <if test="containerNo != null ">  `container_no`,</if>
            <if test="filedSituation != null ">  `filed_situation` ,</if>
            <if test="internalInspection != null ">  `internal_inspection` ,</if>
            <if test="externalInspection != null ">  `external_inspection` ,</if>
            <if test="pressureTest != null ">  `pressure_test`, </if>
            <if test="energyEfficiencyTest != null ">  `energy_efficiency_test` ,</if>
            <if test="factoryInfo != null ">  `factory_info` ,</if>
            <if test="factoryNo != null ">  `factory_no` ,</if>
            <if test="medium != null ">  `medium` ,</if>
            <if test="designUnit != null ">  `design_unit` ,</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="submitdate != null">#{submitdate},</if>
            <if test="status != null">#{status},</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="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="createUnit != null">#{createUnit},</if>
            <if test="burnMode != null">#{burnMode},</if>
            <if test="burnKind != null">#{burnKind},</if>
            <if test="ratedPower != null">#{ratedPower},</if>
            <if test="desPressure != null">#{desPressure},</if>
            <if test="desTemp != null">#{desTemp},</if>
            <if test="optPressure != null">#{optPressure},</if>
            <if test="optTemp != null">#{optTemp},</if>
            <if test="checkUnit != null">#{checkUnit},</if>
            <if test="checkConclusion != null">#{checkConclusion},</if>
            <if test="model != null">#{model},</if>
            <if test="waterMode != null">#{waterMode},</if>
            <if test="reportNo != null">#{reportNo},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="changeTime != null">#{changeTime},</if>
            <if test="plantMaint != null">#{plantMaint},</if>
            <if test="outWarnDate != null">#{outWarnDate},</if>
            <if test="outNextWarnDate != null">#{outNextWarnDate},</if>
            <if test="outCheckConclusion != null">#{outCheckConclusion},</if>
            <if test="outReportNo != null">#{outReportNo},</if>
            <if test="engineer != null">#{engineer},</if>
            <if test="containerNo != null ">  #{containerNo},</if>
            <if test="filedSituation != null ">  #{filedSituation},</if>
            <if test="internalInspection != null ">  #{internalInspection},</if>
            <if test="externalInspection != null ">  #{externalInspection},</if>
            <if test="pressureTest != null ">  #{pressureTest},</if>
            <if test="energyEfficiencyTest != null ">  #{energyEfficiencyTest},</if>
            <if test="factoryInfo != null ">  #{factoryInfo},</if>
            <if test="factoryNo != null ">  #{factoryNo},</if>
            <if test="medium != null ">  #{medium},</if>
            <if test="designUnit != null ">  #{designUnit},</if>
         </trim>
    </insert>

    <update id="updateTSpecdevGl" parameterType="TSpecdevGl">
        update t_specdev_gl
        <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="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="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</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="createUnit != null">create_unit = #{createUnit},</if>
            <if test="burnMode != null">burn_mode = #{burnMode},</if>
            <if test="burnKind != null">burn_kind = #{burnKind},</if>
            <if test="ratedPower != null">rated_power = #{ratedPower},</if>
            <if test="desPressure != null">des_pressure = #{desPressure},</if>
            <if test="desTemp != null">des_temp = #{desTemp},</if>
            <if test="optPressure != null">opt_pressure = #{optPressure},</if>
            <if test="optTemp != null">opt_temp = #{optTemp},</if>
            <if test="checkUnit != null">check_unit = #{checkUnit},</if>
            <if test="checkConclusion != null">check_conclusion = #{checkConclusion},</if>
            <if test="model != null">model = #{model},</if>
            <if test="waterMode != null">water_mode = #{waterMode},</if>
            <if test="reportNo != null">report_no = #{reportNo},</if>
            <if test="approveTime != null">approve_time = #{approveTime},</if>
            <if test="changeTime != null">change_time = #{changeTime},</if>
            <if test="plantMaint != null">plant_maint = #{plantMaint},</if>
            <if test="outWarnDate != null">out_warn_date = #{outWarnDate},</if>
            <if test="outNextWarnDate != null">out_next_warn_date = #{outNextWarnDate},</if>
            <if test="outCheckConclusion != null">out_check_conclusion = #{outCheckConclusion},</if>
            <if test="outReportNo != null">out_report_no = #{outReportNo},</if>
            <if test="engineer != null">engineer = #{engineer},</if>
            <if test="isRepeat != null">is_repeat = #{isRepeat},</if>
            <if test="containerNo != null ">  `container_no`= #{containerNo},</if>
            <if test="filedSituation != null ">  `filed_situation`= #{filedSituation} ,</if>
            <if test="internalInspection != null ">  `internal_inspection` = #{internalInspection},</if>
            <if test="externalInspection != null ">  `external_inspection` = #{externalInspection},</if>
            <if test="pressureTest != null ">  `pressure_test`= #{pressureTest}, </if>
            <if test="energyEfficiencyTest != null ">  `energy_efficiency_test` = #{energyEfficiencyTest},</if>
            <if test="factoryInfo != null ">  `factory_info`= #{factoryInfo} ,</if>
            <if test="factoryNo != null ">  `factory_no` = #{factoryNo},</if>
            <if test="medium != null ">  `medium` = #{medium},</if>
            <if test="designUnit != null ">  `design_unit`= #{designUnit} ,</if>
        </trim>
        where id = #{id}
    </update>

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

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

    <update id="duplicateTSpecdevGl" >
        UPDATE  T_SPECDEV_GL set DEL_FLAG = 2 where id  in  (select b.id from   ( select id from t_specdev_gl a where (a.DEVNO,a.plant_code) in(select DEVNO,plant_code from t_specdev_gl group by DEVNO,plant_code having count(*) > 1)
                                                                                                                  and id not in (select min(id) from t_specdev_gl group by DEVNO,plant_code having count(*)>1)   and a.DEL_FLAG = 0
                                                                                                                  and a.APPROVE_STATUS = 0 ) AS  b )
    </update>

</mapper>
