<?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="cn.ezhizao.project.business.salary.mapper.BizFinancialSalaryDetailMapper">

    <resultMap type="cn.ezhizao.project.business.salary.domain.BizFinancialSalaryDetail" id="BizFinancialSalaryDetailResult">
        <id column="id" property="id"/>
        <collection property="details" select="getEmployees" column="id" />
    </resultMap>


    <resultMap id="EmployeeResult" type="cn.ezhizao.project.business.salary.domain.BizFinancialSalaryDetailEmployee">
        <id column="id" jdbcType="INTEGER" property="id"/>
    </resultMap>

    <select id="getEmployees" resultMap="EmployeeResult">
        select *
        from biz_financial_salary_detail_employee
        where financial_salary_detail_id = #{id}
    </select>

    <select id="getList" parameterType="BizFinancialSalaryDetail" resultMap="BizFinancialSalaryDetailResult">
        SELECT t1.*, t2.name as company_name, t2.tax_type FROM biz_financial_salary_detail t1 left join biz_company t2 on t2.id = t1.company_id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0
            <if test="id != null  and id != ''"> AND t1.id = #{id}</if>
            <if test="financialSalaryId != null  and financialSalaryId != ''"> AND t1.financial_salary_id = #{financialSalaryId}</if>
            <if test="companyId != null  and companyId != ''"> AND t1.company_id = #{companyId}</if>
            <if test="year != null  and year != ''"> AND t1.year = #{year}</if>
            <if test="month != null  and month != ''"> AND t1.month = #{month}</if>
            <if test="status != null "> AND t1.status = #{status}</if>
            <if test="content != null  and content != ''"> AND t1.content = #{content}</if>
            <if test="verifyContent != null  and verifyContent != ''"> AND t1.verify_content = #{verifyContent}</if>
            <if test="feedbackContent != null  and feedbackContent != ''"> AND t1.feedback_content = #{feedbackContent}</if>
            <if test="hasIndividualIncomeTax != null "> AND t1.has_individual_income_tax = #{hasIndividualIncomeTax}</if>
            <if test="number != null "> AND t1.number = #{number}</if>
<!--            <if test="amount != null "> AND t1.amount = #{amount}</if>-->
        </trim>
    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_financial_salary_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
