aa
This commit is contained in:
@@ -199,56 +199,54 @@ func (t *TcpClient) doPrint(key string) (err error) {
|
||||
globals.SugarLogger.Debugf("doPrint timeout")
|
||||
return
|
||||
default:
|
||||
printMsg, ok := <-t.MsgMap[key]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var (
|
||||
data []byte
|
||||
c net.Conn
|
||||
)
|
||||
if printMsg != nil {
|
||||
if err = checkPrintMsg(db, printMsg); err == nil {
|
||||
status := t.getPrintStatus(printMsg.PrintNo)
|
||||
switch status {
|
||||
//只有在线才打印内容
|
||||
case printerStatusOnline:
|
||||
if c = t.getPrintConn(printMsg.PrintNo); c != nil {
|
||||
data, err = buildMsg(printMsg)
|
||||
}
|
||||
case printerStatusOffline:
|
||||
err = fmt.Errorf("打印机离线!")
|
||||
case printerStatusOnlineWithoutPaper:
|
||||
err = fmt.Errorf("打印机缺纸!")
|
||||
default:
|
||||
err = fmt.Errorf("打印机状态未知!")
|
||||
}
|
||||
select {
|
||||
case printMsg, ok := <-t.MsgMap[key]:
|
||||
if !ok{
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("doPrint2 err printNo:%s, msgID:%s, err: %s", printMsg.PrintNo, printMsg.MsgID, err.Error())
|
||||
//t.delConn(printMsg.PrintNo)
|
||||
printMsg.Status = printMsgErr
|
||||
printMsg.Comment = err.Error()
|
||||
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
||||
if t.isExist(key) {
|
||||
t.clear(key)
|
||||
globals.SugarLogger.Debugf("handleTcpMessages clear1...")
|
||||
}
|
||||
} else {
|
||||
if c != nil {
|
||||
if _, err = c.Write(data); err != nil {
|
||||
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
|
||||
//t.delConn(printMsg.PrintNo)
|
||||
if t.isExist(key) {
|
||||
t.clear(key)
|
||||
globals.SugarLogger.Debugf("handleTcpMessages clear2...")
|
||||
var (
|
||||
data []byte
|
||||
c net.Conn
|
||||
)
|
||||
if printMsg != nil {
|
||||
if err = checkPrintMsg(db, printMsg); err == nil {
|
||||
status := t.getPrintStatus(printMsg.PrintNo)
|
||||
switch status {
|
||||
//只有在线才打印内容
|
||||
case printerStatusOnline:
|
||||
if c = t.getPrintConn(printMsg.PrintNo); c != nil {
|
||||
data, err = buildMsg(printMsg)
|
||||
}
|
||||
case printerStatusOffline:
|
||||
err = fmt.Errorf("打印机离线!")
|
||||
case printerStatusOnlineWithoutPaper:
|
||||
err = fmt.Errorf("打印机缺纸!")
|
||||
default:
|
||||
err = fmt.Errorf("打印机状态未知!")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("doPrint2 err printNo:%s, msgID:%s, err: %s", printMsg.PrintNo, printMsg.MsgID, err.Error())
|
||||
//t.delConn(printMsg.PrintNo)
|
||||
printMsg.Status = printMsgErr
|
||||
printMsg.Comment = err.Error()
|
||||
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
||||
close(t.TimeoutMap[key])
|
||||
globals.SugarLogger.Debugf("handleTcpMessages clear1...")
|
||||
} else {
|
||||
if c != nil {
|
||||
if _, err = c.Write(data); err != nil {
|
||||
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
|
||||
//t.delConn(printMsg.PrintNo)
|
||||
close(t.TimeoutMap[key])
|
||||
globals.SugarLogger.Debugf("handleTcpMessages clear2...")
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
|
||||
//等待回调
|
||||
dataStr := <-t.CallBackMap[printMsg.PrintNo]
|
||||
a, b := getCallbackMsgInfo(dataStr)
|
||||
t.changePrintMsg(dataStr, a, b)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
|
||||
//等待回调
|
||||
dataStr := <-t.CallBackMap[printMsg.PrintNo]
|
||||
a, b := getCallbackMsgInfo(dataStr)
|
||||
t.changePrintMsg(dataStr, a, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,6 +254,8 @@ func (t *TcpClient) doPrint(key string) (err error) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
close(t.MsgMap[key])
|
||||
close(t.CallBackMap[key])
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -273,11 +273,9 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
|
||||
//2分钟内没心跳判断打印机掉线了
|
||||
if time.Now().Sub(t.getPrintStatusTime(key)) > time.Minute+time.Second*3 {
|
||||
changePrinterStatus(key, printerStatusOffline)
|
||||
if t.isExist(key) {
|
||||
globals.SugarLogger.Debugf("HandleCheckTcpHeart clear...")
|
||||
//t.clear(key)
|
||||
close(t.TimeoutMap[key])
|
||||
}
|
||||
globals.SugarLogger.Debugf("HandleCheckTcpHeart clear...")
|
||||
//t.clear(key)
|
||||
close(t.TimeoutMap[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,4 +297,5 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
|
||||
//}
|
||||
}
|
||||
}()
|
||||
t.Clients[key].C.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user