<?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"    />
    </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.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,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 == 'true'"> and xzkjxkzh IS NOT NULL</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.kprq desc
    </select>

    <select id="selectTJobticketById" parameterType="Long" resultMap="TJobticketResult">
        <include refid="selectTJobticketVo"/>
        where id = #{id}
    </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>
         </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>
         </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">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>
        </trim>
        where id = #{id}
    </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>
</mapper>
