collectionInfo.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package model
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. ME "app.yhyue.com/moapp/jybase/encrypt"
  5. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXBase/rpc/bxbase"
  6. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXBase/rpc/init"
  7. "strings"
  8. )
  9. // 标题判重
  10. func DuplicatedByTitle(list []*bxbase.NewestList) (res []*bxbase.NewestList) {
  11. var (
  12. i int64 = 0
  13. duplicateMap = map[string]bool{}
  14. )
  15. for _, v := range list {
  16. //判重
  17. if i >= IC.C.NewsLimitNum {
  18. break
  19. }
  20. if duplicateMap[v.Title] {
  21. continue
  22. }
  23. i++
  24. res = append(res, v)
  25. }
  26. return
  27. }
  28. // 是否收藏
  29. func MakeCollection(userId string, list []*bxbase.NewestList) {
  30. var (
  31. param = []interface{}{userId}
  32. wh = []string{}
  33. )
  34. for _, v := range list {
  35. array := ME.DecodeArticleId2ByCheck(v.Id)
  36. if len(array) == 1 && array[0] != "" {
  37. param = append(param, array[0])
  38. wh = append(wh, "?")
  39. }
  40. }
  41. if len(wh) > 0 {
  42. result := IC.MainMysql.SelectBySql(`select bid from bdcollection where userid=? and bid in (`+strings.Join(wh, ",")+`)`, param...)
  43. bid_map := map[string]bool{}
  44. if result != nil {
  45. for _, v := range *result {
  46. bid_map[ME.EncodeArticleId2ByCheck(MC.ObjToString(v["bid"]))] = true
  47. }
  48. }
  49. for _, v := range list {
  50. if !IC.C.FileSignBool {
  51. v.FileExists = false
  52. }
  53. if bid_map[v.Id] {
  54. v.IsCol = true
  55. }
  56. }
  57. }
  58. }