<?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="com.zehong.system.mapper.TEmployedPeopleInfoMapper">

    <resultMap type="TEmployedPeopleInfo" id="TEmployedPeopleInfoResult">
        <result property="employedPeopleId"    column="employed_people_id"    />
        <result property="employedPeopleName"    column="employed_people_name"    />
        <result property="idCard"    column="id_card"    />
        <result property="avatarAddress"    column="avatar_address"    />
        <result property="certificateNum"    column="certificate_num"    />
        <result property="beyondEnterpriseName"    column="beyond_enterprise_name"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="registerExaminationType"    column="register_examination_type"    />
        <result property="peopleOccupation"    column="people_occupation"    />
        <result property="issueDate"    column="issue_date"    />
        <result property="certificateChange"    column="certificate_change"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <resultMap type="TEnterpriseInfo" id="TEnterpriseInfoResult">
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="registerAddress"    column="register_address"    />
        <result property="legalRepresentative"    column="legal_representative"    />
        <result property="businessArea"    column="business_area"    />
        <result property="licenseKey"    column="license_key"    />
        <result property="licenseValidityTime"    column="license_validity_time"    />
        <result property="annualSupervisionInspection"    column="annual_supervision_inspection"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

<!--    <sql id="selectTEmployedPeopleInfoVo">-->
<!--        select employed_people_id, employed_people_name, id_card, certificate_num, beyond_enterprise_name, beyond_enterprise_id, register_examination_type, (CASE people_occupation WHEN '1' THEN '主要负责人' WHEN '2' THEN '安全管理人员' WHEN '3' THEN '运行维护和抢修人员'end ) as  people_occupation, issue_date, certificate_change, create_by, create_time, update_by, update_time, is_del, remarks from t_employed_people_info-->
<!--    </sql>-->
    <sql id="selectTEmployedPeopleInfoVo">
        select employed_people_id, employed_people_name, id_card, certificate_num, beyond_enterprise_name, beyond_enterprise_id, register_examination_type, people_occupation, issue_date, certificate_change, create_by, create_time, update_by, update_time, is_del, remarks from t_employed_people_info
    </sql>

    <select id="selectTEmployedPeopleInfoList" parameterType="TEmployedPeopleInfo" resultMap="TEmployedPeopleInfoResult">
        select employed_people_id, employed_people_name,avatar_address, id_card, certificate_num, beyond_enterprise_name, beyond_enterprise_id, register_examination_type,people_occupation, issue_date, certificate_change, create_by, create_time, update_by, update_time, is_del, remarks from t_employed_people_info
        <where>
        1=1 and is_del='0'
            <if test=" beyondEnterpriseId !='-2'  and  beyondEnterpriseId != null  and beyondEnterpriseId != ''"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="employedPeopleName != null  and employedPeopleName != ''"> and employed_people_name like concat('%', #{employedPeopleName}, '%')</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
        ORDER by employed_people_id desc
    </select>

    <select id="selectTEmployedPeopleInfoById" parameterType="Long" resultMap="TEmployedPeopleInfoResult">
    select employed_people_id, employed_people_name, id_card, certificate_num, beyond_enterprise_name, beyond_enterprise_id, register_examination_type, people_occupation, issue_date, certificate_change, create_by, create_time, update_by, update_time, is_del, remarks,avatar_address from t_employed_people_info
        where employed_people_id = #{employedPeopleId} and is_del='0'
    </select>

    <insert id="insertTEmployedPeopleInfo" parameterType="TEmployedPeopleInfo" useGeneratedKeys="true" keyProperty="employedPeopleId">
        insert into t_employed_people_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="employedPeopleName != null">employed_people_name,</if>
            <if test="idCard != null">id_card,</if>
            <if test="certificateNum != null">certificate_num,</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="registerExaminationType != null">register_examination_type,</if>
            <if test="peopleOccupation != null">people_occupation,</if>
            <if test="issueDate != null">issue_date,</if>
            <if test="certificateChange != null">certificate_change,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
            <if test="avatarAddress != null">avatar_address,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="employedPeopleName != null">#{employedPeopleName},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="certificateNum != null">#{certificateNum},</if>
            <if test="beyondEnterpriseName != null">#{beyondEnterpriseName},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="registerExaminationType != null">#{registerExaminationType},</if>
            <if test="peopleOccupation != null">#{peopleOccupation},</if>
            <if test="issueDate != null">#{issueDate},</if>
            <if test="certificateChange != null">#{certificateChange},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="avatarAddress != null">#{avatarAddress},</if>
         </trim>
    </insert>

    <update id="updateTEmployedPeopleInfo" parameterType="TEmployedPeopleInfo">
        update t_employed_people_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="employedPeopleName != null">employed_people_name = #{employedPeopleName},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="certificateNum != null">certificate_num = #{certificateNum},</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name = #{beyondEnterpriseName},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="registerExaminationType != null">register_examination_type = #{registerExaminationType},</if>
            <if test="peopleOccupation != null">people_occupation = #{peopleOccupation},</if>
            <if test="issueDate != null">issue_date = #{issueDate},</if>
            <if test="certificateChange != null">certificate_change = #{certificateChange},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="avatarAddress != null">avatar_address = #{avatarAddress},</if>
        </trim>
        where employed_people_id = #{employedPeopleId}
    </update>

    <update id="deleteTEmployedPeopleInfoById" parameterType="Long">
        update t_employed_people_info set is_del='1'  where employed_people_id = #{employedPeopleId}
    </update>

    <update id="deleteTEmployedPeopleInfoByIds" parameterType="String">
        update  t_employed_people_info set is_del='1' where employed_people_id in
        <foreach item="employedPeopleId" collection="array" open="(" separator="," close=")">
            #{employedPeopleId}
        </foreach>
    </update>

    <!--企业信息查询(下拉框数据)-->
    <select id="selectTEnterprise"  resultMap="TEnterpriseInfoResult">
        select enterprise_id,enterprise_name from t_enterprise_info where
        <if test="deptId!=null and deptId!= -2">
            enterprise_id =#{deptId} and
        </if>
        is_del='0'
    </select>

    <!--根据企业id查询企业名称-->
    <select id="selectEnterpriseName" resultType="String">
       select enterprise_name from t_enterprise_info where enterprise_id=#{bId} and is_del='0'
    </select>


    <select id="queryPeopleOccupationByGroupBy" resultType="String">
        SELECT
            people_occupation
        FROM
            t_employed_people_info
        where COALESCE(people_occupation, '') <![CDATA[<>]]> '' and is_del='0'
        GROUP BY
            people_occupation
    </select>
</mapper>
