diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index ad8e45fe6..39857c5dd 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -373,10 +373,15 @@ func HandleTcpMessages() { prints, _ := dao.GetPrintMsgs(db, []int{printMsgWait}, time.Now().Add(-time.Hour*3), time.Now(), offset, pageSize) for _, printMsg := range prints { printMsgChan <- printMsg - //select { - //case data, _ := <-printMsgCallbackChan: - // changePrintMsg(data) - //} + Loop: + for { + select { + case data, _ := <-printMsgCallbackChan: + changePrintMsg(data) + default: + break Loop + } + } } } } @@ -387,54 +392,49 @@ func doPrint2(printMsgChan chan *model.PrintMsg) (err error) { ) for { select { - case data, _ := <-printMsgCallbackChan: - changePrintMsg(data) - default: - select { - case printMsg, _ := <-printMsgChan: - var ( - data []byte - c net.Conn - ) - if printMsg != nil { - if err = checkPrintMsg(db, printMsg); err == nil { - tcpClient.s.RLock() - if tcpClient.Clients[printMsg.PrintNo] != nil { - if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnline { - if tcpClient.Clients[printMsg.PrintNo].C != nil { - c = tcpClient.Clients[printMsg.PrintNo].C - data, err = buildMsg(printMsg) - } - } else if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOffline { - err = fmt.Errorf("打印机离线!") - } else if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnlineWithoutPaper { - err = fmt.Errorf("打印机缺纸!") + case printMsg, _ := <-printMsgChan: + var ( + data []byte + c net.Conn + ) + if printMsg != nil { + if err = checkPrintMsg(db, printMsg); err == nil { + tcpClient.s.RLock() + if tcpClient.Clients[printMsg.PrintNo] != nil { + if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnline { + if tcpClient.Clients[printMsg.PrintNo].C != nil { + c = tcpClient.Clients[printMsg.PrintNo].C + data, err = buildMsg(printMsg) } + } else if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOffline { + err = fmt.Errorf("打印机离线!") + } else if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnlineWithoutPaper { + err = fmt.Errorf("打印机缺纸!") } - tcpClient.s.RUnlock() } - } else { - err = fmt.Errorf("未查询到此printMsg") + tcpClient.s.RUnlock() } - if err != nil { - printMsg.Status = printMsgErr - printMsg.Comment = err.Error() - dao.UpdateEntity(db, printMsg, "Status", "Comment") - delete(tcpClient.Clients, printMsg.PrintNo) - if c != nil { + } else { + err = fmt.Errorf("未查询到此printMsg") + } + if err != nil { + printMsg.Status = printMsgErr + printMsg.Comment = err.Error() + dao.UpdateEntity(db, printMsg, "Status", "Comment") + delete(tcpClient.Clients, printMsg.PrintNo) + if c != nil { + c.Close() + } + } else { + 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 { - 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") - } + } else { + globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data)) + printMsg.Status = printMsgAlreadySend + dao.UpdateEntity(db, printMsg, "Status", "Comment") } } }