<?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.manager.dao.TypeDao">
    <insert id="addInfo">
        insert into pb_base_illness_type(illness_type,illness_sex,illness_keyword,is_active)
        values (#{illnessType}, #{illnessSex}, #{illnessKeyword}, '1');
    </insert>
    <update id="updateInfo">

        update pb_base_illness_type
        <set>
            <if test="illnessType !=null and illnessType !='' ">
                illness_type = #{illnessType},
            </if>

            <if test="illnessSex !=null and illnessSex !='' ">
                illness_sex = #{illnessSex},
            </if>

            <if test="illnessKeyword !=null and illnessKeyword !='' ">
                illness_keyword = #{illnessKeyword},
            </if>

        </set>

        where  id = #{id}

    </update>

    <delete id="delById">
        update pb_base_illness_type set is_active = '0' where id = #{id}
    </delete>

    <select id="gettyMsgList" resultType="com.bonus.boot.manager.manager.model.SysType">
        select t.id ,
               t.illness_type as illnessType,
               t.illness_sex as illnessSex,
               t.illness_keyword as illnessKeyword
        from pb_base_illness_type t
        where
            t.is_active = '1'
        <if test="illnessKeyword != null and illnessKeyword != ''">
            and (
            t.illness_keyword like concat('%', #{illnessKeyword}, '%')
            )
        </if>
    </select>

    <select id="gettyMsgListOne" resultType="com.bonus.boot.manager.manager.model.SysType">
        select t.id ,
        t.illness_type as illnessType,
        t.illness_sex as illnessSex,
        t.illness_keyword as illnessKeyword
        from pb_base_illness_type t
        where
        t.is_active = '1' and t.id = #{illnessId}
    </select>


    <select id="getStatisticalGroup" parameterType="com.bonus.boot.manager.physical.entity.CountImportBean" resultType="com.bonus.boot.manager.physical.entity.CountImportBean">

select ci.id,(select COUNT(id) from pm_base_physical where is_active ='1'
        <if test="sex !=null and sex !=''">
            and sex = #{sex}
        </if>

        <if test="hospitalId !=null and hospitalId !='' ">
            and hospital_id = #{hospitalId}
        </if>

            ) as allNum,
        (select COUNT(id) from pm_phy_data_info where is_active ='1' and data_year = #{dataYear}
        <if test="sex !=null and sex !=''">
            and if(phy_sex='男','0','1')=#{sex}
        </if>

        <if test="hospitalId !=null and hospitalId !='' ">
            and hospital_id = #{hospitalId}
        </if>
        ) as thisNum,
        (select COUNT(id) from pm_phy_data_info where is_active ='1' and phy_ole  <![CDATA[< ]]>40

        <if test="sex !=null and sex !=''">
            and if(phy_sex='男','0','1')=#{sex}
        </if>

        <if test="hospitalId !=null and hospitalId !='' ">
            and hospital_id = #{hospitalId}
        </if>

        ) as fortyCJDown,
        (select COUNT(id) from pm_base_physical where is_active ='1' and age <![CDATA[>=]]>40

        <if test="sex !=null and sex !=''">
            and sex = #{sex}
        </if>

        <if test="hospitalId !=null and hospitalId !='' ">
            and hospital_id = #{hospitalId}
        </if>

        ) as fortyUp,
				0 as abnormalNum,
				0 as fortyJCUp,
				0 as fortyJCDown,
        pb.illness_sex as pSex,
        ci.illness_type as illnessType,ci.illness_name as illnessName,ci.phy_number as phyNumber,
        ci.team_id as teamId,ci.team_name as teamName,ci.data_year as dataYear
        from count_import_message ci
        LEFT JOIN pb_base_illness_type pb on pb.id = ci.illness_type
        where ci.data_year = #{dataYear}

         <if test="keyWord !=null and keyWord !=''">
            and ci.illness_type = #{keyWord}
        </if>

        <if test="hospitalId !=null and hospitalId !='' ">
            and hospital_id = #{hospitalId}
        </if>

        <if test="sex ==0 or sex =='0'">
            and (pb.illness_sex ='0' or pb.illness_sex='2')
        </if>
        <if test="sex ==1 or sex =='1'">
            and (pb.illness_sex ='1' or pb.illness_sex='2')
        </if>

        GROUP BY ci.illness_type

    </select>

    <select id="getStatisticalInfo" parameterType="com.bonus.boot.manager.physical.entity.CountImportBean" resultType="com.bonus.boot.manager.physical.entity.CountImportBean">
        select id,illness_type as illnessType,illness_name as illnessName,phy_number as phyNumber,`name` ,
        sex,if(sex='男','0','1') as pSex,old,team_id as teamId,team_name as teamName,data_year as dataYear
        FROM
        count_import_message
        where data_year = #{dataYear} and hospital_id = #{hospitalId}
        <if test="sex !=null and sex !=''">
            and if(sex='男','0','1') = #{sex}
        </if>

    </select>

    <select id="getPositiveDisease" parameterType="com.bonus.boot.manager.basic.entity.MapBean" resultType="com.bonus.boot.manager.basic.entity.MapBean">
        SELECT id as `key` ,illness_type as `value`,illness_sex as `type` from pb_base_illness_type
        where is_active ='1'
        <if test="keyWord ==0 or keyWord == '0'">
            and (illness_sex ='0' or illness_sex ='2')
        </if>
        <if test="keyWord ==1 or keyWord == '1'">
            and (illness_sex ='1' or illness_sex ='2')
        </if>
    </select>

</mapper>