This commit is contained in:
suyl
2021-07-15 09:27:24 +08:00
parent 26f5087072
commit fd69d4dda0
2 changed files with 18 additions and 21 deletions

View File

@@ -1,9 +1,7 @@
package controllers
import (
"bytes"
"crypto/md5"
"encoding/json"
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
@@ -173,7 +171,7 @@ success:
{
callResult.Code = model.ErrCodeSuccess
if len(result) > 0 {
callResult.Data = result[0].String()
callResult.Data = result[0].Interface()
}
c.Data["json"] = callResult
c.ServeJSON()
@@ -356,35 +354,34 @@ func (c *ApiController) DoPrint(dataMap map[string]interface{}) (data, errCode s
}
//获取某打印消息
func (c *ApiController) GetPrintMsg(dataMap map[string]interface{}) (data, errCode string, err error) {
func (c *ApiController) GetPrintMsg(dataMap map[string]interface{}) (printMsg *cms.GetPrintMsgResult, errCode string, err error) {
var (
msgID string
appID int
)
globals.SugarLogger.Debugf("Begin API GetPrintMsg data: [%v]", utils.Format4Output(dataMap, false))
if _, ok := dataMap[keyMsgID].(string); !ok {
return buildParamErrCodeAndErr(keyMsgID)
return printMsg, model.ErrCodeOpenAPIParamErrNormal, fmt.Errorf("参数[%s]错误,请传入正确的值!", keyMsgID)
} else {
if msgID = dataMap[keyMsgID].(string); msgID == "" {
return buildParamErrCodeAndErr(keyMsgID)
return printMsg, model.ErrCodeOpenAPIParamErrNormal, fmt.Errorf("参数[%s]错误,请传入正确的值!", keyMsgID)
}
}
appID = utils.Str2Int(dataMap[keyAppID].(string))
if printMsg, err := cms.GetPrintMsg(appID, msgID); err != nil {
return "", model.ErrCodeGeneralFailed, err
if printMsg, err = cms.GetPrintMsg(appID, msgID); err != nil {
return printMsg, model.ErrCodeGeneralFailed, err
} else if printMsg == nil {
return "", model.ErrCodeGeneralFailed, fmt.Errorf("未查询到该消息! msg_id: %v", msgID)
return printMsg, model.ErrCodeGeneralFailed, fmt.Errorf("未查询到该消息! msg_id: %v", msgID)
} else {
bf := bytes.NewBuffer([]byte{})
jsonEncoder := json.NewEncoder(bf)
jsonEncoder.SetEscapeHTML(false)
if err2 := jsonEncoder.Encode(printMsg); err2 == nil {
data = strings.Replace(bf.String(), "\n", "", strings.LastIndex(bf.String(), "\n"))
} else {
return "", model.ErrCodeGeneralFailed, err
}
//bf := bytes.NewBuffer([]byte{})
//jsonEncoder := json.NewEncoder(bf)
//jsonEncoder.SetEscapeHTML(false)
//if err2 := jsonEncoder.Encode(printMsg); err2 == nil {
// data = strings.Replace(bf.String(), "\n", "", strings.LastIndex(bf.String(), "\n"))
//} else {
return printMsg, model.ErrCodeGeneralFailed, err
}
return data, errCode, err
return printMsg, errCode, err
}
func unicode2utf8(source string) string {
var res = []string{""}

View File

@@ -6,9 +6,9 @@ import (
)
type CallResult struct {
Code string `json:"code"`
Desc string `json:"desc"`
Data string `json:"data"`
Code string `json:"code"`
Desc string `json:"desc"`
Data interface{} `json:"data"`
}
func buildParamRequiredErr(str []string) (err error) {