addsearchlogic.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package logic
  2. import (
  3. "context"
  4. "jyBXBase/rpc/bxbase"
  5. IC "jyBXBase/rpc/init"
  6. "jyBXBase/rpc/util"
  7. "log"
  8. "strings"
  9. "time"
  10. "jyBXBase/rpc/internal/svc"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type AddSearchLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewAddSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddSearchLogic {
  19. return &AddSearchLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 添加搜索列表
  26. func (l *AddSearchLogic) AddSearch(in *bxbase.AddSearchReq) (res *bxbase.CommonRes, err error) {
  27. res = new(bxbase.CommonRes)
  28. newData := make(map[string]interface{})
  29. if in.UserId == "" {
  30. res.ErrCode = 1
  31. res.ErrMsg = "用户未登录"
  32. return
  33. }
  34. if in.InKey == "" {
  35. res.ErrCode = 1
  36. res.ErrMsg = "保存失败"
  37. return
  38. }
  39. log.Println("添加搜索列表:", in)
  40. in.Keywords = strings.Replace(in.Keywords, " ", ",", -1)
  41. switch in.SearchGroup {
  42. case util.SearchGroupBidding:
  43. if ValueSort(util.TopTypesBidding) == in.Subtype {
  44. in.Subtype = ""
  45. }
  46. case util.SearchGroupLeadingProject:
  47. if ValueSort(util.TopTypesLeadingProject) == in.Subtype {
  48. in.Subtype = ""
  49. }
  50. case util.SearchGroupAnnouncementProject:
  51. if in.Subtype == "" {
  52. in.Subtype = "招标公告"
  53. }
  54. case util.SearchGroupForetellProject:
  55. if in.Subtype == "" {
  56. in.Subtype = "招标预告"
  57. }
  58. case util.SearchGroupResultProject:
  59. if in.Subtype == "" {
  60. in.Subtype = "招标结果"
  61. }
  62. }
  63. newData["keywords"] = in.Keywords
  64. newData["type"] = in.Type
  65. newData["publish_time"] = in.PublishTime
  66. newData["area"] = in.Area
  67. newData["city"] = in.City
  68. newData["buyer"] = in.Buyer
  69. newData["winner"] = in.Winner
  70. newData["agency"] = in.Agency
  71. newData["subtype"] = in.Subtype
  72. newData["min_price"] = in.MinPrice
  73. newData["max_price"] = in.MaxPrice
  74. newData["industry"] = in.Industry
  75. newData["select_type"] = in.SelectType
  76. newData["buyer_class"] = in.BuyerClass
  77. newData["buyer_tel"] = in.HasBuyerTel
  78. newData["winner_tel"] = in.HasWinnerTel
  79. newData["file_exists"] = in.FileExists
  80. newData["not_key"] = in.NotKey
  81. newData["creation_time"] = time.Now().Unix()
  82. newData["user_id"] = in.UserId
  83. newData["in_key"] = in.InKey
  84. newData["searchGroup"] = in.SearchGroup
  85. newData["searchMode"] = in.SearchMode
  86. newData["wordsMode"] = in.WordsMode
  87. newData["additionalWords"] = in.AdditionalWords
  88. region := map[string]map[string][]string{}
  89. if in.RegionMap != nil {
  90. for k, v := range in.RegionMap {
  91. areaMap := map[string][]string{}
  92. for k1, v1 := range v.Area {
  93. areaMap[k1] = v1.District
  94. }
  95. region[k] = areaMap
  96. }
  97. }
  98. newData["regionMap"] = region
  99. IC.Mgo.Save("search_condition", newData)
  100. return
  101. }