You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.5 KiB

package data
import (
"context"
"encoding/json"
"fmt"
"matchmaking-system/internal/data/tradedeal/share"
"matchmaking-system/internal/pkg/flags"
"matchmaking-system/internal/pkg/logging/applogger"
models "matchmaking-system/internal/pkg/model"
"matchmaking-system/internal/pkg/setting"
)
// TradeIPoInrByOrderNo
//
// @Description:
// @param data
func TradeIPoInrByOrderNo(data *Data) {
//1、查询当前股票代码为:NSE:IEML.ST的订单
//2、循环生成: map[userId]string 用户和订单列表的map函数
//3、通过缓存key:shareInrSubscribe-userId 解析json找到对应的orderNo(处理为空的状况-即为不是IPO订单)
//4、通过orderNo更新缓存key:USER:ARREAR:ORDER:OrderNo 的value值为OrderId
inrMap := GetBotStockInrTrade(data)
applogger.Error("数据展示:%v", inrMap)
for key, _ := range inrMap {
keyCache := fmt.Sprintf("%v-%v", setting.ShareInrSubscribe, key)
orderCache, err := Reds.HGetAll(context.Background(), keyCache).Result()
if err != nil {
continue
}
for _, vue := range orderCache {
var msg share.ShareInrTallyCache
if err = json.Unmarshal([]byte(vue), &msg); err != nil {
applogger.Error("TradeIPoInrByOrderNo err:%v", err)
continue
}
// 处理IPO缓存订单
switch msg.Status {
case flags.Position: // 持仓
if len(msg.Order.OrderNo) > 0 { // 非空
ipoCache := fmt.Sprintf("%v%v", flags.StockIpoList, msg.Order.OrderNo)
checkInt, err := Reds.Exists(context.Background(), ipoCache).Result()
if err != nil {
applogger.Error("CreatBotUserUsPreStockOrder.Exists err:%v", err)
continue
}
if checkInt > 0 {
//applogger.Debug("有效--用户ID:%v,订单ID:%v,IPO订单号:%v", key, msg.OrderId, msg.Order.OrderNo)
if err = Reds.Set(context.Background(), ipoCache, msg.OrderId, 0).Err(); err != nil {
applogger.Error("CreatBotUserUsPreStockOrder.Set err:%v", err)
continue
}
}
}
default:
}
}
}
}
// GetBotStockInrTrade
//
// @Description:
// @param data
// @return map[int64][]string
func GetBotStockInrTrade(data *Data) map[int64][]string {
var inrList []models.BotStockInTrade
if err := data.mysqlDB.Table(flags.BotStockInTrade).
Where("stock_id = ?", "NSE:GODIGIT.ST"). //NSE:IEML.ST NSE:test123456
Where("status = 1").
Find(&inrList); err != nil {
return nil
}
inrMap := make(map[int64][]string)
for _, inr := range inrList {
userId := int64(inr.UserId)
inrMap[userId] = append(inrMap[userId], inr.OrderId)
}
return inrMap
}