From 0304a3aa292d196b018fa05ffcee0915bc950674 Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Fri, 9 Jul 2021 16:33:27 +0800 Subject: [PATCH] aa --- business/jxstore/event/event_tcp.go | 63 ++++++++++++++++------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index 799f6e82c..427b1cc08 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -194,33 +194,7 @@ func handleConn(c net.Conn) { Status: printStatus2JxStatus(data[len(data)-8 : len(data)-6]), } tcpClient.Clients[printNo] = printInfo - //新开机的打印失败和错误的 - var ( - db = dao.GetDB() - ) - prints, _ := dao.GetPrintMsgsFail(db, time.Now().Add(-time.Hour*3), time.Now()) - for _, printMsg := range prints { - var ( - data []byte - c net.Conn - ) - if printMsg != nil { - if err = checkPrintMsg(printMsg); err == nil { - data, err = buildMsg(printMsg) - if c != nil { - if _, err = c.Write(data); err != nil { - globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err) - delete(tcpClient.Clients, printMsg.PrintNo) - c.Close() - } else { - globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data)) - printMsg.Status = printMsgAlreadySend - dao.UpdateEntity(db, printMsg, "Status", "Comment") - } - } - } - } - } + printFail() } else { //改变打印机状态 //changePrinterStatus(printNo, printerStatusOnline) @@ -238,6 +212,41 @@ func handleConn(c net.Conn) { } } +func printFail() (err error) { + //新开机的打印失败和错误的 + var ( + db = dao.GetDB() + ) + prints, _ := dao.GetPrintMsgsFail(db, time.Now().Add(-time.Hour*3), time.Now()) + for _, printMsg := range prints { + var ( + data []byte + c net.Conn + ) + if printMsg != nil { + if err = checkPrintMsg(printMsg); err == nil { + if tcpClient.Clients[printMsg.PrintNo] != nil { + if tcpClient.Clients[printMsg.PrintNo].C != nil { + c = tcpClient.Clients[printMsg.PrintNo].C + data, err = buildMsg(printMsg) + } + } + if c != nil { + if _, err = c.Write(data); err != nil { + globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err) + delete(tcpClient.Clients, printMsg.PrintNo) + c.Close() + } else { + globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data)) + printMsg.Status = printMsgAlreadySend + dao.UpdateEntity(db, printMsg, "Status", "Comment") + } + } + } + } + } +} + func printStatus2JxStatus(printStatus string) (status int) { if printStatus == heartErrWithoutPaper { return printerStatusOnlineWithoutPaper