This commit is contained in:
suyl
2021-07-30 17:56:24 +08:00
parent 948cabcf52
commit 7bc76205eb
2 changed files with 18 additions and 11 deletions

View File

@@ -25,7 +25,7 @@ func ListenTcp() {
return
}
globals.SugarLogger.Debugf("begin listenTcp port 8000......")
go t.HandleTcpMessages()
//go t.HandleTcpMessages()
go t.HandleCheckTcpHeart()
//go t.doPrint2()
//go t.doPrint(printMsgChanFail)
@@ -96,6 +96,7 @@ func (t *TcpClient) handleConn(c net.Conn) {
t.addConn(c, printNo, status)
//t.buildCallBackMap(printNo)
//t.buildMsgMap(printNo)
t.HandleTcpMessages(printNo)
go t.doPrint2(printNo)
changePrinterStatus(printNo, status)
if status == printerStatusOnline {
@@ -217,20 +218,22 @@ func (t *TcpClient) changePrintMsg(data string, orderNo int64, printNo string) (
return err
}
func (t *TcpClient) HandleTcpMessages() {
func (t *TcpClient) HandleTcpMessages(printNo string) {
var (
db = dao.GetDB()
offset, pageSize = 0, 1
)
for {
//一直读?
prints, _ := dao.GetPrintMsgs(db, []int{printMsgWait}, time.Now().Add(-time.Hour*3), time.Now(), offset, pageSize)
for _, printMsg := range prints {
t.addMsgChan(printMsg)
printMsg.Status = printMsgAlreadyLoad
dao.UpdateEntity(db, printMsg, "Status")
go func(key string) {
for {
//一直读?
prints, _ := dao.GetPrintMsgs(db, printNo, []int{printMsgWait}, time.Now().Add(-time.Hour*3), time.Now(), offset, pageSize)
for _, printMsg := range prints {
t.addMsgChan(printMsg)
printMsg.Status = printMsgAlreadyLoad
dao.UpdateEntity(db, printMsg, "Status")
}
}
}
}(printNo)
}
func (t *TcpClient) doPrint2(key string) (err error) {