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

    <resultMap type="TJobticket" id="TJobticketResult">
        <result property="id" column="id"/>
        <result property="plantCode" column="plant_code"/>
        <result property="kprq" column="kprq"/>
        <result property="qfsj" column="qfsj"/>
        <result property="qfbz" column="qfbz"/>
        <result property="qfr" column="qfr"/>
        <result property="xpxp" column="xpxp"/>
        <result property="yqxkzh" column="yqxkzh"/>
        <result property="whgzxkzh" column="whgzxkzh"/>
        <result property="dhzyxkzh" column="dhzyxkzh"/>
        <result property="hpjb" column="hpjb"/>
        <result property="xzkjxkzh" column="xzkjxkzh"/>
        <result property="content" column="content"/>
        <result property="byclxr" column="byclxr"/>
        <result property="sgdw" column="sgdw"/>
        <result property="lxr" column="lxr"/>
        <result property="lxdh" column="lxdh"/>
        <result property="xpsj" column="xpsj"/>
        <result property="zypzt" column="zypzt"/>
        <result property="jccdr" column="jccdr"/>
        <result property="wcxxbh" column="wcxxbh"/>
        <result property="wcxzt" column="wcxzt"/>
        <result property="cxsj" column="cxsj"/>
        <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="deptName" column="dept_name"/>
        <result property="startDate" column="kprq"/>
        <result property="endDate" column="kprq"/>
        <result property="mbzyxkzh" column="mbzyxkzh"/>
        <result property="gczyxkzh" column="gczyxkzh"/>
        <result property="gczyjb" column="gczyjb"/>
        <result property="postponeNumber" column="postpone_number"/>
        <result property="userMg" column="user_mg"/>
        <result property="userUnit" column="user_unit"/>
        <result property="tag" column="tag"/>
    </resultMap>

    <sql id="selectTJobticketVo">
        select d.id,
               d.plant_code,
               d.kprq,
               d.qfsj,
               d.qfbz,
               d.qfr,
               d.xpxp,
               d.yqxkzh,
               d.whgzxkzh,
               d.dhzyxkzh,
               d.hpjb,
               d.xzkjxkzh,
               d.content,
               d.byclxr,
               d.sgdw,
               d.lxr,
               d.lxdh,
               d.xpsj,
               d.zypzt,
               d.jccdr,
               d.wcxxbh,
               d.wcxzt,
               d.cxsj,
               d.mbzyxkzh,
               d.gczyxkzh,
               d.gczyjb,
               d.postpone_number,
               d.user_mg,
               d.user_unit,
               d.del_flag,
               d.creater_code,
               d.createdate,
               d.updater_code,
               d.updatedate,
               d.dept_id,
               d.remarks,
               d.tag,
               s.dept_name
        from t_jobticket d
                 left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTJobticketList" parameterType="TJobticket" resultMap="TJobticketResult">
        <include refid="selectTJobticketVo"/>
        <where>
            <if test="startDate != null ">and kprq <![CDATA[>=]]> #{startDate}</if>
            <if test="endDate != null">and kprq <![CDATA[<=]]>#{endDate}</if>
            <if test="qfbz != null  and qfbz != ''">and qfbz = #{qfbz}</if>
            <if test="xpxp != null  and xpxp != ''">and xpxp = #{xpxp}</if>
            <if test="hpjb != null  and hpjb != ''">and hpjb = #{hpjb}</if>
            <if test="zypzt != null  and zypzt != ''">and zypzt = #{zypzt}</if>
            <if test="xzkjxkzh !=null and xzkjxkzh!=''">and xzkjxkzh like concat(concat('%',#{xzkjxkzh}),'%')</if>
            <if test="mbzyxkzh != null  and mbzyxkzh != ''">and mbzyxkzh like concat(concat('%',#{mbzyxkzh}),'%')</if>
            <if test="gczyxkzh != null  and gczyxkzh != ''">and gczyxkzh like concat(concat('%',#{gczyxkzh}),'%')</if>
            <if test="content != null  and content != ''">and content like concat(concat('%',#{content}),'%')</if>
            <if test="whgzxkzh != null  and whgzxkzh != ''">and whgzxkzh like concat(concat('%',#{whgzxkzh}),'%')</if>
            <if test="yqxkzh != null  and yqxkzh != ''">and yqxkzh like concat(concat('%',#{yqxkzh}),'%')</if>
            <if test="dhzyxkzh != null  and dhzyxkzh != ''">and dhzyxkzh like concat(concat('%',#{dhzyxkzh}),'%')</if>
            <if test="byclxr != null  and byclxr != ''">and byclxr like concat(concat('%',#{byclxr}),'%')</if>
            <if test="sgdw != null  and sgdw != ''">and sgdw like concat(concat('%',#{sgdw}),'%')</if>
            <if test="jccdr != null  and jccdr != ''">and jccdr like concat(concat('%',#{jccdr}),'%')</if>
            <if test="wcxxbh != null  and wcxxbh != ''">and wcxxbh like concat(concat('%',#{wcxxbh}),'%')</if>
            <if test="wcxzt != null  and wcxzt != ''">and wcxzt like concat(concat('%',#{wcxzt}),'%')</if>
            <if test="xpsj != null ">and xpsj <![CDATA[=]]> #{xpsj}</if>
            <if test="cxsj != null ">and cxsj <![CDATA[=]]> #{cxsj}</if>
            <if test="gczyjb != null  and gczyjb != ''">and gczyjb = #{gczyjb}</if>
            <if test="postponeNumber != null ">and postpone_number = #{postponeNumber}</if>
            <if test="userMg != null ">and user_mg = #{userMg}</if>
            <if test="userUnit != null ">and user_unit = #{userUnit}</if>
            <if test="tag != null and tag != '' ">and tag = #{tag}</if>
            <if test="allNo != null  and allNo != ''">
                and
                (whgzxkzh like concat(concat('%', #{allNo}), '%')
                or dhzyxkzh like concat(concat('%', #{allNo}), '%')
                or xzkjxkzh like concat(concat('%', #{allNo}), '%')
                or mbzyxkzh like concat(concat('%', #{allNo}), '%')
                or gczyxkzh like concat(concat('%', #{allNo}), '%')
                or yqxkzh like concat(concat('%', #{allNo}), '%')
                )
            </if>
            <if test="tableType == 1 ">
                <choose>
                    <when test="xpxp == '12'">
                        and xpxp = #{xpxp}
                    </when>
                    <otherwise>
                        and xpxp = 10
                    </otherwise>
                </choose>
            </if>
            <if test="tableType == 2 ">
                <if test="xpxp != null and xpxp != '' ">and xpxp = #{xpxp}</if>
            </if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.kprq desc
    </select>

    <select id="selectTJobticketChildren" parameterType="TJobticket" resultMap="TJobticketResult">
        <include refid="selectTJobticketVo"/>
        <where>
            <if test="whgzxkzh != null  and whgzxkzh != ''">and whgzxkzh = #{whgzxkzh}</if>
            <if test="dhzyxkzh != null  and dhzyxkzh != ''">and dhzyxkzh = #{dhzyxkzh}</if>
            <if test="xzkjxkzh != null  and xzkjxkzh != ''">and xzkjxkzh = #{xzkjxkzh}</if>
            <if test="mbzyxkzh != null  and mbzyxkzh != ''">and mbzyxkzh = #{mbzyxkzh}</if>
            <if test="gczyxkzh != null  and gczyxkzh != ''">and gczyxkzh = #{gczyxkzh}</if>
            and d.del_flag = 0 and xpxp = 12
        </where>
        order by d.kprq
    </select>

    <select id="selectTJobticketById" parameterType="Long" resultMap="TJobticketResult">
        <include refid="selectTJobticketVo"/>
        where id = #{id}
    </select>

    <!-- 查询相同数据 sql-->
    <select id="selectTJobticketSameData" parameterType="TJobticket" resultType="java.lang.Integer">
        select count(*) from t_jobticket d
        <where>
            <if test="xzkjxkzh != null  and xzkjxkzh != ''">and xzkjxkzh = #{xzkjxkzh}</if>
            <if test="mbzyxkzh != null  and mbzyxkzh != ''">and mbzyxkzh = #{mbzyxkzh}</if>
            <if test="gczyxkzh != null  and gczyxkzh != ''">and gczyxkzh = #{gczyxkzh}</if>
            <if test="whgzxkzh != null  and whgzxkzh != ''">and whgzxkzh = #{whgzxkzh}</if>
            <if test="dhzyxkzh != null  and dhzyxkzh != ''">and dhzyxkzh = #{dhzyxkzh}</if>
            <if test="yqxkzh != null  and yqxkzh != ''">and yqxkzh = #{yqxkzh}</if>
            and d.del_flag = 0
            and d.xpxp = #{xpxp}
        </where>
    </select>

    <select id="countXp" parameterType="TJobticket" resultType="int">
        select count(1) from t_jobticket d
        <where>
            <if test="whgzxkzh != null  and whgzxkzh != ''">and d.whgzxkzh = #{whgzxkzh}</if>
            <if test="dhzyxkzh != null  and dhzyxkzh != ''">and d.dhzyxkzh = #{dhzyxkzh}</if>
            <if test="xzkjxkzh != null  and xzkjxkzh != ''">and d.xzkjxkzh = #{xzkjxkzh}</if>
            <if test="mbzyxkzh != null  and mbzyxkzh != ''">and d.mbzyxkzh = #{mbzyxkzh}</if>
            <if test="gczyxkzh != null  and gczyxkzh != ''">and d.gczyxkzh = #{gczyxkzh}</if>
            <if test="deptId != null ">and d.dept_id = #{deptId}</if>
            and d.del_flag = 0 and d.xpxp = 12 and d.zypzt != 20
        </where>
    </select>

    <insert id="insertTJobticket" parameterType="TJobticket">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_jobticket.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_jobticket
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="kprq != null">kprq,</if>
            <if test="qfsj != null">qfsj,</if>
            <if test="qfbz != null">qfbz,</if>
            <if test="qfr != null">qfr,</if>
            <if test="xpxp != null">xpxp,</if>
            <if test="yqxkzh != null">yqxkzh,</if>
            <if test="whgzxkzh != null">whgzxkzh,</if>
            <if test="dhzyxkzh != null">dhzyxkzh,</if>
            <if test="hpjb != null">hpjb,</if>
            <if test="xzkjxkzh != null">xzkjxkzh,</if>
            <if test="content != null">content,</if>
            <if test="byclxr != null">byclxr,</if>
            <if test="sgdw != null">sgdw,</if>
            <if test="lxr != null">lxr,</if>
            <if test="lxdh != null">lxdh,</if>
            <if test="xpsj != null">xpsj,</if>
            <if test="zypzt != null">zypzt,</if>
            <if test="jccdr != null">jccdr,</if>
            <if test="wcxxbh != null">wcxxbh,</if>
            <if test="wcxzt != null">wcxzt,</if>
            <if test="cxsj != null">cxsj,</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="mbzyxkzh != null">mbzyxkzh,</if>
            <if test="gczyxkzh != null">gczyxkzh,</if>
            <if test="gczyjb != null">gczyjb,</if>
            <if test="postponeNumber != null">postpone_number,</if>
            <if test="userMg != null">user_mg,</if>
            <if test="userUnit != null">user_unit,</if>
            <if test="tag != null">tag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="kprq != null">#{kprq},</if>
            <if test="qfsj != null">#{qfsj},</if>
            <if test="qfbz != null">#{qfbz},</if>
            <if test="qfr != null">#{qfr},</if>
            <if test="xpxp != null">#{xpxp},</if>
            <if test="yqxkzh != null">#{yqxkzh},</if>
            <if test="whgzxkzh != null">#{whgzxkzh},</if>
            <if test="dhzyxkzh != null">#{dhzyxkzh},</if>
            <if test="hpjb != null">#{hpjb},</if>
            <if test="xzkjxkzh != null">#{xzkjxkzh},</if>
            <if test="content != null">#{content},</if>
            <if test="byclxr != null">#{byclxr},</if>
            <if test="sgdw != null">#{sgdw},</if>
            <if test="lxr != null">#{lxr},</if>
            <if test="lxdh != null">#{lxdh},</if>
            <if test="xpsj != null">#{xpsj},</if>
            <if test="zypzt != null">#{zypzt},</if>
            <if test="jccdr != null">#{jccdr},</if>
            <if test="wcxxbh != null">#{wcxxbh},</if>
            <if test="wcxzt != null">#{wcxzt},</if>
            <if test="cxsj != null">#{cxsj},</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="mbzyxkzh != null">#{mbzyxkzh},</if>
            <if test="gczyxkzh != null">#{gczyxkzh},</if>
            <if test="gczyjb != null">#{gczyjb},</if>
            <if test="postponeNumber != null">#{postponeNumber},</if>
            <if test="userMg != null">#{userMg},</if>
            <if test="userUnit != null">#{userUnit},</if>
            <if test="tag != null">#{tag},</if>
        </trim>
    </insert>

    <update id="updateTJobticket" parameterType="TJobticket">
        update t_jobticket
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="kprq != null">kprq = #{kprq},</if>
            <if test="qfsj != null">qfsj = #{qfsj},</if>
            <if test="qfbz != null">qfbz = #{qfbz},</if>
            <if test="qfr != null">qfr = #{qfr},</if>
            <if test="xpxp != null">xpxp = #{xpxp},</if>
            <if test="yqxkzh != null">yqxkzh = #{yqxkzh},</if>
            <if test="whgzxkzh != null">whgzxkzh = #{whgzxkzh},</if>
            <if test="dhzyxkzh != null">dhzyxkzh = #{dhzyxkzh},</if>
            <if test="hpjb != null">hpjb = #{hpjb},</if>
            <if test="xzkjxkzh != null">xzkjxkzh = #{xzkjxkzh},</if>
            <if test="content != null">content = #{content},</if>
            <if test="byclxr != null and byclxr != ''">byclxr = #{byclxr},</if>
            <if test="sgdw != null">sgdw = #{sgdw},</if>
            <if test="lxr != null">lxr = #{lxr},</if>
            <if test="lxdh != null">lxdh = #{lxdh},</if>
            <if test="xpsj != null">xpsj = #{xpsj},</if>
            <if test="zypzt != null">zypzt = #{zypzt},</if>
            <if test="jccdr != null">jccdr = #{jccdr},</if>
            <if test="wcxxbh != null">wcxxbh = #{wcxxbh},</if>
            <if test="wcxzt != null">wcxzt = #{wcxzt},</if>
            <if test="cxsj != null">cxsj = #{cxsj},</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="mbzyxkzh != null">mbzyxkzh = #{mbzyxkzh},</if>
            <if test="gczyxkzh != null">gczyxkzh = #{gczyxkzh},</if>
            <if test="gczyjb != null">gczyjb = #{gczyjb},</if>
            <if test="postponeNumber != null">postpone_number = #{postponeNumber},</if>
            <if test="userMg != null">user_mg = #{userMg},</if>
            <if test="userUnit != null">user_unit = #{userUnit},</if>
            <if test="tag != null">tag = #{tag},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateTJobticketStatus" parameterType="TJobticket">
        update t_jobticket
        <trim prefix="SET" suffixOverrides=",">
            zypzt = #{zypzt},xpsj = sysdate
        </trim>
            <where>
                <if test="whgzxkzh != null  and whgzxkzh != ''">and whgzxkzh = #{whgzxkzh}</if>
                <if test="dhzyxkzh != null  and dhzyxkzh != ''">and dhzyxkzh = #{dhzyxkzh}</if>
                <if test="xzkjxkzh != null  and xzkjxkzh != ''">and xzkjxkzh = #{xzkjxkzh}</if>
                <if test="mbzyxkzh != null  and mbzyxkzh != ''">and mbzyxkzh = #{mbzyxkzh}</if>
                <if test="gczyxkzh != null  and gczyxkzh != ''">and gczyxkzh = #{gczyxkzh}</if>
            </where>
    </update>

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

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

    <select id="selectFireData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum,d.HPJB as dataName FROM t_jobticket d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY HPJB
        order by dataName
    </select>

    <select id="selectStatusData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum,d.ZYPZT as dataName FROM t_jobticket d
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        GROUP BY ZYPZT
        order by dataName
    </select>

    <update id="updateTag" parameterType="TInvoiceTag">
        update t_jobticket set tag = #{tagNew} where tag = #{tag}
    </update>
</mapper>
