From 831857418bb876138053e26663a67df5e84af695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 23 Aug 2022 17:22:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=93=E5=8D=B0=E6=9C=BA?= =?UTF-8?q?=E5=BF=83=E8=B7=B3=E7=9B=91=E5=90=AC,=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E6=88=90=E5=8A=9F,=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=9C=BA=E6=BF=80=E6=B4=BB,=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=8F=AF=E4=BB=A5=E7=BB=91=E5=AE=9A!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/event/event_tcp.go | 4 +++- business/model/dao/print_activation.go | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index ed0c8d0ee..36a2715be 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -91,7 +91,9 @@ func (t *TcpClient) handleConn(c net.Conn) { changePrinterStatus(printNo, status) t.HandleCheckTcpHeart(printNo) // todo 证明打印机已经被激活,将激活打印机存入数据库,保证用户不能无限制绑定打印机 - + if err := dao.NotExistsCreate(printNo); err != nil { + globals.SugarLogger.Debugf("监听打印机心跳,不存在则创建 :[%v]", err) + } } else { //在加到连接池中已经更新了时间,所以放在else里 t.setPrintStatusTime(printNo) diff --git a/business/model/dao/print_activation.go b/business/model/dao/print_activation.go index 910e17ba4..e7aca2058 100644 --- a/business/model/dao/print_activation.go +++ b/business/model/dao/print_activation.go @@ -1,5 +1,14 @@ package dao -func CheckPrintIsHave(printNo string) { - GetRow() +import ( + "time" +) + +func NotExistsCreate(printNo string) error { + sql := `INSERT INTO print_activation (print_no,created_at) SELECT ?,? FROM dual_table WHERE NOT EXISTS (SELECT * FROM print_activation WHERE print_no = ?)` + param := []interface{}{printNo, time.Now(), printNo} + if _, err := ExecuteSQL(GetDB(), sql, param...); err != nil { + return err + } + return nil }