- 解析feie错误信息

This commit is contained in:
gazebo
2019-04-01 20:57:36 +08:00
parent 2004a8ccf6
commit 9b1dfe9684
2 changed files with 39 additions and 14 deletions

View File

@@ -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) {