<?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.com.tenlion.staff.dao.basicstaffinfo.IBasicStaffInfoDao">

    <resultMap id="basicStaffInfoDTO" type="cn.com.tenlion.staff.pojo.dtos.basicstaffinfo.BasicStaffInfoDTO">
        <id column="basic_staff_info_id" property="basicStaffInfoId"></id>
        <result column="card_type" property="cardType"/>
        <result column="id_card_number" property="idCardNumber"/>
        <result column="full_name" property="fullName"/>
        <result column="name_used_before" property="nameUsedBefore"/>
        <result column="gender" property="gender"/>
        <result column="birth_date" property="birthDate"/>
        <result column="nation" property="nation"/>
        <result column="native_place" property="nativePlace"/>
        <result column="native_place_addr" property="nativePlaceAddr"/>
        <result column="political_status" property="politicalStatus"/>
        <result column="marital_status" property="maritalStatus"/>
        <result column="education" property="education"/>
        <result column="religion" property="religion"/>
        <result column="occupation_category" property="occupationCategory"/>
        <result column="occupation" property="occupation"/>
        <result column="service_space" property="serviceSpace"/>
        <result column="telephone" property="telephone"/>
        <result column="registered_residence" property="registeredResidence"/>
        <result column="registered_residence_addr" property="registeredResidenceAddr"/>
        <result column="current_residence" property="currentResidence"/>
        <result column="current_residence_addr" property="currentResidenceAddr"/>
        <result column="user_photo_id" property="userPhotoId"/>
        <result column="id_card_front" property="idCardFront"/>
        <result column="id_card_back" property="idCardBack"/>
        <result column="education_photo" property="educationPhoto"/>
        <result column="body_exam_photo" property="bodyExamPhoto"/>
        <result column="bind_user_account" property="bindUserAccount"/>
        <result column="tags" property="tags"/>
    </resultMap>

    <select id="list" parameterType="map" resultMap="basicStaffInfoDTO">
        SELECT
            t1.basic_staff_info_id,
            t1.id_card_number,
            t1.card_type,
            t1.full_name,
            t1.name_used_before,
            t1.gender,
            t1.birth_date,
            t1.nation,
            t1.native_place,
            t1.native_place_addr,
            t1.political_status,
            t1.marital_status,
            t1.education,
            t1.religion,
            t1.occupation_category,
            t1.occupation,
            t1.service_space,
            t1.telephone,
            t1.registered_residence,
            t1.registered_residence_addr,
            t1.current_residence,
            t1.current_residence_addr,
            t1.user_photo_id,
            t1.id_card_front,
            t1.id_card_back,
            t1.education_photo,
            t1.body_exam_photo,
            t1.bind_user_account,
            t1.tags
        FROM
            m_basic_staff_info t1
        WHERE
        t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
            AND (
                t1.full_name LIKE CONCAT('%', #{keywords}, '%')
                OR
                t1.id_card_number LIKE CONCAT('%', #{keywords}, '%')
            )
        </if>
        <if test="startTime != null and startTime != ''">
            AND LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        ORDER BY t1.gmt_create DESC
    </select>

    <insert id="save" parameterType="map">
        INSERT INTO m_basic_staff_info (
            basic_staff_info_id,
            card_type,
            id_card_number,
            full_name,
            name_used_before,
            gender,
            birth_date,
            nation,
            native_place,
            native_place_addr,
            political_status,
            marital_status,
            education,
            religion,
            occupation_category,
            occupation,
            service_space,
            telephone,
            registered_residence,
            registered_residence_addr,
            current_residence,
            current_residence_addr,
            user_photo_id,
            id_card_front,
            id_card_back,
            education_photo,
            body_exam_photo,
            bind_user_account,
            tags,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{basicStaffInfoId},
            #{cardType},
            #{idCardNumber},
            #{fullName},
            #{nameUsedBefore},
            #{gender},
            #{birthDate},
            #{nation},
            #{nativePlace},
            #{nativePlaceAddr},
            #{politicalStatus},
            #{maritalStatus},
            #{education},
            #{religion},
            #{occupationCategory},
            #{occupation},
            #{serviceSpace},
            #{telephone},
            #{registeredResidence},
            #{registeredResidenceAddr},
            #{currentResidence},
            #{currentResidenceAddr},
            #{userPhotoId},
            #{idCardFront},
            #{idCardBack},
            #{educationPhoto},
            #{bodyExamPhoto},
            #{bindUserAccount},
            #{tags},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <select id="getById" parameterType="map" resultMap="basicStaffInfoDTO">
        SELECT
            t1.basic_staff_info_id,
            t1.card_type,
            t1.id_card_number,
            t1.full_name,
            t1.name_used_before,
            t1.gender,
            t1.birth_date,
            t1.nation,
            t1.native_place,
            t1.native_place_addr,
            t1.political_status,
            t1.marital_status,
            t1.education,
            t1.religion,
            t1.occupation_category,
            t1.occupation,
            t1.service_space,
            t1.telephone,
            t1.registered_residence,
            t1.registered_residence_addr,
            t1.current_residence,
            t1.current_residence_addr,
            t1.user_photo_id,
            t1.id_card_front,
            t1.id_card_back,
            t1.education_photo,
            t1.body_exam_photo,
            t1.bind_user_account,
            t1.tags
        FROM
            m_basic_staff_info t1
        WHERE
        t1.is_delete = 0
        <if test="basicStaffInfoId != null and basicStaffInfoId != ''">
            AND t1.basic_staff_info_id = #{basicStaffInfoId}
        </if>
        <if test="bindUserAccount != null and bindUserAccount != ''">
            AND t1.bind_user_account = #{bindUserAccount}
        </if>
        limit 1
    </select>

    <update id="update" parameterType="map">
        UPDATE
            m_basic_staff_info
        SET
        <if test="cardType != null and cardType != ''">
            card_type = #{cardType},
        </if>
        <if test="idCardNumber != null and idCardNumber != ''">
            id_card_number = #{idCardNumber},
        </if>
        <if test="fullName != null and fullName != ''">
            full_name = #{fullName},
        </if>
        <if test="nameUsedBefore != null and nameUsedBefore != ''">
            name_used_before = #{nameUsedBefore},
        </if>
        <if test="gender != null and gender != ''">
            gender = #{gender},
        </if>
        <if test="birthDate != null and birthDate != ''">
            birth_date = #{birthDate},
        </if>
        <if test="nation != null and nation != ''">
            nation = #{nation},
        </if>
        <if test="nativePlace != null and nativePlace != ''">
            native_place = #{nativePlace},
        </if>
        <if test="nativePlaceAddr != null and nativePlaceAddr != ''">
            native_place_addr = #{nativePlaceAddr},
        </if>
        <if test="politicalStatus != null and politicalStatus != ''">
            political_status = #{politicalStatus},
        </if>
        <if test="maritalStatus != null and maritalStatus != ''">
            marital_status = #{maritalStatus},
        </if>
        <if test="education != null and education != ''">
            education = #{education},
        </if>
        <if test="religion != null and religion != ''">
            religion = #{religion},
        </if>
        <if test="occupationCategory != null and occupationCategory != ''">
            occupation_category = #{occupationCategory},
        </if>
        <if test="occupation != null and occupation != ''">
            occupation = #{occupation},
        </if>
        <if test="serviceSpace != null and serviceSpace != ''">
            service_space = #{serviceSpace},
        </if>
        <if test="telephone != null and telephone != ''">
            telephone = #{telephone},
        </if>
        <if test="registeredResidence != null and registeredResidence != ''">
            registered_residence = #{registeredResidence},
        </if>
        <if test="registeredResidenceAddr != null and registeredResidenceAddr != ''">
            registered_residence_addr = #{registeredResidenceAddr},
        </if>
        <if test="currentResidence != null and currentResidence != ''">
            current_residence = #{currentResidence},
        </if>
        <if test="currentResidenceAddr != null and currentResidenceAddr != ''">
            current_residence_addr = #{currentResidenceAddr},
        </if>
        <if test="userPhotoId != null and userPhotoId != ''">
            user_photo_id = #{userPhotoId},
        </if>
        <if test="idCardFront != null and idCardFront != ''">
            id_card_front = #{idCardFront},
        </if>
        <if test="idCardBack != null and idCardBack != ''">
            id_card_back = #{idCardBack},
        </if>
        <if test="educationPhoto != null and educationPhoto != ''">
            education_photo = #{educationPhoto},
        </if>
        <if test="bodyExamPhoto != null and bodyExamPhoto != ''">
            body_exam_photo = #{bodyExamPhoto},
        </if>
        <if test="bindUserAccount != null and bindUserAccount != ''">
            bind_user_account = #{bindUserAccount},
        </if>
        <if test="tags != null and tags != ''">
            tags = #{tags},
        </if>
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            basic_staff_info_id = #{basicStaffInfoId}
    </update>

    <update id="remove" parameterType="map">
        UPDATE
            m_basic_staff_info
        SET
            is_delete = 1,
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            basic_staff_info_id IN
        <foreach collection="ids" index="index" open="(" separator="," close=")">
            #{ids[${index}]}
        </foreach>
    </update>

    <update id="delete" parameterType="map">
        DELETE FROM
            m_basic_staff_info
        WHERE
            basic_staff_info_id IN
        <foreach collection="ids" index="index" open="(" separator="," close=")">
            #{ids[${index}]}
        </foreach>
    </update>

    <select id="dataAll" parameterType="map" resultType="map">
        select * from data_data where is_delete = '0'
    </select>

</mapper>