247 lines
9.0 KiB
Python
247 lines
9.0 KiB
Python
import sys
|
|
import requests
|
|
import json
|
|
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
|
QLabel, QLineEdit, QPushButton, QTextEdit, QMessageBox,
|
|
QComboBox, QFormLayout, QGroupBox, QSizePolicy)
|
|
from PyQt5.QtCore import Qt
|
|
from PyQt5.QtGui import QFont
|
|
|
|
|
|
class PartAddWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setWindowTitle("新增部件")
|
|
self.setGeometry(100, 100, 600, 600)
|
|
self.setStyleSheet("""
|
|
QMainWindow {
|
|
background-color: #f5f5f5;
|
|
}
|
|
QGroupBox {
|
|
border: 1px solid #ccc;
|
|
border-radius: 5px;
|
|
margin-top: 10px;
|
|
padding-top: 15px;
|
|
}
|
|
QGroupBox::title {
|
|
subcontrol-origin: margin;
|
|
left: 10px;
|
|
padding: 0 3px;
|
|
}
|
|
QLabel {
|
|
font-weight: bold;
|
|
min-width: 80px;
|
|
}
|
|
QPushButton {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
border: none;
|
|
padding: 5px 10px;
|
|
border-radius: 3px;
|
|
}
|
|
QPushButton:hover {
|
|
background-color: #45a049;
|
|
}
|
|
QComboBox, QLineEdit, QTextEdit {
|
|
padding: 5px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 3px;
|
|
}
|
|
""")
|
|
|
|
self.turbine_data = {}
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
central_widget = QWidget()
|
|
self.setCentralWidget(central_widget)
|
|
main_layout = QVBoxLayout()
|
|
|
|
# 项目查询组
|
|
project_group = QGroupBox("项目查询")
|
|
project_layout = QFormLayout()
|
|
|
|
self.project_id_input = QLineEdit()
|
|
self.project_id_input.setPlaceholderText("请输入项目ID")
|
|
project_layout.addRow(QLabel("项目ID*:"), self.project_id_input)
|
|
|
|
self.query_btn = QPushButton("查询机组列表")
|
|
self.query_btn.clicked.connect(self.load_turbine_list)
|
|
project_layout.addRow(self.query_btn)
|
|
|
|
project_group.setLayout(project_layout)
|
|
main_layout.addWidget(project_group)
|
|
|
|
# 部件信息组
|
|
part_group = QGroupBox("部件信息")
|
|
part_layout = QFormLayout()
|
|
|
|
self.turbine_combo = QComboBox()
|
|
part_layout.addRow(QLabel("机组名称*:"), self.turbine_combo)
|
|
|
|
self.part_name_combo = QComboBox()
|
|
self.part_name_combo.addItems(["", "叶片1", "叶片2", "叶片3"])
|
|
part_layout.addRow(QLabel("部件名称*:"), self.part_name_combo)
|
|
|
|
self.part_code_input = QLineEdit()
|
|
part_layout.addRow(QLabel("部件编号:"), self.part_code_input)
|
|
|
|
self.part_type_combo = QComboBox()
|
|
self.part_type_combo.addItems(["", "VANE-1", "VANE-2", "VANE-3"])
|
|
part_layout.addRow(QLabel("部件类型:"), self.part_type_combo)
|
|
|
|
self.part_desc_input = QTextEdit()
|
|
self.part_desc_input.setMaximumHeight(80)
|
|
part_layout.addRow(QLabel("部件描述:"), self.part_desc_input)
|
|
|
|
self.part_manufacturer_input = QLineEdit()
|
|
part_layout.addRow(QLabel("部件厂商:"), self.part_manufacturer_input)
|
|
|
|
self.part_model_input = QLineEdit()
|
|
part_layout.addRow(QLabel("部件型号:"), self.part_model_input)
|
|
|
|
part_group.setLayout(part_layout)
|
|
main_layout.addWidget(part_group)
|
|
|
|
# 按钮区域
|
|
button_layout = QHBoxLayout()
|
|
button_layout.addStretch()
|
|
|
|
self.submit_btn = QPushButton("提交")
|
|
self.submit_btn.setFixedWidth(100)
|
|
self.submit_btn.clicked.connect(self.submit_data)
|
|
button_layout.addWidget(self.submit_btn)
|
|
|
|
main_layout.addLayout(button_layout)
|
|
central_widget.setLayout(main_layout)
|
|
|
|
def load_turbine_list(self):
|
|
project_id = self.project_id_input.text().strip()
|
|
if not project_id:
|
|
QMessageBox.warning(self, "输入错误", "请输入项目ID!")
|
|
return
|
|
|
|
url = "http://pms.dtyx.net:9158/turbine/list"
|
|
headers = {
|
|
"Authorization": "null",
|
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
}
|
|
|
|
try:
|
|
params = {"projectId": project_id}
|
|
response = requests.get(url, headers=headers, params=params)
|
|
response.raise_for_status()
|
|
|
|
result = response.json()
|
|
if result.get("success") and "data" in result:
|
|
self.turbine_data = {}
|
|
self.turbine_combo.clear()
|
|
|
|
turbines = result["data"]
|
|
sorted_turbines = sorted(turbines, key=lambda x: x.get("turbineName", ""))
|
|
|
|
for turbine in sorted_turbines:
|
|
display_name = f"{turbine.get('turbineName', '')} (ID: {turbine.get('turbineId', '')})"
|
|
self.turbine_data[display_name] = turbine.get("turbineId", "")
|
|
self.turbine_combo.addItem(display_name)
|
|
|
|
if self.turbine_data:
|
|
QMessageBox.information(self, "成功", f"成功加载{len(self.turbine_data)}个机组")
|
|
else:
|
|
QMessageBox.warning(self, "警告", "没有找到机组数据")
|
|
else:
|
|
QMessageBox.warning(self, "警告", f"获取机组列表失败: {result.get('msg', '未知错误')}")
|
|
|
|
except Exception as e:
|
|
QMessageBox.critical(self, "错误", f"获取机组列表时出错:\n{str(e)}")
|
|
|
|
def validate_inputs(self):
|
|
if not self.project_id_input.text().strip():
|
|
QMessageBox.warning(self, "输入错误", "请输入项目ID!")
|
|
return False
|
|
if not self.turbine_combo.currentText():
|
|
QMessageBox.warning(self, "输入错误", "请选择机组!")
|
|
return False
|
|
if not self.part_name_combo.currentText():
|
|
QMessageBox.warning(self, "输入错误", "请选择部件名称!")
|
|
return False
|
|
return True
|
|
|
|
def submit_data(self):
|
|
if not self.validate_inputs():
|
|
return
|
|
|
|
selected_turbine = self.turbine_combo.currentText()
|
|
turbine_id = self.turbine_data.get(selected_turbine, "")
|
|
|
|
part_data = {
|
|
"turbineId": turbine_id,
|
|
"partName": self.part_name_combo.currentText(),
|
|
"partCode": self.part_code_input.text().strip(),
|
|
"partType": self.part_type_combo.currentText(),
|
|
"partDesc": self.part_desc_input.toPlainText().strip(),
|
|
"partManufacturer": self.part_manufacturer_input.text().strip(),
|
|
"partModel": self.part_model_input.text().strip()
|
|
}
|
|
|
|
reply = QMessageBox.question(
|
|
self, '确认提交',
|
|
'确定要提交这些部件信息吗?',
|
|
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
|
|
)
|
|
|
|
if reply == QMessageBox.No:
|
|
return
|
|
|
|
url = "http://pms.dtyx.net:9158/part"
|
|
headers = {
|
|
"Authorization": "null",
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
try:
|
|
response = requests.post(url, headers=headers, data=json.dumps(part_data))
|
|
response.raise_for_status()
|
|
|
|
result = response.json()
|
|
|
|
# 创建自定义消息框显示大尺寸结果
|
|
msg_box = QMessageBox(self)
|
|
msg_box.setWindowTitle("提交成功")
|
|
msg_box.setIcon(QMessageBox.Information)
|
|
msg_box.setText("部件信息提交成功!")
|
|
|
|
text_edit = QTextEdit()
|
|
text_edit.setReadOnly(True)
|
|
text_edit.setPlainText(json.dumps(result, indent=2))
|
|
text_edit.setMinimumSize(500, 300)
|
|
text_edit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
|
|
|
msg_box.layout().addWidget(text_edit, 1, 0, 1, msg_box.layout().columnCount())
|
|
msg_box.setStyleSheet("QLabel{min-width: 400px;}")
|
|
msg_box.exec_()
|
|
|
|
except Exception as e:
|
|
error_box = QMessageBox(self)
|
|
error_box.setWindowTitle("提交失败")
|
|
error_box.setIcon(QMessageBox.Critical)
|
|
error_box.setText("部件信息提交失败!")
|
|
|
|
error_text = QTextEdit()
|
|
error_text.setReadOnly(True)
|
|
error_text.setPlainText(str(e))
|
|
error_text.setMinimumSize(500, 150)
|
|
error_text.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
|
|
|
error_box.layout().addWidget(error_text, 1, 0, 1, error_box.layout().columnCount())
|
|
error_box.exec_()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication(sys.argv)
|
|
font = QFont("Microsoft YaHei", 10)
|
|
app.setFont(font)
|
|
|
|
window = PartAddWindow()
|
|
window.show()
|
|
sys.exit(app.exec_()) |