diff --git a/README.md b/README.md index 3616fd0..105923d 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,9 @@ Flask gunicorn python-dotenv lark-oapi -Flask-SQLAlchemy \ No newline at end of file +Flask-SQLAlchemy + +development: + flask run --reload +production: + gunicorn -w 4 -b 0.0.0.0:8000 app:app \ No newline at end of file diff --git a/data.db b/data.db index c240dc9..77c701f 100644 Binary files a/data.db and b/data.db differ diff --git a/inventory_check_lark/models.py b/inventory_check_lark/models.py index f598511..dd19cec 100644 --- a/inventory_check_lark/models.py +++ b/inventory_check_lark/models.py @@ -15,7 +15,7 @@ from lark_oapi.api.auth.v3 import * from lark_oapi.api.bitable.v1 import * class Inventory(db.Model): - id = db.Column(db.Integer, primary_key=True) + id = db.Column(db.Integer, primary_key=True, autoincrement=True) tag = db.Column(db.Text) amount = db.Column(db.Integer) checked = db.Column(db.Boolean, default=False) @@ -23,10 +23,15 @@ class Inventory(db.Model): tableid = db.Column(db.Text) # lasttime = db.Column(db.DateTime, default=datetime.now()) +# client = lark.Client.builder() \ +# .app_id(application.config['LARK_APP_ID']) \ +# .app_secret(application.config['LARK_APP_SECRECT']) \ +# .log_level(lark.LogLevel.DEBUG) \ +# .build() + client = lark.Client.builder() \ .app_id(application.config['LARK_APP_ID']) \ .app_secret(application.config['LARK_APP_SECRECT']) \ - .log_level(lark.LogLevel.DEBUG) \ .build() TIMER = time.time() @@ -107,6 +112,8 @@ def get_table_record(id, page_token=None): page_token = None if rep['data']['has_more']: page_token = rep['data']['page_token'] + else: + page_token = None for i in rep['data']['items']: if '已盘' in i['fields']: cd = i['fields']['已盘'] @@ -130,7 +137,7 @@ def update_record(id, recordid, amount): # 构造请求对象 request: UpdateAppTableRecordRequest = UpdateAppTableRecordRequest.builder() \ .app_token(application.config['LARK_TB_TOKEN']) \ - .table_id(id['table_id']) \ + .table_id(id) \ .record_id(recordid) \ .request_body(AppTableRecord.builder() .fields({"已盘":True,"外库数量":amount}) @@ -160,12 +167,11 @@ def init_db(): youxin, page_token= get_table_record(application.config['YOUXIN_ID']) for i in youxin: inv = Inventory() - inv.id = i['sort'] inv.tag = i['tag'] inv.amount = i['amount'] inv.checked = i['checked'] inv.recordid = i['recordid'] - inv.tableid = application.config['YOUXIN_ID'] + inv.tableid = application.config['YOUXIN_ID']['table_id'] db.session.add(inv) while page_token: youxin, page_token = get_table_record(application.config['YOUXIN_ID'], page_token) @@ -173,23 +179,21 @@ def init_db(): break for i in youxin: inv = Inventory() - inv.id = i['sort'] inv.tag = i['tag'] inv.amount = i['amount'] inv.checked = i['checked'] inv.recordid = i['recordid'] - inv.tableid = application.config['YOUXIN_ID'] + inv.tableid = application.config['YOUXIN_ID']['table_id'] db.session.add(inv) waimo, page_token= get_table_record(application.config['WAIMO_ID']) for i in waimo: inv = Inventory() - inv.id = i['sort'] inv.tag = i['tag'] inv.amount = i['amount'] inv.checked = i['checked'] inv.recordid = i['recordid'] - inv.tableid = application.config['WAIMO_ID'] + inv.tableid = application.config['WAIMO_ID']['table_id'] db.session.add(inv) while page_token: waimo, page_token = get_table_record(application.config['WAIMO_ID'], page_token) @@ -197,12 +201,11 @@ def init_db(): break for i in waimo: inv = Inventory() - inv.id = i['sort'] inv.tag = i['tag'] inv.amount = i['amount'] inv.checked = i['checked'] inv.recordid = i['recordid'] - inv.tableid = application.config['WAIMO_ID'] + inv.tableid = application.config['WAIMO_ID']['table_id'] db.session.add(inv) diff --git a/inventory_check_lark/settings.py b/inventory_check_lark/settings.py index ceb4760..24d1e4e 100644 --- a/inventory_check_lark/settings.py +++ b/inventory_check_lark/settings.py @@ -29,17 +29,11 @@ application.config['LARK_TB_TOKEN'] = os.getenv('LARK_TB_TOKEN', 'lark_app_secre application.config['WAIMO_ID'] = { 'table_id': 'tbluSufkcQm0noBz', - 'view_id': 'vewLYvBFns', - 'tag_id': 'fld2xdCqrs', - 'amount_id': 'fldC9cnnAY', - 'checked_id': 'fldJkHhQgQ' + 'view_id': 'vewLYvBFns' } application.config['YOUXIN_ID'] = { 'table_id': 'tbl9NPZQMl5IVHQ2', - 'view_id': 'vewrOuK32q', - 'tag_id': 'fldrxqL8uz', - 'amount_id': 'fldsOIpOBk', - 'checked_id': 'fldsuS6SuR' + 'view_id': 'vewrOuK32q' } diff --git a/inventory_check_lark/static/js/script.js b/inventory_check_lark/static/js/script.js index c9de89f..a91e550 100644 --- a/inventory_check_lark/static/js/script.js +++ b/inventory_check_lark/static/js/script.js @@ -10,26 +10,16 @@ function decrement() { } function checknext() { var amount = document.getElementById("inventory-amount"); - // 获取ID为"forid"的元素 var idelement = document.getElementById("inventory-id"); - // 获取该元素的文本内容,并解析为整数 - var id = parseInt(idelement.innerText, 10); // 第二个参数10表示解析的基数,这里是十进制 + var id = parseInt(idelement.innerText, 10); var tagelement = document.getElementById("inventory-tag"); - var tag = tagelement.innerText; var msg = document.getElementById("flash-msg"); - var location = document.getElementById("inventory-location"); - // var params = new URLSearchParams({ - // checked: 1, - // id: id, - // amount: amount.value - // }); - // var url = `/check?${params.toString()}`; fetch('/get_inventory', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({id: id, amount: amount.value}) + body: JSON.stringify({id: id, amount: parseInt(amount.value, 10)}) }) .then(response => response.json()) .then(data => { @@ -38,8 +28,6 @@ function checknext() { tagelement.innerText = data.tag; idelement.innerText = data.id; msg.innerText = data.checkedone + " 盘点数 " + data.checkedamount; - location.innerText = data.location; - }) .catch(error => console.error('Error:', error)); diff --git a/inventory_check_lark/templates/base.html b/inventory_check_lark/templates/base.html index d59f562..2f97d6d 100644 --- a/inventory_check_lark/templates/base.html +++ b/inventory_check_lark/templates/base.html @@ -16,7 +16,7 @@ {% block content %}{% endblock %} diff --git a/inventory_check_lark/templates/check.html b/inventory_check_lark/templates/check.html index 4d2adfc..310a63f 100644 --- a/inventory_check_lark/templates/check.html +++ b/inventory_check_lark/templates/check.html @@ -7,7 +7,7 @@
-
+

