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