aa
This commit is contained in:
@@ -192,6 +192,7 @@ func handleConn(c net.Conn) {
|
|||||||
printNoData, _ := hex.DecodeString(data[len(heartText) : len(data)-8])
|
printNoData, _ := hex.DecodeString(data[len(heartText) : len(data)-8])
|
||||||
printNo = string(printNoData)
|
printNo = string(printNoData)
|
||||||
globals.SugarLogger.Debugf("handleConn printno :[%v]", printNo)
|
globals.SugarLogger.Debugf("handleConn printno :[%v]", printNo)
|
||||||
|
status := printStatus2JxStatus(data[len(data)-8 : len(data)-6])
|
||||||
tcpClient.s.Lock()
|
tcpClient.s.Lock()
|
||||||
if tcpClient.Clients[printNo] == nil {
|
if tcpClient.Clients[printNo] == nil {
|
||||||
printInfo := &PrintInfo{
|
printInfo := &PrintInfo{
|
||||||
@@ -200,12 +201,14 @@ func handleConn(c net.Conn) {
|
|||||||
StatusTime: time.Now(),
|
StatusTime: time.Now(),
|
||||||
}
|
}
|
||||||
tcpClient.Clients[printNo] = printInfo
|
tcpClient.Clients[printNo] = printInfo
|
||||||
printFail()
|
changePrinterStatus(printNo, status)
|
||||||
|
if status > 0 {
|
||||||
|
printFail()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//改变打印机状态
|
//改变打印机状态
|
||||||
//changePrinterStatus(printNo, printerStatusOnline)
|
changePrinterStatus(printNo, status)
|
||||||
if tcpClient.Clients[printNo] != nil {
|
if tcpClient.Clients[printNo] != nil {
|
||||||
status := printStatus2JxStatus(data[len(data)-8 : len(data)-6])
|
|
||||||
if tcpClient.Clients[printNo].Status != status {
|
if tcpClient.Clients[printNo].Status != status {
|
||||||
tcpClient.Clients[printNo].Status = status
|
tcpClient.Clients[printNo].Status = status
|
||||||
}
|
}
|
||||||
@@ -220,6 +223,32 @@ func handleConn(c net.Conn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func changePrinterStatus(printNo string, status int) {
|
||||||
|
var (
|
||||||
|
db = dao.GetDB()
|
||||||
|
)
|
||||||
|
if printer, err := dao.GetPrinter(db, printNo); err == nil && printer != nil {
|
||||||
|
feilds := []string{}
|
||||||
|
if printer.Status != status {
|
||||||
|
printer.Status = status
|
||||||
|
feilds = append(feilds, "Status")
|
||||||
|
}
|
||||||
|
isOnline := 0
|
||||||
|
if status == printerStatusOnline || status == printerStatusOnlineWithoutPaper {
|
||||||
|
isOnline = model.YES
|
||||||
|
} else {
|
||||||
|
isOnline = model.NO
|
||||||
|
}
|
||||||
|
if isOnline != printer.IsOnline {
|
||||||
|
printer.IsOnline = isOnline
|
||||||
|
feilds = append(feilds, "IsOnline")
|
||||||
|
}
|
||||||
|
if len(feilds) > 0 {
|
||||||
|
dao.UpdateEntity(db, printer, feilds...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func printFail() (err error) {
|
func printFail() (err error) {
|
||||||
//新开机的打印失败和错误的
|
//新开机的打印失败和错误的
|
||||||
var (
|
var (
|
||||||
@@ -241,7 +270,7 @@ func printFail() (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
tcpClient.s.RUnlock()
|
tcpClient.s.RUnlock()
|
||||||
if c != nil {
|
if c != nil && tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnline {
|
||||||
if _, err = c.Write(data); err != nil {
|
if _, err = c.Write(data); err != nil {
|
||||||
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
|
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
|
||||||
delete(tcpClient.Clients, printMsg.PrintNo)
|
delete(tcpClient.Clients, printMsg.PrintNo)
|
||||||
@@ -324,15 +353,18 @@ func HandleTcpMessages() {
|
|||||||
if err = checkPrintMsg(printMsg); err == nil {
|
if err = checkPrintMsg(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].C != nil {
|
if tcpClient.Clients[printMsg.PrintNo].Status == printerStatusOnline {
|
||||||
c = tcpClient.Clients[printMsg.PrintNo].C
|
if tcpClient.Clients[printMsg.PrintNo].C != nil {
|
||||||
data, err = buildMsg(printMsg)
|
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("打印机缺纸!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tcpClient.s.RUnlock()
|
tcpClient.s.RUnlock()
|
||||||
//else {
|
|
||||||
// changePrinterStatus(printMsg.PrintNo, printerStatusOffline)
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("未查询到此printMsg")
|
err = fmt.Errorf("未查询到此printMsg")
|
||||||
@@ -374,6 +406,7 @@ func HandleCheckTcpHeart() {
|
|||||||
}
|
}
|
||||||
tcpClient.s.Unlock()
|
tcpClient.s.Unlock()
|
||||||
for _, v := range keys {
|
for _, v := range keys {
|
||||||
|
changePrinterStatus(v, printerStatusOffline)
|
||||||
delete(tcpClient.Clients, v)
|
delete(tcpClient.Clients, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user