Files
KCGL/inventory-backend/app/api/v1/common/print.py
dxc cfb36ebf0b feat: add printer config management API
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
2026-02-11 14:23:43 +08:00

50 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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
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