aa
This commit is contained in:
@@ -97,7 +97,7 @@ func (t *TcpClient) handleConn(c net.Conn) {
|
||||
//t.buildCallBackMap(printNo)
|
||||
//t.buildMsgMap(printNo)
|
||||
t.HandleTcpMessages(printNo)
|
||||
go t.doPrint2(printNo)
|
||||
t.doPrint2(printNo)
|
||||
changePrinterStatus(printNo, status)
|
||||
if status == printerStatusOnline {
|
||||
t.printFail()
|
||||
@@ -243,76 +243,78 @@ func (t *TcpClient) doPrint2(key string) (err error) {
|
||||
if !t.isExistMsg(key) {
|
||||
return err
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case printMsg := <-t.MsgMap[key]:
|
||||
var (
|
||||
data []byte
|
||||
c net.Conn
|
||||
)
|
||||
if printMsg != nil {
|
||||
if err = checkPrintMsg(db, printMsg); err == nil {
|
||||
//t.Lock()
|
||||
//if t.Clients[printMsg.PrintNo] != nil {
|
||||
// if t.Clients[printMsg.PrintNo].Status == printerStatusOnline {
|
||||
// if t.Clients[printMsg.PrintNo].C != nil {
|
||||
// c = t.Clients[printMsg.PrintNo].C
|
||||
// data, err = buildMsg(printMsg)
|
||||
// }
|
||||
// } else if t.Clients[printMsg.PrintNo].Status == printerStatusOffline {
|
||||
// err = fmt.Errorf("打印机离线!")
|
||||
// } else if t.Clients[printMsg.PrintNo].Status == printerStatusOnlineWithoutPaper {
|
||||
// err = fmt.Errorf("打印机缺纸!")
|
||||
// }
|
||||
//}
|
||||
//t.Unlock()
|
||||
status := t.getPrintStatus(printMsg.PrintNo)
|
||||
switch status {
|
||||
case printerStatusOnline:
|
||||
if c = t.getPrintConn(printMsg.PrintNo); c != nil {
|
||||
data, err = buildMsg(printMsg)
|
||||
go func(key string) {
|
||||
for {
|
||||
select {
|
||||
case printMsg := <-t.MsgMap[key]:
|
||||
var (
|
||||
data []byte
|
||||
c net.Conn
|
||||
)
|
||||
if printMsg != nil {
|
||||
if err = checkPrintMsg(db, printMsg); err == nil {
|
||||
//t.Lock()
|
||||
//if t.Clients[printMsg.PrintNo] != nil {
|
||||
// if t.Clients[printMsg.PrintNo].Status == printerStatusOnline {
|
||||
// if t.Clients[printMsg.PrintNo].C != nil {
|
||||
// c = t.Clients[printMsg.PrintNo].C
|
||||
// data, err = buildMsg(printMsg)
|
||||
// }
|
||||
// } else if t.Clients[printMsg.PrintNo].Status == printerStatusOffline {
|
||||
// err = fmt.Errorf("打印机离线!")
|
||||
// } else if t.Clients[printMsg.PrintNo].Status == printerStatusOnlineWithoutPaper {
|
||||
// err = fmt.Errorf("打印机缺纸!")
|
||||
// }
|
||||
//}
|
||||
//t.Unlock()
|
||||
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("打印机状态未知!")
|
||||
}
|
||||
case printerStatusOffline:
|
||||
err = fmt.Errorf("打印机离线!")
|
||||
case printerStatusOnlineWithoutPaper:
|
||||
err = fmt.Errorf("打印机缺纸!")
|
||||
default:
|
||||
err = fmt.Errorf("打印机状态未知!")
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("未查询到此printMsg")
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("未查询到此printMsg")
|
||||
}
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("doPrint2 err printNo:%s, msgID:%s, printInfo: %v, err: %s", printMsg.PrintNo, printMsg.MsgID, utils.Format4Output(t.Clients[printMsg.PrintNo], true), err.Error())
|
||||
//t.delConn(printMsg.PrintNo)
|
||||
printMsg.Status = printMsgErr
|
||||
printMsg.Comment = err.Error()
|
||||
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
||||
//delete(t.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)
|
||||
t.delConn(printMsg.PrintNo)
|
||||
//delete(t.Clients, printMsg.PrintNo)
|
||||
//c.Close()
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
|
||||
//printMsg.Status = printMsgAlreadySend
|
||||
//dao.UpdateEntity(db, printMsg, "Status")
|
||||
dataStr := <-t.CallBackMap[printMsg.PrintNo]
|
||||
a, b := getCallbackMsgInfo(dataStr)
|
||||
t.changePrintMsg(dataStr, a, b)
|
||||
//dataStr := <-printMsgCallbackChan
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("doPrint2 err printNo:%s, msgID:%s, printInfo: %v, err: %s", printMsg.PrintNo, printMsg.MsgID, utils.Format4Output(t.Clients[printMsg.PrintNo], true), err.Error())
|
||||
//t.delConn(printMsg.PrintNo)
|
||||
printMsg.Status = printMsgErr
|
||||
printMsg.Comment = err.Error()
|
||||
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
||||
//delete(t.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)
|
||||
t.delConn(printMsg.PrintNo)
|
||||
//delete(t.Clients, printMsg.PrintNo)
|
||||
//c.Close()
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
|
||||
//printMsg.Status = printMsgAlreadySend
|
||||
//dao.UpdateEntity(db, printMsg, "Status")
|
||||
dataStr := <-t.CallBackMap[printMsg.PrintNo]
|
||||
a, b := getCallbackMsgInfo(dataStr)
|
||||
t.changePrintMsg(dataStr, a, b)
|
||||
//dataStr := <-printMsgCallbackChan
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}(key)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user