<?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.CmcWageMapper">
    
    <resultMap type="CmcWage" id="CmcWageResult">
        <result property="wageId"    column="wage_id"    />
        <result property="userId"    column="user_id"    />
        <result property="baseSalary"    column="base_salary"    />
        <result property="yearSalary"    column="year_salary"    />
        <result property="postSalary"    column="post_salary"    />
        <result property="performanceSalary"    column="performance_salary"    />
        <result property="certificatesSubsidy"    column="certificates_subsidy"    />
        <result property="festivalSubsidy"    column="festival_subsidy"    />
        <result property="postStableSubsidy"    column="post_stable_subsidy"    />
        <result property="highTemperatureSubsidy"    column="high_temperature_subsidy"    />
        <result property="attendanceDeduct"    column="attendance_deduct"    />
        <result property="payableWage"    column="payable_wage"    />
        <result property="houseFund"    column="house_fund"    />
        <result property="endowmentInsurance"    column="endowment_insurance"    />
        <result property="unemploymentInsurance"    column="unemployment_insurance"    />
        <result property="medicalInsurance"    column="medical_insurance"    />
        <result property="propertyFee"    column="property_fee"    />
        <result property="deductTotal"    column="deduct_total"    />
        <result property="socialSecurityUnit"    column="social_security_unit"    />
        <result property="individualIncomeTax"    column="individual_income_tax"    />
        <result property="paidWage"    column="paid_wage"    />
        <result property="payDay"    column="pay_day"    />
        <result property="payMonth"    column="pay_month"    />
        <result property="remark"    column="remark"    />
        <result property="performanceId"    column="performance_id"    />
        <association property="user"    javaType="SysUser"         resultMap="SysUserResult" />
        <association property="dept"    javaType="SysDept"         resultMap="SysDeptResult" />
    </resultMap>

    <resultMap type="SysUser" id="SysUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="nick_name"    />
    </resultMap>

    <resultMap type="SysDept" id="SysDeptResult">
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <sql id="selectCmcWageVo">
        select w.wage_id, w.user_id, u.dept_id, d.dept_name, w.base_salary, w.year_salary, w.post_salary, w.performance_salary, w.certificates_subsidy, w.festival_subsidy, w.post_stable_subsidy,
               w.high_temperature_subsidy, w.attendance_deduct, w.payable_wage, w.house_fund, w.endowment_insurance, w.unemployment_insurance, w.medical_insurance, w.property_fee,
               w.deduct_total, w.social_security_unit, w.individual_income_tax, w.paid_wage, w.pay_day, w.pay_month, w.remark, w.performance_id, u.nick_name from cmc_wage as w
        left join sys_user as u on u.user_id = w.user_id
        left join sys_dept as d on d.dept_id = u.dept_id
    </sql>

    <select id="selectCmcWageList" parameterType="CmcWage" resultMap="CmcWageResult">
        <include refid="selectCmcWageVo"/>
        <where>  
            <if test="userId != null "> and w.user_id = #{userId}</if>
            <if test="deptId != null "> and u.dept_id = #{deptId}</if>
            <if test="baseSalary != null "> and w.base_salary = #{baseSalary}</if>
            <if test="yearSalary != null "> and w.year_salary = #{yearSalary}</if>
            <if test="postSalary != null "> and w.post_salary = #{postSalary}</if>
            <if test="performanceSalary != null "> and w.performance_salary = #{performanceSalary}</if>
            <if test="certificatesSubsidy != null "> and w.certificates_subsidy = #{certificatesSubsidy}</if>
            <if test="festivalSubsidy != null "> and w.festival_subsidy = #{festivalSubsidy}</if>
            <if test="postStableSubsidy != null "> and w.post_stable_subsidy = #{postStableSubsidy}</if>
            <if test="highTemperatureSubsidy != null "> and w.high_temperature_subsidy = #{highTemperatureSubsidy}</if>
            <if test="attendanceDeduct != null "> and w.attendance_deduct = #{attendanceDeduct}</if>
            <if test="payableWage != null "> and w.payable_wage = #{payableWage}</if>
            <if test="houseFund != null "> and w.house_fund = #{houseFund}</if>
            <if test="endowmentInsurance != null "> and w.endowment_insurance = #{endowmentInsurance}</if>
            <if test="unemploymentInsurance != null "> and w.unemployment_insurance = #{unemploymentInsurance}</if>
            <if test="medicalInsurance != null "> and w.medical_insurance = #{medicalInsurance}</if>
            <if test="propertyFee != null "> and w.property_fee = #{propertyFee}</if>
            <if test="deductTotal != null "> and w.deduct_total = #{deductTotal}</if>
            <if test="socialSecurityUnit != null "> and w.social_security_unit = #{socialSecurityUnit}</if>
            <if test="individualIncomeTax != null "> and w.individual_income_tax = #{individualIncomeTax}</if>
            <if test="paidWage != null "> and w.paid_wage = #{paidWage}</if>
            <if test="payDay != null "> and w.pay_day = #{payDay}</if>
            <if test="payMonth != null "> and MONTH(w.pay_month) = MONTH(#{payMonth})</if>
            <if test="performanceId != null and performanceId != ''"> and w.performance_id = #{performanceId}</if>
        </where>
        order by w.user_id, w.pay_month
    </select>
    
    <select id="selectCmcWageByWageId" parameterType="Integer" resultMap="CmcWageResult">
        <include refid="selectCmcWageVo"/>
        where wage_id = #{wageId}
    </select>
        
    <insert id="insertCmcWage" parameterType="CmcWage">
        insert into cmc_wage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wageId != null">wage_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="baseSalary != null">base_salary,</if>
            <if test="yearSalary != null">year_salary,</if>
            <if test="postSalary != null">post_salary,</if>
            <if test="performanceSalary != null">performance_salary,</if>
            <if test="certificatesSubsidy != null">certificates_subsidy,</if>
            <if test="festivalSubsidy != null">festival_subsidy,</if>
            <if test="postStableSubsidy != null">post_stable_subsidy,</if>
            <if test="highTemperatureSubsidy != null">high_temperature_subsidy,</if>
            <if test="attendanceDeduct != null">attendance_deduct,</if>
            <if test="payableWage != null">payable_wage,</if>
            <if test="houseFund != null">house_fund,</if>
            <if test="endowmentInsurance != null">endowment_insurance,</if>
            <if test="unemploymentInsurance != null">unemployment_insurance,</if>
            <if test="medicalInsurance != null">medical_insurance,</if>
            <if test="propertyFee != null">property_fee,</if>
            <if test="deductTotal != null">deduct_total,</if>
            <if test="socialSecurityUnit != null">social_security_unit,</if>
            <if test="individualIncomeTax != null">individual_income_tax,</if>
            <if test="paidWage != null">paid_wage,</if>
            <if test="payDay != null">pay_day,</if>
            <if test="payMonth != null">pay_month,</if>
            <if test="remark != null">remark,</if>
            <if test="performanceId != null">performance_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wageId != null">#{wageId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="baseSalary != null">#{baseSalary},</if>
            <if test="yearSalary != null">#{yearSalary},</if>
            <if test="postSalary != null">#{postSalary},</if>
            <if test="performanceSalary != null">#{performanceSalary},</if>
            <if test="certificatesSubsidy != null">#{certificatesSubsidy},</if>
            <if test="festivalSubsidy != null">#{festivalSubsidy},</if>
            <if test="postStableSubsidy != null">#{postStableSubsidy},</if>
            <if test="highTemperatureSubsidy != null">#{highTemperatureSubsidy},</if>
            <if test="attendanceDeduct != null">#{attendanceDeduct},</if>
            <if test="payableWage != null">#{payableWage},</if>
            <if test="houseFund != null">#{houseFund},</if>
            <if test="endowmentInsurance != null">#{endowmentInsurance},</if>
            <if test="unemploymentInsurance != null">#{unemploymentInsurance},</if>
            <if test="medicalInsurance != null">#{medicalInsurance},</if>
            <if test="propertyFee != null">#{propertyFee},</if>
            <if test="deductTotal != null">#{deductTotal},</if>
            <if test="socialSecurityUnit != null">#{socialSecurityUnit},</if>
            <if test="individualIncomeTax != null">#{individualIncomeTax},</if>
            <if test="paidWage != null">#{paidWage},</if>
            <if test="payDay != null">#{payDay},</if>
            <if test="payMonth != null">#{payMonth},</if>
            <if test="remark != null">#{remark},</if>
            <if test="performanceId != null">#{performanceId},</if>
         </trim>
    </insert>

    <update id="updateCmcWage" parameterType="CmcWage">
        update cmc_wage
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="baseSalary != null">base_salary = #{baseSalary},</if>
            <if test="yearSalary != null">year_salary = #{yearSalary},</if>
            <if test="postSalary != null">post_salary = #{postSalary},</if>
            <if test="performanceSalary != null">performance_salary = #{performanceSalary},</if>
            <if test="certificatesSubsidy != null">certificates_subsidy = #{certificatesSubsidy},</if>
            <if test="festivalSubsidy != null">festival_subsidy = #{festivalSubsidy},</if>
            <if test="postStableSubsidy != null">post_stable_subsidy = #{postStableSubsidy},</if>
            <if test="highTemperatureSubsidy != null">high_temperature_subsidy = #{highTemperatureSubsidy},</if>
            <if test="attendanceDeduct != null">attendance_deduct = #{attendanceDeduct},</if>
            <if test="payableWage != null">payable_wage = #{payableWage},</if>
            <if test="houseFund != null">house_fund = #{houseFund},</if>
            <if test="endowmentInsurance != null">endowment_insurance = #{endowmentInsurance},</if>
            <if test="unemploymentInsurance != null">unemployment_insurance = #{unemploymentInsurance},</if>
            <if test="medicalInsurance != null">medical_insurance = #{medicalInsurance},</if>
            <if test="propertyFee != null">property_fee = #{propertyFee},</if>
            <if test="deductTotal != null">deduct_total = #{deductTotal},</if>
            <if test="socialSecurityUnit != null">social_security_unit = #{socialSecurityUnit},</if>
            <if test="individualIncomeTax != null">individual_income_tax = #{individualIncomeTax},</if>
            <if test="paidWage != null">paid_wage = #{paidWage},</if>
            <if test="payDay != null">pay_day = #{payDay},</if>
            <if test="payMonth != null">pay_month = #{payMonth},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="performanceId != null">performance_id = #{performanceId},</if>
        </trim>
        where wage_id = #{wageId}
    </update>

    <delete id="deleteCmcWageByWageId" parameterType="Integer">
        delete from cmc_wage where wage_id = #{wageId}
    </delete>

    <delete id="deleteCmcWageByWageIds" parameterType="String">
        delete from cmc_wage where wage_id in 
        <foreach item="wageId" collection="array" open="(" separator="," close=")">
            #{wageId}
        </foreach>
    </delete>

    <delete id="deleteCmcWageByPerformanceIds" parameterType="String">
        delete from cmc_wage where performance_id in
        <foreach item="performanceId" collection="array" open="(" separator="," close=")">
            #{performanceId}
        </foreach>
    </delete>
</mapper>