修改尾数控制和状态监控逻辑
This commit is contained in:
@ -7,6 +7,7 @@ from database.access_db import AccessDB
|
||||
from database.sql_server import SQLServerDB
|
||||
from config.settings import ACCESS_DB_PATH, ACCESS_DB_PASSWORD, MONITOR_INTERVAL
|
||||
from tcp.server import TCPServer
|
||||
from services.task_service import TaskService
|
||||
|
||||
class MonitoringService:
|
||||
def __init__(self, tcp_server):
|
||||
@ -15,6 +16,7 @@ class MonitoringService:
|
||||
self.monitored_tasks = set()
|
||||
self.inserted_tasks = {}
|
||||
self.tasks_lock = threading.Lock()
|
||||
self.task_service = TaskService(tcp_server)
|
||||
|
||||
def monitor_access_flag_changes(self):
|
||||
"""监控Access数据库中派发任务的Flag状态"""
|
||||
@ -44,8 +46,6 @@ class MonitoringService:
|
||||
erp_ids_str = [str(erp_id) for erp_id in tasks_to_monitor]
|
||||
deleted_from_sql_tasks = set(erp_ids_str) - existing_tasks_in_sql
|
||||
|
||||
print(f"SQL Server中仍存在的任务: {existing_tasks_in_sql}")
|
||||
print(f"已从SQL Server删除的任务: {deleted_from_sql_tasks}")
|
||||
|
||||
# 只有已从SQL Server删除的任务才需要在Access中查找
|
||||
if not deleted_from_sql_tasks:
|
||||
@ -75,8 +75,6 @@ class MonitoringService:
|
||||
current_flag = current_tasks.get(erp_id_str, "")
|
||||
previous_flag = self.task_flags.get(erp_id_str, "")
|
||||
|
||||
# 添加调试信息
|
||||
print(f"检查任务 {erp_id} - 当前Flag: '{current_flag}', 之前Flag: '{previous_flag}'")
|
||||
|
||||
# 如果状态发生变化
|
||||
if current_flag != previous_flag:
|
||||
@ -98,119 +96,114 @@ class MonitoringService:
|
||||
def _handle_flag_status_change(self, erp_id, current_flag, artifact_id):
|
||||
"""处理标志状态变化"""
|
||||
if current_flag.endswith('d'):
|
||||
self._handle_status_d(erp_id, artifact_id)
|
||||
self._handle_status_d(erp_id,artifact_id)
|
||||
elif current_flag.endswith('w'):
|
||||
self._handle_status_w(erp_id, artifact_id)
|
||||
self._handle_status_w(erp_id,artifact_id)
|
||||
elif current_flag.endswith('n'):
|
||||
self._handle_status_n(erp_id, artifact_id)
|
||||
self._handle_status_n(erp_id,artifact_id)
|
||||
elif current_flag.endswith('p'):
|
||||
self._handle_status_p(erp_id, artifact_id)
|
||||
self._handle_status_p(erp_id,artifact_id)
|
||||
elif current_flag.endswith('x'):
|
||||
self._handle_status_x(erp_id, artifact_id)
|
||||
self._handle_status_x(erp_id,artifact_id)
|
||||
|
||||
def _handle_status_d(self, erp_id, artifact_id):
|
||||
def _handle_status_d(self,erp_id, artifact_id):
|
||||
"""处理状态'd' - 未进行生产"""
|
||||
print(f"派发任务 ErpID {erp_id}: 未进行生产")
|
||||
# 调用同事提供的状态更新函数
|
||||
print(f"派发任务 artifact_id {artifact_id}: 未进行生产")
|
||||
try:
|
||||
print(1)
|
||||
update_custom_table_status(erp_id, "未进行生产")
|
||||
self.task_service.update_custom_table_status(artifact_id, "未进行生产")
|
||||
except Exception as e:
|
||||
print(f"更新状态时出错: {e}")
|
||||
|
||||
# 发送数据给TCP客户端(只发送erp_id和状态)
|
||||
try:
|
||||
status_data = {
|
||||
"erp_id": erp_id,
|
||||
"status": "未进行生产"
|
||||
"erp_id":erp_id,
|
||||
"artifact_id": artifact_id,
|
||||
"flag": "未进行生产"
|
||||
}
|
||||
self.tcp_server.send_data(status_data)
|
||||
except Exception as e:
|
||||
print(f"发送状态数据给TCP客户端时出错: {e}")
|
||||
|
||||
def _handle_status_w(self, erp_id, artifact_id):
|
||||
def _handle_status_w(self, erp_id,artifact_id):
|
||||
"""处理状态'w' - 正在生产中"""
|
||||
print(f"派发任务 ErpID {erp_id}: 正在生产中")
|
||||
# 调用同事提供的状态更新函数
|
||||
print(f"派发任务 artifact_id {artifact_id}: 正在生产中")
|
||||
try:
|
||||
print(2)
|
||||
update_custom_table_status(erp_id, "正在生产中")
|
||||
self.task_service.update_custom_table_status(artifact_id, "正在生产中")
|
||||
except Exception as e:
|
||||
print(f"更新状态时出错: {e}")
|
||||
|
||||
# 发送数据给TCP客户端(只发送erp_id和状态)
|
||||
try:
|
||||
status_data = {
|
||||
"erp_id": erp_id,
|
||||
"status": "正在生产中"
|
||||
"erp_id":erp_id,
|
||||
"artifact_id": artifact_id,
|
||||
"flag": "正在生产中"
|
||||
}
|
||||
self.tcp_server.send_data(status_data)
|
||||
except Exception as e:
|
||||
print(f"发送状态数据给TCP客户端时出错: {e}")
|
||||
|
||||
def _handle_status_n(self, erp_id, artifact_id):
|
||||
def _handle_status_n(self,erp_id, artifact_id):
|
||||
"""处理状态'n' - 生产完毕"""
|
||||
print(f"派发任务 ErpID {erp_id}: 生产完毕")
|
||||
print(f"派发任务 artifact_id {artifact_id}: 生产完毕")
|
||||
# 任务完成,可以从监控列表中移除
|
||||
with self.tasks_lock:
|
||||
self.monitored_tasks.discard(erp_id)
|
||||
print(f"派发任务 ErpID {erp_id} 已完成,停止监控")
|
||||
# 调用同事提供的状态更新函数
|
||||
self.monitored_tasks.discard(artifact_id)
|
||||
print(f"派发任务 artifact_id {artifact_id} 已完成,停止监控")
|
||||
try:
|
||||
print(3)
|
||||
update_custom_table_status(erp_id, "生产完毕")
|
||||
self.task_service.update_custom_table_status(artifact_id, "生产完毕")
|
||||
except Exception as e:
|
||||
print(f"更新状态时出错: {e}")
|
||||
|
||||
# 发送数据给TCP客户端(只发送erp_id和状态)
|
||||
try:
|
||||
status_data = {
|
||||
"erp_id": erp_id,
|
||||
"status": "生产完毕"
|
||||
"erp_id":erp_id,
|
||||
"artifact_id": artifact_id,
|
||||
"flag": "生产完毕"
|
||||
}
|
||||
self.tcp_server.send_data(status_data)
|
||||
except Exception as e:
|
||||
print(f"发送状态数据给TCP客户端时出错: {e}")
|
||||
|
||||
def _handle_status_p(self, erp_id, artifact_id):
|
||||
def _handle_status_p(self, erp_id,artifact_id):
|
||||
"""处理状态'p' - 生产中断"""
|
||||
print(f"派发任务 ErpID {erp_id}: 生产中断")
|
||||
print(f"派发任务 ErpID {artifact_id}: 生产中断")
|
||||
# 任务中断,可以从监控列表中移除
|
||||
with self.tasks_lock:
|
||||
self.monitored_tasks.discard(erp_id)
|
||||
print(f"派发任务 ErpID {erp_id} 已中断,停止监控")
|
||||
# 调用同事提供的状态更新函数
|
||||
self.monitored_tasks.discard(artifact_id)
|
||||
print(f"派发任务 ErpID {artifact_id} 已中断,停止监控")
|
||||
try:
|
||||
print(4)
|
||||
update_custom_table_status(erp_id, "生产中断")
|
||||
self.task_service.update_custom_table_status(artifact_id, "生产中断")
|
||||
except Exception as e:
|
||||
print(f"更新状态时出错: {e}")
|
||||
|
||||
# 发送数据给TCP客户端(只发送erp_id和状态)
|
||||
try:
|
||||
status_data = {
|
||||
"erp_id": erp_id,
|
||||
"status": "生产中断"
|
||||
"artifact_id": artifact_id,
|
||||
"flag": "生产中断"
|
||||
}
|
||||
self.tcp_server.send_data(status_data)
|
||||
except Exception as e:
|
||||
print(f"发送状态数据给TCP客户端时出错: {e}")
|
||||
|
||||
def _handle_status_x(self, erp_id, artifact_id):
|
||||
def _handle_status_x(self, erp_id,artifact_id):
|
||||
"""处理状态'x' - 数据已接收"""
|
||||
print(f"派发任务 ErpID {erp_id}: 数据已接收")
|
||||
# 调用同事提供的状态更新函数
|
||||
print(f"派发任务 ErpID {artifact_id}: 已插入")
|
||||
try:
|
||||
print(5)
|
||||
# update_custom_table_status(erp_id, "数据已接收")
|
||||
self.task_service.update_custom_table_status(artifact_id, "已插入")
|
||||
except Exception as e:
|
||||
print(f"更新状态时出错: {e}")
|
||||
|
||||
# 发送数据给TCP客户端(只发送erp_id和状态)
|
||||
try:
|
||||
status_data = {
|
||||
"erp_id": erp_id,
|
||||
"status": "数据已接收"
|
||||
"erp_id":erp_id,
|
||||
"artifact_id": artifact_id,
|
||||
"flag": "已插入"
|
||||
}
|
||||
self.tcp_server.send_data(status_data)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user