<?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.TPractitionerInfoMapper">

    <resultMap type="TPractitionerInfo" id="TPractitionerInfoResult">
        <result property="practitionerId"    column="practitioner_id"    />
        <result property="stationId"    column="station_id"    />
        <result property="practitionerNum"    column="practitioner_num"    />
        <result property="name"    column="name"    />
        <result property="sex"    column="sex"    />
        <result property="birthDate"    column="birth_date"    />
        <result property="postId"    column="post_id"    />
        <result property="telNum"    column="tel_num"    />
        <result property="deliveryArea"    column="delivery_area"    />
        <result property="personPhoto"    column="person_photo"    />
        <result property="licenseFile"    column="license_file"    />
        <result property="certificateNum"    column="certificate_num"    />
        <result property="certificateEffectiveDate"    column="certificate_effective_date"    />
        <result property="password"    column="password"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remark"    column="remark"    />
        <result property="stationName" column="station_name"/>
        <result property="postName" column="post_name"/>
    </resultMap>

    <sql id="selectTPractitionerInfoVo">
        SELECT
            info.practitioner_id,
            info.station_id,
            info.practitioner_num,
            info.NAME,
            info.sex,
            info.birth_date,
            info.post_id,
            info.tel_num,
            info.delivery_area,
            info.person_photo,
            info.license_file,
            info.certificate_num,
            info.certificate_effective_date,
            info.PASSWORD,
            info.create_time,
            info.update_time,
            info.is_del,
            info.remark,
          (SELECT station_name FROM t_gas_storage_station_info station WHERE station.station_id = info.station_id) AS station_name,
          (SELECT post_name FROM sys_post p WHERE p.post_id = info.post_id) AS post_name
        FROM
            t_practitioner_info info
    </sql>

    <select id="selectTPractitionerInfoList" parameterType="TPractitionerInfo" resultMap="TPractitionerInfoResult">
        <include refid="selectTPractitionerInfoVo"/>
        <where>
            <if test="stationId != null "> and info.station_id = #{stationId}</if>
            <if test="practitionerNum != null  and practitionerNum != ''"> and info.practitioner_num = #{practitionerNum}</if>
            <if test="name != null  and name != ''"> and info.name like concat('%', #{name}, '%')</if>
            <if test="sex != null  and sex != ''"> and info.sex = #{sex}</if>
            <if test="birthDate != null "> and info.birth_date = #{birthDate}</if>
            <if test="postId != null "> and info.post_id = #{postId}</if>
            <if test="telNum != null  and telNum != ''"> and info.tel_num = #{telNum}</if>
            <if test="deliveryArea != null  and deliveryArea != ''"> and info.delivery_area = #{deliveryArea}</if>
            <if test="personPhoto != null  and personPhoto != ''"> and info.info.person_photo = #{personPhoto}</if>
            <if test="licenseFile != null  and licenseFile != ''"> and info.license_file = #{licenseFile}</if>
            <if test="certificateNum != null  and certificateNum != ''"> and info.certificate_num = #{certificateNum}</if>
            <if test="certificateEffectiveDate != null "> and info.certificate_effective_date = #{certificateEffectiveDate}</if>
            <if test="password != null  and password != ''"> and info.password = #{password}</if>
            <if test="isDel != null  and isDel != ''"> and info.is_del = #{isDel}</if>
        </where>
        order by   info.practitioner_id desc
    </select>

    <select id="selectTPractitionerInfoById" parameterType="Long" resultMap="TPractitionerInfoResult">
        <include refid="selectTPractitionerInfoVo"/>
        where info.practitioner_id = #{practitionerId}
    </select>

    <!--查询登录信息-->
    <select id="loginTPractitioner" resultMap="TPractitionerInfoResult">
        <include refid="selectTPractitionerInfoVo"/>
        where info.tel_num = #{telNum} and is_del='0'
    </select>

    <insert id="insertTPractitionerInfo" parameterType="TPractitionerInfo" useGeneratedKeys="true" keyProperty="practitionerId">
        insert into t_practitioner_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationId != null">station_id,</if>
            <if test="practitionerNum != null">practitioner_num,</if>
            <if test="name != null">name,</if>
            <if test="sex != null">sex,</if>
            <if test="birthDate != null">birth_date,</if>
            <if test="postId != null">post_id,</if>
            <if test="telNum != null">tel_num,</if>
            <if test="deliveryArea != null">delivery_area,</if>
            <if test="personPhoto != null">person_photo,</if>
            <if test="licenseFile != null">license_file,</if>
            <if test="certificateNum != null">certificate_num,</if>
            <if test="certificateEffectiveDate != null">certificate_effective_date,</if>
            <if test="password != null">password,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationId != null">#{stationId},</if>
            <if test="practitionerNum != null">#{practitionerNum},</if>
            <if test="name != null">#{name},</if>
            <if test="sex != null">#{sex},</if>
            <if test="birthDate != null">#{birthDate},</if>
            <if test="postId != null">#{postId},</if>
            <if test="telNum != null">#{telNum},</if>
            <if test="deliveryArea != null">#{deliveryArea},</if>
            <if test="personPhoto != null">#{personPhoto},</if>
            <if test="licenseFile != null">#{licenseFile},</if>
            <if test="certificateNum != null">#{certificateNum},</if>
            <if test="certificateEffectiveDate != null">#{certificateEffectiveDate},</if>
            <if test="password != null">#{password},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTPractitionerInfo" parameterType="TPractitionerInfo">
        update t_practitioner_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="practitionerNum != null">practitioner_num = #{practitionerNum},</if>
            <if test="name != null">name = #{name},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="birthDate != null">birth_date = #{birthDate},</if>
            <if test="postId != null">post_id = #{postId},</if>
            <if test="telNum != null">tel_num = #{telNum},</if>
            <if test="deliveryArea != null">delivery_area = #{deliveryArea},</if>
            <if test="personPhoto != null">person_photo = #{personPhoto},</if>
            <if test="licenseFile != null">license_file = #{licenseFile},</if>
            <if test="certificateNum != null">certificate_num = #{certificateNum},</if>
            <if test="certificateEffectiveDate != null">certificate_effective_date = #{certificateEffectiveDate},</if>
            <if test="password != null">password = #{password},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where practitioner_id = #{practitionerId}
    </update>

    <delete id="deleteTPractitionerInfoById" parameterType="Long">
        delete from t_practitioner_info where practitioner_id = #{practitionerId}
    </delete>

    <delete id="deleteTPractitionerInfoByIds" parameterType="String">
        delete from t_practitioner_info where practitioner_id in
        <foreach item="practitionerId" collection="array" open="(" separator="," close=")">
            #{practitionerId}
        </foreach>
    </delete>
</mapper>