- 门店网络打印机设置修改,只有在成功绑定后才执行可能的解绑(之前是先解绑,可能有问题)
- 所有网络打印机适配层写入性API添加EnableStoreWrite控制
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/msg"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/netprinter"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
@@ -521,7 +520,7 @@ func checkCreateStore(store *model.Store) (err error) {
|
||||
}
|
||||
|
||||
func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
globals.SugarLogger.Debugf("UpdateStore storeID:%d, payload:%s", storeID, utils.Format4Output(payload, false))
|
||||
globals.SugarLogger.Debugf("UpdateStore storeID:%d, payload:%s", storeID, utils.Format4Output(payload, true))
|
||||
if err = checkBankBranch(utils.Interface2String(payload["payeeBankBranchName"])); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -544,27 +543,23 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
|
||||
store.Name = valid["name"].(string)
|
||||
syncStatus |= model.SyncFlagStoreName
|
||||
}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
||||
// 网络打印机处理
|
||||
if valid["printerVendorID"] != nil || valid["printerSN"] != nil || valid["printerKey"] != nil {
|
||||
if handler := partner.GetPrinterPlatformFromVendorID(store.PrinterVendorID); handler != nil {
|
||||
handler.UnregisterPrinter(ctx, store.PrinterSN, store.PrinterKey)
|
||||
}
|
||||
if valid["printerVendorID"] == nil {
|
||||
valid["printerVendorID"] = store.PrinterVendorID
|
||||
} else {
|
||||
store.PrinterVendorID = int(utils.Interface2Int64WithDefault(valid["printerVendorID"], 0))
|
||||
}
|
||||
if store.PrinterVendorID > 0 {
|
||||
if printerVendorID := int(utils.Interface2Int64WithDefault(valid["printerVendorID"], 0)); printerVendorID > 0 {
|
||||
handler := partner.GetPrinterPlatformFromVendorID(printerVendorID)
|
||||
if handler == nil {
|
||||
return 0, fmt.Errorf("不支持的打印机厂商ID:%d", printerVendorID)
|
||||
}
|
||||
if valid["printerSN"] == nil {
|
||||
valid["printerSN"] = store.PrinterSN
|
||||
}
|
||||
if valid["printerKey"] == nil {
|
||||
valid["printerKey"] = store.PrinterKey
|
||||
}
|
||||
var handler partner.IPrinterHandler
|
||||
if handler, err = netprinter.GetHandlerFromStore(store); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
newID1, newID2, err2 := handler.RegisterPrinter(ctx, valid["printerSN"].(string), valid["printerKey"].(string), store.Name)
|
||||
if err = err2; err != nil {
|
||||
return 0, err
|
||||
@@ -576,8 +571,14 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
|
||||
if newID2 != "" {
|
||||
valid["printerKey"] = newID2
|
||||
}
|
||||
|
||||
valid["printerBindInfo"] = ""
|
||||
} else {
|
||||
valid["printerVendorID"] = 0
|
||||
valid["printerSN"] = ""
|
||||
valid["printerKey"] = ""
|
||||
}
|
||||
valid["printerBindInfo"] = ""
|
||||
if handler := partner.GetPrinterPlatformFromVendorID(store.PrinterVendorID); handler != nil {
|
||||
handler.UnregisterPrinter(ctx, store.PrinterSN, store.PrinterKey)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,7 +615,7 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
|
||||
// }
|
||||
// valid["districtCode"] = api.AutonaviAPI.GetCoordinateDistrictCode(lng, lat)
|
||||
// }
|
||||
globals.SugarLogger.Debugf("UpdateStore track:%s, valid:%s", ctx.GetTrackInfo(), utils.Format4Output(valid, true))
|
||||
globals.SugarLogger.Debugf("UpdateStore track:%s, storeID:%d, valid:%s", ctx.GetTrackInfo(), storeID, utils.Format4Output(valid, true))
|
||||
if len(valid) > 0 {
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
@@ -708,10 +709,9 @@ func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (i
|
||||
store.Name = jxutils.FormalizeName(store.Name)
|
||||
store.DeliveryRange = strings.Trim(store.DeliveryRange, ";")
|
||||
if store.PrinterSN != "" {
|
||||
var handler partner.IPrinterHandler
|
||||
handler, err = netprinter.GetHandlerFromStore(store)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
handler := partner.GetPrinterPlatformFromVendorID(store.PrinterVendorID)
|
||||
if handler == nil {
|
||||
return 0, fmt.Errorf("不支持的打印机厂商ID:%d", store.PrinterVendorID)
|
||||
}
|
||||
newID1, newID2, err2 := handler.RegisterPrinter(ctx, store.PrinterSN, store.PrinterKey, store.Name)
|
||||
if err = err2; err != nil {
|
||||
|
||||
@@ -57,11 +57,7 @@ func PrintOrderByOrder(ctx *jxcontext.Context, order *model.GoodsOrder) (printRe
|
||||
PrintResult: partner.PrintResultNoPrinter,
|
||||
}, nil
|
||||
}
|
||||
if globals.EnableStoreWrite {
|
||||
printResult, err = handler.PrintOrder(ctx, store, order)
|
||||
} else {
|
||||
err = fmt.Errorf("当前环境不支持打印")
|
||||
}
|
||||
printResult, err = handler.PrintOrder(ctx, store, order)
|
||||
if err == nil {
|
||||
dao.SetOrderPrintFlag(db, ctx.GetUserName(), order.VendorOrderID, order.VendorID, true)
|
||||
}
|
||||
|
||||
@@ -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