<?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.BizSocialSecurityConfirmDetailEmployeeMapper">
    <!-- 基础的返回map 多表复杂的 自行组合 -->
    <resultMap id="BaseResultMap"
               type="cn.ezhizao.project.business.socialSecurity.domain.BizSocialSecurityConfirmDetailEmployee">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="id" jdbcType="BIGINT" property="id"/>
        <result column="social_security_confirm_id" jdbcType="BIGINT"
                property="socialSecurityConfirmId"/>
        <result column="social_security_confirm_detail_id" jdbcType="BIGINT"
                property="socialSecurityConfirmDetailId"/>
        <result column="employee_name" jdbcType="CHAR" property="employeeName"/>
        <result column="phone" jdbcType="CHAR" property="phone"/>
        <result column="id_card_image" jdbcType="CHAR" property="idCardImage"/>
        <result column="id_card_image_back" jdbcType="CHAR" property="idCardImageBack"/>
        <result column="cardinal_number" jdbcType="DECIMAL" property="cardinalNumber"/>
        <result column="remark" jdbcType="CHAR" property="remark"/>
        <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"/>
    </resultMap>

    <!--带条件的List查询-->
    <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 * FROM biz_social_security_confirm_detail_employee
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0 AND
            <if test="id != null  ">
                id = #{id} AND
            </if>
            <if test="socialSecurityConfirmId != null  ">
                social_security_confirm_id = #{socialSecurityConfirmId} AND
            </if>
            <if test="socialSecurityConfirmDetailId != null  ">
                social_security_confirm_detail_id = #{socialSecurityConfirmDetailId} AND
            </if>
            <if test="employeeName != null  and employeeName != '' ">
                employee_name = #{employeeName} AND
            </if>
            <if test="phone != null  and phone != '' ">
                phone = #{phone} AND
            </if>
            <if test="idCardImage != null  and idCardImage != '' ">
                id_card_image = #{idCardImage} AND
            </if>
            <if test="idCardImageBack != null  and idCardImageBack != '' ">
                id_card_image_back = #{idCardImageBack} AND
            </if>
            <if test="cardinalNumber != null  ">
                cardinal_number = #{cardinalNumber} AND
            </if>
            <if test="remark != null  and remark != '' ">
                remark = #{remark} AND
            </if>
            <if test="createTime != null  ">
                create_time = #{createTime} AND
            </if>
            <if test="creatorId != null  ">
                creator_id = #{creatorId} AND
            </if>
            <if test="updateTime != null  ">
                update_time = #{updateTime} AND
            </if>
            <if test="updaterId != null  ">
                updater_id = #{updaterId} AND
            </if>
            <if test="deleted != null  ">
                deleted = #{deleted} AND
            </if>
            <if test="version != null  ">
                version = #{version} AND
            </if>
        </trim>
    </sql>


    <!--根据主表id，删除 为的是表单保存时，明细统一物理删除后，再统一插入-->
    <delete id="physicallyDelete">
        DELETE FROM
        biz_social_security_confirm_detail_employee
        where social_security_confirm_detail_id = #{socialSecurityConfirmDetailId}
    </delete>
</mapper>
