Files
KCGL/inventory-backend/app/api/v1/common/print.py

50 lines
1.8 KiB
Python
Raw Normal View History

2026-02-02 15:06:20 +08:00
# app/api/v1/common/print.py
from flask import Blueprint, request, jsonify
from app.services.print.label_service import LabelPrintService
from app.services.print.print_config import PrintConfigManager
2026-02-02 15:06:20 +08:00
from app.models.inbound.buy import StockBuy
# 引入其他模型 StockSemi, StockProduct
import traceback
print_bp = Blueprint('print', __name__)
@print_bp.route('/preview', methods=['POST'])
def preview_label():
try:
data = request.get_json()
# 如果只传了ID和类型,可以在这里查库补全数据,也可以直接前端传全量数据
img_base64 = LabelPrintService.generate_preview_image(data)
return jsonify({"code": 200, "msg": "success", "data": img_base64})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500
@print_bp.route('/execute', methods=['POST'])
def execute_print():
try:
data = request.get_json()
LabelPrintService.send_to_printer(data)
return jsonify({"code": 200, "msg": "指令已发送至打印机"})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500
@print_bp.route('/config', methods=['GET'])
def get_printer_config():
try:
label = PrintConfigManager.get_config('label_printer')
network = PrintConfigManager.get_config('network_printer')
config = {'label_printer': label, 'network_printer': network}
return jsonify({"code": 200, "msg": "success", "data": config})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500
@print_bp.route('/config', methods=['POST'])
def update_printer_config():
try:
data = request.get_json()
PrintConfigManager.save_config(data)
return jsonify({"code": 200, "msg": "配置保存成功"})
except Exception as e:
return jsonify({"code": 500, "msg": str(e)}), 500