抓取生产工单,抓取发料异常

This commit is contained in:
hjq
2026-06-11 17:51:01 +08:00
parent 5b19790037
commit a160d5d48f
12 changed files with 965 additions and 58 deletions

View File

@@ -155,6 +155,11 @@ def abnormal_report_page():
"""渲染发料异常检查数据看板"""
return render_template('abnormal_report.html')
@app.route('/reconciliation')
def reconciliation_page():
"""渲染绩效核查与BOM比对看板"""
return render_template('reconciliation.html')
@app.route('/api/receipts')
def get_receipts():
"""获取收货明细数据(支持分页和多条件搜索)"""
@@ -299,6 +304,81 @@ def get_abnormal_report():
"rows": [dict(ix) for ix in orders]
})
@app.route('/api/analysis/match_work_orders', methods=['POST'])
def match_work_orders():
"""触发:第一步提取并匹配工单"""
global is_browser_busy
if is_browser_busy:
return jsonify({
"success": False,
"message": f"系统忙碌:当前正在执行 '{current_task_name}',请稍后再试。"
}), 409
def run_match_task():
set_browser_busy("自动清洗并匹配工单数据")
try:
sys.path.insert(0, str(BROWSER_LOGIN_DIR))
from analysis_service import MaterialReconciliationService
service = MaterialReconciliationService()
updated = service.step1_extract_and_match_work_orders()
print(f"✅ 工单匹配任务执行成功!共处理了 {updated} 条发料记录。")
except Exception as e:
print(f"❌ 自动清洗匹配失败: {e}")
finally:
release_browser()
try:
threading.Thread(target=run_match_task, daemon=True).start()
return jsonify({"success": True, "message": "已触发后台自动清洗匹配工单任务!"})
except Exception as e:
return jsonify({"success": False, "message": str(e)}), 500
@app.route('/api/analysis/unmatched_materials')
def get_unmatched_materials():
"""获取:第二步没有匹配到工单的物料明细"""
try:
start_date = request.args.get('start')
end_date = request.args.get('end')
sys.path.insert(0, str(BROWSER_LOGIN_DIR))
from analysis_service import MaterialReconciliationService
service = MaterialReconciliationService()
data = service.step2_get_unmatched_materials(start_date, end_date)
return jsonify({"total": len(data), "rows": data})
except Exception as e:
return jsonify({"success": False, "message": str(e)}), 500
@app.route('/api/analysis/bom_reconciliation')
def get_bom_reconciliation():
"""获取第三步比对发料与BOM差异"""
try:
start_date = request.args.get('start')
end_date = request.args.get('end')
sys.path.insert(0, str(BROWSER_LOGIN_DIR))
from analysis_service import MaterialReconciliationService
service = MaterialReconciliationService()
data = service.step3_bom_reconciliation(start_date, end_date)
# 支持前端筛选
status_filter = request.args.get('status', '')
if status_filter:
data = [r for r in data if r['status'] == status_filter]
return jsonify({"total": len(data), "rows": data})
except Exception as e:
return jsonify({"success": False, "message": str(e)}), 500
@app.route('/api/analysis/summary')
def get_analysis_summary():
"""获取当前对账数据的周期等汇总信息"""
try:
sys.path.insert(0, str(BROWSER_LOGIN_DIR))
from analysis_service import MaterialReconciliationService
service = MaterialReconciliationService()
period = service.get_data_period()
return jsonify(period)
except Exception as e:
return jsonify({"start": "-", "end": "-"}), 500
@app.route('/api/task_status')
def get_task_status():
"""获取当前浏览器控制任务的状态"""
@@ -451,7 +531,11 @@ def sync_bom():
from fetch_bom_cost_full_tree import fetch_bom_cost_tree
fetch_bom_cost_tree()
except Exception as e:
print(f"BOM 抓取失败: {e}")
import traceback
err_msg = f"BOM 抓取失败: {e}\n{traceback.format_exc()}"
print(err_msg)
with open("app_error.log", "w") as f:
f.write(err_msg)
finally:
release_browser()