diff --git a/platformapi/feieapi/feieapi.go b/platformapi/feieapi/feieapi.go
index 9bb4381a..e0d517bd 100644
--- a/platformapi/feieapi/feieapi.go
+++ b/platformapi/feieapi/feieapi.go
@@ -6,6 +6,7 @@ import (
"net/http"
"strings"
"time"
+ "unicode"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi"
@@ -28,6 +29,10 @@ const (
PrinterStatusOnlineAbnormal = "在线,工作状态不正常。"
)
+const (
+ ErrMsgAlredyAdded = "(错误:已被添加过)"
+)
+
var (
exceedLimitCodes = map[int]int{}
@@ -122,7 +127,7 @@ func (a *API) AccessAPI(apiName string, apiParams map[string]interface{}) (retVa
return retVal, err
}
-func (a *API) PrinterAddList(printerList []*PrinterInfo) (ok, no []*PrinterResultInfo, err error) {
+func (a *API) PrinterAddList(printerList []*PrinterInfo) (ok, no map[string]string, err error) {
printerContent := []string{}
for _, v := range printerList {
printerContent = append(printerContent, strings.Join([]string{
@@ -142,7 +147,8 @@ func (a *API) PrinterAddList(printerList []*PrinterInfo) (ok, no []*PrinterResul
return nil, nil, err
}
-func interface2PrinterResultList4Add(value interface{}) (printerResultList []*PrinterResultInfo) {
+func interface2PrinterResultList4Add(value interface{}) (printerResultMap map[string]string) {
+ printerResultMap = make(map[string]string)
for _, v := range value.([]interface{}) {
strList := strings.Split(v.(string), "#")
if len(strList) == 4 {
@@ -150,13 +156,10 @@ func interface2PrinterResultList4Add(value interface{}) (printerResultList []*Pr
if len(strList2) == 1 {
strList2 = append(strList2, "")
}
- printerResultList = append(printerResultList, &PrinterResultInfo{
- SN: strList[0],
- ErrMsg: strList2[1],
- })
+ printerResultMap[strList[0]] = strList2[1]
}
}
- return printerResultList
+ return printerResultMap
}
func (a *API) PrintMsg(sn, content string, times int) (orderID string, err error) {
@@ -171,7 +174,7 @@ func (a *API) PrintMsg(sn, content string, times int) (orderID string, err error
return "", err
}
-func (a *API) PrinterDelList(snList []string) (ok, no []*PrinterResultInfo, err error) {
+func (a *API) PrinterDelList(snList []string) (ok, no map[string]string, err error) {
result, err := a.AccessAPI("Open_printerDelList", map[string]interface{}{
"snlist": strings.Join(snList, "-"),
})
@@ -182,13 +185,28 @@ func (a *API) PrinterDelList(snList []string) (ok, no []*PrinterResultInfo, err
return nil, nil, err
}
-func interface2PrinterResultList4Del(value interface{}) (printerResultList []*PrinterResultInfo) {
+func interface2PrinterResultList4Del(value interface{}) (printerResultMap map[string]string) {
+ printerResultMap = make(map[string]string)
for _, v := range value.([]interface{}) {
- printerResultList = append(printerResultList, &PrinterResultInfo{
- ErrMsg: v.(string),
- })
+ sn, errMsg := splitMsg(v.(string))
+ printerResultMap[sn] = errMsg
}
- return printerResultList
+ return printerResultMap
+}
+
+func splitMsg(msg string) (sn, errMsg string) {
+ runeList := []rune(msg)
+ index := 0
+ for ; index < len(runeList); index++ {
+ if !unicode.Is(unicode.ASCII_Hex_Digit, runeList[index]) {
+ break
+ }
+ }
+ if index > 0 && index < len(runeList) {
+ sn = string(runeList[:index])
+ errMsg = string(runeList[index:])
+ }
+ return sn, errMsg
}
func (a *API) PrinterEdit(sn, name, phoneNum string) (err error) {
diff --git a/platformapi/feieapi/feieapi_test.go b/platformapi/feieapi/feieapi_test.go
index 4fd18b4b..903fd53c 100644
--- a/platformapi/feieapi/feieapi_test.go
+++ b/platformapi/feieapi/feieapi_test.go
@@ -24,7 +24,7 @@ func init() {
}
func TestPrintMsg(t *testing.T) {
- result, err := api.PrintMsg("218510310", "hello", 1)
+ result, err := api.PrintMsg("218510310", "京西菜市
手机买菜上京西
极速到家送惊喜--------------------------------
下单时间: 2018-09-28 06:27:52
预计送达: 2018-09-28 09:00:00
订单编号: 823351245000021
京东到家#2
823351245000021
客户: 佛**
电话: 18575789646,6168
地址: 订单完结5小时后,隐藏顾客地址。
客户备注:
其他商品继续配送(缺货商品退款)
实际支付:26.74
商品明细:
品名 数量 单价 小计--------------------------------
小葱约100g/份
1 1.44 1.44
小白菜约250g/份
1 4.85 4.85
紫鲜茄约400g/份
1 6.00 6.00
散装泡姜约100g/份
1 3.12 3.12
老姜约200g/份
1 5.20 5.20
泡野山椒约100g/份
1 4.88 4.88
[新鲜]刺黄瓜约300g/份
1 5.00 5.00
薄皮青椒约250g/份
1 2.75 2.75
[优]土豆约500g/份
1 1.00 1.00
共9种9件商品
--------------------------------
商品质量问题请联系:
京西菜市-乐从店:13600309530
官方服务热线: 18011516898
更多信息请关注官方微信: 京西菜市
----------------------------------------------------------------
", 1)
if err != nil {
t.Fatalf("PrintMsg return error:%v", err)
}
@@ -66,6 +66,13 @@ func TestQueryOrderInfoByDate(t *testing.T) {
baseapi.SugarLogger.Debug(utils.Format4Output(data, false))
}
+func TestDelPrinterSqs(t *testing.T) {
+ err := api.DelPrinterSqs("218510310")
+ if err != nil {
+ t.Fatalf("DelPrinterSqs return error:%v", err)
+ }
+}
+
func TestQueryPrinterStatus(t *testing.T) {
status, err := api.QueryPrinterStatus("218510310")
if err != nil {