<?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.TByxWorklicenseMapper">

    <resultMap type="TByxWorklicense" id="TByxWorklicenseResult">
        <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="post"    column="post"    />
        <result property="idtype"    column="idtype"    />
        <result property="containerIdnum"    column="container_idnum"    />
        <result property="boiler"    column="boiler"    />
        <result property="container"    column="container"    />
        <result property="pipe"    column="pipe"    />
        <result property="alkylation"    column="alkylation"    />
        <result property="aromatic"    column="aromatic"    />
        <result property="recertificatedate"    column="recertificatedate"    />
        <result property="validity"    column="validity"    />
        <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="pipeIdnum"    column="pipe_idnum"    />
        <result property="alkylationIdnum"    column="alkylation_idnum"    />
        <result property="pipeDate"    column="pipe_date"    />
        <result property="pipeLifespan"    column="pipe_lifespan"    />
        <result property="alkylationDate"    column="alkylation_date"    />
        <result property="alkylationLifespan"    column="alkylation_lifespan"    />
        <result property="containerDate"    column="container_date"    />
        <result property="containerLifespan"    column="container_lifespan"    />
        <result property="boilerIdnum"    column="boiler_idnum"    />
        <result property="boilerDate"    column="boiler_date"    />
        <result property="boilerLifespan"    column="boiler_lifespan"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTByxWorklicenseVo">
        select d.id, d.plant_code, d.name, d.employeeid, d.classes, d.post, d.idtype, d.container_idnum, d.boiler, d.container, d.pipe, d.alkylation, d.aromatic, d.recertificatedate, d.validity, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id, d.pipe_idnum, d.alkylation_idnum, d.pipe_date, d.alkylation_date, d.container_date, d.boiler_idnum, d.boiler_date ,d.boiler_lifespan ,d.pipe_lifespan, d.alkylation_lifespan, d.container_lifespan,s.dept_name from t_byx_worklicense d
        left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTByxWorklicenseList" parameterType="TByxWorklicense" resultMap="TByxWorklicenseResult">
        <include refid="selectTByxWorklicenseVo"/>
        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="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="name != null  and name != ''"> and d.name like concat(concat('%', #{name}), '%')</if>
            <if test="employeeid != null  and employeeid != ''"> and employeeid = #{employeeid}</if>
            <if test="classes != null  and classes != ''"> and classes = #{classes}</if>
            <if test="post != null  and post != ''"> and post = #{post}</if>
            <if test="idtype != null  and idtype != ''"> and idtype = #{idtype}</if>
            <if test="containerIdnum != null  and containerIdnum != ''"> and container_idnum = #{containerIdnum}</if>
            <if test="aromatic != null  and aromatic != ''"> and aromatic = #{aromatic}</if>
            <if test="boiler != null  and boiler != '' and boiler == 'true'"> and boiler=1</if>
            <if test="container != null  and container != '' and container == 'true'"> and container=1</if>
            <if test="pipe != null  and pipe != '' and pipe == 'true'"> and pipe=1</if>
            <if test="alkylation != null  and alkylation != '' and alkylation == 'true'"> and alkylation=1</if>
            <if test="notHave == 'true'"> and boiler = 0 and container = 0 and pipe = 0 and alkylation = 0</if>
            <if test="expiring == 'true'">and (boiler_lifespan <![CDATA[<=]]> #{expiringDate} or
                container_lifespan <![CDATA[<=]]> #{expiringDate} or
                pipe_lifespan <![CDATA[<=]]> #{expiringDate} or
                alkylation_lifespan <![CDATA[<=]]> #{expiringDate})
                </if>
            <if test="recertificatedate != null "> and recertificatedate = #{recertificatedate}</if>
            <if test="validity != null "> and validity = #{validity}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="pipeIdnum != null  and pipeIdnum != ''"> and pipe_idnum = #{pipeIdnum}</if>
            <if test="alkylationIdnum != null  and alkylationIdnum != ''"> and alkylation_idnum = #{alkylationIdnum}</if>
            <if test="pipeDate != null "> and pipe_date = #{pipeDate}</if>
            <if test="alkylationDate != null "> and alkylation_date = #{alkylationDate}</if>
            <if test="containerDate != null "> and container_date = #{containerDate}</if>
            <if test="boilerIdnum != null  and boilerIdnum != ''"> and boiler_idnum = #{boilerIdnum}</if>
            <if test="boilerDate != null "> and boiler_date = #{boilerDate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by sdd2.DICT_SORT,sdd.DICT_SORT
    </select>

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

    <select id="selectTByxWorklicenseById" parameterType="Long" resultMap="TByxWorklicenseResult">
        <include refid="selectTByxWorklicenseVo"/>
        where id = #{id}
    </select>

    <select id="selectTByxWorklicenseByEmployeeid" parameterType="String" resultMap="TByxWorklicenseResult">
        <include refid="selectTByxWorklicenseVo"/>
        where employeeid = #{employeeid}
    </select>

    <insert id="insertTByxWorklicense" parameterType="TByxWorklicense">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_byx_worklicense.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_byx_worklicense
        <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="post != null">post,</if>
            <if test="idtype != null">idtype,</if>
            <if test="containerIdnum != null">container_idnum,</if>
            <if test="boiler == 'true'">boiler,</if>
            <if test="container == 'true'">container,</if>
            <if test="pipe == 'true'">pipe,</if>
            <if test="alkylation == 'true'">alkylation,</if>
            <if test="boiler == 'false'">boiler,</if>
            <if test="container == 'false'">container,</if>
            <if test="pipe == 'false'">pipe,</if>
            <if test="alkylation == 'false'">alkylation,</if>
            <if test="aromatic != null">aromatic,</if>
            <if test="recertificatedate != null">recertificatedate,</if>
            <if test="validity != null">validity,</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="pipeIdnum != null">pipe_idnum,</if>
            <if test="alkylationIdnum != null">alkylation_idnum,</if>
            <if test="pipeDate != null">pipe_date,</if>
            <if test="alkylationDate != null">alkylation_date,</if>
            <if test="containerDate != null">container_date,</if>
            <if test="boilerIdnum != null">boiler_idnum,</if>
            <if test="boilerDate != null">boiler_date,</if>
            <if test="boilerLifespan != null">boiler_lifespan,</if>
            <if test="pipeLifespan != null">pipe_lifespan,</if>
            <if test="alkylationLifespan != null">alkylation_lifespan,</if>
            <if test="containerLifespan != null">container_lifespan,</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="post != null">#{post},</if>
            <if test="idtype != null">#{idtype},</if>
            <if test="containerIdnum != null">#{containerIdnum},</if>
            <if test="boiler == 'false'">0,</if>
            <if test="container == 'false'">0,</if>
            <if test="pipe == 'false'">0,</if>
            <if test="alkylation == 'false'">0,</if>
            <if test="boiler == 'true'">1,</if>
            <if test="container == 'true'">1,</if>
            <if test="pipe == 'true'">1,</if>
            <if test="alkylation == 'true'">1,</if>
            <if test="recertificatedate != null">#{recertificatedate},</if>
            <if test="validity != null">#{validity},</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="pipeIdnum != null">#{pipeIdnum},</if>
            <if test="alkylationIdnum != null">#{alkylationIdnum},</if>
            <if test="pipeDate != null">#{pipeDate},</if>
            <if test="alkylationDate != null">#{alkylationDate},</if>
            <if test="containerDate != null">#{containerDate},</if>
            <if test="boilerIdnum != null">#{boilerIdnum},</if>
            <if test="boilerDate != null">#{boilerDate},</if>
            <if test="boilerLifespan != null">#{boilerLifespan},</if>
            <if test="pipeLifespan != null">#{pipeLifespan},</if>
            <if test="alkylationLifespan != null">#{alkylationLifespan},</if>
            <if test="containerLifespan != null">#{containerLifespan},</if>
        </trim>
    </insert>

    <update id="updateTByxWorklicense" parameterType="TByxWorklicense">
        update t_byx_worklicense
        <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="post != null">post = #{post},</if>
            <if test="idtype != null">idtype = #{idtype},</if>
            <if test="containerIdnum != null">container_idnum = #{containerIdnum},</if>
            <if test="boiler == 'false'">boiler =0,</if>
            <if test="container == 'false'">container =0,</if>
            <if test="pipe == 'false'">pipe =0,</if>
            <if test="alkylation == 'false'">alkylation =0,</if>
            <if test="boiler == 'true'">boiler =1,</if>
            <if test="container == 'true'">container =1,</if>
            <if test="pipe == 'true'">pipe =1,</if>
            <if test="alkylation == 'true'">alkylation =1,</if>
            <if test="aromatic != null">aromatic = #{aromatic},</if>
            <if test="recertificatedate != null">recertificatedate = #{recertificatedate},</if>
            <if test="validity != null">validity = #{validity},</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="pipeIdnum != null">pipe_idnum = #{pipeIdnum},</if>
            <if test="alkylationIdnum != null">alkylation_idnum = #{alkylationIdnum},</if>
            <if test="pipeDate != null">pipe_date = #{pipeDate},</if>
            <if test="alkylationDate != null">alkylation_date = #{alkylationDate},</if>
            <if test="containerDate != null">container_date = #{containerDate},</if>
            <if test="boilerIdnum != null">boiler_idnum = #{boilerIdnum},</if>
            <if test="boilerDate != null">boiler_date = #{boilerDate},</if>
            <if test="boilerLifespan != null">boiler_lifespan=#{boilerLifespan},</if>
            <if test="pipeLifespan != null">pipe_lifespan=#{pipeLifespan},</if>
            <if test="alkylationLifespan != null">alkylation_lifespan=#{alkylationLifespan},</if>
            <if test="containerLifespan != null">container_lifespan=#{containerLifespan},</if>
        </trim>
        where id = #{id}
    </update>

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

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

    <select id="selectLicenseData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum from t_byx_worklicense
        <where>
            <if test="type == 1">
                and boiler = 1
            </if>
            <if test="type == 2">
                and container = 1
            </if>
            <if test="type == 3">
                and pipe = 1
            </if>
            <if test="type == 4">
                and alkylation = 1
            </if>
        </where>
    </select>


</mapper>
