- 解析feie错误信息
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -24,7 +24,7 @@ func init() {
|
||||
}
|
||||
|
||||
func TestPrintMsg(t *testing.T) {
|
||||
result, err := api.PrintMsg("218510310", "hello", 1)
|
||||
result, err := api.PrintMsg("218510310", "<CB>京西菜市</CB><BR><C>手机买菜上京西</C><BR><C>极速到家送惊喜</C>--------------------------------<BR>下单时间: 2018-09-28 06:27:52<BR>预计送达: 2018-09-28 09:00:00<BR>订单编号: 823351245000021<BR><BR><B>京东到家#2</B><BR><BR><QR>823351245000021</QR><BR>客户: 佛**<BR>电话: 18575789646,6168<BR>地址: 订单完结5小时后,隐藏顾客地址。<BR><BR>客户备注: <BR><B>其他商品继续配送(缺货商品退款)</B><BR><BR><BOLD>实际支付:</BOLD>26.74<BR><BR>商品明细: <BR>品名 数量 单价 小计--------------------------------<BR>小葱约100g/份<BR> 1 1.44 1.44<BR>小白菜约250g/份<BR> 1 4.85 4.85<BR>紫鲜茄约400g/份<BR> 1 6.00 6.00<BR>散装泡姜约100g/份<BR> 1 3.12 3.12<BR>老姜约200g/份<BR> 1 5.20 5.20<BR>泡野山椒约100g/份<BR> 1 4.88 4.88<BR>[新鲜]刺黄瓜约300g/份<BR> 1 5.00 5.00<BR>薄皮青椒约250g/份<BR> 1 2.75 2.75<BR>[优]土豆约500g/份<BR> 1 1.00 1.00<BR><BR><BOLD>共9种9件商品</BOLD><BR>--------------------------------<BR><C><L><BOLD>商品质量问题请联系:</BOLD></L><BR></C><C><L><BOLD>京西菜市-乐从店:13600309530</BOLD></L><BR></C><BR><BR>官方服务热线: 18011516898<BR>更多信息请关注官方微信: 京西菜市<BR><BR><BR><BR>----------------------------------------------------------------<BR><BR>", 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 {
|
||||
|
||||
Reference in New Issue
Block a user