iscollactionlogic.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. se "app.yhyue.com/moapp/jybase/encrypt"
  5. "app.yhyue.com/moapp/jybase/redis"
  6. "context"
  7. "fmt"
  8. IC "jyBXBase/rpc/init"
  9. util2 "jyBXBase/rpc/util"
  10. "strconv"
  11. "strings"
  12. "jyBXBase/rpc/bxbase"
  13. "jyBXBase/rpc/internal/svc"
  14. "github.com/zeromicro/go-zero/core/logx"
  15. )
  16. type IsCollActionLogic struct {
  17. ctx context.Context
  18. svcCtx *svc.ServiceContext
  19. logx.Logger
  20. }
  21. func NewIsCollActionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *IsCollActionLogic {
  22. return &IsCollActionLogic{
  23. ctx: ctx,
  24. svcCtx: svcCtx,
  25. Logger: logx.WithContext(ctx),
  26. }
  27. }
  28. // 招标信息是否被收藏
  29. func (l *IsCollActionLogic) IsCollAction(in *bxbase.IsCollActionReq) (*bxbase.IsCollActionRes, error) {
  30. var idata bxbase.IData
  31. if in.Label != "" {
  32. bid := util2.DecodeId(strings.Split(in.Bids, ",")[0])
  33. if bdinfos := IC.MainMysql.SelectBySql(fmt.Sprintf("SELECT labelid FROM %s WHERE userid = ? AND bid = ?", "bdcollection"), in.UserId, bid); bdinfos != nil && len(*bdinfos) > 0 {
  34. bdinfo := (*bdinfos)[0]
  35. label_ids := common.ObjToString(bdinfo["labelid"])
  36. //var labArr = []map[string]interface{}{}
  37. var labArr []*bxbase.Labels
  38. if label_ids != "" {
  39. label_ids_inter := []interface{}{}
  40. var instatus = "?"
  41. for k, id := range strings.Split(label_ids, ",") {
  42. if k > 0 {
  43. instatus += ",?"
  44. }
  45. label_ids_inter = append(label_ids_inter, id)
  46. }
  47. if labinfos := IC.MainMysql.SelectBySql(fmt.Sprintf("SELECT * FROM %s WHERE id IN (%s)", "bdlabel", instatus), label_ids_inter...); labinfos != nil && len(*labinfos) > 0 {
  48. for _, v := range *labinfos {
  49. lid := strconv.FormatInt(v["id"].(int64), 10)
  50. lid_str := se.SE.EncodeString(lid)
  51. labArr = append(labArr, &bxbase.Labels{
  52. Labelname: common.ObjToString(v["labelname"]),
  53. Id: lid_str,
  54. })
  55. }
  56. }
  57. }
  58. idata.Iscoll = true
  59. idata.Labels = labArr
  60. }
  61. return &bxbase.IsCollActionRes{
  62. Data: &idata,
  63. }, nil
  64. }
  65. res := []string{}
  66. collBidMap := map[string]bool{}
  67. isCollkey := fmt.Sprintf("isColl_%s", in.UserId)
  68. collStatus := redis.GetInt("other", isCollkey)
  69. if collStatus == 0 {
  70. if count := int(IC.MainMysql.CountBySql(fmt.Sprintf(`select count(1)
  71. from %s where userid = ?`, "bdcollection"), in.UserId)); count > 100 {
  72. collStatus = 2
  73. } else if count == 0 {
  74. collStatus = 0
  75. } else {
  76. collStatus = 1
  77. }
  78. redis.Put("other", isCollkey, collStatus, 259200)
  79. }
  80. if collStatus == 1 { //100条内 取redis
  81. list := util2.GetCollRedis(in.UserId, collStatus)
  82. for _, v := range list {
  83. collBidMap[v] = true
  84. }
  85. } else if collStatus == 2 { //大于100条 取mysql
  86. if labArr := IC.MainMysql.SelectBySql(fmt.Sprintf("select bid from %s where userid = ?", "bdcollection"), in.UserId); labArr != nil && len(*labArr) > 0 {
  87. for _, v := range *labArr {
  88. bid_id := common.ObjToString(v["bid"])
  89. collBidMap[bid_id] = true
  90. }
  91. }
  92. } else { //0条
  93. idata.Bids = res
  94. return &bxbase.IsCollActionRes{
  95. Data: &idata,
  96. }, nil
  97. }
  98. if in.Bids == "" {
  99. for k := range collBidMap {
  100. res = append(res, k)
  101. }
  102. } else {
  103. for _, v := range strings.Split(in.Bids, ",") {
  104. //招标信息解密
  105. bid := util2.DecodeId(v)
  106. if collBidMap[bid] {
  107. // url.QueryEscape(v)
  108. res = append(res, v)
  109. }
  110. }
  111. }
  112. return &bxbase.IsCollActionRes{
  113. Data: &idata,
  114. }, nil
  115. }