更新代码
parent
ead7b8fc94
commit
46e8e308f2
@ -0,0 +1,57 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from sqlalchemy import Column, Integer, String, DateTime, func
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
|
from website.db_mysql import get_session
|
||||||
|
|
||||||
|
"""
|
||||||
|
CREATE TABLE `enterprise_busi_model_node_device` (
|
||||||
|
`id` int NOT NULL,
|
||||||
|
`suid` varchar(10) DEFAULT NULL,
|
||||||
|
`entity_suid` varchar(10) DEFAULT NULL,
|
||||||
|
`node_id` int DEFAULT NULL,
|
||||||
|
`node_suid` varchar(10) DEFAULT NULL,
|
||||||
|
`busi_model_id` int DEFAULT NULL,
|
||||||
|
`busi_model_suid` varchar(10) DEFAULT NULL,
|
||||||
|
`device_id` int DEFAULT NULL,
|
||||||
|
`device_suid` varchar(10) DEFAULT NULL,
|
||||||
|
`create_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='节点-业务模型-设备关联表';
|
||||||
|
"""
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
|
class EnterpriseBusiModelNodeDevice(Base):
|
||||||
|
__tablename__ = 'enterprise_busi_model_node_device'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True)
|
||||||
|
suid = Column(String(10))
|
||||||
|
entity_suid = Column(String(10))
|
||||||
|
node_id = Column(Integer)
|
||||||
|
node_suid = Column(String(10))
|
||||||
|
busi_model_id = Column(Integer)
|
||||||
|
busi_model_suid = Column(String(10))
|
||||||
|
device_id = Column(Integer)
|
||||||
|
device_suid = Column(String(10))
|
||||||
|
create_time = Column(DateTime, default=func.current_timestamp(), onupdate=func.current_timestamp())
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"EnterpriseBusiModelNodeDevice(id={self.id}, suid='{self.suid}')"
|
||||||
|
|
||||||
|
|
||||||
|
class EnterpriseBusiModelNodeDeviceRepository(object):
|
||||||
|
|
||||||
|
def insert_record(self, records: List[EnterpriseBusiModelNodeDevice]):
|
||||||
|
with get_session() as session:
|
||||||
|
for record in records:
|
||||||
|
session.add(record)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
def batch_insert_record(self, records: List[dict]):
|
||||||
|
with get_session() as session:
|
||||||
|
session.bulk_insert_mappings(EnterpriseBusiModelNodeDevice, records)
|
||||||
|
session.commit()
|
Loading…
Reference in New Issue