<?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.canteen.core.nutrition.mapper.HealthInfoMapper">

    <select id="getSimpleInfo" resultType="com.bonus.canteen.core.nutrition.common.vo.HealthInfoSimpleVo">
        SELECT a.user_id,
               a.nick_name,
               a.phonenumber as mobile,
               a.photo_url as custPhotoUrl,
               a.sex,
               d.height,
               d.weight,
               d.bmi,
               b.doctor_advice,
               b.allergen,
               b.labour_intensity,
               b.pregnant_status,
               GROUP_CONCAT(c.chronic_name ORDER BY c.chronic_id desc) AS chronic_names,
               GROUP_CONCAT(c.chronic_id ORDER BY c.chronic_id desc)   AS chronic_ids
        from sys_user a
                 left join health_info b on a.user_id = b.user_id
                 left join health_info_chronic c on a.user_id = c.user_id
                 left join health_body_record d on a.user_id = d.user_id and d.if_latest = 1
        where 1 = 1
          and a.user_id = #{userId}
        group by a.user_id,
                 a.nick_name,
                 a.dept_id,
                 a.phonenumber,
                 a.photo_url,
                 a.sex,
                 d.height,
                 d.weight,
                 d.bmi,
                 b.doctor_advice,
                 b.allergen,
                 b.labour_intensity,
                 b.pregnant_status
    </select>

    <select id="fullHealthInfo" resultType="com.bonus.canteen.core.nutrition.common.vo.HealthInfoFullVo">
        select a.user_id,
               a.nick_name,
               a.phonenumber as mobile,
               a.sex,
               a.dept_id as orgId,
               a.user_type,
               b.marital_status,
               b.pregnant_status,
               b.pregnancy_date,
               b.doctor_advice,
               b.if_hospitalized,
               b.doctor_num,
               b.hospital_num,
               b.inpatient_date,
               b.inpatient_result,
               b.weight_control,
               b.allergen,
               b.labour_intensity,
               b.health_state,
               b.blood_type,
               c.height,
               c.weight,
               c.bmi,
               c.shape,
               c.bust,
               c.waistline,
               c.blood_sugar,
               c.blood_fat,
               c.blood_pressure_high,
               c.blood_pressure_low,
               c.heart_rate,
               c.blood_oxygen,
               c.uric_acid,
               c.blood_pressure,
               GROUP_CONCAT(d.chronic_name ORDER BY d.chronic_id desc) AS chronic_names,
               GROUP_CONCAT(d.chronic_id ORDER BY d.chronic_id desc)   AS chronic_ids
        from sys_user a
                 left join health_info b on a.user_id = b.user_id
                 left join health_body_record c on a.user_id = c.user_id and c.if_latest = 1
                 left join health_info_chronic d on a.user_id = d.user_id
        where a.user_id = #{userId}
        group by a.user_id,
                 a.user_name,
                 a.phonenumber,
                 a.sex,
                 a.dept_id,
                 a.user_type,
                 b.marital_status,
                 b.pregnant_status,
                 b.pregnancy_date,
                 b.doctor_advice,
                 b.if_hospitalized,
                 b.doctor_num,
                 b.hospital_num,
                 b.inpatient_date,
                 b.inpatient_result,
                 b.weight_control,
                 b.allergen,
                 b.labour_intensity,
                 b.health_state,
                 b.blood_type,
                 c.height,
                 c.weight,
                 c.bmi,
                 c.shape,
                 c.bust,
                 c.waistline,
                 c.blood_sugar,
                 c.blood_fat,
                 c.blood_pressure_high,
                 c.blood_pressure_low,
                 c.heart_rate,
                 c.blood_oxygen,
                 c.uric_acid,
                 c.blood_pressure
    </select>
</mapper>
