This commit is contained in:
邹宗楠
2023-02-03 14:29:48 +08:00
parent 942f9f93b4
commit aedff383c6
2 changed files with 38 additions and 10 deletions

View File

@@ -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)

View File

@@ -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
}