From 5ee7e6326c61e1e1de18498797909532306b1dd0 Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Tue, 20 Jul 2021 17:43:28 +0800 Subject: [PATCH] aa --- business/jxstore/event/event_tcp.go | 17 +++++++++++------ business/model/dao/dao_print.go | 26 ++++++++++++++++---------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index 840ffa01d..6a7694889 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -267,9 +267,11 @@ func printFail() (err error) { if err = checkPrintMsg(printMsg); err == nil { tcpClient.s.RLock() if tcpClient.Clients[printMsg.PrintNo] != nil { - if tcpClient.Clients[printMsg.PrintNo].C != nil { - c = tcpClient.Clients[printMsg.PrintNo].C - data, err = buildMsg(printMsg) + if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnline { + if tcpClient.Clients[printMsg.PrintNo].C != nil { + c = tcpClient.Clients[printMsg.PrintNo].C + data, err = buildMsg(printMsg) + } } } tcpClient.s.RUnlock() @@ -417,7 +419,7 @@ func HandleCheckTcpHeart() { } } -func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) { +func buildMsg(printMsg *dao.GetPrintMsgsResult) (data []byte, err error) { var ( content = printMsg.Content orderNo = printMsg.OrderNo @@ -452,7 +454,7 @@ func getCheckSum(str string) (check string) { } //内容中的标签替换成指令 -func replaceContent(content string, printMsg *model.PrintMsg) (result string) { +func replaceContent(content string, printMsg *dao.GetPrintMsgsResult) (result string) { var ( lenqr int hexLenqr string @@ -550,7 +552,10 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) { return result } -func checkPrintMsg(printMsg *model.PrintMsg) (err error) { +func checkPrintMsg(printMsg *dao.GetPrintMsgsResult) (err error) { + if printMsg.FlowFlag == 1 { + return fmt.Errorf("打印机当月流量已经超过30MB,请及时充值!printNo:[%v]", printMsg.PrintNo) + } if printMsg.Content == "" { return fmt.Errorf("此打印信息内容为空!printMsg printNo:[%v], orderNo :[%v]", printMsg.PrintNo, printMsg.OrderNo) } diff --git a/business/model/dao/dao_print.go b/business/model/dao/dao_print.go index 245c31e27..fcd851494 100644 --- a/business/model/dao/dao_print.go +++ b/business/model/dao/dao_print.go @@ -25,32 +25,38 @@ func GetPrintMsgNoPage(db *DaoDB, printNo string, orderNo int64) (prints []*mode return prints, err } -func GetPrintMsgs(db *DaoDB, statuss []int, beginAt, endAt time.Time, offset, pageSize int) (prints []*model.PrintMsg, err error) { +type GetPrintMsgsResult struct { + *model.PrintMsg + FlowFlag int `json:"flowFlag"` +} + +func GetPrintMsgs(db *DaoDB, statuss []int, beginAt, endAt time.Time, offset, pageSize int) (prints []*GetPrintMsgsResult, err error) { sql := ` - SELECT * - FROM print_msg - WHERE 1 = 1 AND deleted_at = ? + SELECT a.*, b.flow_flag + FROM print_msg a + LEFT JOIN printer b ON a.print_no = b.print_no AND b.deleted_at = ? + WHERE 1 = 1 AND a.deleted_at = ? ` - sqlParams := []interface{}{utils.DefaultTimeValue} + sqlParams := []interface{}{utils.DefaultTimeValue, utils.DefaultTimeValue} if len(statuss) > 0 { - sql += " AND status IN(" + GenQuestionMarks(len(statuss)) + ")" + sql += " AND a.status IN(" + GenQuestionMarks(len(statuss)) + ")" sqlParams = append(sqlParams, statuss) } if !utils.IsTimeZero(beginAt) { - sql += " AND created_at > ?" + sql += " AND a.created_at > ?" sqlParams = append(sqlParams, beginAt) } if !utils.IsTimeZero(endAt) { - sql += " AND created_at < ?" + sql += " AND a.created_at < ?" sqlParams = append(sqlParams, endAt) } - sql += " ORDER BY created_at LIMIT ? OFFSET ?" + sql += " ORDER BY a.created_at LIMIT ? OFFSET ?" sqlParams = append(sqlParams, pageSize, offset) err = GetRows(db, &prints, sql, sqlParams) return prints, err } -func GetPrintMsgsFail(db *DaoDB, beginAt, endAt time.Time) (prints []*model.PrintMsg, err error) { +func GetPrintMsgsFail(db *DaoDB, beginAt, endAt time.Time) (prints []*GetPrintMsgsResult, err error) { sql := ` SELECT * FROM print_msg