Exemple #1
0
def deal_sign_out(account_id, current_date, sign_time, manual_flag=False):
    content = get_status_by_user(account_id, current_date)
    process = None
    if content is not None:
        status = content[0]
        process = content[1]
        if status == "out_done":
            return invalid_message()

    if process is None or process != "sign_in_done":
        return invalid_message()

    return deal_sign_out_message(sign_time, manual_flag)
Exemple #2
0
def manual_sign_in_content(account_id, current_date):
    """
    Update user status and generate manual check-in message.

    :param account_id: user account id
    :param current_date: current date by local time.
    :return: message content list
    """

    content = get_status_by_user(account_id, current_date)

    if content is not None:
        status = content[0]
        process = content[1]
        if process is not None:
            return [invalid_message()]

        if status == "wait_in" or status == "in_done":
            delete_status_by_user_date(account_id, current_date)

    yield asyncio.sleep(1)

    insert_replace_status_by_user_date(account_id, current_date, "wait_in")

    return manual_sign_in_message()
def manual_sign_out_content(account_id, current_date):
    """
    Update user status and generate manual check-out message.

    :param account_id: user account id
    :param current_date: current date by local time.
    :return: message content list
    """

    content = get_status_by_user(account_id, current_date)
    process = None
    if content is not None:
        status = content[0]
        process = content[1]

    if process is None or process != "sign_in_done":
        return [invalid_message()]

    if status == "wait_out" or status == "out_done":
        set_status_by_user_date(account_id, current_date, status="in_done")

    yield asyncio.sleep(1)
    set_status_by_user_date(account_id, current_date, "wait_out")

    return manual_sign_out_message()
Exemple #4
0
def deal_user_message(account_id, current_date, create_time, message):
    """
    Process messages entered by users,
    Different scenarios need different processing functions.
    Please see the internal implementation of the handler.

    :param account_id: user account id.
    :param current_date: current date by local time.
    :param create_time: Time when the user requests to arrive at the BOT server.
    :param message: User entered message.
    :return: message content
    """

    date_time = local_date_time(create_time)

    content = get_status_by_user(account_id, current_date)

    if content is None or content[0] is None:
        LOGGER.info("status is None account_id:%s message:%s content:%s",
                    account_id, message, str(content))
        raise HTTPError(403, "Messages not need to be processed")

    status = content[0]
    process = content[1]
    try:
        user_time = int(message)
    except Exception:
        if status == "wait_in" or status == "wait_out":
            return error_message()
        else:
            raise HTTPError(403, "Messages not need to be processed")

    if (status == "wait_in" or status == "wait_out") \
            and (user_time < 0 or user_time > 2400):
        return error_message()

    tm = date_time.replace(hour=int(user_time / 100),
                           minute=int(user_time % 100))
    user_time_ticket = int(tm.timestamp())

    if status == "wait_in":
        content = yield deal_sign_in(account_id,
                                     current_date, user_time_ticket, True)
        set_status_by_user_date(account_id, current_date, status="in_done")
        return [content]
    if status == "wait_out":
        content = yield deal_sign_out(account_id,
                                      current_date, user_time_ticket, True)
        set_status_by_user_date(account_id, current_date, status="out_done")
        return [content]
    if process == "sign_in_done" or process == "sign_out_done":
        return [invalid_message()]

    LOGGER.info("can't deal this message account_id:%s message:%s status:%s",
                account_id, message, status)
    raise HTTPError(403, "Messages not need to be processed")
Exemple #5
0
def deal_sign_in(account_id, current_date, sign_time, manual_flag=False):
    content = get_status_by_user(account_id, current_date)

    if content is not None:
        status = content[0]
        process = content[1]
        if process is not None:
            return invalid_message()

        if status == "wait_in" or status == "in_done":
            delete_status_by_user_date(account_id, current_date)

    return deal_sign_in_message(sign_time, manual_flag)
Exemple #6
0
def manual_sign_out_content(account_id, current_date):
    """
    Update user status and generate manual check-out message.

    :param account_id: user account id
    :param current_date: current date by local time.
    :return: message content list
    """
    yield asyncio.sleep(1)
    content = get_status_by_user(account_id, current_date)

    if content is None or content[1] is None or content[1] != "sign_in_done":
        return [invalid_message()]

    set_status_by_user_date(account_id, current_date, "wait_out")

    return manual_sign_out_message()
Exemple #7
0
def deal_sign_out(account_id, current_date, sign_time, manual_flag=False):
    content = get_status_by_user(account_id, current_date)
    process = None
    if content is not None:
        status = content[0]
        process = content[1]

    if process is None or process != "sign_in_done":
        return [invalid_message()], True

    if status == "wait_out" or status == "out_done":
        set_status_by_user_date(account_id, current_date, status="in_done")

    info = get_schedule_by_user(account_id, current_date)
    if info is None:
        raise HTTPError(500, "Internal data error")
    begin_time_st = info[1]
    user_time = TimeStruct(sign_time)
    if int(user_time.str_current_time_tick) < begin_time_st:
        set_status_by_user_date(account_id, current_date, status="wait_out")
        return number_message(), False

    return [deal_sign_out_message(sign_time, manual_flag)], True