This commit is contained in:
suyl
2021-07-09 16:33:27 +08:00
parent 35979a2e91
commit 0304a3aa29

View File

@@ -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