|
@@ -16,7 +16,7 @@ from django.views import View
|
|
|
from Ansjer.cn_config.config_formal import SECRET_ACCESS_KEY, ACCESS_KEY_ID, REGION_NAME
|
|
|
|
|
|
from Object.AWS.AmazonS3Util import AmazonS3Util
|
|
|
-from Roomumy.models import BabyUser
|
|
|
+from Roomumy.models import BabyUser, BabyGrowthStandard
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Service.CommonService import CommonService
|
|
|
|
|
@@ -112,11 +112,6 @@ class BabyView(View):
|
|
|
def query_baby_info(cls, request_dict, user_id, response):
|
|
|
"""
|
|
|
获取宝宝信息
|
|
|
- @param request_dict: 请求参数
|
|
|
- @param user_id: 用户id
|
|
|
- @request_dict baby_id: 宝宝id
|
|
|
- @param response: 响应对象
|
|
|
- @return: response
|
|
|
"""
|
|
|
baby_id = request_dict.get('baby_id', None)
|
|
|
|
|
@@ -125,10 +120,44 @@ class BabyView(View):
|
|
|
if baby_id:
|
|
|
baby_qs = baby_qs.filter(id=baby_id)
|
|
|
count = baby_qs.count()
|
|
|
- baby_qs = baby_qs.values('id', 'nick_name', 'sex', 'birthday', 'icon_url', 'device_id', 'is_default')
|
|
|
- return response.json(0, {'total': count, 'baby_list': list(baby_qs)})
|
|
|
+ baby_list = list(
|
|
|
+ baby_qs.values('id', 'nick_name', 'sex', 'birthday', 'icon_url', 'device_id', 'is_default'))
|
|
|
+
|
|
|
+ current_time = int(time.time()) # 获取当前时间戳
|
|
|
+
|
|
|
+ for baby in baby_list:
|
|
|
+ birthday = baby.get('birthday', 0)
|
|
|
+ baby['growth_standard'] = None # 初始化字段
|
|
|
+
|
|
|
+ # 仅处理有效生日数据
|
|
|
+ if birthday > 0:
|
|
|
+ age_days = (current_time - birthday) // 86400 # 计算年龄天数
|
|
|
+
|
|
|
+ # 查询成长标准数据
|
|
|
+ standards = BabyGrowthStandard.objects.filter(
|
|
|
+ age_min__lte=age_days,
|
|
|
+ age_max__gte=age_days,
|
|
|
+ gender=baby.get('sex', 0) # 默认性别为女
|
|
|
+ ).first() # 直接获取第一条匹配记录
|
|
|
+
|
|
|
+ if standards:
|
|
|
+ baby['growth_standard'] = {
|
|
|
+ 'height': {'min': standards.height_min, 'max': standards.height_max},
|
|
|
+ 'weight': {'min': standards.weight_min, 'max': standards.weight_max},
|
|
|
+ 'head_circumference': {
|
|
|
+ 'min': standards.head_circumference_min,
|
|
|
+ 'max': standards.head_circumference_max
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else:
|
|
|
+ baby['growth_standard'] = {
|
|
|
+ 'height': {'min': None, 'max': None},
|
|
|
+ 'weight': {'min': None, 'max': None},
|
|
|
+ 'head_circumference': {'min': None, 'max': None}
|
|
|
+ }
|
|
|
+ return response.json(0, {'total': count, 'baby_list': baby_list})
|
|
|
except Exception as e:
|
|
|
- return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(500, f'error_line:{e.__traceback__.tb_lineno}, error_msg:{repr(e)}')
|
|
|
|
|
|
@classmethod
|
|
|
def delete_baby(cls, request_dict, user_id, response):
|