{{ inventory.tag }}


diff --git a/inventory_check_lark/templates/index.html b/inventory_check_lark/templates/index.html index 2a1840d..d2774d4 100644 --- a/inventory_check_lark/templates/index.html +++ b/inventory_check_lark/templates/index.html @@ -1,7 +1,9 @@ {% extends 'base.html' %} {% block content %} - +
+ +
diff --git a/inventory_check_lark/templates/init.html b/inventory_check_lark/templates/init.html index eb956e9..f2bbbd1 100644 --- a/inventory_check_lark/templates/init.html +++ b/inventory_check_lark/templates/init.html @@ -1,15 +1,13 @@ {% extends "base.html" %} -{% block title %}上传Excel文件{% endblock %} +{% block title %}初始化{% endblock %} {% block content %} -

初始化

-
-
-
初始化是从多维表格获取数据,修改多维表格后务必运行,花费约1-5分钟,请耐心等待
+
初始化是从多维表格获取数据,
修改多维表格后务必运行,
花费约1-5分钟,
不要多次点击按钮,
请耐心等待页面刷新
+
diff --git a/inventory_check_lark/templates/readme.html b/inventory_check_lark/templates/readme.html new file mode 100644 index 0000000..87ad937 --- /dev/null +++ b/inventory_check_lark/templates/readme.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% block title %}说明{% endblock %} + +{% block content %} +
+ +
+
+
本应用绑定这个飞书多维表格
+ 修改多维表格后务必运行 >> 初始化
+ 1.盘点前检查飞书表格添加或删除行
+ 2.将 已盘 一列全部修改为空心方框
+ 3.返回 >> 主页 点击 >> 初始化,
+ 4.初始化后,点继续盘点按顺序展示
+ 5.盘点若出错可以直接修改飞书表格
+ 6.因需与飞书通信,确认按钮会卡手
+ 7.其它问题联系作者
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/inventory_check_lark/views.py b/inventory_check_lark/views.py index b79a210..37dfe1a 100644 --- a/inventory_check_lark/views.py +++ b/inventory_check_lark/views.py @@ -15,9 +15,18 @@ from werkzeug.exceptions import BadRequest def index(): return render_template('index.html') +@application.route('/readme') +def readme(): + return render_template('readme.html') + @application.route('/init') def init(): - return 'ok' if init_db() else 'error' + return render_template('init.html') + +@application.route('/import') +def do_init(): + init_db() + return render_template('after.html',msg="初始化完成") @application.route('/check', methods=['GET']) def check(): @@ -26,16 +35,16 @@ def check(): return render_template('after.html',msg="未初始化或已盘完") return render_template('check.html',inventory=inventory) -@application.route('/get_youxin_inventory', methods=['POST']) -def update_youxin_inventory(): +@application.route('/get_inventory', methods=['POST']) +def update_inventory(): try: # 获取并验证表单数据 data = request.get_json() inventory_id = data['id'] amount = data['amount'] - if not inventory_id or not amount: - raise BadRequest('Missing inventory id or amount') + # if not inventory_id or not amount: + # raise BadRequest('Missing inventory id or amount') # 查询并更新库存对象 inventory = Inventory.query.get(inventory_id)