<?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.finance.IndividualIncomeTax.mapper.BizFinancialIndividualIncomeTaxDetailMapper">
    <resultMap id="BaseResultMap"
               type="cn.ezhizao.project.business.finance.IndividualIncomeTax.domain.BizFinancialIndividualIncomeTaxDetail">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="id" jdbcType="BIGINT" property="id"/>
        <result column="financial_individual_income_tax_id" jdbcType="BIGINT"
                property="financialIndividualIncomeTaxId"/>
        <result column="company_id" jdbcType="BIGINT" property="companyId"/>
        <result column="year" jdbcType="CHAR" property="year"/>
        <result column="month" jdbcType="CHAR" property="month"/>
        <result column="amount" jdbcType="DECIMAL" property="amount"/>
        <result column="status" jdbcType="TINYINT" property="status"/>
        <result column="content" jdbcType="CHAR" property="content"/>
        <result column="verify_content" jdbcType="CHAR" property="verifyContent"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="creator_id" jdbcType="BIGINT" property="creatorId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="updater_id" jdbcType="BIGINT" property="updaterId"/>
        <result column="deleted" jdbcType="TINYINT" property="deleted"/>
        <result column="version" jdbcType="INTEGER" property="version"/>
        <collection property="files" ofType="cn.ezhizao.general.bean.FileStorage" select="getFiles" column="id"/>
    </resultMap>
    <resultMap
            type="cn.ezhizao.project.business.finance.IndividualIncomeTax.domain.BizFinancialIndividualIncomeTaxDetail"
            id="BizFinancialIndividualIncomeTaxResult">
        <id column="id" property="id"/>
    </resultMap>

    <resultMap type="cn.ezhizao.project.system.domain.SysFileStorage"
               id="SysFileStorageResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getFiles" parameterType="SysFileStorage" resultMap="SysFileStorageResult">
        SELECT *
        FROM sys_file_storage
        WHERE deleted = 0
          AND master_id = #{id}
    </select>



    <select id="getList" resultMap="BaseResultMap">
        <include refid="getListSql"/>
    </select>

    <!--带条件的List查询 数据总条数-->
    <select id="getTotal" resultType="java.lang.Integer">
        SELECT COUNT(1) FROM (<include refid="getListSql"/>) AS C
    </select>

    <sql id="getListSql">
        SELECT t1.*, t2.name as company_name FROM biz_financial_individual_income_tax_detail t1 left join biz_company t2 on t2.id = t1.company_id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0 AND
            <if test="id != null  ">
                t1.id = #{id} AND
            </if>
            <if test="companyName != null and companyName != '' ">
                t2.name like concat('%', #{companyName}, '%') AND
            </if>
            <if test="currentMonth != null and currentMonth != '' ">
                concat(t1.year, '-', t1.month) = #{currentMonth} AND
            </if>
            <if test="financialIndividualIncomeTaxId != null  ">
                t1.financial_individual_income_tax_id = #{financialIndividualIncomeTaxId} AND
            </if>
            <if test="companyId != null  ">
                t1.company_id = #{companyId} AND
            </if>
            <if test="year != null  and year != '' ">
                t1.year = #{year} AND
            </if>
            <if test="month != null  and month != '' ">
                t1.month = #{month} AND
            </if>
            <if test="amount != null  ">
                t1.amount = #{amount} AND
            </if>
            <if test="status != null  ">
                t1.status = #{status} AND
            </if>
            <if test="content != null  and content != '' ">
                t1.content = #{content} AND
            </if>
            <if test="verifyContent != null  and verifyContent != '' ">
                t1.verify_content = #{verifyContent} AND
            </if>
            <if test="mainIds != null and mainIds.size > 0">
                t1.financial_individual_income_tax_id in
                <foreach collection="mainIds" index="index" item="item" separator="," open="(" close=")">
                    #{item,jdbcType=BIGINT}
                </foreach>
            </if>
        </trim>
    </sql>



</mapper>
