<?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.logistics.mapper.BizFinancialAdjustmentRecordMapper">
    
    <resultMap type="com.ruoyi.logistics.domain.BizFinancialAdjustmentRecord" id="BizFinancialAdjustmentRecordResult">
        <result property="financialAdjustId"    column="financial_adjust_id"    />
        <result property="waybillNo"    column="waybill_no"    />
        <result property="waybillCostDetailId"    column="waybill_cost_detail_id"    />
        <result property="adjustmentType"    column="adjustment_type"    />
        <result property="originalAmount"    column="original_amount"    />
        <result property="adjustedAmount"    column="adjusted_amount"    />
        <result property="adjustmentAmount"    column="adjustment_amount"    />
        <result property="adjustmentReason"    column="adjustment_reason"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="deptId"    column="dept_id"    />
        <result property="userId"    column="user_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="userName"    column="user_name"    />
        <result property="deptName"    column="dept_name"    />
        <result property="summaryMonth"    column="summary_month"    />
    </resultMap>

    <sql id="selectBizFinancialAdjustmentRecordVo">
        select a.financial_adjust_id, a.waybill_no, a.waybill_cost_detail_id, a.adjustment_type, a.original_amount, a.adjusted_amount, a.adjustment_amount, a.adjustment_reason, a.create_time, a.update_time, a.remark, a.dept_id, a.user_id, a.del_flag, a.create_by, a.update_by,u.nick_name  user_name,d.dept_name  from biz_financial_adjustment_record  a
                                                                                                                                                                                                                                                                                                                                       left  join sys_user u on  a.user_id=u.user_id
                                                                                                                                                                                                                                                                                                                                       left join sys_dept d on  a.dept_id=d.dept_id
    </sql>

    <select id="selectBizFinancialAdjustmentRecordList" parameterType="com.ruoyi.logistics.domain.BizFinancialAdjustmentRecord" resultMap="BizFinancialAdjustmentRecordResult">
        select a.financial_adjust_id, a.waybill_no, a.waybill_cost_detail_id, a.adjustment_type, a.original_amount, a.adjusted_amount, a.adjustment_amount, a.adjustment_reason, a.create_time, a.update_time, a.remark, a.dept_id, a.user_id, a.del_flag, a.create_by, a.update_by,u.nick_name user_name,d.dept_name  from biz_financial_adjustment_record  a
        left  join sys_user u on  a.user_id=u.user_id
        left join sys_dept d on  a.dept_id=d.dept_id
        <where>  
            <if test="waybillNo != null  and waybillNo != ''"> and waybill_no = #{waybillNo}</if>
            <if test="waybillCostDetailId != null "> and waybill_cost_detail_id = #{waybillCostDetailId}</if>
            <if test="adjustmentType != null  and adjustmentType != ''"> and adjustment_type = #{adjustmentType}</if>
            <if test="originalAmount != null "> and original_amount = #{originalAmount}</if>
            <if test="adjustedAmount != null "> and adjusted_amount = #{adjustedAmount}</if>
            <if test="adjustmentAmount != null "> and adjustment_amount = #{adjustmentAmount}</if>
            <if test="adjustmentReason != null  and adjustmentReason != ''"> and adjustment_reason = #{adjustmentReason}</if>
            <if test="deptId != null "> and a.dept_id = #{deptId}</if>
            <if test="userId != null "> and a.user_id = #{userId}</if>

            <!-- 数据范围过滤 -->
            ${params.dataScope}
        </where>
     order by a.create_time DESC

    </select>




    <select id="selectBizFinancialAdjustmentRecordListNoPermission" parameterType="com.ruoyi.logistics.domain.BizFinancialAdjustmentRecord" resultMap="BizFinancialAdjustmentRecordResult">
        <include refid="selectBizFinancialAdjustmentRecordVo"/>
        where a.dept_id = #{deptId}  and  a.summary_month=#{summaryMonth}

    </select>


    
    <select id="selectBizFinancialAdjustmentRecordByFinancialAdjustId" parameterType="Long" resultMap="BizFinancialAdjustmentRecordResult">
        <include refid="selectBizFinancialAdjustmentRecordVo"/>
        where financial_adjust_id = #{financialAdjustId}
    </select>

    <insert id="insertBizFinancialAdjustmentRecord" parameterType="com.ruoyi.logistics.domain.BizFinancialAdjustmentRecord" useGeneratedKeys="true" keyProperty="financialAdjustId">
        insert into biz_financial_adjustment_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="waybillNo != null">waybill_no,</if>
            <if test="waybillCostDetailId != null">waybill_cost_detail_id,</if>
            <if test="adjustmentType != null">adjustment_type,</if>
            <if test="originalAmount != null">original_amount,</if>
            <if test="adjustedAmount != null">adjusted_amount,</if>
            <if test="adjustmentAmount != null">adjustment_amount,</if>
            <if test="adjustmentReason != null">adjustment_reason,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="summaryMonth != null">summary_month,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="waybillNo != null">#{waybillNo},</if>
            <if test="waybillCostDetailId != null">#{waybillCostDetailId},</if>
            <if test="adjustmentType != null">#{adjustmentType},</if>
            <if test="originalAmount != null">#{originalAmount},</if>
            <if test="adjustedAmount != null">#{adjustedAmount},</if>
            <if test="adjustmentAmount != null">#{adjustmentAmount},</if>
            <if test="adjustmentReason != null">#{adjustmentReason},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="summaryMonth != null">#{summaryMonth},</if>
         </trim>
    </insert>

    <update id="updateBizFinancialAdjustmentRecord" parameterType="com.ruoyi.logistics.domain.BizFinancialAdjustmentRecord">
        update biz_financial_adjustment_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="waybillNo != null">waybill_no = #{waybillNo},</if>
            <if test="waybillCostDetailId != null">waybill_cost_detail_id = #{waybillCostDetailId},</if>
            <if test="adjustmentType != null">adjustment_type = #{adjustmentType},</if>
            <if test="originalAmount != null">original_amount = #{originalAmount},</if>
            <if test="adjustedAmount != null">adjusted_amount = #{adjustedAmount},</if>
            <if test="adjustmentAmount != null">adjustment_amount = #{adjustmentAmount},</if>
            <if test="adjustmentReason != null">adjustment_reason = #{adjustmentReason},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where financial_adjust_id = #{financialAdjustId}
    </update>

    <delete id="deleteBizFinancialAdjustmentRecordByFinancialAdjustId" parameterType="Long">
        delete from biz_financial_adjustment_record where financial_adjust_id = #{financialAdjustId}
    </delete>

    <delete id="deleteBizFinancialAdjustmentRecordByFinancialAdjustIds" parameterType="String">
        delete from biz_financial_adjustment_record where financial_adjust_id in 
        <foreach item="financialAdjustId" collection="array" open="(" separator="," close=")">
            #{financialAdjustId}
        </foreach>
    </delete>
</mapper>