This commit is contained in:
suyl
2021-07-29 15:43:38 +08:00
parent 89c4769b69
commit b29bdba37f

View File

@@ -27,7 +27,7 @@ func ListenTcp() {
go HandleTcpMessages()
go t.HandleCheckTcpHeart()
go t.doPrint2(printMsgChan)
go t.doPrint(printMsgChanFail)
//go t.doPrint(printMsgChanFail)
for {
c, err := l.Accept()
if err != nil {
@@ -153,55 +153,11 @@ func printFail() (err error) {
)
prints, _ := dao.GetPrintMsgs(db, []int{printMsgFail, printMsgErr, printMsgAlreadyLoad, printMsgAlreadySend}, time.Now().Add(-time.Hour*3), time.Now(), 0, 999)
for _, printMsg := range prints {
printMsgChanFail <- printMsg
printMsgChan <- printMsg
}
return err
}
func (t *TcpClient) doPrint(printMsgChanFail chan *model.PrintMsg) (err error) {
var (
db = dao.GetDB()
)
for {
select {
case printMsg, _ := <-printMsgChanFail:
var (
data []byte
c net.Conn
)
if printMsg != nil {
if err = checkPrintMsg(db, printMsg); err == nil {
//t.Lock()
//if t.Clients[printMsg.PrintNo] != nil {
// if t.Clients[printMsg.PrintNo].Status == printerStatusOnline {
// if t.Clients[printMsg.PrintNo].C != nil {
// c = t.Clients[printMsg.PrintNo].C
// data, err = buildMsg(printMsg)
// }
// }
//}
//t.Unlock()
if c = t.getPrintConn(printMsg.PrintNo); c != nil {
data, err = buildMsg(printMsg)
if _, err = c.Write(data); err != nil {
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
t.delConn(printMsg.PrintNo)
//delete(t.Clients, printMsg.PrintNo)
//c.Close()
} else {
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
dataStr := <-printMsgCallbackChan
t.changePrintMsg(dataStr)
}
}
}
}
default:
}
}
}
func printStatus2JxStatus(printStatus string) (status int) {
if printStatus == heartErrWithoutPaper {
return printerStatusOnlineWithoutPaper