<?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.socialSecurity.mapper.BizSocialSecurityDeclareDetailMapper">
    <!-- 基础的返回map 多表复杂的 自行组合 -->
    <resultMap id="BaseResultMap"
               type="cn.ezhizao.project.business.socialSecurity.domain.BizSocialSecurityDeclareDetail">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="id" jdbcType="BIGINT" property="id"/>
        <collection property="evidenceFiles" ofType="cn.ezhizao.project.system.domain.SysFileStorage" select="getFiles"
                    column="id"/>
        <collection property="reportFiles"
                    ofType="cn.ezhizao.project.system.domain.SysFileStorage"
                    select="getReportFiles" column="id"/>
    </resultMap>
    <resultMap id="BaseResultMap2"
               type="cn.ezhizao.project.business.socialSecurity.domain.BizSocialSecurityDeclareDetail">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="id" jdbcType="BIGINT" property="id"/>

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

    <select id="getFiles" resultMap="FileStorageResult">
        select s.*
        from sys_file_storage s
        where s.deleted = 0
          and s.master_table_name = 'biz_social_security_declare_detail'
          and s.master_id = #{id}
          and s.type = 'evidenceFile'
    </select>

    <select id="getReportFiles" resultMap="FileStorageResult">
        select s.*
        from sys_file_storage s
        where s.deleted = 0
          and s.master_table_name = 'biz_social_security_declare_detail'
          and s.master_id = #{id}
          and s.type = 'reportFile'
    </select>
    <!--带条件的List查询-->
    <select id="getList" resultMap="BaseResultMap">
        <include refid="getListSql"/>
    </select>
    <select id="getList2" resultMap="BaseResultMap2">
        <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, t2.government_account_no
        , t2.government_password, t2.social_security_account_no, t2.social_security_password
        , t2.employee_password, t2.is_first_social_security
        FROM biz_social_security_declare_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="socialSecurityDeclareId != null  ">
                t1.social_security_declare_id = #{socialSecurityDeclareId} 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="unitPension != null  ">
                t1.unit_pension = #{unitPension} AND
            </if>
            <if test="unitMedical != null  ">
                t1.unit_medical = #{unitMedical} AND
            </if>
            <if test="unitInjury != null  ">
                t1.unit_injury = #{unitInjury} AND
            </if>
            <if test="unitUnemployment != null  ">
                t1.unit_unemployment = #{unitUnemployment} AND
            </if>
            <if test="unitProcreate != null  ">
                t1.unit_procreate = #{unitProcreate} AND
            </if>
            <if test="unitSeriousIllness != null  ">
                t1.unit_serious_illness = #{unitSeriousIllness} AND
            </if>
            <if test="individualPension != null  ">
                t1.individual_pension = #{individualPension} AND
            </if>
            <if test="individualMedical != null  ">
                t1.individual_medical = #{individualMedical} AND
            </if>
            <if test="individualUnemployment != null  ">
                t1.individual_unemployment = #{individualUnemployment} AND
            </if>
            <if test="individualSeriousIllness != null  ">
                t1.individual_serious_illness = #{individualSeriousIllness} 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>
        </trim>
    </sql>

</mapper>
