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

    <select id="getSimpleInfo" resultType="com.bonus.core.nutrition.common.vo.HealthInfoSimpleVo">
        SELECT a.cust_id,
               a.cust_num,
               a.cust_name,
               a.org_full_name,
               cp.place_full_name,
               a.mobile,
               a.cust_photo_url,
               a.birthday,
               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 cust_info a
                 left join cust_place cp on a.place_id = cp.place_id
                 left join health_info b on a.cust_id = b.cust_id
                 left join health_info_chronic c on a.cust_id = c.cust_id
                 left join health_body_record d on a.cust_id = d.cust_id and d.if_latest = 1
        where 1 = 1
          and a.cust_id = #{custId}
        group by a.cust_id,
                 a.cust_num,
                 a.cust_name,
                 a.org_full_name,
                 cp.place_full_name,
                 a.mobile,
                 a.cust_photo_url,
                 a.birthday,
                 a.sex,
                 d.height,
                 d.weight,
                 d.bmi,
                 b.doctor_advice,
                 b.allergen,
                 b.labour_intensity,
                 b.pregnant_status
    </select>
</mapper>
