<?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.aegis.resource.requisition.mapper.ResourceRequisitionCompensationMapper">

    <resultMap type="RequisitionCompensation" id="RequisitionCompensationResult">
        <id     property="id"                  column="id"                   />
        <result property="requisitionId"       column="requisition_id"        />
        <result property="workload"            column="workload"              />
        <result property="workloadUnit"        column="workload_unit"         />
        <result property="unitPrice"           column="unit_price"            />
        <result property="amount"              column="amount"                />
        <result property="currency"            column="currency"              />
        <result property="invoiceNo"           column="invoice_no"            />
        <result property="paidAt"             column="paid_at"               />
        <result property="status"              column="status"                />
        <result property="createBy"            column="create_by"             />
        <result property="createTime"          column="create_time"            />
        <result property="updateBy"            column="update_by"              />
        <result property="updateTime"         column="update_time"            />
        <result property="remark"              column="remark"                 />
    </resultMap>

    <sql id="selectRequisitionCompensationVo">
        select id, requisition_id, workload, workload_unit, unit_price, amount, currency,
               invoice_no, paid_at, status, create_by, create_time, update_by, update_time, remark
        from resource_requisition_compensation
    </sql>

    <select id="selectRequisitionCompensationList" parameterType="RequisitionCompensation" resultMap="RequisitionCompensationResult">
        <include refid="selectRequisitionCompensationVo"/>
        <where>
            <if test="requisitionId != null">
                AND requisition_id = #{requisitionId}
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectRequisitionCompensationListByRequisitionId" parameterType="Long" resultMap="RequisitionCompensationResult">
        <include refid="selectRequisitionCompensationVo"/>
        where requisition_id = #{requisitionId}
        order by create_time desc
    </select>

    <select id="selectRequisitionCompensationById" parameterType="Long" resultMap="RequisitionCompensationResult">
        <include refid="selectRequisitionCompensationVo"/>
        where id = #{id}
    </select>

    <insert id="insertRequisitionCompensation" parameterType="RequisitionCompensation" useGeneratedKeys="true" keyProperty="id">
        insert into resource_requisition_compensation(
            <if test="requisitionId != null">requisition_id,</if>
            <if test="workload != null">workload,</if>
            <if test="workloadUnit != null">workload_unit,</if>
            <if test="unitPrice != null">unit_price,</if>
            <if test="amount != null">amount,</if>
            <if test="currency != null">currency,</if>
            <if test="invoiceNo != null">invoice_no,</if>
            <if test="paidAt != null">paid_at,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            create_time
        )values(
            <if test="requisitionId != null">#{requisitionId},</if>
            <if test="workload != null">#{workload},</if>
            <if test="workloadUnit != null">#{workloadUnit},</if>
            <if test="unitPrice != null">#{unitPrice},</if>
            <if test="amount != null">#{amount},</if>
            <if test="currency != null">#{currency},</if>
            <if test="invoiceNo != null">#{invoiceNo},</if>
            <if test="paidAt != null">#{paidAt},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            sysdate()
        )
    </insert>

    <update id="updateRequisitionCompensation" parameterType="RequisitionCompensation">
        update resource_requisition_compensation
        <set>
            <if test="workload != null">workload = #{workload},</if>
            <if test="workloadUnit != null">workload_unit = #{workloadUnit},</if>
            <if test="unitPrice != null">unit_price = #{unitPrice},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="currency != null">currency = #{currency},</if>
            <if test="invoiceNo != null">invoice_no = #{invoiceNo},</if>
            <if test="paidAt != null">paid_at = #{paidAt},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            update_time = sysdate()
        </set>
        where id = #{id}
    </update>

    <delete id="deleteRequisitionCompensationById" parameterType="Long">
        delete from resource_requisition_compensation where id = #{id}
    </delete>

    <delete id="deleteRequisitionCompensationByRequisitionId" parameterType="Long">
        delete from resource_requisition_compensation where requisition_id = #{requisitionId}
    </delete>

</mapper>