._.
This commit is contained in:
parent
191c2fc6f2
commit
42a4fe0539
@ -22,6 +22,8 @@ class Department(base):
|
|||||||
title = Column(VARCHAR(100))
|
title = Column(VARCHAR(100))
|
||||||
description = Column(VARCHAR(1000))
|
description = Column(VARCHAR(1000))
|
||||||
|
|
||||||
|
parent_id = Column(Integer, ForeignKey('departments.id'))
|
||||||
|
|
||||||
|
|
||||||
class User(base):
|
class User(base):
|
||||||
__tablename__ = 'users'
|
__tablename__ = 'users'
|
||||||
|
|||||||
198
Desktop/data/connect.py
Normal file
198
Desktop/data/connect.py
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
from sqlalchemy import create_engine, Column, Integer, VARCHAR, Float, ForeignKey, Date, Text, Boolean, DateTime
|
||||||
|
from sqlalchemy.orm import Session, sessionmaker, relationship
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
|
base = declarative_base()
|
||||||
|
__factory = None
|
||||||
|
|
||||||
|
|
||||||
|
class Post(base):
|
||||||
|
__tablename__ = 'posts'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
|
||||||
|
users = relationship('User', back_populates='post')
|
||||||
|
|
||||||
|
|
||||||
|
class Department(base):
|
||||||
|
__tablename__ = 'departments'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
description = Column(VARCHAR(1000))
|
||||||
|
|
||||||
|
parent_id = Column(Integer, ForeignKey('departments.id'))
|
||||||
|
|
||||||
|
|
||||||
|
class User(base):
|
||||||
|
__tablename__ = 'users'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
first_name = Column(VARCHAR(100))
|
||||||
|
last_name = Column(VARCHAR(100))
|
||||||
|
patronymic = Column(VARCHAR(100))
|
||||||
|
work_phone = Column(VARCHAR(20))
|
||||||
|
phone = Column(VARCHAR(20))
|
||||||
|
office = Column(VARCHAR(10))
|
||||||
|
birthday = Column(Date)
|
||||||
|
other_info = Column(Text)
|
||||||
|
email = Column(VARCHAR(100))
|
||||||
|
password = Column(VARCHAR(150))
|
||||||
|
|
||||||
|
helper_id = Column(Integer, ForeignKey('users.id'))
|
||||||
|
director_id = Column(Integer, ForeignKey('users.id'))
|
||||||
|
post_id = Column(Integer, ForeignKey('posts.id'))
|
||||||
|
department_id = Column(Integer, ForeignKey('departments.id'))
|
||||||
|
|
||||||
|
post = relationship('Post', back_populates='users')
|
||||||
|
|
||||||
|
comments = relationship('Comment', back_populates='user')
|
||||||
|
|
||||||
|
|
||||||
|
class DepartmentUser(base):
|
||||||
|
__tablename__ = 'department_users'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
department_id = Column(Integer, ForeignKey('departments.id'))
|
||||||
|
user_id = Column(Integer, ForeignKey('users.id'))
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentCategory(base):
|
||||||
|
__tablename__ = 'document_categories'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
|
||||||
|
documents = relationship('Document', back_populates='category')
|
||||||
|
|
||||||
|
|
||||||
|
class Document(base):
|
||||||
|
__tablename__ = 'documents'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
date_created = Column(DateTime)
|
||||||
|
date_updated = Column(DateTime)
|
||||||
|
|
||||||
|
category_id = Column(Integer, ForeignKey('document_categories.id'))
|
||||||
|
|
||||||
|
category = relationship('DocumentCategory', back_populates='documents')
|
||||||
|
|
||||||
|
comments = relationship('Comment', back_populates='document')
|
||||||
|
|
||||||
|
|
||||||
|
class Comment(base):
|
||||||
|
__tablename__ = 'comments'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
text = Column(Text)
|
||||||
|
date_created = Column(DateTime)
|
||||||
|
date_updated = Column(DateTime)
|
||||||
|
|
||||||
|
user_id = Column(Integer, ForeignKey('users.id'))
|
||||||
|
document_id = Column(Integer, ForeignKey('documents.id'))
|
||||||
|
|
||||||
|
document = relationship('Document', back_populates='comments')
|
||||||
|
user = relationship('User', back_populates='comments')
|
||||||
|
|
||||||
|
|
||||||
|
class MaterialType(base):
|
||||||
|
__tablename__ = 'material_types'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
|
||||||
|
|
||||||
|
class MaterialStatus(base):
|
||||||
|
__tablename__ = 'material_statuses'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
|
||||||
|
|
||||||
|
class Material(base):
|
||||||
|
__tablename__ = 'materials'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
success_date = Column(Date)
|
||||||
|
edit_date = Column(DateTime)
|
||||||
|
area = Column(Text)
|
||||||
|
|
||||||
|
user_id = Column(Integer, ForeignKey('users.id'))
|
||||||
|
status_id = Column(Integer, ForeignKey('material_statuses.id'))
|
||||||
|
type_id = Column(Integer, ForeignKey('material_types.id'))
|
||||||
|
|
||||||
|
|
||||||
|
class EventType(base):
|
||||||
|
__tablename__ = 'event_types'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
|
||||||
|
|
||||||
|
class EventStatus(base):
|
||||||
|
__tablename__ = 'event_statuses'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
|
||||||
|
|
||||||
|
class Event(base):
|
||||||
|
__tablename__ = 'events'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(100))
|
||||||
|
datetime_event = Column(DateTime)
|
||||||
|
short_description = Column(VARCHAR(1500))
|
||||||
|
|
||||||
|
type_id = Column(Integer, ForeignKey('event_types.id'))
|
||||||
|
status_id = Column(Integer, ForeignKey('event_statuses.id'))
|
||||||
|
|
||||||
|
|
||||||
|
class DepartmentEvent(base):
|
||||||
|
__tablename__ = 'department_events'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
event_id = Column(Integer, ForeignKey('events.id'))
|
||||||
|
department_id = Column(Integer, ForeignKey('departments.id'))
|
||||||
|
|
||||||
|
|
||||||
|
class ResponsibleUser(base):
|
||||||
|
__tablename__ = 'responsible_users'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
event_id = Column(Integer, ForeignKey('events.id'))
|
||||||
|
user_id = Column(Integer, ForeignKey('users.id'))
|
||||||
|
|
||||||
|
|
||||||
|
class UserEvent(base):
|
||||||
|
__tablename__ = 'user_events'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
event_id = Column(Integer, ForeignKey('events.id'))
|
||||||
|
user_id = Column(Integer, ForeignKey('users.id'))
|
||||||
|
|
||||||
|
|
||||||
|
class WorkingCalendar(base):
|
||||||
|
__tablename__ = 'workingcalendar'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
exceptiondate = Column(Date)
|
||||||
|
isworkingday = Column(Boolean)
|
||||||
|
|
||||||
|
|
||||||
|
def init_db():
|
||||||
|
eng = create_engine(
|
||||||
|
'postgresql+psycopg2://postgres:2509@localhost:5432/prb1'
|
||||||
|
)
|
||||||
|
|
||||||
|
global __factory
|
||||||
|
__factory = sessionmaker(bind=eng)
|
||||||
|
base.metadata.create_all(eng)
|
||||||
|
|
||||||
|
|
||||||
|
def connect() -> Session:
|
||||||
|
global __factory
|
||||||
|
return __factory()
|
||||||
62
Desktop/main.py
Normal file
62
Desktop/main.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QApplication, QGraphicsView, QGraphicsScene, QPushButton, QGraphicsProxyWidget
|
||||||
|
from PyQt5.QtGui import QPen
|
||||||
|
from PyQt5.QtCore import Qt
|
||||||
|
|
||||||
|
from Desktop.data.connect import connect, Department, init_db
|
||||||
|
|
||||||
|
|
||||||
|
class DepartmentGraph(QGraphicsView):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.scene = QGraphicsScene(self)
|
||||||
|
self.setScene(self.scene)
|
||||||
|
with connect() as session:
|
||||||
|
self.departments = session.query(Department).all() # Список департаментов с их иерархией
|
||||||
|
self.nodes = {}
|
||||||
|
self.render_graph()
|
||||||
|
|
||||||
|
def render_graph(self):
|
||||||
|
root_departments = [d for d in self.departments if d.parent_id is None]
|
||||||
|
x, y = 50, 50 # Начальные координаты
|
||||||
|
for root in root_departments:
|
||||||
|
self.add_department_node(root, x, y)
|
||||||
|
x += 200 # Расстояние между корневыми узлами
|
||||||
|
|
||||||
|
def add_department_node(self, department, x, y, parent_item=None):
|
||||||
|
# Создаем кнопку
|
||||||
|
button = QPushButton(department.title)
|
||||||
|
proxy = QGraphicsProxyWidget()
|
||||||
|
proxy.setWidget(button)
|
||||||
|
proxy.setPos(x, y)
|
||||||
|
self.scene.addItem(proxy)
|
||||||
|
|
||||||
|
# Сохраняем узел
|
||||||
|
self.nodes[department.id] = proxy
|
||||||
|
|
||||||
|
# Если есть родитель, добавляем линию
|
||||||
|
if parent_item:
|
||||||
|
parent_center = parent_item.sceneBoundingRect().center()
|
||||||
|
current_center = proxy.sceneBoundingRect().center()
|
||||||
|
line = self.scene.addLine(parent_center.x(), parent_center.y(), current_center.x(), current_center.y(),
|
||||||
|
QPen(Qt.black))
|
||||||
|
|
||||||
|
# Рекурсивно добавляем подразделы
|
||||||
|
child_departments = [d for d in self.departments if d.parent_id == department.id]
|
||||||
|
child_x = x - len(child_departments) * 100 // 2
|
||||||
|
for child in child_departments:
|
||||||
|
self.add_department_node(child, child_x, y + 100, proxy)
|
||||||
|
child_x += 200
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
init_db()
|
||||||
|
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
window = DepartmentGraph()
|
||||||
|
window.setWindowTitle("Иерархия департаментов")
|
||||||
|
window.resize(800, 600)
|
||||||
|
window.show()
|
||||||
|
|
||||||
|
sys.exit(app.exec_())
|
||||||
Loading…
x
Reference in New Issue
Block a user