import copy

from console.task.models import SerialNumber


def get_serial_number():
    '''
    获取当前流水号
    :return:
    '''
    serial_number = SerialNumber.objects.first()
    if not serial_number:
        serial_number = SerialNumber.objects.create(number=1)
    result = copy.deepcopy(serial_number.number)

    serial_number.last_number = serial_number.number
    serial_number.number += 1
    serial_number.save()
    return result
