This commit is contained in:
suyl
2021-07-22 11:38:12 +08:00
parent 688710fb1c
commit 83cf5d536b

View File

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