newestBidding.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. package model
  2. import (
  3. "app.yhyue.com/moapp/jybase/redis"
  4. "context"
  5. "encoding/json"
  6. "fmt"
  7. "jyBXBase/entity"
  8. "jyBXBase/rpc/bxbase"
  9. IC "jyBXBase/rpc/init"
  10. "jyBXBase/rpc/internal/config"
  11. "jyBXBase/rpc/util"
  12. "log"
  13. "sort"
  14. "strings"
  15. "time"
  16. MC "app.yhyue.com/moapp/jybase/common"
  17. ME "app.yhyue.com/moapp/jybase/encrypt"
  18. elastic "app.yhyue.com/moapp/jybase/es"
  19. "app.yhyue.com/moapp/jybase/mongodb"
  20. "app.yhyue.com/moapp/jybase/mysql"
  21. "github.com/zeromicro/go-zero/core/logx"
  22. "go.mongodb.org/mongo-driver/bson/primitive"
  23. )
  24. const (
  25. search_index = "bidding"
  26. search_type = "bidding"
  27. mongodb_fields = `{"_id":1,"area":1,"publishtime":1,"s_subscopeclass":1,"subtype":1,"title":1,"toptype":1,"type":1, "buyerclass":1,"budget":1,"bidamount":1,"s_winner":1,"bidopentime":1,"buyer":1,"projectname":1,"spidercode":1,"site":1}`
  28. query = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","area", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget","projectname","buyer","bidopentime","s_winner","filetext","spidercode","site"],"from":0,"size":%d}`
  29. multi_match = `{"multi_match": {"query": %s,"type": "phrase", "fields": ["title"]}}`
  30. query_bool_must = `{"terms":{"%s":[%s]}}`
  31. query_bool_must_and = `{"bool":{"must":[%s],"must_not":[%s]}}`
  32. search_field = `"_id","area", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget","projectname","buyer","bidopentime","s_winner","filetext","isValidFile","spidercode","site"`
  33. query_city_hkeys = `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match":%d}},"highlight": {"pre_tags": ["<a>"],"post_tags": ["</a>"],"fields": {"title": {"fragment_size": 0,"number_of_fragments": 1}}},"_source":[` + search_field + `],"sort":[{"publishtime":"desc"},{"budget":"desc"}],"from":0,"size":%d}`
  34. Pushbidding = "global_common_data.dws_f_bid_baseinfo"
  35. Province = "province"
  36. StatusCache = iota // 0 -不存缓存 本来查的就是缓存的数据
  37. StatusNoLogin // 1-未登录用户
  38. StatusLoginUser // 2-用户自己的key
  39. StatusLogin // 3-登录用户最新标讯
  40. )
  41. type NewestInfo struct {
  42. TableName string
  43. UserId string
  44. MysqlDb *mysql.Mysql
  45. NewUserId int64
  46. PushMysql *mysql.Mysql
  47. NewsLimitNum int64 // 最新标讯数量条数限制
  48. IsEnt bool
  49. }
  50. var mysqlTables = map[string]string{
  51. "f": "push.pushsubscribe",
  52. "v": "push.pushsubscribe",
  53. "m": "push.pushmember",
  54. "e": "push.pushentniche",
  55. }
  56. func GetRoleNewestInfoService(AppId, MgoUserId string, NewUserId, AccountId, EntId, EntUserId, PositionType, PositionId int64) (roleNewestInfo *NewestInfo, flag string) {
  57. powerCheck := IC.Middleground.PowerCheckCenter.Check(AppId, MgoUserId, NewUserId, AccountId, EntId, PositionType, PositionId)
  58. thisUserId := MC.If(PositionType == 1, MC.InterfaceToStr(EntUserId), MC.InterfaceToStr(NewUserId)).(string)
  59. thisNewUserId := MC.If(PositionType == 1, EntUserId, NewUserId).(int64)
  60. if powerCheck.Member.Status > 0 {
  61. // 大会员
  62. flag = "m"
  63. } else if powerCheck.Entniche.Status > 0 && powerCheck.Entniche.PowerSource != 1 && powerCheck.Entniche.IsEntPower == 1 {
  64. // 商机管理
  65. flag = "e"
  66. } else if powerCheck.Vip.Status > 0 {
  67. // 超级订阅
  68. flag = "v"
  69. } else {
  70. // 普通用户
  71. flag = "f"
  72. }
  73. thisUserType := MC.If(PositionType == 1, "e", flag).(string)
  74. return GetNewestInfo(thisUserId, thisUserType, thisNewUserId), flag
  75. }
  76. func GetNewestInfo(userId, userType string, newUserId int64) *NewestInfo {
  77. nt := &NewestInfo{
  78. UserId: userId,
  79. TableName: mysqlTables[userType],
  80. MysqlDb: IC.BaseServiceMysql,
  81. NewUserId: newUserId,
  82. NewsLimitNum: IC.C.NewsLimitNum,
  83. }
  84. return nt
  85. }
  86. // GetPushHistoryCount 缓存code 配置最新的redis code;可以感觉redis内存大小 调节redis存储;
  87. // 根据GetPushHistoryCount 返回值 作为列表缓存key中一个参数
  88. func (n *NewestInfo) GetPushHistoryCount() int64 {
  89. countKey := fmt.Sprintf(IC.C.NewsCache.Count.Key, n.TableName, n.UserId)
  90. if b := redis.GetInt("new", countKey); b != 0 {
  91. return int64(b)
  92. }
  93. countSql := "SELECT COUNT(1) FROM (SELECT 1 FROM %s WHERE userid = %d LIMIT 1) AS ph"
  94. //countSql := "select count(1) from %s a where a.userid=%d order by a.id desc"
  95. countSql = fmt.Sprintf(countSql, n.TableName, n.NewUserId)
  96. timeOut := IC.C.NewsCache.Count.Timeout
  97. c := n.MysqlDb.CountBySql(countSql)
  98. if c > 0 {
  99. timeOut = timeOut * 7
  100. } else {
  101. c = -1
  102. }
  103. redis.Put("new", countKey, c, timeOut) //过期时间走配置,比最新标讯列表缓存时间 要短1/10 尽量不超过两分钟
  104. return c
  105. }
  106. // 判断当前用户是否有最新推送信息
  107. func (n *NewestInfo) IsHasNewPushData(time int64) bool {
  108. return n.MysqlDb.CountBySql(fmt.Sprintf("SELECT COUNT(1) FROM (SELECT 1 FROM %s WHERE userid = %d AND date > %d LIMIT 1) AS ph", n.TableName, n.NewUserId, time)) > 0
  109. }
  110. // GetPushHistory
  111. func (n *NewestInfo) GetPushHistory() (res []*bxbase.NewestList) {
  112. findSQL := "select a.infoid,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.attachment_count,a.budget,a.bidamount from %s a where a.userid=%d order by a.id desc limit ?"
  113. findSQL = fmt.Sprintf(findSQL, n.TableName, n.NewUserId)
  114. logx.Info(n.TableName, "-------", n.NewUserId, ",findSQL:", findSQL)
  115. t := time.Now()
  116. list := n.MysqlDb.SelectBySql(findSQL, n.NewsLimitNum)
  117. log.Println("SQL 订阅信息耗时:", time.Since(t))
  118. if len(*list) > 0 && list != nil {
  119. m := map[string]bool{}
  120. es_ids := []string{}
  121. infos := map[string]*bxbase.NewestList{}
  122. for _, v := range *list {
  123. infoId := MC.ObjToString(v["infoid"])
  124. if m[infoId] {
  125. continue
  126. }
  127. es_ids = append(es_ids, infoId)
  128. m[MC.ObjToString(v["infoid"])] = true
  129. //
  130. infos[infoId] = &bxbase.NewestList{
  131. Id: ME.EncodeArticleId2ByCheck(MC.ObjToString(v["infoid"])),
  132. Matchkeys: strings.Split(MC.ObjToString(v["matchkeys"]), " "),
  133. Budget: MC.Int64All(v["budget"]),
  134. Bidamount: MC.Int64All(v["bidamount"]),
  135. FileExists: MC.Int64All(v["attachment_count"]) > 0,
  136. }
  137. }
  138. if len(es_ids) > 0 {
  139. t = time.Now()
  140. esList := elastic.Get(search_index, search_type, fmt.Sprintf(query, strings.Join(es_ids, `","`), len(es_ids)))
  141. log.Println("elastic 招标信息耗时:", time.Since(t))
  142. if esList != nil && len(*esList) > 0 {
  143. for _, v := range *esList {
  144. _id := MC.ObjToString(v["_id"])
  145. bn := infos[_id]
  146. bn.Title = MC.ObjToString(v["title"])
  147. bn.PublishTime = MC.Int64All(v["publishtime"])
  148. bn.Subtype = MC.If(v["subtype"] != nil, MC.ObjToString(v["subtype"]), MC.ObjToString(v["toptype"])).(string)
  149. bn.Area = MC.If(MC.ObjToString(v["area"]) == "A", "全国", MC.ObjToString(v["area"])).(string)
  150. bn.Buyerclass = MC.ObjToString(v["buyerclass"])
  151. bn.City = MC.ObjToString(v["city"])
  152. bn.Industry = MC.If(MC.ObjToString(v["s_subscopeclass"]) != "", strings.Split(strings.Split(MC.ObjToString(v["s_subscopeclass"]), ",")[0], "_")[0], "").(string)
  153. bn.SpiderCode = MC.ObjToString(v["spidercode"])
  154. bn.Site = MC.ObjToString(v["site"])
  155. }
  156. }
  157. }
  158. //mongodb bidding
  159. mgo_ids := []primitive.ObjectID{}
  160. for _, v := range es_ids {
  161. if infos[v].Title == "" {
  162. mgo_ids = append(mgo_ids, mongodb.StringTOBsonId(v))
  163. }
  164. }
  165. if len(mgo_ids) > 0 {
  166. t = time.Now()
  167. mgoList, ok := IC.MgoBidding.Find("bidding", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
  168. log.Println("mongodb bidding 招标信息耗时:", time.Since(t))
  169. if ok && *mgoList != nil && len(*mgoList) > 0 {
  170. for _, v := range *mgoList {
  171. _id := mongodb.BsonIdToSId(v["_id"])
  172. bn := infos[_id]
  173. bn.Title = MC.ObjToString(v["title"])
  174. bn.PublishTime = MC.Int64All(v["publishtime"])
  175. bn.Subtype = MC.If(v["subtype"] != nil, MC.ObjToString(v["subtype"]), MC.ObjToString(v["toptype"])).(string)
  176. bn.Area = MC.If(MC.ObjToString(v["area"]) == "A", "全国", MC.ObjToString(v["area"])).(string)
  177. bn.Buyerclass = MC.ObjToString(v["buyerclass"])
  178. bn.City = MC.ObjToString(v["city"])
  179. bn.Industry = MC.If(MC.ObjToString(v["s_subscopeclass"]) != "", strings.Split(strings.Split(MC.ObjToString(v["s_subscopeclass"]), ",")[0], "_")[0], "").(string)
  180. bn.SpiderCode = MC.ObjToString(v["spidercode"])
  181. bn.Site = MC.ObjToString(v["site"])
  182. }
  183. }
  184. }
  185. //mongodb bidding_back
  186. mgo_back_ids := []primitive.ObjectID{}
  187. for _, v := range mgo_ids {
  188. if infos[mongodb.BsonIdToSId(v)].Title == "" {
  189. mgo_back_ids = append(mgo_back_ids, v)
  190. }
  191. }
  192. if len(mgo_back_ids) > 0 {
  193. t = time.Now()
  194. mgoBKList, ok := IC.MgoBidding.Find("bidding_back", map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
  195. log.Println("mongodb bidding_back 招标信息耗时:", time.Since(t))
  196. if ok && *mgoBKList != nil && len(*mgoBKList) > 0 {
  197. for _, v := range *mgoBKList {
  198. _id := mongodb.BsonIdToSId(v["_id"])
  199. bn := infos[_id]
  200. bn.Title = MC.ObjToString(v["title"])
  201. bn.PublishTime = MC.Int64All(v["publishtime"])
  202. bn.Subtype = MC.If(v["subtype"] != nil, MC.ObjToString(v["subtype"]), MC.ObjToString(v["toptype"])).(string)
  203. bn.Area = MC.If(MC.ObjToString(v["area"]) == "A", "全国", MC.ObjToString(v["area"])).(string)
  204. bn.Buyerclass = MC.ObjToString(v["buyerclass"])
  205. bn.City = MC.ObjToString(v["city"])
  206. bn.Industry = MC.If(MC.ObjToString(v["s_subscopeclass"]) != "", strings.Split(strings.Split(MC.ObjToString(v["s_subscopeclass"]), ",")[0], "_")[0], "").(string)
  207. bn.SpiderCode = MC.ObjToString(v["spidercode"])
  208. bn.Site = MC.ObjToString(v["site"])
  209. }
  210. }
  211. }
  212. //
  213. for _, v := range infos {
  214. res = append(res, v)
  215. }
  216. }
  217. return
  218. }
  219. // 根据定位或者搜索历史 查es
  220. func NewestQuery(city, keys, subtype string) (str string) {
  221. var musts, bools []string
  222. if keys != "" {
  223. for _, v := range strings.Split(keys, ",") {
  224. keys := strings.Split(v, " ") //历史搜索 空格划分
  225. must_tmp := []string{}
  226. for _, key := range keys {
  227. must_tmp = append(must_tmp, fmt.Sprintf(multi_match, "\""+key+"\""))
  228. }
  229. bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(must_tmp, ","), ""))
  230. }
  231. }
  232. if city != "" {
  233. musts = append(musts, fmt.Sprintf(query_bool_must, "city", `"`+city+`"`))
  234. }
  235. //未登录首页推送数据限制
  236. if subtype != "" {
  237. musts = append(musts, fmt.Sprintf(query_bool_must, "subtype", subtype))
  238. }
  239. minimum_should_match := 0
  240. if len(bools) > 0 {
  241. minimum_should_match = 1
  242. }
  243. str = fmt.Sprintf(query_city_hkeys, strings.Join(musts, ","), strings.Join(bools, ","), minimum_should_match, IC.C.NewsLimitNum)
  244. logx.Info("str:", str)
  245. return
  246. }
  247. // es查询
  248. func NewestES(doSearchStr string) (res []*bxbase.NewestList) {
  249. list := elastic.Get(search_index, search_type, doSearchStr)
  250. if list != nil && len(*list) > 0 {
  251. for _, v := range *list {
  252. _id := mongodb.BsonIdToSId(v["_id"])
  253. isValidFile, _ := v["isValidFile"].(bool)
  254. res = append(res, &bxbase.NewestList{
  255. Id: ME.EncodeArticleId2ByCheck(_id),
  256. Title: MC.ObjToString(v["title"]),
  257. Subtype: MC.If(v["subtype"] != nil, MC.ObjToString(v["subtype"]), MC.ObjToString(v["toptype"])).(string),
  258. Area: MC.If(MC.ObjToString(v["area"]) == "A", "全国", MC.ObjToString(v["area"])).(string),
  259. Buyerclass: MC.ObjToString(v["buyerclass"]),
  260. City: MC.ObjToString(v["city"]),
  261. Industry: MC.If(MC.ObjToString(v["s_subscopeclass"]) != "", strings.Split(strings.Split(MC.ObjToString(v["s_subscopeclass"]), ",")[0], "_")[0], "").(string),
  262. Budget: MC.Int64All(v["budget"]),
  263. Bidamount: MC.Int64All(v["bidamount"]),
  264. FileExists: isValidFile, //附件
  265. PublishTime: MC.Int64All(v["publishtime"]),
  266. Site: MC.ObjToString(v["site"]),
  267. SpiderCode: MC.ObjToString(v["spidercode"]),
  268. })
  269. }
  270. }
  271. return
  272. }
  273. // GetRedisKeyTimeout 获取缓存的key 和超时时间
  274. func GetRedisKeyTimeout(status int, positionId int64) config.CacheConfig {
  275. var (
  276. redisKey, cuKey string
  277. timeOut, cuTimeOut int
  278. )
  279. switch status {
  280. case StatusNoLogin:
  281. redisKey = IC.C.NewsCache.NoLogin.Key
  282. //redisKey = fmt.Sprintf(redisKey, time.Now().Year(), time.Now().Month(), time.Now().Day())
  283. redisKey = fmt.Sprintf(redisKey, time.Now().Year(), 8, 8) //最开始逻辑是每日更新---》每7天更新一次;不麻烦改配置,就改代码默认月份是8 日期是8
  284. timeOut = IC.C.NewsCache.NoLogin.Timeout
  285. cuKey = fmt.Sprintf("%s_%s", redisKey, IC.C.NewsCache.NoLogin.CacheUpdateKey)
  286. cuTimeOut = IC.C.NewsCache.NoLogin.CacheUpdateTimeout
  287. case StatusLoginUser:
  288. redisKey = IC.C.NewsCache.LoginUser.Key // 登录用户使用的缓存key
  289. //redisKey = fmt.Sprintf(redisKey, positionId, time.Now().Year(), time.Now().Month(), time.Now().Day())
  290. redisKey = fmt.Sprintf(redisKey, positionId, time.Now().Year(), 8, 8) //
  291. timeOut = IC.C.NewsCache.LoginUser.Timeout
  292. cuKey = fmt.Sprintf("%s_%s", redisKey, IC.C.NewsCache.LoginUser.CacheUpdateKey)
  293. cuTimeOut = IC.C.NewsCache.LoginUser.CacheUpdateTimeout
  294. case StatusLogin:
  295. redisKey = IC.C.NewsCache.Login.Key // 登录用户使用的最新标讯缓存key
  296. //redisKey = fmt.Sprintf(redisKey, time.Now().Year(), time.Now().Month(), time.Now().Day())
  297. redisKey = fmt.Sprintf(redisKey, time.Now().Year(), 8, 8) //
  298. timeOut = IC.C.NewsCache.Login.Timeout
  299. cuKey = fmt.Sprintf("%s_%s", redisKey, IC.C.NewsCache.Login.CacheUpdateKey)
  300. cuTimeOut = IC.C.NewsCache.Login.CacheUpdateTimeout
  301. }
  302. return config.CacheConfig{
  303. Key: redisKey,
  304. Timeout: timeOut,
  305. CacheUpdateKey: cuKey,
  306. CacheUpdateTimeout: cuTimeOut,
  307. }
  308. }
  309. // PutNewsCache 存缓存
  310. func PutNewsCache(redisKey string, redisTimeout int, list []*bxbase.NewestList) {
  311. b, err := json.Marshal(list)
  312. if err != nil {
  313. log.Printf("保存缓存 序列化异常,data:%s,err:%s\n", list, err.Error())
  314. return
  315. }
  316. redisTimeout = redisTimeout + util.GetRand(604800) //缓存时间随机性7d+
  317. if err = redis.PutBytes("new", redisKey, &b, redisTimeout); err != nil {
  318. log.Printf("保存缓存 redis 异常,key:%s,err:%s\n", redisKey, err.Error())
  319. }
  320. }
  321. // GetNewsCache 取缓存
  322. func GetNewsCache(cc config.CacheConfig) (list []*bxbase.NewestList, err error) {
  323. redisByte, err := redis.GetBytes("new", cc.Key)
  324. if err != nil || redisByte == nil || len(*redisByte) == 0 {
  325. return list, err
  326. }
  327. err = json.Unmarshal(*redisByte, &list)
  328. if err != nil {
  329. logx.Info(fmt.Sprintf("读取缓存 序列化异常,err:%s", err.Error()))
  330. return nil, err
  331. }
  332. return list, nil
  333. }
  334. type NewSet struct {
  335. Status int
  336. RedisKeyModel config.CacheConfig
  337. RedisStatus int
  338. Query string
  339. }
  340. // 排序 入缓存
  341. // status : 0 -拿到的是缓存 不用再处理也不用存缓存 1-存到未登录用户 2-存到用户自己的key 3-存到登录用户最新标讯
  342. func DataSortInRedis(r *bxbase.NewsetBiddingResp, status int, positionId int64) {
  343. //排序
  344. sort.Slice(r.Data.List, func(i, j int) bool {
  345. return r.Data.List[i].PublishTime > r.Data.List[j].PublishTime
  346. })
  347. redisKeyModel := GetRedisKeyTimeout(status, positionId)
  348. go PutNewsCache(redisKeyModel.Key, redisKeyModel.Timeout, r.Data.List)
  349. }
  350. // 延长缓存
  351. // 获取最新数据 -- 延长缓存时间7天---待调整: 1、判断是否需要更新;2、判断订阅信息是否存在,如果存在是否是最新推送,3、订阅信息查推送缓存(只有个人版有缓存:pushcache_2_a )
  352. func ExtendNewListCache(n *NewSet, in *bxbase.NewestBiddingReq, list []*bxbase.NewestList) {
  353. if flag := entity.ReqLimitInit.Limit(context.Background()); flag != 1 {
  354. if flag == -2 {
  355. log.Println("等待队列已满")
  356. } else if flag == -1 {
  357. log.Println("等待超时")
  358. }
  359. } else {
  360. defer entity.ReqLimitInit.Release()
  361. if n.RedisKeyModel.Key != "" {
  362. now := time.Now()
  363. if n.RedisKeyModel.CacheUpdateKey != "" {
  364. var (
  365. res = &bxbase.NewsetBiddingResp{
  366. Data: &bxbase.NewsetBidding{
  367. List: []*bxbase.NewestList{},
  368. },
  369. }
  370. updateTime = redis.GetInt("new", n.RedisKeyModel.CacheUpdateKey)
  371. isDoing bool
  372. )
  373. //防止穿透
  374. entity.ReqLimitLock.Lock()
  375. isDoing, _ = redis.Exists("new", fmt.Sprintf("p1_indexMessage_new_recovery_%d", in.PositionId))
  376. entity.ReqLimitLock.Unlock()
  377. if !isDoing {
  378. entity.ReqLimitLock.Lock()
  379. redis.Put("new", fmt.Sprintf("p1_indexMessage_new_recovery_%d", in.PositionId), "1", 15*60) //十五分钟
  380. entity.ReqLimitLock.Unlock()
  381. switch n.RedisStatus {
  382. case StatusLoginUser:
  383. //十五分钟内 更新过一次 不再更新
  384. if int(now.Unix())-updateTime > n.RedisKeyModel.CacheUpdateTimeout {
  385. // 登录用户
  386. roleNewestInfo, _ := GetRoleNewestInfoService(in.AppId, in.MgoUserId, in.NewUserId, in.AccountId, in.EntId, in.EntUserId, in.PositionType, in.PositionId)
  387. //当前用户有最新推送信息
  388. lastPublishTime := list[len(list)-1].PublishTime
  389. if roleNewestInfo.IsHasNewPushData(lastPublishTime) {
  390. // 查推送
  391. subscribeTime := time.Now()
  392. res.Data.List = roleNewestInfo.GetPushHistory()
  393. log.Println(in.PositionId, "获取订阅数据 存缓存 耗时:", time.Since(subscribeTime).Seconds())
  394. } else {
  395. res.Data.List = list
  396. }
  397. }
  398. default:
  399. //十五分钟内 更新过一次 不再更新
  400. if int(now.Unix())-updateTime > n.RedisKeyModel.CacheUpdateTimeout {
  401. res.Data.List = NewestES(n.Query)
  402. }
  403. }
  404. if len(res.Data.List) > 0 {
  405. //更新update time
  406. redis.Put("new", n.RedisKeyModel.CacheUpdateKey, now.Unix(), n.RedisKeyModel.CacheUpdateTimeout)
  407. go DataSortInRedis(res, n.RedisStatus, in.PositionId)
  408. }
  409. }
  410. }
  411. ////剩余时间 在 IC.C.NewsTimeOut 之内
  412. //if ttl := redis.GetTTL("new", n.RedisKeyModel.Key); ttl-IC.C.NewsTimeOut < 0 {
  413. //
  414. //}
  415. }
  416. }
  417. }