1. 程式人生 > >智慧餐廳 之 (收銀小票列印)

智慧餐廳 之 (收銀小票列印)

Web收銀小票列印基本流程

Created with Raphaël 2.1.2使用者使用者webwebserverserverwinform殼winform殼點選列印按鈕呼叫列印服務組裝列印報文ESC指令,再用Base64編碼通過goeasy推送,web前端再根據列印型別呼叫TCP\USB\COM列印

思路:通過java server組裝ESC樣式和指令,然後通過推送到web前段,前段通過js呼叫到winform殼的方法分發 TCP\USB\COM列印指令。

package com.takeout.service.print.impl;
/**
 * 列印基本指令
 */
public
class PrinterCmdUtils { public static byte ESC = 27; // 換碼 public static byte FS = 28; // 文字分隔符 public static byte GS = 29; // 組分隔符 public static byte DLE = 16; // 資料連線換碼 public static byte EOT = 4; // 傳輸結束 public static byte ENQ = 5; // 詢問字元 public static byte
SP = 32; // 空格 public static byte HT = 9; // 橫向列表 public static byte LF = 10; // 列印並換行(水平定位) public static byte CR = 13; // 歸位鍵 public static byte FF = 12; // 走紙控制(列印並回到標準模式(在頁模式下) ) public static byte CAN = 24; // 作廢(頁模式下取消列印資料 ) /** * 列印紙一行最大的位元組 */ private
int LINE_BYTE_SIZE = 32; /** * 分隔符 */ private String SEPARATOR = "$"; private static StringBuilder sb = new StringBuilder(); /** * 印表機初始化 * * @return */ public static byte[] init_printer() { byte[] result = new byte[2]; result[0] = ESC; result[1] = 64; return result; } /** * 開啟錢箱 * * @return */ public static byte[] open_money() { byte[] result = new byte[5]; result[0] = ESC; result[1] = 112; result[2] = 48; result[3] = 64; result[4] = 0; return result; } /** * 換行 * * @param lineNum要換幾行 * @return */ public static byte[] nextLine(int lineNum) { byte[] result = new byte[lineNum]; for (int i = 0; i < lineNum; i++) { result[i] = LF; } return result; } /** * 繪製下劃線(1點寬) * * @return */ public static byte[] underlineWithOneDotWidthOn() { byte[] result = new byte[3]; result[0] = ESC; result[1] = 45; result[2] = 1; return result; } /** * 繪製下劃線(2點寬) * * @return */ public static byte[] underlineWithTwoDotWidthOn() { byte[] result = new byte[3]; result[0] = ESC; result[1] = 45; result[2] = 2; return result; } /** * 取消繪製下劃線 * * @return */ public static byte[] underlineOff() { byte[] result = new byte[3]; result[0] = ESC; result[1] = 45; result[2] = 0; return result; } /** * 選擇加粗模式 * * @return */ public static byte[] boldOn() { byte[] result = new byte[3]; result[0] = ESC; result[1] = 69; result[2] = 0xF; return result; } /** * 取消加粗模式 * * @return */ public static byte[] boldOff() { byte[] result = new byte[3]; result[0] = ESC; result[1] = 69; result[2] = 0; return result; } /** * 左對齊 * * @return */ public static byte[] alignLeft() { byte[] result = new byte[3]; result[0] = ESC; result[1] = 97; result[2] = 0; return result; } /** * 居中對齊 * * @return */ public static byte[] alignCenter() { byte[] result = new byte[3]; result[0] = ESC; result[1] = 97; result[2] = 1; return result; } /** * 右對齊 * * @return */ public static byte[] alignRight() { byte[] result = new byte[3]; result[0] = ESC; result[1] = 97; result[2] = 2; return result; } /** * 水平方向向右移動col列 * * @param col * @return */ public static byte[] set_HT_position(byte col) { byte[] result = new byte[4]; result[0] = ESC; result[1] = 68; result[2] = col; result[3] = 0; return result; } /** * 字型變大為標準的n倍 * * @param num * @return */ public static byte[] fontSizeSetBig(int num) { byte realSize = 0; switch (num) { case 0: realSize = 0; break; case 1: realSize = 1; break; case 2: realSize = 17; break; case 3: realSize = 34; break; case 4: realSize = 51; break; case 5: realSize = 68; break; case 6: realSize = 85; break; case 7: realSize = 102; break; case 8: realSize = 119; break; } byte[] result = new byte[3]; result[0] = 29; result[1] = 33; result[2] = realSize; return result; } /** * 字型取消倍寬倍高 * * @return */ public static byte[] fontSizeSetSmall() { byte[] result = new byte[3]; result[0] = ESC; result[1] = 33; return result; } /** * 進紙並全部切割 * * @return */ public static byte[] feedPaperCutAll() { byte[] result = new byte[4]; result[0] = GS; result[1] = 86; result[2] = 65; result[3] = 0; return result; } /** * 進紙並切割(左邊留一點不切) * * @return */ public static byte[] feedPaperCutPartial() { byte[] result = new byte[4]; result[0] = GS; result[1] = 86; result[2] = 66; result[3] = 0; return result; } /* public static byte[] bmpToByte(Bitmap bmp) { int h = bmp.Height / 24 + 1; int w = bmp.Width; byte[][] all = new byte[4 + 2 * h + h * w][]; all[0] = new byte[] { 0x1B, 0x33, 0x00 }; Color pixelColor; // ESC * m nL nH 點陣圖 byte[] escBmp = new byte[] { 0x1B, 0x2A, 0x21, (byte)(w % 256), (byte)(w / 256) }; // 每行進行列印 for (int i = 0; i < h; i++) { all[i * (w + 2) + 1] = escBmp; for (int j = 0; j < w; j++) { byte[] data = new byte[] { 0x00, 0x00, 0x00 }; for (int k = 0; k < 24; k++) { if (((i * 24) + k) < bmp.Height) { pixelColor = bmp.GetPixel(j, (i * 24) + k); if (pixelColor.R == 0) { data[k / 8] += (byte)(128 >> (k % 8)); } } } all[i * (w + 2) + j + 2] = data; } //換行 all[(i + 1) * (w + 2)] = PrinterCmdUtils.nextLine(1); } all[h * (w + 2) + 1] = PrinterCmdUtils.nextLine(2); all[h * (w + 2) + 2] = PrinterCmdUtils.feedPaperCutAll(); all[h * (w + 2) + 3] = PrinterCmdUtils.open_money(); return PrinterCmdUtils.byteMerger(all); } */ // ------------------------切紙----------------------------- /* public static byte[] byteMerger(byte[] byte_1, byte[] byte_2) { byte[] byte_3 = new byte[byte_1.Length + byte_2.Length]; System.Array.Copy(byte_1, 0, byte_3, 0, byte_1.Length); System.Array.Copy(byte_2, 0, byte_3, byte_1.Length, byte_2.Length); return byte_3; } public static byte[] byteMerger(byte[][] byteList) { int Length = 0; for (int i = 0; i < byteList.Length; i++) { Length += byteList[i].Length; } byte[] result = new byte[Length]; int index = 0; for (int i = 0; i < byteList.Length; i++) { byte[] nowByte = byteList[i]; for (int k = 0; k < byteList[i].Length; k++) { result[index] = nowByte[k]; index++; } } return result; } public static byte[][] byte20Merger(byte[] bytes) { int size = bytes.Length / 10 + 1; byte[][] result = new byte[size][]; for (int i = 0; i < size; i++) { byte[] by = new byte[((i + 1) * 10) - (i * 10)]; //從bytes中的第 i * 10 個位置到第 (i + 1) * 10 個位置; System.Array.Copy(bytes, i * 10, by, 0, (i + 1) * 10); result[i] = by; } return result; } */ }

列印樣式示例

/**
 * 結賬單 - 門店
 * shop_name 店名
 * order_type_and_source 桌號:小桌01、[桌牌:39]、[自提--流水號:02341]、[外帶--流水號:36252]
 * cashier 收銀員
 * meal_num
 * order_num
 * order_time 時間
 * order_goods
 * order_other
 * order_orgin_money
 * order_should_pay_money
 * order_real_pay_money
 * shop_phone
 * shop_address
 * @return
 */
protected String shopBillContent50() {
    // TODO Auto-generated method stub
    StringBuffer content = new StringBuffer();

    content.append("<CENTER>@shop_name</CENTER><BR>");
    content.append("<TITLE>結賬單</TITLE><BR>");
    content.append("<CB>@order_type_and_source</CB><BR>");
    content.append("單號:@order_no<BR>");
    content.append("收銀員:@cashier<BR>");
    content.append("用餐人數:@meal_num<BR>");
    content.append("時間:@order_time<BR>");
    content.append("------------------------------<BR>");
    content.append("菜品名稱     數量   原價  金額<BR>");
    content.append("------------------------------<BR>");
    content.append("@order_goods");
    content.append("------------------------------<BR>");
    content.append("消費總額:@order_orgin_money元<BR>");
    content.append("@order_other");
    content.append("應收金額:@order_should_pay_money元<BR>");
    content.append("@order_pay_item");
    content.append("實收金額:@order_real_pay_money元<BR>");
    content.append("--------------------------------<BR>");
    content.append("簽名:<BR>");
    content.append("門店電話:@shop_phone<BR>");
    content.append("門店地址:@shop_address<BR>");
    return content.toString();
}
/**
 * 格式化資料
 * @throws UnsupportedEncodingException 
 * @throws SQLException 
 */
private String prepareContent(String content, PrinterConfigBean pcBean, PrinterUniversalConfigBean uconfig) throws UnsupportedEncodingException, SQLException {
    String msg = content;

    msg = msg.replaceAll("<TITLE>", new String(b_center,"GBK") + new String(PrinterCmdUtils.fontSizeSetBig(2),"GBK"));//放大居中
    msg = msg.replaceAll("</TITLE>", new String(PrinterCmdUtils.fontSizeSetBig(0),"GBK") + new String(b_nextLine,"GBK") + new String(b_left,"GBK"));//結束

    if(uconfig.getFontSize().equals(MyConstant.BIG)) {
        msg = msg.replaceAll("<L>", new String(PrinterCmdUtils.fontSizeSetBig(1),"GBK"));
        msg = msg.replaceAll("</L>", new String(PrinterCmdUtils.fontSizeSetBig(0),"GBK"));
        msg = msg.replaceAll("<CB>", new String(PrinterCmdUtils.fontSizeSetBig(2),"GBK"));
        msg = msg.replaceAll("</CB>", new String(PrinterCmdUtils.fontSizeSetBig(0),"GBK"));
    } else {
        msg = msg.replaceAll("<L>", "");
        msg = msg.replaceAll("</L>", "");
        msg = msg.replaceAll("<CB>", "");
        msg = msg.replaceAll("</CB>", "");
    }
    msg = msg.replaceAll("<BR>", new String(b_nextLine,"GBK"));
    msg = msg.replaceAll("<CENTER>", new String(b_center,"GBK"));
    msg = msg.replaceAll("</CENTER>", new String(b_nextLine,"GBK") + new String(b_left,"GBK"));
    msg = msg.replaceAll("<CUT>", new String(b_breakAll,"GBK"));
    msg = msg.replaceAll("<OPENMONEY>", new String(b_openMoney,"GBK"));
    return Base64.encode(msg, "GBK");
}

通過上面介紹,可以獲得基本列印指令的Base64編碼後字串。然後通過goeasy推送到web頁面,再通過呼叫js,進入殼方法,進行解碼轉發就好了。

相關推薦

智慧餐廳 小票列印

Web收銀小票列印基本流程 Created with Raphaël 2.1.2使用者使用者webwebserverserverwinform殼winform殼點選列印按鈕呼叫列印服務組裝列印報文ESC指令,再用Base64編碼通過goeasy推送,web

強大智慧:餐飲連鎖店支付系統 讓你的店鋪走在時代前沿

強大智慧 連鎖店支付收銀系統 在這個互聯網時代,逛市場都要攜二維碼出街,這意味著信息化和智能化發展已成趨勢已成定局。那麽這種簡便,智能的互聯網情況之下一種收銀系統會使你的店鋪成為當今最流行、最受歡迎的一家。 采寶移動支付收款系統會解決收銀、促銷、會員等一系列管理

智慧景區專案建設方案票務管理詳細介紹

智慧景區票務系統的解決思路 利用大資料、智慧景區和網際網路+技術和思路,解決景區智慧票務系統現有問題,建設智慧票務系統。 採用新技術架構設計:利用完善的總體架構設計,採用新的技術路線,優化完善電子票務系統。 拓展售票檢票渠道:在景區電子票務系統的基礎上擴充套件多種售票、檢票方式

1.python3基礎還沒寫完

pycha 文件名 linu pytho 代碼 nbsp tro windows arm 1.新建項目 打開pycharm-新建項目-新建python文件 2.輸出 #!/usr/bin/python3 print("aaa") print(1+2) #!/usr/

Spring2 AOP 面向切面程式設計AOP目錄

Spring Core: Spring的核心功能即IOC容器,解決物件的建立及物件之間的依賴關係 Spring WEB: Spring對WEB模組的支援 Spring AOP: 面向切面程式設計 AOP的概述 AOP的底層實現 Spring AOP開發

iOS開發玩轉藍芽不看此文,枉做開發

前言: 之前詳細談過不少關於HTTP協議的知識點,TCP/IP也通過tcpdump做過簡單的介紹,但網路協議的本質其實是連線,裝置或者端之間連線的方式有多種,常見的http或者基於tcp的socket只是森林一葉,還有些不那麼常見的協議比如藍芽。適當腦洞,也能玩出不少新花樣

Solidify實現一個智慧合約8動態大小位元組陣列

動態大小位元組陣列 string是一個動態尺寸的UTF-8編碼字串,它其實是一個特殊的可變位元組陣列,string是引用型別,而非值型別。 bytes動態位元組陣列,引用型別。 常規字串string轉換為bytes string字串中沒有提供length方法獲取字串長

資料結構與演算法-----單向線性連結串列逆轉和反向列印

單向連結串列沒有前指標,所以實現反向列印還是比較麻煩,我們這裡使用遞迴原理解決此問題。 這裡提到逆轉,也就是將單鏈表的next指標指向前一個節點,我們也使用遞迴實現。 // 練習:實現單向線性連

MongoDB基本操作mongodb的簡單封裝

具體的程式碼實現如下: /********************************************* * CLR 版本: 4.0.30319.42000 * 類 名 稱: MongoHelper * 機器名稱:

Python基礎異常與開發規範

一、異常 1.1、Python中錯誤分為兩種: 語法錯誤,這種錯誤根本過不了python直譯器的語法檢測,必須在程式執行前就改正 邏輯錯誤,如int("m") 異常就是程式執行時發生錯誤的訊號(在程式出現錯誤時,則會產生一個異常,若程式沒有處理它,則會丟擲該異常,程式的執行也隨之終止),在

AI神經網路+深度學習

目前的人工智慧,或者說以深度學習為代表的一些方法論的研究,更像是古代的鍊金術,而不像是現代的化學

華萊士的 第一個python程序用戶登錄

用戶名 word true sha shang print 密碼 tin pri Name = "shangzb"password = 43while True:   _Name = input("Name:")   if _Name == Name:

JMeter壓力測試案例大全ftp伺服器和sftp

目錄 1.jmeter安裝 2.資料庫的壓力測試 3. ftp伺服器的壓力測試 4. sftp的壓力測試(缺) 5.http請求的壓力測試 6. socket的壓力測試 7.郵件伺服器測試 7.1基於命令列 7.2基於介面 8.元件介紹 9.1執行緒組 9.2控制器 9.3

React-Native小白計劃六SwipeableFlatList滑動的列表

程式碼:import React, { Component } from 'react'; import { StyleSheet, Text, View, TouchableHighlight, SwipeableFlatList,//側滑列表 } from 're

Linux Shell指令碼攻略—不止小試牛刀1簡介、終端列印

Bash 和 Dash 的問題 Debian和Ubuntu中,/bin/sh預設已經指向dash,它主要是為了執行指令碼而出現,而不是互動,原因是dash更快、更高效,但功能相比bash要少很多,語法嚴格遵守POSIX標準。 從Ubuntu 6.10開始,預

OpenStack入門以及一些資料二、neutron網路

L1 L1 是物理層,主要是涉及硬體的一些電氣特性,與偏軟體的 Neutron 虛擬網路從知識脈絡上關係甚少,不展開。 L2 FLAT L2 資料鏈路層通過交換機裝置進行幀轉發。交換機在接收到幀之後(L2 層叫幀,L3 層叫包)先解析出幀頭中的 MAC 地址,再在轉發表中查詢是否有對應 MAC

阿里介面呼叫——智慧植物識別含花卉與雜草

方法一,根據RestClient,輕量級元件,在GitHub的地址 public object PsotBaiDuAPIIdentify() { var client = new RestClient("http://plantgw.

系統間通訊方式RPC的基本概念

1、概述 經過了詳細的資訊格式、網路IO模型的講解,並且通過JAVA RMI的講解進行了預熱。從這篇文章開始我們將進入這個系列博文的另一個重點知識體系的講解:RPC。在後續的幾篇文章中,我們首先講解RPC的基本概念,一個具體的RPC實現會有哪些基本要素構成,然後我們詳細介紹一款典型的RPC框架:Apac

基於Qt的點餐系統小票列印

待解決問題: 顧客在點餐完畢後給列印一份小票。如圖所示: 解決方案:最開始拿到了一個基於JAVA實現的小票列印demo,使用的是ECS/POS指令集。但是並沒有成功地用Qt也實現出來。 本文基於QPainter + QPrinter 實現小票列印 (程

【NOIP模擬賽】一道好的查分約束題

bsp max int printf out 以及 void def 判斷 /* s[]表示最優方案的序列中的前綴和,那麽s[23]就是最優方案 由題意我們可以列出這樣一些式子: s[i]+s[23]-s[16+i]>