From 4d498f99a35c22b712bd1b67ebea11236866dcaa Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 6 Aug 2024 16:11:27 +0800 Subject: [PATCH 1/8] =?UTF-8?q?fix:=20enm/task=20=E6=B0=B4=E6=B3=A5?= =?UTF-8?q?=E6=89=B9=E5=8F=B7=E6=8F=92=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/tasks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index b7054764..a60b4710 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -90,13 +90,13 @@ def db_ins_mplogx(): 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: - bill_date = rows[-1][0] - print(rows) + bill_date = rows[-1][-1] db_insert_mplogx_batch(rows) - update_sysconfig({'enm1': {'bill_date': bill_date}}) + update_sysconfig({'enm1': {'bill_date': str(bill_date)}}) From 679165cbd06a2a49d2af3a8c28e2432f718a418b Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 6 Aug 2024 17:12:58 +0800 Subject: [PATCH 2/8] =?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: From 91e9ac38f6cfcf14c16f7c3708f0810a9cbc8e2a Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 6 Aug 2024 17:22:28 +0800 Subject: [PATCH 3/8] fix: db_insert_mplogx_batch bug --- apps/enm/tasks.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index ca8576a6..ccf4800d 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -42,8 +42,6 @@ def get_current_and_previous_time(): def db_insert_mplogx_batch(rows): for row in rows: _, tag_val, tag_code, tag_update = row - if cache.get("tag_code", None) is None: - continue insert_mplogx_item(tag_code, tag_val, make_aware(tag_update), {}) @shared_task(base=CustomTask) From f97c99bf8aa4d95fa88d2da57f3f05a37b49bf5c Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 6 Aug 2024 17:52:21 +0800 Subject: [PATCH 4/8] =?UTF-8?q?fix:=20cal=5Fmpointstat=5Fhour=E5=AF=B9?= =?UTF-8?q?=E4=BA=8Eis=5Funit=E7=9A=84=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index ccf4800d..45b15df2 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -143,7 +143,7 @@ def cal_mpointstat_hour(mpointId: str, year: int, month: int, day: int, hour: in val_type = mpoint.val_type if mpoint.type == Mpoint.MT_AUTO: if mpoint.is_unit: - val = MpLogx.objects.filter(mpoint=mpoint, timex__gte=dt, timex__lt=dt_hour_n).aggregate(Sum("val"))["val__sum"] or 0 + val = MpLogx.objects.filter(mpoint=mpoint, timex__gte=dt, timex__lt=dt_hour_n).aggregate(sum=Sum(f'val_{mpoint.val_type}'))["sum"] or 0 else: mrs0 = MpLogx.objects.filter(mpoint=mpoint, timex__gte=dt_hour_p, timex__lte=dt).order_by("timex") mrs = MpLogx.objects.filter(mpoint=mpoint, timex__gte=dt, timex__lte=dt_hour_n).order_by("timex") From 5461fb5f557752e511ae0aece011071549c43e7b Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 6 Aug 2024 18:40:34 +0800 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20cal=5Fexp=5Fduration=5Fsec=20?= =?UTF-8?q?=E8=BF=98=E9=9C=80=E8=A6=81=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E4=B8=BANone=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wpm/tasks.py b/apps/wpm/tasks.py index 75e88e37..f5e6b313 100644 --- a/apps/wpm/tasks.py +++ b/apps/wpm/tasks.py @@ -66,7 +66,7 @@ def cal_exp_duration_sec(stlogId: str='', all=False, now: datetime=None): elif all: stlogs = StLog.objects.all() else: # 不传就默认更新未结束的 - stlogs = StLog.objects.filter(end_time=None) + stlogs = StLog.objects.filter(end_time=None)|StLog.objects.filter(duration_sec=None) if now is None: now = timezone.now() for stlog in stlogs: From 1fe8c7ae76721e11cbdd9c32d83ed017cf766b77 Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 6 Aug 2024 18:43:20 +0800 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20cal=5Fexp=5Fduration=5Fsec=20?= =?UTF-8?q?=E8=BF=98=E9=9C=80=E8=A6=81=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E4=B8=BANone2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/tasks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/wpm/tasks.py b/apps/wpm/tasks.py index f5e6b313..6dafc52d 100644 --- a/apps/wpm/tasks.py +++ b/apps/wpm/tasks.py @@ -70,6 +70,9 @@ def cal_exp_duration_sec(stlogId: str='', all=False, now: datetime=None): if now is None: now = timezone.now() for stlog in stlogs: + if stlog.duration_sec is None and stlog.end_time is not None: + stlog.duration_sec = (stlog.end_time-stlog.start_time).total_seconds() + stlog.save() is_shutdown_stlog = True if stlog.is_shutdown is False: is_shutdown_stlog = False From 314b614c53342a10ff3f393e76dff1e9e724c6a7 Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 6 Aug 2024 19:00:38 +0800 Subject: [PATCH 7/8] =?UTF-8?q?fix:=20cal=5Fexp=5Fduration=5Fsec=20?= =?UTF-8?q?=E8=BF=98=E9=9C=80=E8=A6=81=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E4=B8=BANone3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wpm/tasks.py b/apps/wpm/tasks.py index 6dafc52d..9dd6e657 100644 --- a/apps/wpm/tasks.py +++ b/apps/wpm/tasks.py @@ -70,7 +70,7 @@ def cal_exp_duration_sec(stlogId: str='', all=False, now: datetime=None): if now is None: now = timezone.now() for stlog in stlogs: - if stlog.duration_sec is None and stlog.end_time is not None: + if stlog.duration_sec is None and stlog.end_time: stlog.duration_sec = (stlog.end_time-stlog.start_time).total_seconds() stlog.save() is_shutdown_stlog = True From 6bdc5a04aad1fbba596771d57d173c14b10c389b Mon Sep 17 00:00:00 2001 From: zty Date: Wed, 7 Aug 2024 09:30:56 +0800 Subject: [PATCH 8/8] =?UTF-8?q?fix=20:enm=20service.py=20=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=BC=93=E5=AD=98=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/services.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/enm/services.py b/apps/enm/services.py index 59c1c561..fb07f1f1 100644 --- a/apps/enm/services.py +++ b/apps/enm/services.py @@ -142,7 +142,8 @@ class MpointCache: try: mpoint = Mpoint.objects.get(code=code) except Exception: - return None + cache.set(key, {}, timeout=None) + return {} mpoint_data = MpointSerializer(instance=mpoint).data mpoint_data["last_data"] = {"last_val": None, "last_timex": None, "last_mrs": None} # 初始化 if update_mplogx: @@ -324,7 +325,7 @@ def insert_mplogx_item(code: str, val, timex: datetime, enp_mpoints_dict): """ mc = MpointCache(code) mpoint_data = mc.data - if mpoint_data is None or not mpoint_data["enabled"]: + if mpoint_data in (None, {}) or not mpoint_data["enabled"]: return mpoint_interval = mpoint_data["interval"]