<?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.oa.mapper.CmcBudgetMapper">

    <resultMap type="CmcBudget" id="CmcBudgetResult">
        <result property="budgetId"    column="budget_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="staffCost"    column="staff_cost"    />
        <result property="carCost"    column="car_cost"    />
        <result property="deviceCost"    column="device_cost"    />
        <result property="fixCost"    column="fix_cost"    />
        <result property="settleExpense"    column="settle_expense"    />
        <result property="outExpense"    column="out_expense"    />
        <result property="businessExpense"    column="business_expense"    />
        <result property="businessCost"    column="business_cost"    />
        <result property="taxExpense"    column="tax_expense"    />
        <result property="rentExpense"    column="rent_expense"    />
        <result property="otherExpense"    column="other_expense"    />
        <result property="outRemark"    column="out_remark"    />
        <result property="businessRemark"    column="business_remark"    />
        <result property="taxRemark"    column="tax_remark"    />
        <result property="rentRemark"    column="rent_remark"    />
        <result property="otherRemark"    column="other_remark"    />
        <result property="directExpense"    column="direct_expense"    />
        <result property="totalBudget"    column="total_budget"    />
        <result property="compiler"    column="compiler"    />
        <result property="manager"    column="manager"    />
        <result property="auditor"    column="auditor"    />
        <result property="approver"    column="approver"    />
        <result property="managerComment"    column="manager_comment"    />
        <result property="zjlComment"    column="zjl_comment"    />
        <result property="dszComment"    column="dsz_comment"    />
        <result property="managerTime"    column="manager_time"    />
        <result property="zjlTime"    column="zjl_time"    />
        <result property="dszTime"    column="dsz_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
        <result property="document"    column="document"    />
        <result property="letterExpense"    column="letter_expense"    />
        <result property="winExpense"    column="win_expense"    />
        <result property="travelExpense"    column="travel_expense"    />
        <result property="settleAdjust"    column="settle_adjust"    />
        <result property="letterRemark"    column="letter_remark"    />
        <result property="travelRemark"    column="travel_remark"    />
        <result property="winRemark"    column="win_remark"    />
        <result property="outAdjust"    column="out_adjust"    />
        <result property="taxAdjust"    column="tax_adjust"    />
        <result property="letterAdjust"    column="letter_adjust"    />
        <result property="winAdjust"    column="win_adjust"    />
        <result property="travelAdjust"    column="travel_adjust"    />
        <result property="staffAdjust"    column="staff_adjust"    />
        <result property="carAdjust"    column="car_adjust"    />
        <result property="deviceAdjust"    column="device_adjust"    />
        <result property="businessAdjust"    column="business_adjust"    />
        <result property="siteCost"    column="site_cost"    />
        <result property="otherCost"    column="other_cost"    />
        <result property="siteAdjust"    column="site_adjust"    />
        <result property="procInstId"    column="proc_inst_id"    />
        <association property="compilerUser"    javaType="SysUser"         resultMap="CompilerResult" />
        <association property="managerUser"    javaType="SysUser"         resultMap="ManagerResult" />
        <association property="zjlUser"    javaType="SysUser"         resultMap="ZjlResult" />
        <association property="dszUser"    javaType="SysUser"         resultMap="DszResult" />
        <association property="project"    javaType="CmcProject"         resultMap="CmcProjectResult" />
    </resultMap>

    <resultMap type="SysUser" id="CompilerResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="compiler_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ManagerResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="manager_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ZjlResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="zjl_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="DszResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="dsz_nick_name"    />
    </resultMap>

    <resultMap type="CmcProject" id="CmcProjectResult">
        <result property="projectId"    column="project_id"    />
        <result property="projectNumber"    column="project_number"    />
        <result property="projectName"    column="project_name"    />
    </resultMap>

    <sql id="selectCmcBudgetVo">
        select b.budget_id, b.project_id, p.project_number, p.project_name, b.staff_cost, b.car_cost, b.device_cost, b.fix_cost, b.settle_expense, b.out_expense, b.business_expense, b.business_cost, b.tax_expense,
               b.rent_expense, b.other_expense, b.out_remark, b.business_remark, b.tax_remark, b.rent_remark, b.other_remark, b.direct_expense, b.total_budget, b.compiler, b.site_cost, b.other_cost, b.site_adjust,
               u.nick_name as compiler_nick_name, b.manager, u1.nick_name as manager_nick_name, b.auditor, u2.nick_name as zjl_nick_name, b.approver, u3.nick_name as dsz_nick_name, b.create_time, b.manager_time, b.zjl_time, b.dsz_time,
               b.manager_comment, b.zjl_comment, b.dsz_comment, b.remark, b.document, b.letter_expense, b.win_expense, b.travel_expense, b.settle_adjust, b.letter_remark, b.travel_remark, b.win_remark,
               b.out_adjust, b.tax_adjust, b.letter_adjust, b.win_adjust, b.travel_adjust, b.staff_adjust, b.car_adjust, b.device_adjust, b.business_adjust, b.proc_inst_id from cmc_budget as b
            left join sys_user as u on u.user_id = b.compiler
            left join sys_user as u1 on u1.user_id = b.manager
            left join sys_user as u2 on u2.user_id = b.auditor
            left join sys_user as u3 on u3.user_id = b.approver
            left join cmc_project as p on b.project_id = p.project_id
    </sql>

    <select id="selectCmcBudgetList" parameterType="CmcBudget" resultMap="CmcBudgetResult">
        <include refid="selectCmcBudgetVo"/>
        <where>
            <if test="budgetId != null  and budgetId != ''"> and b.budget_id = #{budgetId}</if>
            <if test="projectId != null  and projectId != ''"> and b.project_id = #{projectId}</if>
            <if test="staffCost != null "> and b.staff_cost = #{staffCost}</if>
            <if test="carCost != null "> and b.car_cost = #{carCost}</if>
            <if test="deviceCost != null "> and b.device_cost = #{deviceCost}</if>
            <if test="fixCost != null "> and b.fix_cost = #{fixCost}</if>
            <if test="settleExpense != null "> and b.settle_expense = #{settleExpense}</if>
            <if test="outExpense != null "> and b.out_expense = #{outExpense}</if>
            <if test="businessExpense != null "> and b.business_expense = #{businessExpense}</if>
            <if test="rentExpense != null "> and b.rent_expense = #{rentExpense}</if>
            <if test="otherExpense != null "> and b.other_expense = #{otherExpense}</if>
            <if test="directExpense != null "> and b.direct_expense = #{directExpense}</if>
            <if test="totalBudget != null "> and b.total_budget = #{totalBudget}</if>
            <if test="compiler != null "> and b.compiler = #{compiler}</if>
            <if test="auditor != null "> and b.auditor = #{auditor}</if>
            <if test="procInstId != null  and procInstId != ''"> and b.proc_inst_id = #{procInstId}</if>
        </where>
        order by b.create_time desc
    </select>

    <select id="selectCmcBudgetByBudgetId" parameterType="String" resultMap="CmcBudgetResult">
        <include refid="selectCmcBudgetVo"/>
        where budget_id = #{budgetId}
    </select>

    <insert id="insertCmcBudget" parameterType="CmcBudget">
        insert into cmc_budget
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="budgetId != null">budget_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="staffCost != null">staff_cost,</if>
            <if test="carCost != null">car_cost,</if>
            <if test="deviceCost != null">device_cost,</if>
            <if test="fixCost != null">fix_cost,</if>
            <if test="settleExpense != null">settle_expense,</if>
            <if test="outExpense != null">out_expense,</if>
            <if test="businessExpense != null">business_expense,</if>
            <if test="businessCost != null">business_cost,</if>
            <if test="taxExpense != null">tax_expense,</if>
            <if test="rentExpense != null">rent_expense,</if>
            <if test="otherExpense != null">other_expense,</if>
            <if test="outRemark != null">out_remark,</if>
            <if test="businessRemark != null">business_remark,</if>
            <if test="taxRemark != null">tax_remark,</if>
            <if test="rentRemark != null">rent_remark,</if>
            <if test="otherRemark != null">other_remark,</if>
            <if test="directExpense != null">direct_expense,</if>
            <if test="totalBudget != null">total_budget,</if>
            <if test="compiler != null">compiler,</if>
            <if test="manager != null">manager,</if>
            <if test="auditor != null">auditor,</if>
            <if test="approver != null">approver,</if>
            <if test="managerTime != null">manager_time,</if>
            <if test="zjlTime != null">zjl_time,</if>
            <if test="dszTime != null">dsz_time,</if>
            <if test="managerComment != null">manager_comment,</if>
            <if test="zjlComment != null">zjl_comment,</if>
            <if test="dszComment != null">dsz_comment,</if>
            <if test="remark != null">remark,</if>
            <if test="document != null">document,</if>
            <if test="letterExpense != null">letter_expense,</if>
            <if test="winExpense != null">win_expense,</if>
            <if test="travelExpense != null">travel_expense,</if>
            <if test="settleAdjust != null">settle_adjust,</if>
            <if test="letterRemark != null">letter_remark,</if>
            <if test="travelRemark != null">travel_remark,</if>
            <if test="winRemark != null">win_remark,</if>
            <if test="outAdjust != null">out_adjust,</if>
            <if test="taxAdjust != null">tax_adjust,</if>
            <if test="letterAdjust != null">letter_adjust,</if>
            <if test="winAdjust != null">win_adjust,</if>
            <if test="travelAdjust != null">travel_adjust,</if>
            <if test="staffAdjust != null">staff_adjust,</if>
            <if test="carAdjust != null">car_adjust,</if>
            <if test="deviceAdjust != null">device_adjust,</if>
            <if test="businessAdjust != null">business_adjust,</if>
            <if test="procInstId != null">proc_inst_id,</if>
            <if test="siteCost != null">site_cost,</if>
            <if test="otherCost != null">other_cost,</if>
            <if test="siteAdjust != null">site_adjust,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="budgetId != null">#{budgetId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="staffCost != null">#{staffCost},</if>
            <if test="carCost != null">#{carCost},</if>
            <if test="deviceCost != null">#{deviceCost},</if>
            <if test="fixCost != null">#{fixCost},</if>
            <if test="settleExpense != null">#{settleExpense},</if>
            <if test="outExpense != null">#{outExpense},</if>
            <if test="businessExpense != null">#{businessExpense},</if>
            <if test="businessCost != null">#{businessCost},</if>
            <if test="taxExpense != null">#{taxExpense},</if>
            <if test="rentExpense != null">#{rentExpense},</if>
            <if test="otherExpense != null">#{otherExpense},</if>
            <if test="outRemark != null">#{outRemark},</if>
            <if test="businessRemark != null">#{businessRemark},</if>
            <if test="taxRemark != null">#{taxRemark},</if>
            <if test="rentRemark != null">#{rentRemark},</if>
            <if test="otherRemark != null">#{otherRemark},</if>
            <if test="directExpense != null">#{directExpense},</if>
            <if test="totalBudget != null">#{totalBudget},</if>
            <if test="compiler != null">#{compiler},</if>
            <if test="manager != null">#{manager},</if>
            <if test="auditor != null">#{auditor},</if>
            <if test="approver != null">#{approver},</if>
            <if test="managerTime != null">#{managerTime},</if>
            <if test="zjlTime != null">#{zjlTime},</if>
            <if test="dszTime != null">#{dszTime},</if>
            <if test="managerComment != null">#{managerComment},</if>
            <if test="zjlComment != null">#{zjlComment},</if>
            <if test="dszComment != null">#{dszComment},</if>
            <if test="remark != null">#{remark},</if>
            <if test="document != null">#{document},</if>
            <if test="letterExpense != null">#{letterExpense},</if>
            <if test="winExpense != null">#{winExpense},</if>
            <if test="travelExpense != null">#{travelExpense},</if>
            <if test="settleAdjust != null">#{settleAdjust},</if>
            <if test="letterRemark != null">#{letterRemark},</if>
            <if test="travelRemark != null">#{travelRemark},</if>
            <if test="winRemark != null">#{winRemark},</if>
            <if test="outAdjust != null">#{outAdjust},</if>
            <if test="taxAdjust != null">#{taxAdjust},</if>
            <if test="letterAdjust != null">#{letterAdjust},</if>
            <if test="winAdjust != null">#{winAdjust},</if>
            <if test="travelAdjust != null">#{travelAdjust},</if>
            <if test="staffAdjust != null">#{staffAdjust},</if>
            <if test="carAdjust != null">#{carAdjust},</if>
            <if test="deviceAdjust != null">#{deviceAdjust},</if>
            <if test="businessAdjust != null">#{businessAdjust},</if>
            <if test="procInstId != null">#{procInstId},</if>
            <if test="siteCost != null">#{siteCost},</if>
            <if test="otherCost != null">#{otherCost},</if>
            <if test="siteAdjust != null">#{siteAdjust},</if>
            sysdate()
        </trim>
    </insert>

    <update id="updateCmcBudget" parameterType="CmcBudget">
        update cmc_budget
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="staffCost != null">staff_cost = #{staffCost},</if>
            <if test="carCost != null">car_cost = #{carCost},</if>
            <if test="deviceCost != null">device_cost = #{deviceCost},</if>
            <if test="fixCost != null">fix_cost = #{fixCost},</if>
            <if test="settleExpense != null">settle_expense = #{settleExpense},</if>
            <if test="outExpense != null">out_expense = #{outExpense},</if>
            <if test="businessExpense != null">business_expense = #{businessExpense},</if>
            <if test="businessCost != null">business_cost = #{businessCost},</if>
            <if test="taxExpense != null">tax_expense = #{taxExpense},</if>
            <if test="rentExpense != null">rent_expense = #{rentExpense},</if>
            <if test="otherExpense != null">other_expense = #{otherExpense},</if>
            <if test="outRemark != null">out_remark = #{outRemark},</if>
            <if test="businessRemark != null">business_remark = #{businessRemark},</if>
            <if test="taxRemark != null">tax_remark = #{taxRemark},</if>
            <if test="rentRemark != null">rent_remark = #{rentRemark},</if>
            <if test="otherRemark != null">other_remark = #{otherRemark},</if>
            <if test="directExpense != null">direct_expense = #{directExpense},</if>
            <if test="totalBudget != null">total_budget = #{totalBudget},</if>
            <if test="compiler != null">compiler = #{compiler},</if>
            <if test="manager != null">manager = #{manager},</if>
            <if test="auditor != null">auditor = #{auditor},</if>
            <if test="approver != null">approver = #{approver},</if>
            <if test="managerTime != null">manager_time = #{managerTime},</if>
            <if test="zjlTime != null">zjl_time = #{zjlTime},</if>
            <if test="dszTime != null">dsz_time = #{dszTime},</if>
            <if test="managerComment != null">manager_comment = #{managerComment},</if>
            <if test="zjlComment != null">zjl_comment = #{zjlComment},</if>
            <if test="dszComment != null">dsz_comment = #{dszComment},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="document != null">document = #{document},</if>
            <if test="letterExpense != null">letter_expense = #{letterExpense},</if>
            <if test="winExpense != null">win_expense = #{winExpense},</if>
            <if test="travelExpense != null">travel_expense = #{travelExpense},</if>
            <if test="settleAdjust != null">settle_adjust = #{settleAdjust},</if>
            <if test="letterRemark != null">letter_remark = #{letterRemark},</if>
            <if test="travelRemark != null">travel_remark = #{travelRemark},</if>
            <if test="winRemark != null">win_remark = #{winRemark},</if>
            <if test="outAdjust != null">out_adjust = #{outAdjust},</if>
            <if test="taxAdjust != null">tax_adjust = #{taxAdjust},</if>
            <if test="letterAdjust != null">letter_adjust = #{letterAdjust},</if>
            <if test="winAdjust != null">win_adjust = #{winAdjust},</if>
            <if test="travelAdjust != null">travel_adjust = #{travelAdjust},</if>
            <if test="staffAdjust != null">staff_adjust = #{staffAdjust},</if>
            <if test="carAdjust != null">car_adjust = #{carAdjust},</if>
            <if test="deviceAdjust != null">device_adjust = #{deviceAdjust},</if>
            <if test="businessAdjust != null">business_adjust = #{businessAdjust},</if>
            <if test="procInstId != null">proc_inst_id = #{procInstId},</if>
            <if test="siteCost != null">site_cost = #{siteCost},</if>
            <if test="otherCost != null">other_cost = #{otherCost},</if>
            <if test="siteAdjust != null">site_adjust = #{siteAdjust},</if>
        </trim>
        where budget_id = #{budgetId}
    </update>

    <delete id="deleteCmcBudgetByBudgetId" parameterType="String">
        delete from cmc_budget where budget_id = #{budgetId}
    </delete>

    <delete id="deleteCmcBudgetByBudgetIds" parameterType="String">
        delete from cmc_budget where budget_id in
        <foreach item="budgetId" collection="array" open="(" separator="," close=")">
            #{budgetId}
        </foreach>
    </delete>
</mapper>