本文整理汇总了Python中helpers.queryhelper.QueryHelper.get_terminal_by_activation_code方法的典型用法代码示例。如果您正苦于以下问题:Python QueryHelper.get_terminal_by_activation_code方法的具体用法?Python QueryHelper.get_terminal_by_activation_code怎么用?Python QueryHelper.get_terminal_by_activation_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.queryhelper.QueryHelper
的用法示例。
在下文中一共展示了QueryHelper.get_terminal_by_activation_code方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_by_activation_code [as 别名]
def post(self):
"""Activate a YDWQ terminal.
"""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
activation_code = data.activation_code.upper()
sn = data.get('sn', '')
logging.info("[UWEB] Activate request: %s",
data)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception("[UWEB] Invalid data format. Exception: %s",
e.args)
self.write_ret(status)
return
try:
if not sn: # we assume it's activated by monitor
terminal = self.db.get("SELECT id, service_status, mobile"
" FROM T_TERMINAL_INFO"
" WHERE activation_code = %s"
" AND sn = '' "
" AND service_status = %s "
" AND biz_type = %s LIMIT 1",
activation_code, UWEB.SERVICE_STATUS.TO_BE_ACTIVATED,
UWEB.BIZ_TYPE.YDWQ)
if terminal:
self.db.execute("UPDATE T_TERMINAL_INFO"
" SET service_status = %s"
" WHERE activation_code = %s",
UWEB.SERVICE_STATUS.ON, activation_code)
logging.info("[UWEB] monitored is activated by monitor. activation_code: %s, sn: %s",
activation_code, sn)
else:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.info("[UWEB] Invalid data format. data: %s", data)
self.write_ret(status)
return
terminal = self.db.get("SELECT id, service_status, mobile"
" FROM T_TERMINAL_INFO"
" WHERE activation_code = %s"
" AND sn = %s"
" AND biz_type = %s LIMIT 1",
activation_code, sn,
UWEB.BIZ_TYPE.YDWQ)
if terminal: # normal login
logging.info("[UWEB] normal login. activation_code: %s, sn: %s.",
activation_code, sn)
self.db.execute("UPDATE T_TERMINAL_INFO"
" SET service_status = %s"
" WHERE activation_code = %s",
UWEB.SERVICE_STATUS.ON, activation_code)
self.write_ret(status,
dict_=DotDict(mobile=terminal.mobile))
else:
terminal = self.db.get("SELECT id, service_status, mobile, sn"
" FROM T_TERMINAL_INFO"
" WHERE activation_code = %s"
" AND biz_type = %s LIMIT 1",
activation_code, UWEB.BIZ_TYPE.YDWQ)
if not terminal: # no code
status = ErrorCode.TERMINAL_NOT_EXISTED
logging.error("[UWEB] activation_code: %s can not be found.",
activation_code)
self.write_ret(status)
else: # has code
if not terminal['sn']:
terminal_ = self.get_terminal_by_sn(sn)
if terminal_: # has code, but sn is used
status = ErrorCode.ACCOUNT_NOT_MATCH
logging.info("[UWEB] sn: %s has exist.", sn)
self.write_ret(status,
dict_=DotDict(mobile=terminal.mobile))
return
status = ErrorCode.SUCCESS
self.db.execute("UPDATE T_TERMINAL_INFO"
" SET sn = %s,"
" service_status = %s"
" WHERE activation_code = %s",
sn, UWEB.SERVICE_STATUS.ON, activation_code)
logging.info("[UWEB] monitored is activated by monitor. now update the sn. activation_code: %s, sn: %s",
activation_code, sn)
self.write_ret(status,
dict_=DotDict(mobile=terminal.mobile))
return
terminal = self.get_terminal_by_sn(sn)
if terminal: # has code, but sn is used
status = ErrorCode.ACCOUNT_NOT_MATCH
logging.info("[UWEB] sn: %s has exist.", sn)
self.write_ret(status,
dict_=DotDict(mobile=terminal.mobile))
else: # has code, sn not exist: a new activate
terminal = QueryHelper.get_terminal_by_activation_code(
activation_code, self.db)
# the code is used normal with another sn
if terminal['service_status'] == UWEB.SERVICE_STATUS.ON:
#.........这里部分代码省略.........