<?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.BizSocialSecurityConfirmDetailMapper">
    <!-- 基础的返回map 多表复杂的 自行组合 -->
    <resultMap id="BaseResultMap"
               type="cn.ezhizao.project.business.socialSecurity.domain.BizSocialSecurityConfirmDetail">
        <id column="id" jdbcType="BIGINT" property="id"/>
<!--        <collection property="details" select="getEmployees" column="id" />-->
    </resultMap>
    <resultMap id="BaseResultMap2"
               type="cn.ezhizao.project.business.socialSecurity.domain.BizSocialSecurityConfirmDetail">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <collection property="details" select="getEmployees" column="id" />
    </resultMap>
    <resultMap id="EmployeeResult" type="cn.ezhizao.project.business.socialSecurity.domain.BizSocialSecurityConfirmDetailEmployee">
        <id column="id" jdbcType="INTEGER" property="id"/>
    </resultMap>

    <select id="getEmployees" resultMap="EmployeeResult">
        select *
        from biz_social_security_confirm_detail_employee
        where social_security_confirm_detail_id = #{id} and deleted = 0
    </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.government_account_no, t2.name as company_name
        , t2.government_password, t2.social_security_account_no, t2.social_security_password
        , t2.employee_password, t2.is_first_social_security FROM biz_social_security_confirm_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="socialSecurityConfirmId != null  ">
                t1.social_security_confirm_id = #{socialSecurityConfirmId} 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="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>
        </trim>
    </sql>

</mapper>
