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 }