From 4db13466b13cfaabf37a7f08ad4970dcced4ce27 Mon Sep 17 00:00:00 2001 From: 6286e01d70b7ea73fee6b212 <6286e01d70b7ea73fee6b212@devide> Date: Thu, 4 May 2023 06:07:59 +0000 Subject: [PATCH] Auto commit --- ...41\345\217\267\344\275\277\347\224\250.py" | 163 ++++++++++++++++++ readme.md | 37 ++++ requirements.txt | 22 +++ 3 files changed, 222 insertions(+) create mode 100644 "pyqt6\344\277\241\345\217\267\344\275\277\347\224\250.py" create mode 100644 readme.md diff --git "a/pyqt6\344\277\241\345\217\267\344\275\277\347\224\250.py" "b/pyqt6\344\277\241\345\217\267\344\275\277\347\224\250.py" new file mode 100644 index 0000000..5523b53 --- /dev/null +++ "b/pyqt6\344\277\241\345\217\267\344\275\277\347\224\250.py" @@ -0,0 +1,163 @@ + +from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QPushButton, QFileDialog, QVBoxLayout, \ + QHBoxLayout, QWidget, QMessageBox +from PyQt6.QtCore import QThread, pyqtSignal +import sys +import pandas as pd +import os +import datetime + + +class MatchThread(QThread): + match_success = pyqtSignal(str) + match_failed = pyqtSignal(str) + + def __init__(self, match_type, sfname, bdh): + super().__init__() + self.match_type = match_type + self.sfname = sfname + self.bdh = bdh + + def run(self): + try: + + df = pd.read_excel('{}'.format(self.sfname)) + df['匹配内容'] = df['匹配内容'].astype(str) + if self.match_type == "身份证": + result = self.bdh[self.bdh['被保险人证件号'].isin(df['匹配内容'].to_list())] + elif self.match_type == "电话": + result = self.bdh[(self.bdh['付款人电话'].isin(df['匹配内容'].to_list())) | ( + self.bdh['团单电话'].isin(df['匹配内容'].to_list())) | ( + self.bdh['被保险人电话'].isin(df['匹配内容'].to_list()))] + elif self.match_type == "投保人": + result = self.bdh[self.bdh['付款人'].isin(df['匹配内容'].to_list())] + + result.to_excel('{}匹配{}.xlsx'.format(self.match_type, datetime.datetime.now().strftime('%Y%d%m-%H%M%S')), + index=False) + self.match_success.emit(self.match_type + "匹配成功") + except: + self.match_failed.emit("检查是否只选择一个文件路径。\n且列名为匹配内容。") +class DataLoadThread(QThread): + load_finished = pyqtSignal(bool, str,pd.DataFrame) + + def run(self): + try: + bdh = pd.read_parquet('{}\\cb.parquet.gzip'.format(os.getcwd())) + bdh['被保险人证件号'] = bdh['被保险人证件号'].astype(str) + bdh['付款人电话'] = bdh['付款人电话'].astype(str) + bdh['团单电话'] = bdh['团单电话'].astype(str) + bdh['被保险人电话'] = bdh['被保险人电话'].astype(str) + self.bdh = bdh + # 传递信息变量出去 + self.load_finished.emit(True, '',self.bdh) + + except Exception as e: + + self.load_finished.emit(False, str(e),None) + +class App(QMainWindow): + def __init__(self): + super().__init__() + + self.sfname = '' + self.bdh = None + self.match_thread=None + + self.setWindowTitle('2022年度参保匹配系统') + self.setGeometry(100, 100, 500, 300) + # 加入 msg_box + self.msg_box = QMessageBox(self) + layout = QVBoxLayout() + + label1 = QLabel('请选择匹配文件:') + self.text1 = QLineEdit() + button1 = QPushButton('浏览', clicked=self.select_excelfile) + label2 = QLabel('请选择匹配方式') + label3 = QLabel('匹配前请先加载数据:') + label4 = QLabel('再次选择文件请清空路径:', self) + label4.setStyleSheet("color: red") + + button2 = QPushButton('被保险人身份证', clicked=lambda: self.do_process("身份证")) + button3 = QPushButton('电话', clicked=lambda: self.do_process("电话")) + button4 = QPushButton('投保人', clicked=lambda: self.do_process("投保人")) + button5 = QPushButton('退出', clicked=self.close) + + button5.setStyleSheet("color: red") + + self.load_thread = DataLoadThread() + self.load_thread.load_finished.connect(self.on_load_finished) + button6 = QPushButton('加载数据', clicked=self.load_data) + button6.setStyleSheet("color: red") + button7 = QPushButton('清空', clicked=self.clear_path) + button7.setStyleSheet("background-color: red") + + layout.addWidget(label1) + layout.addWidget(self.text1) + layout.addWidget(button1) + + layout.addWidget(label3) + layout.addWidget(button6) + + layout.addWidget(label2) + + button_layout = QHBoxLayout() + button_layout.addWidget(button2) + button_layout.addWidget(button3) + button_layout.addWidget(button4) + button_layout.addWidget(button5) + layout.addLayout(button_layout) + + layout.addWidget(label4) + layout.addWidget(button7) + + central_widget = QWidget() + central_widget.setLayout(layout) + self.setCentralWidget(central_widget) + def on_load_finished(self, success, error=None,bdh=None): + # 在主线程中处理加载完成或出错的情况, 接受bdh参数 + + if success: + print("yes") + self.bdh=bdh + self.msg_box.setText('加载数据成功!') + self.msg_box.exec() + else: + self.msg_box.setText('加载数据失败:{}'.format(error)) + self.msg_box.exec() + def select_excelfile(self): + try: + options = QFileDialog.Option(QFileDialog.Option.ReadOnly) + # options |= QFileDialog.ReadOnly + self.sfname, _ = QFileDialog.getOpenFileName(self, "选择Excel文件", "", "Excel (*.xlsx);;All Files (*)", + options=options) + self.text1.setText(self.sfname) + except Exception as e: + print("An error occurred: ", str(e)) + def load_data(self): + # 启动子线程 + self.load_thread.start() + def do_process(self, match_type): + if self.sfname == '' or self.bdh is None: + # if self.sfname == '': + QMessageBox.warning(self, '警告', '请选择匹配文件并加载数据!') + return + else: + self.match_thread = MatchThread(match_type, self.sfname, self.bdh) + self.match_thread.match_success.connect(self.on_match_success) + self.match_thread.match_failed.connect(self.on_match_failed) + self.match_thread.start() + def on_match_success(self, message): + QMessageBox.information(self, '提示', message) + def on_match_failed(self, message): + QMessageBox.warning(self, '警告', message) + + + def clear_path(self): + self.text1.clear() + + +if __name__ == '__main__': + app = QApplication(sys.argv) + ex = App() + ex.show() + sys.exit(app.exec()) \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..9603cf5 --- /dev/null +++ b/readme.md @@ -0,0 +1,37 @@ +** +class MatchThread(QThread): + match_success = pyqtSignal(str) + match_failed = pyqtSignal(str) + def __init__(self, match_type, sfname, bdh): + super().__init__() + self.match_type = match_type + self.sfname = sfname + self.bdh = bdh + + def run(self): + try: + self.match_success.emit(self.match_type + "匹配成功") + except: + self.match_failed.emit("检查是否只选择一个文件路径。\n且列名为匹配内容。") +** +解析如何使用,使用的是多线程QThread,单独在主线程的之外的线程,pyqtSignal 进行的是一个信号的传递,emit是对一个信号的输出(使用 emit() 方法可以发出信号,通知连接的槽函数执行相应的操作。)。 +match_type, sfname, bdh 是类的初始化的参数。 + +** + def do_process(self, match_type): + if self.sfname == '' or self.bdh is None: + QMessageBox.warning(self, '警告', '请选择匹配文件并加载数据!') + return + else: + self.match_thread = MatchThread(match_type, self.sfname, self.bdh) + self.match_thread.match_success.connect(self.on_match_success) + self.match_thread.match_failed.connect(self.on_match_failed) + self.match_thread.start() + def on_match_success(self, message): + QMessageBox.information(self, '提示', message) + def on_match_failed(self, message): + QMessageBox.warning(self, '警告', message) + +** +connect在信号里面传入,将信号连接到槽函数。例如:sender.signal.connect(receiver.slot) sender 是发出信号的对象,signal 是信号名称,receiver 是接收信号的对象,slot 是槽函数名称。 + diff --git a/requirements.txt b/requirements.txt index e69de29..a76431b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,22 @@ +pyarrow==11.0.0 +pyinstall==0.1.4 +pyinstaller==5.7.0 +pyinstaller-hooks-contrib==2022.15 +PyMySQL==1.0.2 +PyQt6==6.5.0 +PyQt6-Qt6==6.5.0 +PyQt6-sip==13.4.1 +PySide6==6.4.2 +PySide6-Addons==6.4.2 +PySide6-Essentials==6.4.2 +pytz==2022.7.1 +pywin32-ctypes==0.2.0 +requests==2.28.2 +shiboken6==6.4.2 +sqlparse==0.4.4 +tkcalendar==1.6.1 +tkhtmlview==0.2.0 +ttkthemes==3.2.2 +tzdata==2023.3 +wincertstore==0.2 +xlrd==2.0.1 -- GitLab