From e15f83f91386a7c0ba632bfab1404ebbe2612cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 9 Feb 2023 11:35:17 +0800 Subject: [PATCH] 1 --- business/jxstore/event/event_tcp.go | 28 ++----------- business/jxstore/event/timing_task.go | 58 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 business/jxstore/event/timing_task.go diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index a5a142427..db35f2273 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -34,6 +34,8 @@ func ListenTcp() { } } +var clientMap = make(map[string]*TcpClient, 0) + func (t *TcpClient) handleConn(c net.Conn) { if c == nil { globals.SugarLogger.Debugf("conn is nil") @@ -162,31 +164,6 @@ 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() @@ -220,6 +197,7 @@ func (t *TcpClient) HandleTcpMessages(printNo string) { } }() } + func (t *TcpClient) readTimeoutMap(key string) bool { t.Lock() defer t.Unlock() diff --git a/business/jxstore/event/timing_task.go b/business/jxstore/event/timing_task.go new file mode 100644 index 000000000..868b94407 --- /dev/null +++ b/business/jxstore/event/timing_task.go @@ -0,0 +1,58 @@ +package event + +// +//import ( +// "git.rosy.net.cn/baseapi/utils" +// "git.rosy.net.cn/jx-callback/business/model/dao" +// "git.rosy.net.cn/jx-callback/globals" +// "time" +//) +// +//func ScheduleTimerFuncByInterval(handler func(), delay, inerval time.Duration) { +// utils.AfterFuncWithRecover(delay, func() { +// beginTime := time.Now() +// handler() +// delay = inerval - time.Now().Sub(beginTime) +// if delay < time.Second { +// delay = time.Second +// } +// ScheduleTimerFuncByInterval(handler, delay, inerval) +// }) +//} +// +//func (t *TcpClient) HandleTcpMessages2() { +// var ( +// db = dao.GetDB() +// offset, pageSize = 0, 10 +// ) +//for printNo,have := range +// select { +// case <-t.TimeoutMap[printNo]: +// globals.SugarLogger.Debugf("HandleTcpMessages timeout") +// return +// default: +// //一直读? +// timeNow := time.Now() +// timeStart := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, timeNow.Location()) +// timeEnd := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 23, 59, 59, 0, timeNow.Location()) +// prints, _ := dao.GetPrintMsgs(db, printNo, []int{printMsgWait}, timeStart, timeEnd, offset, pageSize) +// for _, printMsg := range prints { +// printMsg.Status = printMsgAlreadyLoad +// //先避免重复读再插到channel? +// if _, err := dao.UpdateEntity(db, printMsg, "Status"); err == nil { +// if err = t.addMsgChan(printMsg); err != nil { +// globals.SugarLogger.Debugf("HandleTcpMessages addMsgChan Err: %v", err) +// } +// } +// } +// } +//} +// +//func (t *TcpClient) GetTimeOutMap() map[string]chan bool { +// t.RLock() +// defer t.RUnlock() +// if len(t.TimeoutMap) > 0 { +// return t.TimeoutMap +// } +// return nil +//}