aa
This commit is contained in:
@@ -383,56 +383,55 @@ func doPrint2(printMsgChan chan *model.PrintMsg) (err error) {
|
|||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
)
|
)
|
||||||
for {
|
select {
|
||||||
select {
|
case printMsg, _ := <-printMsgChan:
|
||||||
case printMsg, _ := <-printMsgChan:
|
var (
|
||||||
var (
|
data []byte
|
||||||
data []byte
|
c net.Conn
|
||||||
c net.Conn
|
)
|
||||||
)
|
if printMsg != nil {
|
||||||
if printMsg != nil {
|
if err = checkPrintMsg(db, printMsg); err == nil {
|
||||||
if err = checkPrintMsg(db, printMsg); err == nil {
|
tcpClient.s.RLock()
|
||||||
tcpClient.s.RLock()
|
if tcpClient.Clients[printMsg.PrintNo] != nil {
|
||||||
if tcpClient.Clients[printMsg.PrintNo] != nil {
|
if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnline {
|
||||||
if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnline {
|
if tcpClient.Clients[printMsg.PrintNo].C != nil {
|
||||||
if tcpClient.Clients[printMsg.PrintNo].C != nil {
|
c = tcpClient.Clients[printMsg.PrintNo].C
|
||||||
c = tcpClient.Clients[printMsg.PrintNo].C
|
data, err = buildMsg(printMsg)
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleCheckTcpHeart() {
|
func HandleCheckTcpHeart() {
|
||||||
|
|||||||
Reference in New Issue
Block a user