shan
This commit is contained in:
89
business/partner/partner_printer.go
Normal file
89
business/partner/partner_printer.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
const (
|
||||
PrinterStatusUnknown = 0
|
||||
PrinterStatusOffline = 1
|
||||
PrinterStatusOnlineOK = 2
|
||||
PrinterStatusOnlineAbnormal = 3
|
||||
)
|
||||
|
||||
const (
|
||||
PrintResultSuccess = 0 // 成功
|
||||
PrintResultNoPrinter = 1 // 没有配置网络打印机
|
||||
)
|
||||
|
||||
const (
|
||||
PrinterFontSizeNormal = int8(0) //正常大小
|
||||
PrinterFontSizeBig = int8(1) //两倍大小
|
||||
)
|
||||
|
||||
var (
|
||||
PrinterStatusName = map[int]string{
|
||||
PrinterStatusUnknown: "未知",
|
||||
PrinterStatusOffline: "离线",
|
||||
PrinterStatusOnlineOK: "正常",
|
||||
PrinterStatusOnlineAbnormal: "异常",
|
||||
}
|
||||
)
|
||||
|
||||
type PrinterStatus struct {
|
||||
PrintResult int `json:"printResult"`
|
||||
PrinterStatus int `json:"printerStatus"`
|
||||
Printed int `json:"printed"` // 已经打印的单数
|
||||
Waiting int `json:"waiting"` // 等待打印的单数,超过1一般不太正常
|
||||
}
|
||||
|
||||
type BindPrinterResult struct {
|
||||
PrinterSN string `json:"printerSN"`
|
||||
PrinterKey string `json:"printerKey"`
|
||||
PrinterKey2 string `json:"printerKey2"`
|
||||
ExpiresAt int64 `json:"expiresAt"`
|
||||
}
|
||||
|
||||
type IPrinterHandler interface {
|
||||
GetVendorID() int
|
||||
PrintMsg(ctx *jxcontext.Context, id1, id2, msgTitle, msgContent string) (printerStatus *PrinterStatus, err error)
|
||||
GetPrinterStatus(ctx *jxcontext.Context, id1, id2 string) (printerStatus *PrinterStatus, err error)
|
||||
|
||||
RegisterPrinter(ctx *jxcontext.Context, id1, id2, printerName string) (newID1, newID2 string, err error)
|
||||
UnregisterPrinter(ctx *jxcontext.Context, id1, id2 string) (err error)
|
||||
|
||||
BindPrinter(ctx *jxcontext.Context, mapData map[string]interface{}) (bindResult *BindPrinterResult, err error)
|
||||
RebindPrinter(ctx *jxcontext.Context, lastBindResult *BindPrinterResult) (bindResult *BindPrinterResult, err error)
|
||||
|
||||
// PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *PrinterStatus, err error)
|
||||
|
||||
EmptyPrintList(ctx *jxcontext.Context, id1, id2 string) (err error)
|
||||
PlayText(ctx *jxcontext.Context, id1, id2, orderID, text string) (printerStatus *PrinterStatus, err error)
|
||||
SetSound(ctx *jxcontext.Context, id1, id2, sound string) (err error)
|
||||
}
|
||||
|
||||
var (
|
||||
PrinterPlatformHandlers map[int]IPrinterHandler
|
||||
)
|
||||
|
||||
func init() {
|
||||
PrinterPlatformHandlers = make(map[int]IPrinterHandler)
|
||||
}
|
||||
|
||||
func RegisterPrinterPlatform(handler IPrinterHandler) {
|
||||
vendorID := handler.GetVendorID()
|
||||
if !(model.IsPrinterVendorExist(vendorID)) {
|
||||
panic(fmt.Sprintf("printer vendor:%d is illegal", vendorID))
|
||||
}
|
||||
if _, ok := PrinterPlatformHandlers[vendorID]; ok {
|
||||
panic(fmt.Sprintf("printer vendor:%d, already exists", vendorID))
|
||||
}
|
||||
PrinterPlatformHandlers[vendorID] = handler
|
||||
}
|
||||
|
||||
func GetPrinterPlatformFromVendorID(vendorID int) IPrinterHandler {
|
||||
return PrinterPlatformHandlers[vendorID]
|
||||
}
|
||||
Reference in New Issue
Block a user