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

    <resultMap type="TInvoiceWorkcontent" id="TInvoiceWorkcontentResult">
        <result property="id"    column="id"    />
        <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="workType"    column="work_type"    />
        <result property="riskLevel"    column="risk_level"    />
        <result property="workDescription"    column="work_description"    />
        <result property="workPeopleNumber"    column="work_people_number"    />
        <result property="hpjb"    column="hpjb"    />
        <result property="estimateWorktime"    column="estimate_worktime"    />
        <result property="bookingticketId"    column="bookingticket_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
        <result property="reservationNumber"    column="reservation_number"    />
        <result property="whgzxkzh"    column="whgzxkzh"    />
        <result property="dhzyxkzh"    column="dhzyxkzh"    />
        <result property="xzkjxkzh"    column="xzkjxkzh"    />
        <result property="mbzyxkzh"    column="mbzyxkzh"    />
        <result property="gczyxkzh"    column="gczyxkzh"    />
        <result property="gczyjb"    column="gczyjb"    />
        <result property="tag"    column="tag"    />
        <result property="yqxkzh"    column="yqxkzh"    />
        <result property="xpxp"    column="xpxp"    />
        <result property="addStatus"    column="add_status"    />
    </resultMap>

    <sql id="selectTInvoiceWorkcontentVo">
        select d.id, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.work_type, d.risk_level, d.work_description, d.work_people_number, d.hpjb, d.estimate_worktime, d.bookingticket_id, d.dept_id ,
               d.whgzxkzh,d.dhzyxkzh,d.xzkjxkzh,d.mbzyxkzh,d.gczyxkzh,d.gczyjb,d.reservation_number,d.tag,d.yqxkzh,d.xpxp,d.add_status, s.dept_name from t_invoice_workcontent d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTInvoiceWorkcontentList" parameterType="TInvoiceWorkcontent" resultMap="TInvoiceWorkcontentResult">
        <include refid="selectTInvoiceWorkcontentVo"/>
        <where>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="workType != null "> and work_type = #{workType}</if>
            <if test="riskLevel != null "> and risk_level = #{riskLevel}</if>
            <if test="workDescription != null  and workDescription != ''"> and work_description = #{workDescription}</if>
            <if test="workPeopleNumber != null "> and work_people_number = #{workPeopleNumber}</if>
            <if test="hpjb != null  and hpjb != ''"> and hpjb = #{hpjb}</if>
            <if test="estimateWorktime != null  and estimateWorktime != ''"> and estimate_worktime = #{estimateWorktime}</if>
            <if test="bookingticketId != null "> and bookingticket_id = #{bookingticketId}</if>
            <if test="reservationNumber != null  and reservationNumber != ''"> and reservation_number = #{reservationNumber}</if>
            <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>
            <if test="gczyjb != null  and gczyjb != ''"> and gczyjb = #{gczyjb}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="countXp" parameterType="TInvoiceWorkcontent" resultType="int">
        select count(1) from  t_invoice_workcontent d
            left join t_invoice_bookingworkticket b on b.id = d.bookingticket_id
        <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 xpxp = 12 and b.status != 7
        </where>
    </select>



    <select id="selectTInvoiceWorkcontentById" parameterType="Long" resultMap="TInvoiceWorkcontentResult">
        <include refid="selectTInvoiceWorkcontentVo"/>
        where id = #{id}
        and d.del_flag = 0
    </select>

    <select id="selectTInvoiceWorkcontentBybookingticketId" parameterType="Long" resultMap="TInvoiceWorkcontentResult">
        <include refid="selectTInvoiceWorkcontentVo"/>
        where d.bookingticket_id = #{bookingticketId}
        and d.del_flag = 0
    </select>

    <insert id="insertTInvoiceWorkcontent" parameterType="TInvoiceWorkcontent">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT T_INVOICE_WORKCONTENT_SEQ.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_invoice_workcontent
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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="workType != null">work_type,</if>
            <if test="riskLevel != null">risk_level,</if>
            <if test="workDescription != null">work_description,</if>
            <if test="workPeopleNumber != null">work_people_number,</if>
            <if test="hpjb != null">hpjb,</if>
            <if test="estimateWorktime != null">estimate_worktime,</if>
            <if test="bookingticketId != null">bookingticket_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="reservationNumber != null">reservation_number,</if>
            <if test="whgzxkzh != null">whgzxkzh,</if>
            <if test="dhzyxkzh != null">dhzyxkzh,</if>
            <if test="xzkjxkzh != null">xzkjxkzh,</if>
            <if test="mbzyxkzh != null">mbzyxkzh,</if>
            <if test="gczyxkzh != null">gczyxkzh,</if>
            <if test="gczyjb != null">gczyjb,</if>
            <if test="xpxp != null">xpxp,</if>
            <if test="yqxkzh != null">yqxkzh,</if>
            <if test="tag != null">tag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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="workType != null">#{workType},</if>
            <if test="riskLevel != null">#{riskLevel},</if>
            <if test="workDescription != null">#{workDescription},</if>
            <if test="workPeopleNumber != null">#{workPeopleNumber},</if>
            <if test="hpjb != null">#{hpjb},</if>
            <if test="estimateWorktime != null">#{estimateWorktime},</if>
            <if test="bookingticketId != null">#{bookingticketId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="reservationNumber != null">#{reservationNumber},</if>
            <if test="whgzxkzh != null">#{whgzxkzh},</if>
            <if test="dhzyxkzh != null">#{dhzyxkzh},</if>
            <if test="xzkjxkzh != null">#{xzkjxkzh},</if>
            <if test="mbzyxkzh != null">#{mbzyxkzh},</if>
            <if test="gczyxkzh != null">#{gczyxkzh},</if>
            <if test="gczyjb != null">#{gczyjb},</if>
            <if test="xpxp != null">#{xpxp},</if>
            <if test="yqxkzh != null">#{yqxkzh},</if>
            <if test="tag != null">#{tag},</if>
         </trim>
    </insert>


    <update id="updateTInvoiceWorkcontent" parameterType="TInvoiceWorkcontent">
        update t_invoice_workcontent
        <trim prefix="SET" suffixOverrides=",">
            <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="workType != null">work_type = #{workType},</if>
            <if test="riskLevel != null">risk_level = #{riskLevel},</if>
            <if test="workDescription != null">work_description = #{workDescription},</if>
            <if test="workPeopleNumber != null">work_people_number = #{workPeopleNumber},</if>
            <if test="hpjb != null">hpjb = #{hpjb},</if>
            <if test="estimateWorktime != null">estimate_worktime = #{estimateWorktime},</if>
            <if test="bookingticketId != null">bookingticket_id = #{bookingticketId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="reservationNumber != null">reservation_number = #{reservationNumber},</if>
            <if test="whgzxkzh != null">whgzxkzh = #{whgzxkzh},</if>
            <if test="dhzyxkzh != null">dhzyxkzh = #{dhzyxkzh},</if>
            <if test="xzkjxkzh != null">xzkjxkzh = #{xzkjxkzh},</if>
            <if test="mbzyxkzh != null">mbzyxkzh = #{mbzyxkzh},</if>
            <if test="gczyxkzh != null">gczyxkzh = #{gczyxkzh},</if>
            <if test="gczyjb != null">gczyjb = #{gczyjb},</if>
            <if test="tag != null">tag = #{tag},</if>
            <if test="yqxkzh != null">yqxkzh = #{yqxkzh},</if>
            <if test="xpxp != null">xpxp = #{xpxp},</if>
            <if test="addStatus != null">add_status = #{addStatus},</if>
        </trim>
        where id = #{id}
    </update>

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

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

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


</mapper>
