Commit a35819f1 by Aeolus

update

parent 757d141a
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
author:Aeolus author:Aeolus
@file: hatch_portal.py @file: hatch_portal.py
""" """
import datetime
import logging import logging
import time import time
...@@ -106,12 +107,15 @@ def run_create_machine_no(): ...@@ -106,12 +107,15 @@ def run_create_machine_no():
if machine: if machine:
return jsonify(MACHINE_MAC_DUPLICATE_ERROR) return jsonify(MACHINE_MAC_DUPLICATE_ERROR)
for i in range(3): date_str = datetime.datetime.now().date().strftime("%Y%m%d")[2:]
machine_no = int(time.time()) sql = "SELECT max(machine_no) as machine_no FROM machine where machine_no like '{}%'".format(date_str)
machine = Machine.query.filter_by(machine_no=machine_no).first() result = db.session.execute(sql).fetchone()
if not machine: if result:
break max_machine_no = int(result["machine_no"])
return jsonify(MACHINE_NO_CREATE_ERROR) machine_no = str(max_machine_no + 1)
else:
machine_no = date_str + "0001"
machine_model = Machine() machine_model = Machine()
machine_model.machine_no = machine_no machine_model.machine_no = machine_no
machine_model.mac = mac machine_model.mac = mac
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment