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

    <resultMap type="TByxWorkcertificate" id="TByxWorkcertificateResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="name"    column="name"    />
        <result property="employeeid"    column="employeeid"    />
        <result property="classes"    column="classes"    />
        <result property="container"    column="container"    />
        <result property="fireFacilities"    column="fire_facilities"    />
        <result property="idnum"    column="idnum"    />
        <result property="reviewdate"    column="reviewdate"    />
        <result property="pipevalidity"    column="pipevalidity"    />
        <result property="guardian"    column="guardian"    />
        <result property="boilvalidity"    column="boilvalidity"    />
        <result property="foremantrain"    column="foremantrain"    />
        <result property="foremanreview"    column="foremanreview"    />
        <result property="foremannextreview"    column="foremannextreview"    />
        <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" />
        <result property="containerIdnum" column="container_idnum" />
        <result property="containerDate" column="container_date" />
        <result property="fireFacilitiesDate" column="fire_facilities_date" />
        <result property="fireFacilitiesIdnum" column="fire_facilities_idnum" />
        <result property="guardianIdnum" column="guardian_idnum" />
    </resultMap>

    <sql id="selectTByxWorkcertificateVo">
        select d.id, d.plant_code, d.name, d.employeeid, d.classes, d.container, d.fire_facilities, d.idnum, d.reviewdate, d.pipevalidity, d.guardian, d.boilvalidity, d.foremantrain, d.foremanreview, d.foremannextreview, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id,d.container_idnum, d.container_date,
               d.fire_facilities_idnum,
               d.fire_facilities_date,
               d.guardian_idnum
,s.dept_name from t_byx_workcertificate d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTByxWorkcertificateList" parameterType="TByxWorkcertificate" resultMap="TByxWorkcertificateResult">
        <include refid="selectTByxWorkcertificateVo"/>
        LEFT JOIN t_staffmgr t on d.employeeid = t.staffid and t.del_flag = 0
        LEFT JOIN SYS_DICT_DATA sdd on t.ACTUALPOST = sdd.DICT_VALUE and sdd.DICT_TYPE = 'ACTUALPOST'
        LEFT JOIN SYS_DICT_DATA sdd2 on d.classes = sdd2.DICT_VALUE and sdd2.DICT_TYPE = 'TEAM_DIVIDE'

