This commit is contained in:
邹宗楠
2023-02-09 11:35:17 +08:00
parent aedff383c6
commit e15f83f913
2 changed files with 61 additions and 25 deletions

View File

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

View File

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