27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
|
|
# app/api/v1/common/print.py
|
|||
|
|
from flask import Blueprint, request, jsonify
|
|||
|
|
from app.services.print.label_service import LabelPrintService
|
|||
|
|
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
|