<where>
            <if test="classes != null  and classes != ''"> and classes = #{classes}</if>
            <!-- 王子文 2022年8月15日 -->
            <!-- 过滤掉锅炉证、加氢工艺、裂化工艺字段中值为（一个或多个）空格的数据 -->
            <if test="guardian == 'true'">and LTRIM(guardian) is not null</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by sdd2.DICT_SORT,sdd.DICT_SORT
    </select>

    <select id="selectList" parameterType="TByxWorkcertificate" resultMap="TByxWorkcertificateResult">
        <include refid="selectTByxWorkcertificateVo"/>
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectTByxWorkcertificateById" parameterType="Long" resultMap="TByxWorkcertificateResult">
        <include refid="selectTByxWorkcertificateVo"/>
        where id = #{id}
    </select>

    <select id="selectTByxWorkcertificateByEmployeeid" parameterType="String" resultMap="TByxWorkcertificateResult">
        <include refid="selectTByxWorkcertificateVo"/>
        where employeeid = #{employeeid}
    </select>

    <insert id="insertTByxWorkcertificate" parameterType="TByxWorkcertificate">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_byx_workcertificate.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_byx_workcertificate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="name != null">name,</if>
            <if test="employeeid != null">employeeid,</if>
            <if test="classes != null">classes,</if>
            <if test="container != null">container,</if>
            <if test="fireFacilities != null">fire_facilities,</if>
            <if test="idnum != null">idnum,</if>
            <if test="reviewdate != null">reviewdate,</if>
            <if test="pipevalidity != null">pipevalidity,</if>
            <if test="guardian != null">guardian,</if>
            <if test="boilvalidity != null">boilvalidity,</if>
            <if test="foremantrain != null">foremantrain,</if>
            <if test="foremanreview != null">foremanreview,</if>
            <if test="foremannextreview != null">foremannextreview,</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>
            <if test="containerIdnum!= null">container_idnum,</if>
            <if test="containerDate != null">container_date,</if>
            <if test="fireFacilitiesDate != null">fire_facilities_date,</if>
            <if test="fireFacilitiesIdnum != null">fire_facilities_idnum,</if>
            <if test="guardianIdnum != null">guardian_idnum,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="name != null">#{name},</if>
            <if test="employeeid != null">#{employeeid},</if>
            <if test="classes != null">#{classes},</if>
            <if test="container != null">#{container},</if>
            <if test="fireFacilities != null">#{fireFacilities},</if>
            <if test="idnum != null">#{idnum},</if>
            <if test="reviewdate != null">#{reviewdate},</if>
            <if test="pipevalidity != null">#{pipevalidity},</if>
            <if test="guardian != null">#{guardian},</if>
            <if test="boilvalidity != null">#{boilvalidity},</if>
            <if test="foremantrain != null">#{foremantrain},</if>
            <if test="foremanreview != null">#{foremanreview},</if>
            <if test="foremannextreview != null">#{foremannextreview},</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>
            <if test="containerIdnum!= null">#{containerIdnum},</if>
            <if test="containerDate != null">#{containerDate},</if>
            <if test="fireFacilitiesDate != null">#{fireFacilitiesDate},</if>
            <if test="fireFacilitiesIdnum != null">#{fireFacilitiesIdnum},</if>
            <if test="guardianIdnum != null">#{guardianIdnum},</if>
         </trim>
    </insert>

    <update id="updateTByxWorkcertificate" parameterType="TByxWorkcertificate">
        update t_byx_workcertificate
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="name != null">name = #{name},</if>
            <if test="employeeid != null">employeeid = #{employeeid},</if>
            <if test="classes != null">classes = #{classes},</if>
            <if test="container != null">container = #{container},</if>
            <if test="fireFacilities != null">fire_facilities = #{fireFacilities},</if>
            <if test="idnum != null">idnum = #{idnum},</if>
            <if test="reviewdate != null">reviewdate = #{reviewdate},</if>
            <if test="pipevalidity != null">pipevalidity = #{pipevalidity},</if>
            <if test="guardian != null">guardian = #{guardian},</if>
            <if test="boilvalidity != null">boilvalidity = #{boilvalidity},</if>
            <if test="foremantrain != null">foremantrain = #{foremantrain},</if>
            <if test="foremanreview != null">foremanreview = #{foremanreview},</if>
            <if test="foremannextreview != null">foremannextreview = #{foremannextreview},</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>
            <if test="containerIdnum!= null">container_idnum = #{containerIdnum},</if>
            <if test="containerDate != null">container_date = #{containerDate},</if>
            <if test="fireFacilitiesDate != null">fire_facilities_date = #{fireFacilitiesDate},</if>
            <if test="fireFacilitiesIdnum != null">fire_facilities_idnum = #{fireFacilitiesIdnum},</if>
            <if test="guardianIdnum != null">guardian_idnum = #{guardianIdnum},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateTByxWorkcertificateByEmployeeid" parameterType="TByxWorkcertificate">
        update t_byx_workcertificate
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="name != null">name = #{name},</if>
            <if test="employeeid != null">employeeid = #{employeeid},</if>
            <if test="classes != null">classes = #{classes},</if>
            <if test="container != null">container = #{container},</if>
            <if test="fireFacilities != null">fire_facilities = #{fireFacilities},</if>
            <if test="idnum != null">idnum = #{idnum},</if>
            <if test="reviewdate != null">reviewdate = #{reviewdate},</if>
            <if test="pipevalidity != null">pipevalidity = #{pipevalidity},</if>
            <if test="guardian != null">guardian = #{guardian},</if>
            <if test="boilvalidity != null">boilvalidity = #{boilvalidity},</if>
            <if test="foremantrain != null">foremantrain = #{foremantrain},</if>
            <if test="foremanreview != null">foremanreview = #{foremanreview},</if>
            <if test="foremannextreview != null">foremannextreview = #{foremannextreview},</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>
            <if test="containerIdnum!= null">container_idnum = #{containerIdnum},</if>
            <if test="containerDate != null">container_date = #{containerDate},</if>
            <if test="fireFacilitiesDate != null">fire_facilities_date = #{fireFacilitiesDate},</if>
            <if test="fireFacilitiesIdnum != null">fire_facilities_idnum = #{fireFacilitiesIdnum},</if>
            <if test="guardianIdnum != null">guardian_idnum = #{guardianIdnum},</if>
        </trim>
        where employeeid = #{employeeid}
    </update>


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

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

    <select id="selectCerData" resultType="com.ruoyi.project.common.domain.DataEntity">
       SELECT count(1) as dataNum from T_BYX_WORKCERTIFICATE
       <where>
           <if test="cert == 1">
        and BOILER is not null and TRIM(BOILER) != ' '
           </if>
           <if test="cert == 2">
               and HYDROGENATION is not null and TRIM(HYDROGENATION) != ' '
           </if>
           <if test="cert == 3">
               and CRACKING is not null and TRIM(CRACKING) != ' '
           </if>
       </where>
    </select>

</mapper>
