From 679165cbd06a2a49d2af3a8c28e2432f718a418b Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 6 Aug 2024 17:12:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20db=5Finsert=5Fmplogx=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=99=90=E5=88=B6=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/tasks.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index a60b4710..ca8576a6 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -47,7 +47,7 @@ def db_insert_mplogx_batch(rows): insert_mplogx_item(tag_code, tag_val, make_aware(tag_update), {}) @shared_task(base=CustomTask) -def db_insert_mplogx(): +def db_insert_mplogx(limit:bool=True): """ 从数据库转存到超表 """ @@ -58,7 +58,7 @@ def db_insert_mplogx(): raise Exception("last_tag_id is None") cursor.execute("select count(id) from tag_value where id > %s", (last_tag_id)) count = cursor.fetchone()[0] - if count > 400: + if limit and count > 400: raise Exception("db inset count > 400") cursor.execute( "select id, val, tag_code, update_time from tag_value where id > %s order by id, update_time", (last_tag_id, )) @@ -85,12 +85,11 @@ def db_ins_mplogx(): # raise Exception("db inset count > 400") # materials_name = ['水泥+P.C42.5 袋装', '水泥+P.O42.5R 袋装', '水泥+P.O42.5 散装','水泥+P.O42.5 袋装', '水泥+P.O52.5 散装', '水泥+P.C42.5 散装', '水泥+P.O42.5R 散装'] query = """ - SELECT id, CONCAT('x', inv_name) AS inv_name, de_real_quantity, bill_date + SELECT id, de_real_quantity, CONCAT('x', inv_name) AS inv_name, bill_date FROM sa_weigh_view WHERE bill_date > %s ORDER BY id, bill_date """ - # date_obj = datetime.datetime.strptime(bill_date, '%Y-%m-%d %H:%M:%S') cursor.execute(query, (bill_date,)) rows = cursor.fetchall() # 获取数据后保存至本地 if rows: