From aedff383c6bc5c96fc969e7d58e4b08811413e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 3 Feb 2023 14:29:48 +0800 Subject: [PATCH] 1 --- business/jxstore/event/event_tcp.go | 41 ++++++++++++++++++----- business/jxstore/event/event_tcp_utils.go | 7 +++- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index f408fed84..a5a142427 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -162,6 +162,31 @@ func (t *TcpClient) changePrintMsg(data string, orderNo int64, printNo string) ( return err } +// +//var ( +// printClient = make(map[string]*TcpClient, 0) +// db = dao.GetDB() +// offset, pageSize = 0, 100 +//) +// +//func init() { +// go func() { +// for { +// if time.Now().Unix()%2 != 0 { +// continue +// } +// for printNo, PrintTcpClient := range printClient { +// if !PrintTcpClient.isExistMsg(printNo) { +// return +// } +// +// } +// +// } +// }() +// +//} + func (t *TcpClient) HandleTcpMessages(printNo string) { var ( db = dao.GetDB() @@ -170,10 +195,8 @@ func (t *TcpClient) HandleTcpMessages(printNo string) { if !t.isExistMsg(printNo) { return } - go func() { for { - select { case <-t.TimeoutMap[printNo]: globals.SugarLogger.Debugf("HandleTcpMessages timeout") @@ -253,13 +276,13 @@ func (t *TcpClient) doPrint(key string) (err error) { close(t.TimeoutMap[key]) } else { if c != nil { - encryption := "" - for _, v := range data { - encryption += fmt.Sprintf("%d", v) - } - printMsg.ContentEncryption = encryption - - dao.UpdateEntity(db, printMsg, "ContentEncryption") + //encryption := "" + //for _, v := range data { + // encryption += fmt.Sprintf("%d", v) + //} + //printMsg.ContentEncryption = encryption + // + //dao.UpdateEntity(db, printMsg, "ContentEncryption") if _, err = c.Write(data); err != nil { globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err) //t.delConn(printMsg.PrintNo) diff --git a/business/jxstore/event/event_tcp_utils.go b/business/jxstore/event/event_tcp_utils.go index 7b41924d9..f67b24f91 100644 --- a/business/jxstore/event/event_tcp_utils.go +++ b/business/jxstore/event/event_tcp_utils.go @@ -181,6 +181,12 @@ func (t *TcpClient) buildTimeoutMap(key string) { t.TimeoutMap[key] = dataChan } +func (t *TcpClient) getTimeOut(key string) bool { + t.RLock() + defer t.RUnlock() + return <-t.TimeoutMap[key] +} + func (t *TcpClient) buildAllMap(key string) { t.Lock() defer t.Unlock() @@ -402,7 +408,6 @@ func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) { lenData := int64(len(str) + len(const1) + len(orderNoHexH) + len(orderNoHexL) + len(printInit) + 2 + 4 + len(printData)) x1, x2 := int2h8l8(lenData / 2) dataStr := str + x1 + x2 + const1 + orderNoHexH + orderNoHexL + printInit + printData - globals.SugarLogger.Debugf("============dataste %s", dataStr) check := getCheckSum(dataStr) return jxutils.Hextob(dataStr + check), err }