feat:实现接口删除功能

This commit is contained in:
zhu-mengmeng 2025-07-20 15:34:17 +08:00
parent fe1df2e3e2
commit 7dbf1c1efc
5 changed files with 68 additions and 11 deletions

View File

@ -125,6 +125,34 @@ class GcApi:
logging.error(f"添加订单信息失败: {str(e)}") logging.error(f"添加订单信息失败: {str(e)}")
return None return None
def remove_order_info(self, xpack, ddmo, sgc):
"""
删除订单信息
Args:
xpack: 托盘号
ddmo: 订单号
sgc: 工程号
Returns:
dict: 接口响应结果
"""
try:
# API 配置中的键名
api_key = "remove_order_info"
# 构建 form-data 格式的数据
data = {
"xpack": xpack,
"ddmo": ddmo,
"gch": sgc
}
# 调用接口
response = self.api_utils.post(api_key, data=data)
return response
except Exception as e:
logging.error(f"删除订单信息失败: {str(e)}")
return {"status": False, "message": f"删除订单信息失败: {str(e)}"}
def get_xpack(self, order_id,corp_id): def get_xpack(self, order_id,corp_id):
""" """
获取包装号 获取包装号

View File

@ -15,6 +15,7 @@
"get_gc_info": "/jsjt/xcsc/tprk/getBZGCInfoToWsbz.do", "get_gc_info": "/jsjt/xcsc/tprk/getBZGCInfoToWsbz.do",
"get_order_info": "/jsjt/xcsc/tprk/getXsddBzrkGridListToWsbz.do", "get_order_info": "/jsjt/xcsc/tprk/getXsddBzrkGridListToWsbz.do",
"add_order_info": "/jsjt/xcsc/tprk/bzrkAdd01.do", "add_order_info": "/jsjt/xcsc/tprk/bzrkAdd01.do",
"remove_order_info": "/jsjt/xcsc/tprk/removeByOrder.do",
"get_xpack": "/jsjt/xcsc/tprk/getXpackToWsbz.do", "get_xpack": "/jsjt/xcsc/tprk/getXpackToWsbz.do",
"ismt_option": "/jsjt/xcsc/tprk/ismtOptioTonWsbz.do", "ismt_option": "/jsjt/xcsc/tprk/ismtOptioTonWsbz.do",
"get_params": "/select/getcombcodeWsbz.do", "get_params": "/select/getcombcodeWsbz.do",

Binary file not shown.

View File

@ -2,7 +2,7 @@ from pymodbus.client import ModbusTcpClient
import time import time
client = ModbusTcpClient('localhost', port=5020) client = ModbusTcpClient('localhost', port=5020)
client.connect() client.connect()
client.write_registers(address=11, values=[9422]) client.write_registers(address=11, values=[14322])
# client.write_registers(address=3, values=[0]) # client.write_registers(address=3, values=[0])
# time.sleep(2) # time.sleep(2)
# client.write_registers(address=0, values=[0]) # client.write_registers(address=0, values=[0])

View File

@ -3831,6 +3831,20 @@ class MainWindow(MainWindowUI):
# 获取托盘号 # 获取托盘号
tray_id = self.tray_edit.currentText() tray_id = self.tray_edit.currentText()
# 如果开启 api 模式,则调用接口删除远程数据
if AppMode.is_api():
from apis.gc_api import GcApi
gc_api = GcApi()
# 调用删除接口
response = gc_api.remove_order_info(tray_id, self._current_order_code, gc_note)
if response.get("status", False):
logging.info(f"已从远程删除订单信息: 托盘号={tray_id}, 订单号={self._current_order_code}, 工程号={gc_note}")
else:
error_msg = response.get("message", "未知错误")
logging.warning(f"远程删除订单信息失败: {error_msg}")
# 可以选择是否继续删除本地数据,这里选择继续
# 从数据库中删除该工程号的检验数据 # 从数据库中删除该工程号的检验数据
inspection_dao.delete_inspection_data(self._current_order_code, gc_note, tray_id) inspection_dao.delete_inspection_data(self._current_order_code, gc_note, tray_id)
logging.info(f"已从数据库中删除工程号 {gc_note} 的检验数据") logging.info(f"已从数据库中删除工程号 {gc_note} 的检验数据")
@ -3842,8 +3856,9 @@ class MainWindow(MainWindowUI):
# 重新加载数据 # 重新加载数据
self._safe_load_data() self._safe_load_data()
# 清除选中状态,防止误操作 # 确保清除选中状态,防止误操作
self.process_table.clearSelection() self.process_table.clearSelection()
self.process_table.setCurrentItem(None)
# 显示成功消息 # 显示成功消息
QMessageBox.information(self, "删除成功", "已成功删除选中的微丝产线数据") QMessageBox.information(self, "删除成功", "已成功删除选中的微丝产线数据")
@ -3911,16 +3926,25 @@ class MainWindow(MainWindowUI):
logging.warning(f"{row} 行工程号为空,跳过删除") logging.warning(f"{row} 行工程号为空,跳过删除")
continue continue
# 获取托盘号(第6列 # 获取托盘号(从前端组件获取
tray_id_item = self.record_table.item(row, 5) tray_id = self.tray_edit.currentText()
if not tray_id_item: if not tray_id:
logging.warning(f"{row}托盘号为空,跳过删除") logging.warning("托盘号为空,跳过删除")
continue continue
tray_id = tray_id_item.text().strip() # 如果开启 api 模式,则调用接口删除远程数据
if not tray_id: if AppMode.is_api():
logging.warning(f"{row} 行托盘号为空,跳过删除") from apis.gc_api import GcApi
continue gc_api = GcApi()
# 调用删除接口
response = gc_api.remove_order_info(tray_id, order_id, gc_note)
if response.get("status", False):
logging.info(f"已从远程删除订单信息: 托盘号={tray_id}, 订单号={order_id}, 工程号={gc_note}")
else:
error_msg = response.get("message", "未知错误")
logging.warning(f"远程删除订单信息失败: {error_msg}")
# 可以选择是否继续删除本地数据,这里选择继续
# 从数据库中删除该包装记录 # 从数据库中删除该包装记录
success = inspection_dao.delete_package_record(order_id, gc_note, tray_id) success = inspection_dao.delete_package_record(order_id, gc_note, tray_id)
@ -3936,7 +3960,11 @@ class MainWindow(MainWindowUI):
# 重新加载包装记录 # 重新加载包装记录
self.show_pack_item() self.show_pack_item()
# 确保清除选中状态,防止误操作
self.record_table.clearSelection() self.record_table.clearSelection()
self.record_table.setCurrentItem(None)
# 显示成功消息 # 显示成功消息
QMessageBox.information(self, "删除成功", "已成功删除选中的包装记录") QMessageBox.information(self, "删除成功", "已成功删除选中的包装记录")