<?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.positive.dao.NegativeResultDao">

    <select id="getList" parameterType="com.bonus.boot.manager.physical.entity.NegativeResultBean" resultType="com.bonus.boot.manager.physical.entity.NegativeResultBean">
        select phy_number as phyNumber,phy_name as phyName,profile_position as profilePosition,phy_sex as phySex,phy_ole as phyOle,
        phy_unit as phyUnit,team_id as teamId,team_name as teamName,team_depart as teamDepart,sign_date as signDate,
        mas_result as masResult,conc_word as concWord,gener_recom as generRecom
        from pm_phy_data_info
        where 1=1  and hospital_id = #{hospitalId}
        <if test="keyWord !=null and keyWord !=''">
            and (
            phy_name like concat ('%',#{keyWord},'%') or
            team_name like concat ('%',#{keyWord},'%')
            )
        </if>
    </select>

    <select id="getMessageByPhyNumber" parameterType="com.bonus.boot.manager.physical.entity.NegativeResultBean" resultType="int">
        select count(id) from pm_phy_data_info where phy_number = #{phyNumber} and data_year = #{dataYear}
    </select>

    <insert id="addDataInfo" parameterType="com.bonus.boot.manager.physical.entity.NegativeResultBean">
        replace into pm_phy_data_info
        (id,phy_number,phy_name,profile_position,phy_sex,phy_ole,
        phy_unit,team_id,team_name,team_depart,sign_date,
        mas_result,conc_word,gener_recom,data_year,hospital_id)
         values
          (#{id},#{phyNumber},#{phyName},#{profilePosition},#{phySex},#{phyOle},
          #{phyUnit},#{teamId},#{teamName},#{teamDepart},#{signDate},
          #{masResult},#{concWord},#{generRecom},#{dataYear},#{hospitalId});
    </insert>

    <update id="updateDataInfo" parameterType="com.bonus.boot.manager.physical.entity.NegativeResultBean">
        update pm_phy_data_info
        <set>
            <if test="phyNumber !=null and phyNumber !=''">
                phy_number = #{phyNumber},
            </if>
            <if test="phyName !=null and phyName !=''">
                phy_name = #{phyName},
            </if>
            <if test="profilePosition !=null and profilePosition !=''">
                profile_position = #{profilePosition},
            </if>
            <if test="phySex !=null and phySex !=''">
                phy_sex = #{phySex},
            </if>
            <if test="phyOle !=null and phyOle !=''">
                phy_ole = #{phyOle},
            </if>


            <if test="phyUnit !=null and phyUnit !=''">
                phy_unit = #{phyUnit},
            </if>
            <if test="teamId !=null and teamId !=''">
                team_id = #{teamId},
            </if>
            <if test="teamName !=null and teamName !=''">
                team_name = #{teamName},
            </if>
            <if test="teamDepart !=null and teamDepart !=''">
                team_depart = #{teamDepart},
            </if>
            <if test="signDate !=null and signDate !=''">
                sign_date = #{signDate},
            </if>


            <if test="masResult !=null and masResult !=''">
                mas_result = #{masResult},
            </if>
            <if test="concWord !=null and concWord !=''">
                conc_word = #{concWord},
            </if>
            <if test="generRecom !=null and generRecom !=''">
                gener_recom = #{generRecom},
            </if>

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

        </set>
        where phy_number = #{phyNumber}
    </update>


    <select id="getIllnessType" parameterType="com.bonus.boot.manager.manager.model.SysType" resultType="com.bonus.boot.manager.manager.model.SysType">
   SELECT
	b.id AS id,
	b.illness_type AS illnessType,
	CASE b.illness_sex
	WHEN '0' THEN '男'
	WHEN '1' THEN '女'
	ELSE
		'全部'
	END	as illnessSex,

	REPLACE ( b.illness_keyword, ']**]', ';' ) AS illnessKeyword ,
	0 as countNum
FROM
	pb_base_illness_type b

    </select>

    <insert id="addCountResultMessage" parameterType="com.bonus.boot.manager.physical.entity.CountImportBean">
        replace into count_import_message(
        id,hospital_id,
        illness_type,phy_number,`name`,sex,old,
        team_name,illness_name,team_id,data_year
        )
        values (
        #{id},#{hospitalId},
        #{illnessType},#{phyNumber},#{name},#{sex},#{old},
        #{teamName},#{illnessName},#{teamId},#{dataYear}
        )
    </insert>

</mapper>

