fix: 동물약 안내서 인쇄를 네트워크 프린터로 변경

- USB 프린터에서 네트워크 프린터(192.168.0.174:9100)로 변경
- pos_printer.print_text() 함수 사용 (특이사항 인쇄와 동일 방식)
- 80mm 프린터 기준 48자 레이아웃
This commit is contained in:
thug0bin 2026-03-04 19:20:26 +09:00
parent 321fd0de1e
commit 097bc4c84f

View File

@ -6504,93 +6504,68 @@ def api_animal_drug_info_print():
dosage = strip_html(row.dosage_instructions)
precautions = strip_html(row.precautions)
# ESC/POS 인쇄 데이터 생성
from escpos.printer import Usb
# 80mm 프린터 = 48자 기준
LINE = "=" * 48
THIN = "-" * 48
# 프린터 연결 (아침에 설정한 영수증 프린터)
try:
# POS 프린터 (VID/PID 확인 필요)
printer = Usb(0x0483, 0x5743, profile="default")
except Exception as e:
logging.error(f"프린터 연결 실패: {e}")
return jsonify({'success': False, 'error': f'프린터 연결 실패: {str(e)}'}), 500
# 텍스트 메시지 생성
message = f"""
{LINE}
🐾 동물약 안내서
{LINE}
{pg_product_name}
"""
if company:
message += f"제조: {company}\n"
try:
# 헤더
printer.set(align='center', bold=True, double_height=True)
printer.text("🐾 동물약 안내서\n")
printer.set(align='center', bold=False, double_height=False)
printer.text("=" * 42 + "\n\n")
# 제품명
printer.set(align='center', bold=True)
printer.text(f"{pg_product_name}\n")
printer.set(bold=False)
if company:
printer.text(f"제조: {company}\n")
printer.text("\n")
# 주성분
if ingredient and ingredient != 'NaN':
printer.set(align='left')
printer.text("-" * 42 + "\n")
printer.set(bold=True)
printer.text("▶ 주성분\n")
printer.set(bold=False)
for line in wrap_text(ingredient):
printer.text(f" {line}\n")
printer.text("\n")
# 효능효과
if efficacy:
printer.set(align='left')
printer.text("-" * 42 + "\n")
printer.set(bold=True)
printer.text("▶ 효능효과\n")
printer.set(bold=False)
for line in wrap_text(efficacy[:300]): # 최대 300자
printer.text(f" {line}\n")
printer.text("\n")
# 용법용량
if dosage:
printer.text("-" * 42 + "\n")
printer.set(bold=True)
printer.text("▶ 용법용량\n")
printer.set(bold=False)
for line in wrap_text(dosage[:400]): # 최대 400자
printer.text(f" {line}\n")
printer.text("\n")
# 주의사항
if precautions:
printer.text("-" * 42 + "\n")
printer.set(bold=True)
printer.text("▶ 주의사항\n")
printer.set(bold=False)
for line in wrap_text(precautions[:300]): # 최대 300자
printer.text(f" {line}\n")
printer.text("\n")
# 푸터
printer.set(align='center')
printer.text("=" * 42 + "\n")
printer.text("청 춘 약 국\n")
printer.text("Tel: 033-481-5222\n\n")
# 커팅
printer.cut()
printer.close()
if ingredient and ingredient != 'NaN':
message += f"""
{THIN}
주성분
"""
for line in wrap_text(ingredient, 46):
message += f" {line}\n"
if efficacy:
message += f"""
{THIN}
효능효과
"""
for line in wrap_text(efficacy[:400], 46):
message += f" {line}\n"
if dosage:
message += f"""
{THIN}
용법용량
"""
for line in wrap_text(dosage[:500], 46):
message += f" {line}\n"
if precautions:
message += f"""
{THIN}
주의사항
"""
for line in wrap_text(precautions[:400], 46):
message += f" {line}\n"
message += f"""
{LINE}
Tel: 033-481-5222
"""
# 네트워크 프린터로 인쇄 (pos_printer 사용)
from pos_printer import print_text
result = print_text(message, cut=True)
if result:
return jsonify({'success': True, 'message': '동물약 안내서 인쇄 완료'})
except Exception as e:
logging.error(f"인쇄 오류: {e}")
try:
printer.close()
except:
pass
return jsonify({'success': False, 'error': f'인쇄 오류: {str(e)}'}), 500
else:
return jsonify({'success': False, 'error': '프린터 출력 실패'}), 500
except Exception as e:
logging.error(f"동물약 정보 인쇄 API 오류: {e}")