56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package partner
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
)
|
|
|
|
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)
|
|
}
|
|
|
|
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]
|
|
}
|