aa
This commit is contained in:
@@ -373,10 +373,15 @@ 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 {
|
Loop:
|
||||||
//case data, _ := <-printMsgCallbackChan:
|
for {
|
||||||
// changePrintMsg(data)
|
select {
|
||||||
//}
|
case data, _ := <-printMsgCallbackChan:
|
||||||
|
changePrintMsg(data)
|
||||||
|
default:
|
||||||
|
break Loop
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,54 +392,49 @@ func doPrint2(printMsgChan chan *model.PrintMsg) (err error) {
|
|||||||
)
|
)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case data, _ := <-printMsgCallbackChan:
|
case printMsg, _ := <-printMsgChan:
|
||||||
changePrintMsg(data)
|
var (
|
||||||
default:
|
data []byte
|
||||||
select {
|
c net.Conn
|
||||||
case printMsg, _ := <-printMsgChan:
|
)
|
||||||
var (
|
if printMsg != nil {
|
||||||
data []byte
|
if err = checkPrintMsg(db, printMsg); err == nil {
|
||||||
c net.Conn
|
tcpClient.s.RLock()
|
||||||
)
|
if tcpClient.Clients[printMsg.PrintNo] != nil {
|
||||||
if printMsg != nil {
|
if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnline {
|
||||||
if err = checkPrintMsg(db, printMsg); err == nil {
|
if tcpClient.Clients[printMsg.PrintNo].C != nil {
|
||||||
tcpClient.s.RLock()
|
c = tcpClient.Clients[printMsg.PrintNo].C
|
||||||
if tcpClient.Clients[printMsg.PrintNo] != nil {
|
data, err = buildMsg(printMsg)
|
||||||
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 {
|
||||||
|
err = fmt.Errorf("打印机离线!")
|
||||||
|
} else if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnlineWithoutPaper {
|
||||||
|
err = fmt.Errorf("打印机缺纸!")
|
||||||
}
|
}
|
||||||
tcpClient.s.RUnlock()
|
|
||||||
}
|
}
|
||||||
} else {
|
tcpClient.s.RUnlock()
|
||||||
err = fmt.Errorf("未查询到此printMsg")
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
} else {
|
||||||
printMsg.Status = printMsgErr
|
err = fmt.Errorf("未查询到此printMsg")
|
||||||
printMsg.Comment = err.Error()
|
}
|
||||||
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
if err != nil {
|
||||||
delete(tcpClient.Clients, printMsg.PrintNo)
|
printMsg.Status = printMsgErr
|
||||||
if c != nil {
|
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()
|
c.Close()
|
||||||
}
|
} else {
|
||||||
} else {
|
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
|
||||||
if c != nil {
|
printMsg.Status = printMsgAlreadySend
|
||||||
if _, err = c.Write(data); err != nil {
|
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user