zhou.xiaoning 2 vuotta sitten
vanhempi
commit
3e6d606779
2 muutettua tiedostoa jossa 26 lisäystä ja 39 poistoa
  1. 18 35
      quote_publish/quote_publish.go
  2. 8 4
      service/account/login.go

+ 18 - 35
quote_publish/quote_publish.go

@@ -14,10 +14,9 @@ import (
 var QuotePublishSer = QuotePublish{}
 
 type QuotePublish struct {
-	conn    net.Conn      // 与行情发布服务的连接
-	closeCh chan struct{} // 连接断开信息
-	mtx     sync.RWMutex  // 锁
-	status  int           // 连接状态 -1:连接已断开 0:初始状态 1:已连接 2:正在连接
+	conn   net.Conn     // 与行情发布服务的连接
+	mtx    sync.RWMutex // 锁
+	status int          // 连接状态 -1:连接已断开 0:初始状态 1:已连接 2:正在连接
 }
 
 func (r *QuotePublish) Run() {
@@ -36,18 +35,12 @@ func (r *QuotePublish) setStatus(status int) {
 
 // connQuotePublish 连接行情发布服务
 func (r *QuotePublish) connQuotePublish() {
-	r.closeCh = make(chan struct{})
-
 	var err error
 	for {
-		// if r.conn != nil {
-		// 	r.conn.Close()
-		// 	close(r.closeCh)
-		// }
-
 		r.setStatus(2)
 		global.M2A_LOG.Info("正在尝试连接行情发布服务", zap.Any("host", global.M2A_CONFIG.System.QuotePublishAddr))
-		if r.conn, err = net.Dial("tcp", global.M2A_CONFIG.System.QuotePublishAddr); err != nil {
+		r.conn, err = net.Dial("tcp", global.M2A_CONFIG.System.QuotePublishAddr)
+		if err != nil {
 			global.M2A_LOG.Error("尝试连接行情发布服务失败,将在3秒后重试", zap.Any("err", err))
 			time.Sleep(time.Second * 3)
 			continue
@@ -66,7 +59,6 @@ func (r *QuotePublish) onDisconnected() {
 	}
 	global.M2A_LOG.Error("行情发布服务连接已断开,将会尝试重新连接行情发布服务", zap.Any("host", global.M2A_CONFIG.System.QuotePublishAddr))
 
-	// close(r.closeCh)
 	r.setStatus(-1)
 	go func() {
 		r.connQuotePublish()
@@ -77,29 +69,20 @@ func (r *QuotePublish) onDisconnected() {
 // readQuote 从行情发布服务读取行情信息
 func (r *QuotePublish) readQuote() {
 	for {
-		// Set a deadline for reading messages
-		r.conn.SetReadDeadline(time.Now().Add(40 * time.Second))
-
-		select {
-		case <-r.closeCh:
-			// Quit signal received, exit loop and clean up
-			return
-		default:
-			// 从行情发布服务读取行情信息
-			var p packet.MiQuotePacket
-			if _, err := p.ReadMessage(&r.conn); err != nil {
-				go r.onDisconnected()
-				break
-			}
-
-			// 心跳包
-			if p.BigType == 0x12 && p.Length <= 24 {
-				global.M2A_LOG.Debug("接收到行情发页服务心跳回复")
-				continue
-			}
+		// 从行情发布服务读取行情信息
+		var p packet.MiQuotePacket
+		if _, err := p.ReadMessage(&r.conn); err != nil {
+			go r.onDisconnected()
+			break
+		}
 
-			// 分发给订阅者
-			global.M2A_Publish.Publish(publish.Topic_Quote, &p)
+		// 心跳包
+		if p.BigType == 0x12 && p.Length <= 24 {
+			global.M2A_LOG.Debug("接收到行情发页服务心跳回复")
+			continue
 		}
+
+		// 分发给订阅者
+		global.M2A_Publish.Publish(publish.Topic_Quote, &p)
 	}
 }

+ 8 - 4
service/account/login.go

@@ -219,10 +219,14 @@ func GetClientsByAccountID(accountID uint64) (clients []*client.Client, err erro
 	clients = make([]*client.Client, 0)
 
 	loginIds := make([]string, 0)
-	if err = global.M2A_DB.Table("loginaccount t").
-		Select(`t.loginid`).
-		Join("INNER", "taaccount a", "a.userid = t.userid").
-		Where("a.accountid = ?", accountID).Find(&loginIds); err != nil {
+	sql := fmt.Sprintf(`
+	SELECT 
+		to_char(t.loginid) 
+	FROM loginaccount t 
+	INNER JOIN taaccount a ON a.userid = t.userid
+	WHERE a.accountid = %v
+	`, accountID)
+	if err = global.M2A_DB.SQL(sql).Find(&loginIds); err != nil {
 
 		global.M2A_LOG.Error("获取LoginID失败", zap.Error(err))
 		return