This commit is contained in:
suyl
2021-08-02 17:24:54 +08:00
parent 895a17a46b
commit b87b12f548
2 changed files with 23 additions and 11 deletions

View File

@@ -228,6 +228,13 @@ func (t *TcpClient) doPrint(key string) (err error) {
printMsg.Status = printMsgErr
printMsg.Comment = err.Error()
dao.UpdateEntity(db, printMsg, "Status", "Comment")
if t.isExist(key) {
timeoutChan <- 1
timeoutChan <- 1
timeoutChan <- 1
t.clear(key)
}
return
} else {
if c != nil {
if _, err = c.Write(data); err != nil {
@@ -253,16 +260,21 @@ func (t *TcpClient) doPrint(key string) (err error) {
func (t *TcpClient) HandleCheckTcpHeart(key string) {
go func() {
for {
if !utils.IsTimeZero(t.getPrintStatusTime(key)) {
//2分钟内没心跳判断打印机掉线了
if time.Now().Sub(t.getPrintStatusTime(key)) > time.Minute*2 {
changePrinterStatus(key, printerStatusOffline)
if t.isExist(key) {
globals.SugarLogger.Debugf("HandleCheckTcpHeart del key,%v", key)
timeoutChan <- 1
timeoutChan <- 1
t.clear(key)
return
select {
case <-timeoutChan:
return
default:
if !utils.IsTimeZero(t.getPrintStatusTime(key)) {
//2分钟内没心跳判断打印机掉线了
if time.Now().Sub(t.getPrintStatusTime(key)) > time.Minute*2 {
changePrinterStatus(key, printerStatusOffline)
if t.isExist(key) {
timeoutChan <- 1
timeoutChan <- 1
timeoutChan <- 1
t.clear(key)
return
}
}
}
}

View File

@@ -108,7 +108,7 @@ var (
regexpQrr = regexp.MustCompile(byteSignQrRight + "(.*?)" + byteSignQrRightE)
regexpSound = regexp.MustCompile(byteSignSound + "(.*?)" + byteSignSoundE)
timeoutChan = make(chan int, 2)
timeoutChan = make(chan int, 3)
)
type PrintInfo struct {