- 门店网络打印机设置修改,只有在成功绑定后才执行可能的解绑(之前是先解绑,可能有问题)
- 所有网络打印机适配层写入性API添加EnableStoreWrite控制
This commit is contained in:
@@ -108,7 +108,10 @@ func (c *PrinterHandler) GetVendorID() int {
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, id1, id2, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("PrintMsg id1:%s", id1)
|
||||
if id1 != "" {
|
||||
if _, err = api.FeieAPI.PrintMsg(id1, msgContent, 1); err == nil {
|
||||
if globals.EnableStoreWrite {
|
||||
_, err = api.FeieAPI.PrintMsg(id1, msgContent, 1)
|
||||
}
|
||||
if err == nil {
|
||||
printerStatus, err = c.GetPrinterStatus(ctx, id1, id2)
|
||||
}
|
||||
} else {
|
||||
@@ -138,13 +141,18 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store,
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, printerSN, printerKey, printerName string) (notUsed1, notUsed2 string, err error) {
|
||||
_, no, err := api.FeieAPI.PrinterAddList([]*feieapi.PrinterInfo{
|
||||
&feieapi.PrinterInfo{
|
||||
SN: printerSN,
|
||||
Key: printerKey,
|
||||
Name: printerName,
|
||||
},
|
||||
})
|
||||
var no map[string]string
|
||||
if globals.EnableStoreWrite {
|
||||
_, no, err = api.FeieAPI.PrinterAddList([]*feieapi.PrinterInfo{
|
||||
&feieapi.PrinterInfo{
|
||||
SN: printerSN,
|
||||
Key: printerKey,
|
||||
Name: printerName,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
no = make(map[string]string)
|
||||
}
|
||||
if err == nil {
|
||||
if no[printerSN] != "" {
|
||||
if no[printerSN] == feieapi.ErrMsgAlredyAdded {
|
||||
@@ -158,7 +166,9 @@ func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, printerSN, prin
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, printerSN, notUsed string) (err error) {
|
||||
_, _, err = api.FeieAPI.PrinterDelList([]string{printerSN})
|
||||
if globals.EnableStoreWrite {
|
||||
_, _, err = api.FeieAPI.PrinterDelList([]string{printerSN})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -171,7 +181,9 @@ func (c *PrinterHandler) RebindPrinter(ctx *jxcontext.Context, lastBindResult *p
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) EmptyPrintList(ctx *jxcontext.Context, id1, id2 string) (err error) {
|
||||
err = api.FeieAPI.DelPrinterSqs(id1)
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.FeieAPI.DelPrinterSqs(id1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,10 @@ func (c *PrinterHandler) GetVendorID() int {
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, printerNumber, printerToken, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("PrintMsg printerNumber:%s", printerNumber)
|
||||
if printerNumber != "" {
|
||||
if _, err = api.XiaoWMAPI.SendMsg(printerNumber, printerToken, msgContent); err == nil {
|
||||
if globals.EnableStoreWrite {
|
||||
_, err = api.XiaoWMAPI.SendMsg(printerNumber, printerToken, msgContent)
|
||||
}
|
||||
if err == nil {
|
||||
printerStatus, err = c.GetPrinterStatus(ctx, printerNumber, printerToken)
|
||||
}
|
||||
} else {
|
||||
@@ -235,9 +238,14 @@ func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, printerNumber,
|
||||
if printerNumber == "" { //len(printerNumber) != len("7JizmSyiXNzkggaqU") {
|
||||
err = fmt.Errorf("外卖管家打印机设备编号:%s长度不合法", printerNumber)
|
||||
} else {
|
||||
if printerToken, err = api.XiaoWMAPI.AuthPrinter(printerNumber, "", ""); err == nil {
|
||||
if globals.EnableStoreWrite {
|
||||
printerToken, err = api.XiaoWMAPI.AuthPrinter(printerNumber, "", "")
|
||||
}
|
||||
if err == nil {
|
||||
if _, err = c.GetPrinterStatus(ctx, printerNumber, printerToken); err != nil {
|
||||
c.UnregisterPrinter(ctx, printerNumber, printerToken)
|
||||
if globals.EnableStoreWrite {
|
||||
c.UnregisterPrinter(ctx, printerNumber, printerToken)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,7 +254,9 @@ func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, printerNumber,
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, printerNumber, printerToken string) (err error) {
|
||||
err = api.XiaoWMAPI.DelPrinter(printerNumber, printerToken)
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.XiaoWMAPI.DelPrinter(printerNumber, printerToken)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,10 @@ func (c *PrinterHandler) GetVendorID() int {
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, machineCode, possibleToken, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("PrintMsg machineCode:%s", machineCode)
|
||||
if machineCode != "" {
|
||||
if err = getApiByToken(possibleToken).PrintMsgWithToken(machineCode, msgTitle, msgContent, possibleToken); err == nil {
|
||||
if globals.EnableStoreWrite {
|
||||
err = getApiByToken(possibleToken).PrintMsgWithToken(machineCode, msgTitle, msgContent, possibleToken)
|
||||
}
|
||||
if err == nil {
|
||||
printerStatus, err = c.GetPrinterStatus(ctx, machineCode, possibleToken)
|
||||
}
|
||||
} else {
|
||||
@@ -137,12 +140,16 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store,
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, machineCode, secret, printerName string) (notUsed1, notUsed2 string, err error) {
|
||||
err = api.YilianyunAPI.AddPrinter(machineCode, secret, printerName)
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.YilianyunAPI.AddPrinter(machineCode, secret, printerName)
|
||||
}
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, machineCode, notUsed string) (err error) {
|
||||
err = api.YilianyunAPI.DeletePrinter(machineCode)
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.YilianyunAPI.DeletePrinter(machineCode)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -160,7 +167,12 @@ func (c *PrinterHandler) BindPrinter(ctx *jxcontext.Context, mapData map[string]
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) RebindPrinter(ctx *jxcontext.Context, lastBindResult *partner.BindPrinterResult) (bindResult *partner.BindPrinterResult, err error) {
|
||||
tokenInfo, err := api.YilianyunAPI2.RefreshToken(lastBindResult.PrinterKey2)
|
||||
var tokenInfo *yilianyunapi.TokenInfo
|
||||
if globals.EnableStoreWrite {
|
||||
tokenInfo, err = api.YilianyunAPI2.RefreshToken(lastBindResult.PrinterKey2)
|
||||
} else {
|
||||
tokenInfo = &yilianyunapi.TokenInfo{}
|
||||
}
|
||||
if err == nil {
|
||||
bindResult = yilianyunToken2BindResult(tokenInfo)
|
||||
}
|
||||
@@ -184,11 +196,15 @@ func getApiByToken(possibleToken string) *yilianyunapi.API {
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) EmptyPrintList(ctx *jxcontext.Context, id1, id2 string) (err error) {
|
||||
err = api.YilianyunAPI.CancelAll(id1, id2)
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.YilianyunAPI.CancelAll(id1, id2)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) PlayText(ctx *jxcontext.Context, id1, id2, orderID, text string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
err = api.YilianyunAPI.PlayText(id1, orderID, text, id2)
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.YilianyunAPI.PlayText(id1, orderID, text, id2)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -104,7 +104,9 @@ func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, deviceID, deviceSecret
|
||||
globals.SugarLogger.Debugf("PrintMsg deviceID:%s", deviceID)
|
||||
if deviceID != "" {
|
||||
var status int
|
||||
_, status, err = api.ZhongwuAPI.PrintMsg(deviceID, deviceSecret, msgContent)
|
||||
if globals.EnableStoreWrite {
|
||||
_, status, err = api.ZhongwuAPI.PrintMsg(deviceID, deviceSecret, msgContent)
|
||||
}
|
||||
if err == nil {
|
||||
printerStatus = c.translateStatus(status)
|
||||
}
|
||||
@@ -166,7 +168,9 @@ func (c *PrinterHandler) RebindPrinter(ctx *jxcontext.Context, lastBindResult *p
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) EmptyPrintList(ctx *jxcontext.Context, id1, id2 string) (err error) {
|
||||
_, err = api.ZhongwuAPI.EmptyPrintQueue(id1, id2)
|
||||
if globals.EnableStoreWrite {
|
||||
_, err = api.ZhongwuAPI.EmptyPrintQueue(id1, id2)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user