This commit is contained in:
suyl
2021-07-30 18:24:53 +08:00
parent e99af06e67
commit 9dbb64073a

View File

@@ -76,6 +76,7 @@ func (t *TcpClient) handleConn(c net.Conn) {
globals.SugarLogger.Debugf("handleConn printno :[%v]", printNo) globals.SugarLogger.Debugf("handleConn printno :[%v]", printNo)
status := printStatus2JxStatus(data[len(data)-8 : len(data)-6]) status := printStatus2JxStatus(data[len(data)-8 : len(data)-6])
if t.Clients[printNo] == nil { if t.Clients[printNo] == nil {
timeoutChan <- 1
t.addConn(c, printNo, status) t.addConn(c, printNo, status)
t.HandleTcpMessages(printNo) t.HandleTcpMessages(printNo)
t.doPrint(printNo) t.doPrint(printNo)
@@ -146,17 +147,17 @@ func (t *TcpClient) HandleTcpMessages(printNo string) {
offset, pageSize = 0, 1 offset, pageSize = 0, 1
) )
globals.SugarLogger.Debugf("build HandleTcpMessages printNo: %s", printNo) globals.SugarLogger.Debugf("build HandleTcpMessages printNo: %s", printNo)
go func(key string) { go func() {
for { for {
//一直读? //一直读?
prints, _ := dao.GetPrintMsgs(db, key, []int{printMsgWait}, time.Now().Add(-time.Hour*3), time.Now(), offset, pageSize) prints, _ := dao.GetPrintMsgs(db, printNo, []int{printMsgWait}, time.Now().Add(-time.Hour*3), time.Now(), offset, pageSize)
for _, printMsg := range prints { for _, printMsg := range prints {
t.addMsgChan(printMsg) t.addMsgChan(printMsg)
printMsg.Status = printMsgAlreadyLoad printMsg.Status = printMsgAlreadyLoad
dao.UpdateEntity(db, printMsg, "Status") dao.UpdateEntity(db, printMsg, "Status")
} }
} }
}(printNo) }()
} }
func (t *TcpClient) doPrint(key string) (err error) { func (t *TcpClient) doPrint(key string) (err error) {
@@ -167,10 +168,10 @@ func (t *TcpClient) doPrint(key string) (err error) {
if !t.isExistMsg(key) { if !t.isExistMsg(key) {
return err return err
} }
go func(key string) { go func(printNo string) {
for { for {
select { select {
case printMsg := <-t.MsgMap[key]: case printMsg := <-t.MsgMap[printNo]:
var ( var (
data []byte data []byte
c net.Conn c net.Conn
@@ -213,6 +214,7 @@ func (t *TcpClient) doPrint(key string) (err error) {
} }
} }
} }
case <-timeoutChan:
} }
} }
}(key) }(key)