<?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.bonus.boot.manager.statistics.dao.ResStatisticsDao">

    <select id="getList" resultType="com.bonus.boot.manager.basic.entity.MapBean" parameterType="com.bonus.boot.manager.basic.entity.MapBean">
        SELECT a.phy_appont_time as `key`,COUNT(a.id) as `value`
        FROM pm_base_phy_appont a
        LEFT JOIN pm_base_physical b on b.id = a.user_id
        WHERE a.if_cancel ='2' and b.is_active = '1' and a.if_career_appoint = '2'

              <if test="hospitalId !=null and hospitalId !='null'">
                  <if test="type == 1">
                      <if test="userId != 1">
                          <if test="hospitalId == 35">
                              and a.hospital_id = '35' AND (check_content_id != "" OR check_content_id IS NOT NULL)

                          </if>
                          <if test="hospitalId != 35">
                              and a.hospital_id = #{hospitalId}
                          </if>
                      </if>
                  </if>
                  <if test="type == 2">
                      and a.hospital_id = '35' AND a.is_special != '0'
                  </if>
              </if>
        <if test="personName !=null and personName !='null'">
            and b.phy_name like concat ('%',#{personName},'%')
        </if>
        <if test="reservationTime !=null and reservationTime !='null'">
            and a.phy_appont_time = #{reservationTime}
        </if>
        <if test="phyTimeStart !=null and phyTimeStart !='null'">
            and a.phy_appont_time between #{phyTimeStart} and #{phyTimeEnd}
        </if>
        GROUP BY a.phy_appont_time
    </select>


    <select id="getChildList" resultType="com.bonus.boot.manager.basic.entity.PersonnelLibraryBean" parameterType="com.bonus.boot.manager.basic.entity.PersonnelLibraryBean">
        SELECT
            a.id AS personId,
            b.id AS reservationId,
            a.phy_name AS personName,
            a.idcard AS idNumber,
            a.age,
            CASE
            WHEN check_content_id = 1 THEN
            '心血管'
            WHEN check_content_id = 2 THEN
            '肿瘤'
            WHEN check_content_id = 3 THEN
            '综合'
            ELSE
            '' end AS checkContentId,
            IF (a.sex = '0', '男', '女') AS sex,
#             IF (b.if_edu  = '0', '否', '是') AS ifEdu,
            IF(a.if_higher = '0', '否', '是') AS higherJob,
            comb_name as combName,
            a.telep_number AS phone,
            pmo.`NAME` AS department,
            b.phy_appont_time AS reservationTime,
            pbh.hospital AS NAME,
            b.appont_time AS operateTime,
            sysu.username AS operatePerson,
            pbh.id AS id,
            if_cancel AS ifCancel
            FROM
            pm_base_physical a
            LEFT JOIN (
            SELECT
            *
            FROM
            pm_base_phy_appont
            WHERE
            if_cancel = '2' AND (check_content_id != "" OR check_content_id IS NOT NULL)
        ) b ON a.id = b.user_id and  a.is_active ='1'
            LEFT JOIN pm_phy_organization pmo ON pmo.ID = a.depart_id and pmo.IS_ACTIVE ='1'
            LEFT JOIN pm_base_hospital pbh ON pbh.id = b.hospital_id and pbh.is_active = '1'
            LEFT JOIN sys_user sysu ON sysu.id = b.appoint_name_id and sysu.is_active ='1'
        WHERE
        b.id IS NOT NULL
        <if test="id !=null and id !='null'">
            and pbh.id = #{id}
        </if>
        <if test="personName !=null and personName !='null'">
            and a.phy_name like concat ('%',#{personName},'%')
        </if>
        <if test="reservationTime !=null and reservationTime !=''">
            and b.phy_appont_time  = #{reservationTime}
        </if>
        <if test="name !=null and name !=''">
            and b.hospital_id  = #{name}
        </if>
        <if test="phyTimeEnd !=null and phyTimeEnd !=''">
            and b.phy_appont_time  between #{phyTimeStart} and #{phyTimeEnd}
        </if>
        <if test="userId != 1">
            <if test="hospId !=null and hospId !=''">
                and b.hospital_id   = #{hospId}
            </if>
        </if>

    </select>
    <select id="getHospitalId" resultType="java.lang.String">
        select hospital_id AS hospitalId from sys_user where phone = #{phone}
    </select>
    <select id="getHospitalIds" resultType="java.lang.String">
        select hospital_id AS hospitalId from sys_user where phone = #{phone}
    </select>


</mapper>

