delsearchlogic.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package logic
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/logx"
  5. "go.mongodb.org/mongo-driver/bson/primitive"
  6. "jyBXBase/rpc/bxcollection/bxcol"
  7. "jyBXBase/rpc/bxcollection/internal/svc"
  8. "jyBXBase/rpc/bxcollection/model"
  9. "strings"
  10. )
  11. type DelSearchLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewDelSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelSearchLogic {
  17. return &DelSearchLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // 获取收藏列表
  24. func (l *DelSearchLogic) DelSearch(in *bxcol.DelSearchReq) (res *bxcol.CommonRes, err error) {
  25. // todo: add your logic here and delete this line
  26. res = new(bxcol.CommonRes)
  27. delId := strings.Split(in.Id, ",")
  28. if len(delId) < 1 {
  29. return
  30. }
  31. var allDelId []primitive.ObjectID
  32. for _, v := range delId {
  33. ss, _ := primitive.ObjectIDFromHex(v)
  34. allDelId = append(allDelId, ss)
  35. }
  36. query := map[string]interface{}{
  37. "_id": map[string]interface{}{"$in": allDelId},
  38. }
  39. delCount := model.Mgo.Delete("search_condition", query)
  40. if delCount == 0 {
  41. res.ErrCode = 1
  42. res.ErrMsg = "删除失败"
  43. }
  44. return
  45. }