修改acturetime/data 入库无值问题
This commit is contained in:
48
db/orm.py
48
db/orm.py
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import logging
|
||||
import re
|
||||
from decimal import Decimal, InvalidOperation
|
||||
|
||||
from model import DrillingRealtimeData
|
||||
|
||||
@@ -52,7 +53,21 @@ DB_COLUMNS = [
|
||||
"space5",
|
||||
]
|
||||
|
||||
INT_COLUMNS = {"stknum", "recid", "seqid", "actcod", "rpma", "spm1", "spm2", "spm3", "mfop", "stkc", "lagstks"}
|
||||
INT_COLUMNS = {
|
||||
"stknum",
|
||||
"recid",
|
||||
"seqid",
|
||||
"actual_date",
|
||||
"actual_time",
|
||||
"actcod",
|
||||
"rpma",
|
||||
"spm1",
|
||||
"spm2",
|
||||
"spm3",
|
||||
"mfop",
|
||||
"stkc",
|
||||
"lagstks",
|
||||
}
|
||||
|
||||
|
||||
def sanitize_identifier(value, fallback):
|
||||
@@ -78,12 +93,12 @@ class DrillingRealtimeORM:
|
||||
if not isinstance(payload, dict):
|
||||
raise ValueError("payload is not JSON object")
|
||||
entity = DrillingRealtimeData.from_payload(payload)
|
||||
meta = payload.get("meta") if isinstance(payload.get("meta"), dict) else {}
|
||||
meta = get_dict_alias(payload, "meta", "mate")
|
||||
equipment_code = (
|
||||
str(self.default_device_code).strip()
|
||||
or str(meta.get("equipment_code", "")).strip()
|
||||
or str(meta.get("equipment_sn", "")).strip()
|
||||
str(get_alias_value(meta, ("equipment_code", "equipmentCode"), "")).strip()
|
||||
or str(get_alias_value(meta, ("equipment_sn", "equipmentSN"), "")).strip()
|
||||
or entity.wellid
|
||||
or str(self.default_device_code).strip()
|
||||
or "GJ-304-0088"
|
||||
)
|
||||
table_name = sanitize_identifier(f"drilling_realtime_{equipment_code}", "drilling_realtime_default")
|
||||
@@ -108,8 +123,8 @@ def to_int(value, default=0):
|
||||
try:
|
||||
if value is None or value == "":
|
||||
return default
|
||||
return int(value)
|
||||
except Exception:
|
||||
return int(Decimal(str(value).strip()))
|
||||
except (InvalidOperation, TypeError, ValueError):
|
||||
return default
|
||||
|
||||
|
||||
@@ -119,4 +134,19 @@ def to_float(value, default=0.0):
|
||||
return default
|
||||
return float(value)
|
||||
except Exception:
|
||||
return default
|
||||
return default
|
||||
|
||||
|
||||
def get_alias_value(source, keys, default=None):
|
||||
if not isinstance(source, dict):
|
||||
return default
|
||||
for key in keys:
|
||||
value = source.get(key)
|
||||
if value is not None:
|
||||
return value
|
||||
return default
|
||||
|
||||
|
||||
def get_dict_alias(source, *keys):
|
||||
value = get_alias_value(source, keys, {})
|
||||
return value if isinstance(value, dict) else {}
|
||||
|
||||
Reference in New Issue
Block a user