获取打印消息
This commit is contained in:
@@ -20,7 +20,7 @@ func AddPrinter(appID int, printNo, printKey, name string) (err error) {
|
|||||||
PrintNo: printNo,
|
PrintNo: printNo,
|
||||||
PrintKey: printKey,
|
PrintKey: printKey,
|
||||||
Name: name,
|
Name: name,
|
||||||
Status: model.PrinterStatusNormal,
|
Status: model.PrinterStatusOffline,
|
||||||
}
|
}
|
||||||
dao.WrapAddIDCULDEntity(printer, "")
|
dao.WrapAddIDCULDEntity(printer, "")
|
||||||
if err = dao.CreateEntity(db, printer); err != nil {
|
if err = dao.CreateEntity(db, printer); err != nil {
|
||||||
@@ -68,7 +68,7 @@ func DelPrinterSeq(appID int, printNo string) (err error) {
|
|||||||
if printers, _ := dao.GetPrinters(db, appID, printNo); len(printers) == 0 {
|
if printers, _ := dao.GetPrinters(db, appID, printNo); len(printers) == 0 {
|
||||||
return fmt.Errorf("该应用下未找到该打印机!print_no : %v", printNo)
|
return fmt.Errorf("该应用下未找到该打印机!print_no : %v", printNo)
|
||||||
} else {
|
} else {
|
||||||
printMsgs, _ := dao.GetPrintMsgs(db, printNo)
|
printMsgs, _ := dao.GetPrintMsgs(db, printNo, "", model.PrintMsgWait)
|
||||||
for _, v := range printMsgs {
|
for _, v := range printMsgs {
|
||||||
v.DeletedAt = time.Now()
|
v.DeletedAt = time.Now()
|
||||||
if _, err = dao.UpdateEntity(db, v, "DeletedAt"); err != nil {
|
if _, err = dao.UpdateEntity(db, v, "DeletedAt"); err != nil {
|
||||||
@@ -78,3 +78,35 @@ func DelPrinterSeq(appID int, printNo string) (err error) {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DoPrint(appID int, msgID, printNo, content string, orderNo int) (err error) {
|
||||||
|
var (
|
||||||
|
db = dao.GetDB()
|
||||||
|
)
|
||||||
|
|
||||||
|
printMsg := &model.PrintMsg{
|
||||||
|
PrintNo: printNo,
|
||||||
|
Content: content,
|
||||||
|
OrderNo: orderNo,
|
||||||
|
MsgID: msgID,
|
||||||
|
}
|
||||||
|
dao.WrapAddIDCULDEntity(printMsg, "")
|
||||||
|
if err = dao.CreateEntity(db, printMsg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPrintMsg(appID int, msgID string) (printMsg *model.PrintMsg, err error) {
|
||||||
|
var (
|
||||||
|
db = dao.GetDB()
|
||||||
|
)
|
||||||
|
if printMsgs, _ := dao.GetPrintMsgs(db, "", msgID, model.PrintMsgAll); len(printMsgs) > 0 {
|
||||||
|
for _, v := range printMsgs {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return printMsg, fmt.Errorf("未找到该消息!msg_id :%v", msgID)
|
||||||
|
}
|
||||||
|
return printMsg, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,19 +26,27 @@ func GetPrinters(db *DaoDB, appID int, printNo string) (printers []*model.Printe
|
|||||||
return printers, err
|
return printers, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPrintMsgs(db *DaoDB, printNo string) (printMsgs []*model.PrintMsg, err error) {
|
func GetPrintMsgs(db *DaoDB, printNo, msgID string, status int) (printMsgs []*model.PrintMsg, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM print_msg
|
FROM print_msg
|
||||||
WHERE 1 = 1 AND deleted_at = ? AND status = ?
|
WHERE 1 = 1 AND deleted_at = ?
|
||||||
`
|
`
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
utils.DefaultTimeValue, model.PrinterStatusNormal,
|
utils.DefaultTimeValue,
|
||||||
|
}
|
||||||
|
if status != model.PrintMsgAll {
|
||||||
|
sql += " AND status = ?"
|
||||||
|
sqlParams = append(sqlParams, status)
|
||||||
}
|
}
|
||||||
if printNo != "" {
|
if printNo != "" {
|
||||||
sql += " AND print_no = ?"
|
sql += " AND print_no = ?"
|
||||||
sqlParams = append(sqlParams, printNo)
|
sqlParams = append(sqlParams, printNo)
|
||||||
}
|
}
|
||||||
|
if msgID != "" {
|
||||||
|
sql += " AND msg_id = ?"
|
||||||
|
sqlParams = append(sqlParams, msgID)
|
||||||
|
}
|
||||||
err = GetRows(db, &printMsgs, sql, sqlParams)
|
err = GetRows(db, &printMsgs, sql, sqlParams)
|
||||||
return printMsgs, err
|
return printMsgs, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ const (
|
|||||||
PrinterStatusOnlineWithoutPaper = 2 //在线正常缺纸
|
PrinterStatusOnlineWithoutPaper = 2 //在线正常缺纸
|
||||||
PrinterStatusOnline = 1 //在线正常
|
PrinterStatusOnline = 1 //在线正常
|
||||||
PrinterStatusOffline = -1 //离线
|
PrinterStatusOffline = -1 //离线
|
||||||
|
|
||||||
|
PrintMsgAlreadySend = 2 //已经发出打印消息
|
||||||
|
PrintMsgSuccess = 1 //打印成功
|
||||||
|
PrintMsgWait = 0 //待打印
|
||||||
|
PrintMsgFail = -1 //打印失败(打印机报出)
|
||||||
|
PrintMsgErr = -2 //京西报出
|
||||||
|
PrintMsgAll = -9
|
||||||
)
|
)
|
||||||
|
|
||||||
type Printer struct {
|
type Printer struct {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||||
@@ -33,6 +34,8 @@ const (
|
|||||||
keyName = "name"
|
keyName = "name"
|
||||||
keyStatus = "status"
|
keyStatus = "status"
|
||||||
keyOrderNo = "order_no"
|
keyOrderNo = "order_no"
|
||||||
|
keyContent = "content"
|
||||||
|
keyMsgID = "msg_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -273,27 +276,67 @@ func (c *ApiController) DelPrinterSeq(dataMap map[string]interface{}) (data, err
|
|||||||
return "", errCode, err
|
return "", errCode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//发送打印消息
|
||||||
func (c *ApiController) DoPrint(dataMap map[string]interface{}) (data, errCode string, err error) {
|
func (c *ApiController) DoPrint(dataMap map[string]interface{}) (data, errCode string, err error) {
|
||||||
var (
|
var (
|
||||||
content = dataMap["data"].(string)
|
printNo, content string
|
||||||
printNo = dataMap["print_no"].(string)
|
orderNo, appID int
|
||||||
orderNo = utils.Interface2Int64WithDefault(dataMap["order_no"], 0)
|
|
||||||
db = dao.GetDB()
|
|
||||||
)
|
)
|
||||||
globals.SugarLogger.Debugf("Begin API DoPrint data: [%v]", utils.Format4Output(dataMap, false))
|
globals.SugarLogger.Debugf("Begin API DoPrint data: [%v]", utils.Format4Output(dataMap, false))
|
||||||
if orderNo == 0 {
|
if _, ok := dataMap[keyPrintNo].(string); !ok {
|
||||||
return data, model.ErrCodeOpenAPIParamErrNormal, fmt.Errorf("参数错误:order_no 不能为空")
|
return buildParamErrCodeAndErr(keyPrintNo)
|
||||||
|
} else {
|
||||||
|
if printNo = dataMap[keyPrintNo].(string); printNo == "" {
|
||||||
|
return buildParamErrCodeAndErr(keyPrintNo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if _, ok := dataMap[keyContent].(string); !ok {
|
||||||
|
return buildParamErrCodeAndErr(keyContent)
|
||||||
|
} else {
|
||||||
|
if content = dataMap[keyContent].(string); content == "" {
|
||||||
|
return buildParamErrCodeAndErr(keyContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := dataMap[keyOrderNo].(int); !ok {
|
||||||
|
return buildParamErrCodeAndErr(keyOrderNo)
|
||||||
|
} else {
|
||||||
|
if orderNo = dataMap[keyOrderNo].(int); orderNo == 0 {
|
||||||
|
return buildParamErrCodeAndErr(keyOrderNo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appID = dataMap[keyAppID].(int)
|
||||||
msgID := time.Now().Format("20060102150405") + "_" + jxutils.RandStringBytes(8)
|
msgID := time.Now().Format("20060102150405") + "_" + jxutils.RandStringBytes(8)
|
||||||
printMsg := &model.PrintMsg{
|
if err = cms.DoPrint(appID, msgID, content, printNo, orderNo); err != nil {
|
||||||
PrintNo: printNo,
|
return "", model.ErrCodeGeneralFailed, err
|
||||||
Content: content,
|
|
||||||
OrderNo: int(orderNo),
|
|
||||||
MsgID: msgID,
|
|
||||||
}
|
|
||||||
dao.WrapAddIDCULDEntity(printMsg, "")
|
|
||||||
if err = dao.CreateEntity(db, printMsg); err != nil {
|
|
||||||
return data, model.ErrCodeGeneralFailed, err
|
|
||||||
}
|
}
|
||||||
return msgID, errCode, err
|
return msgID, errCode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取某打印消息
|
||||||
|
func (c *ApiController) GetPrintMsg(dataMap map[string]interface{}) (data, 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)
|
||||||
|
} else {
|
||||||
|
if msgID = dataMap[keyMsgID].(string); msgID == "" {
|
||||||
|
return buildParamErrCodeAndErr(keyMsgID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appID = dataMap[keyAppID].(int)
|
||||||
|
if printMsg, err := cms.GetPrintMsg(appID, msgID); err != nil {
|
||||||
|
return "", model.ErrCodeGeneralFailed, err
|
||||||
|
} else if printMsg == nil {
|
||||||
|
return "", model.ErrCodeGeneralFailed, fmt.Errorf("未查询到该消息! msg_id: %v", msgID)
|
||||||
|
} else {
|
||||||
|
if byteData, err := json.Marshal(printMsg); err == nil {
|
||||||
|
data = string(byteData)
|
||||||
|
} else {
|
||||||
|
return "", model.ErrCodeGeneralFailed, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data, errCode, err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user