async def post(self): try: libs.validator.space_id(self.post_data.get('space_id')) libs.validator.vaccine_id(self.post_data.get('vaccine_id')) libs.validator.record_at(self.post_data.get('date_of_inoculation')) libs.validator.injection_no(self.post_data.get('injection_no')) except libs.validator.ValidationError as e: self.send_to_client(-1, message=e.__str__()) return today = datetime.datetime.now().date() date = datetime.datetime.strptime(self.post_data.get("date_of_inoculation"), "%Y-%m-%d").date() if date < today: self.send_to_client(-1, message='计划接种日期应大于当前日期') return pb_space_detail = await SpaceServer().get_space_details(space_id=zbase62.decode(self.post_data.get('space_id')), request_id=self.request_id) if pb_space_detail: result = await VaccineServer().update_plan_inject(account_id=pb_space_detail.owner_id, vaccine_id=self.post_data.get("vaccine_id"), injection_no=self.post_data.get("injection_no"), date_of_inoculation=self.post_data.get( "date_of_inoculation"), request_id=self.request_id, space_id=zbase62.decode(self.post_data.get('space_id')), creator_id=self.current_user.account_id) rd.redis_del('injection_detail:{}'.format(zbase62.decode(self.post_data.get('space_id')))) pb_detail_list = await VaccineServer().get_vaccine_detail_list(request_id=self.request_id) pb_injection_log = await VaccineServer().get_injection_details(account_id=pb_space_detail.owner_id, request_id=self.request_id, space_id=zbase62.decode( self.post_data.get('space_id')), creator_id=self.current_user.account_id) inject_dict = {} if pb_injection_log: for inject in pb_injection_log.inject_detail: i = InjectDetail(inject).inject_detail i["date_of_inoculation"] = time.strftime("%Y-%m-%d", time.localtime(inject.date_of_inoculation.seconds)) inject_dict[(i.get("vaccine_id"), i.get("injection_no"))] = i detail_list = [] if pb_detail_list: for vaccine in pb_detail_list.vaccines: v = Vaccine(vaccine).vaccine vd = inject_dict.get((v.get("vaccine_id"), v.get("injection_no"))) v['is_injected'] = vd.get("is_injected") if vd else None v['date_of_inoculation'] = vd.get("date_of_inoculation") if vd else None detail_list.append(v) if result: self.send_to_client(0, message='设置成功', response=detail_list) return raise HTTPError(500, "update plan inject failed", reason="设置失败,请联系客服解决") raise HTTPError(500, "get space failed", reason="服务器出错,请联系客服解决")
async def post(self): if (self.post_data.get("height") or self.post_data.get("weight") or self.post_data.get("head_circumference")) is None: self.send_to_client(-1, message='请至少输入一项数据') return try: libs.validator.space_id(self.post_data.get("space_id")) libs.validator.growth_id(self.post_data.get("growth_id")) libs.validator.record_at(self.post_data.get("record_at")) if self.post_data.get("height"): libs.validator.height(float(self.post_data.get("height"))) if self.post_data.get("weight"): libs.validator.weight(float(self.post_data.get("weight"))) if self.post_data.get("head_circumference"): libs.validator.head_circumference( float(self.post_data.get("head_circumference"))) except libs.validator.ValidationError as e: self.send_to_client(-1, message=e.__str__()) return record_at = arrow.get(self.post_data.get('record_at')) record_at_utc = record_at.utcfromtimestamp( record_at.timestamp).datetime if bool(self.post_data.get("height") and self.post_data.get("weight")): # bmi值异常检测 if self.post_data.get("weight") / (self.post_data.get("height") * self.post_data.get("height") / 10000) > 60: self.send_to_client(-1, message='bmi值异常, 请正确输入宝宝的体重身高信息') return is_done, message = await RecordServer().update_record( growth_id=self.post_data.get("growth_id"), height=self.post_data.get("height"), weight=self.post_data.get("weight"), head_circumference=self.post_data.get("head_circumference"), record_at=record_at_utc, space_id=zbase62.decode(self.post_data.get('space_id')), creator_id=self.current_user.account_id, request_id=self.request_id) if is_done: rd.redis_del('growth_list:{}'.format( zbase62.decode(self.post_data.get('space_id')))) self.send_to_client(0, message='修改成功') else: self.send_to_client( -1, message=message if message else '服务器出错,请联系客服解决')
async def post(self): try: validator.account_id(self.post_data.get('from_id')) validator.message_id(self.post_data.get('message_id')) except validator.ValidationError as e: self.send_to_client(-1, message=e.__str__()) return result = await MsgBoxServer().set_message_as_unread( message_id=zbase62.decode(self.post_data.get("message_id")), to_id=zbase62.decode(self.post_data.get("from_id")), request_id=self.request_id) rd.redis_del('message_center_list:{}'.format( zbase62.decode(self.post_data.get("from_id")))) if result: self.send_to_client(-1, '设置消息未读失败!') return self.send_to_client(0, '设置消息未读成功!') return
async def post(self): try: libs.validator.space_id(self.post_data.get("space_id")) libs.validator.growth_id(self.post_data.get("growth_id")) except libs.validator.ValidationError as e: self.send_to_client(-1, message=e.__str__()) return is_done, message = await RecordServer().delete_record( growth_id=self.post_data.get("growth_id"), space_id=zbase62.decode(self.post_data.get('space_id')), creator_id=self.current_user.account_id, request_id=self.request_id) if is_done: rd.redis_del('growth_list:{}'.format( zbase62.decode(self.post_data.get('space_id')))) self.send_to_client(0, message='删除成功') else: self.send_to_client( -1, message=message if message else '服务器出错,请联系客服解决')
async def post(self): try: validator.account_id(self.post_data.get('from_id')) validator.space_id(self.post_data.get('space_id')) validator.msgtype(self.post_data.get('msg_type')) except validator.ValidationError as e: self.send_to_client(-1, message=e.__str__()) return result = await MsgBoxServer().set_all_message_as_read( product_id=Config().product, to_id=zbase62.decode(self.post_data.get("from_id")), msg_type=self.post_data.get("msg_type"), space_id=zbase62.decode(self.post_data.get("space_id")), request_id=self.request_id) rd.redis_del('message_center_list:{}'.format( zbase62.decode(self.post_data.get("from_id")))) if result: self.send_to_client(-1, '设置所有消息已读失败!') return self.send_to_client(0, '设置所有消息已读成功!') return
async def post(self): if (self.post_data.get("height") or self.post_data.get("weight") or self.post_data.get("head_circumference")) is None: self.send_to_client(-1, message='请至少输入一项数据') return try: libs.validator.space_id(self.post_data.get("space_id")) libs.validator.record_at(self.post_data.get("record_at")) if self.post_data.get("height"): libs.validator.height(float(self.post_data.get("height"))) if self.post_data.get("weight"): libs.validator.weight(float(self.post_data.get("weight"))) if self.post_data.get("head_circumference"): libs.validator.head_circumference( float(self.post_data.get("head_circumference"))) except libs.validator.ValidationError as e: self.send_to_client(-1, message=e.__str__()) return record_at = arrow.get(self.post_data.get('record_at')) record_at_utc = record_at.utcfromtimestamp( record_at.timestamp).datetime record_at_timestamp = record_at.timestamp if record_at_timestamp > time.time(): self.send_to_client(-1, message='记录日期有误') return if self.post_data.get("height") and self.post_data.get("weight"): # bmi值异常检测 if self.post_data.get("weight") / (self.post_data.get("height") * self.post_data.get("height") / 10000) > 60: self.send_to_client(-1, message='bmi值异常, 请正确输入宝宝的体重身高信息') return is_done, message = await RecordServer().add_record( account_id=zbase62.decode(self.post_data.get("account_id")), height=self.post_data.get("height"), weight=self.post_data.get("weight"), head_circumference=self.post_data.get("head_circumference"), record_at=record_at_utc, space_id=zbase62.decode(self.post_data.get('space_id')), creator_id=self.current_user.account_id, request_id=self.request_id) if is_done: rd.redis_del('growth_list:{}'.format( zbase62.decode(self.post_data.get('space_id')))) # to feed word_list = [] if self.post_data.get("weight") is not None: word_list.append("体重:{}KG".format( self.post_data.get("weight"))) if self.post_data.get("height") is not None: word_list.append("身高:{}CM".format( self.post_data.get("height"))) if self.post_data.get("head_circumference") is not None: word_list.append("头围:{}CM".format( self.post_data.get("head_circumference"))) feed_id = await ZIDServer().generate(self.request_id) if feed_id is None: raise HTTPError(500, "zid-server generate failed", reason="服务器出错,请联系客服解决") await FeedServer().create_feed( feed_id=feed_id, space_id=[zbase62.decode(self.post_data.get('space_id'))], # privacy=self.post_data.get('privacy'), #todo: 第一版本先不加权限 record_at=record_at_utc, creator_id=self.current_user.account_id, word='\n'.join(word_list), feed_type=pbfeed_pb2.FEED_TYPE_GROWTH, feed_size=0, request_id=self.request_id) self.send_to_client(0, message='添加成功') else: self.send_to_client( -1, message=message if message else '服务器出错,请联系客服解决')
async def post(self): mobile = self.post_data.get('mobile', '') smscode = self.post_data.get('smscode', '') errors = self._check_input({"mobile": mobile, "smscode": smscode}) if errors: err = '' for item, er in errors.items(): err = er break self.send_to_client(error_id=error.input_error.id, message=err) return # Check smscode mobile_smscode = rd.redis_get('verify:{}'.format(mobile)) if mobile_smscode: mobile_smscode = mobile_smscode.decode() if mobile_smscode != smscode: self.send_to_client(-1, '登陆验证码错误') return # Exists Mobile exists_account_already = False try: exists_account_already = await AccountServer( ).exists_account_by_mobile(mobile, request_id=self.request_id) except grpc.RpcError as e: self.send_to_client(error_id=500, message='服务器内部错误,请联系管理员确认') return pb_account = None if not exists_account_already: # not exists, create account pb_account = await AccountServer().create_account( mobile=mobile, country_code="86", app_id=self.app_id_int64, request_id=self.request_id) # 分配空间 result = await MembershipServer().set_total_storage_change( account_id=pb_account.account_id, changed_value=Config().membership.get("register_default_size"), title=Config().membership.get("register_default_title"), details=Config().membership.get("register_default_details"), request_id=self.request_id) else: # exists, get the account pb_account = await AccountServer().get_account_by_mobile( mobile=mobile, country_code="86", app_id=self.app_id_int64, request_id=self.request_id) # make Account Model if pb_account is None: self.send_to_client(error_id=500, message='服务器内部错误,请联系管理员确认') return account = Account(pb_account) # get account userinfo if account.status == pbaccount_pb2.STATUS_ACTIVATED: rd.redis_del('verify:{}'.format(mobile)) pb_userinfo = await AccountServer().get_userinfo( account.account_id, app_id=self.app_id_int64, request_id=self.request_id) await account.set_userinfo(pb_userinfo) self.send_to_client(0, message='登陆成功', response=account.dump()) return status_error = {0: "未知状态的账号", 2: "未激活账号", 3: "锁定并暂停账号或封号", 4: "账号已注销"} self.send_to_client(-1, message=status_error.get(account.status))