package logic import ( "context" "errors" "jyBXBase/entity" IC "jyBXBase/rpc/init" "jyBXBase/rpc/internal/svc" "jyBXBase/rpc/type/bxbase" "github.com/zeromicro/go-zero/core/logx" ) type SaveListModeLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewSaveListModeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveListModeLogic { return &SaveListModeLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } // SaveListMode 搜索/订阅 列表模式保存 func (l *SaveListModeLogic) SaveListMode(in *bxbase.SaveListModeReq) (res *bxbase.CommonRes, err error) { res = new(bxbase.CommonRes) query := map[string]interface{}{ "user_id": in.UserId, "type": in.Type, // 类型 search-标讯搜索列表 subscribe-订阅列表 } updateInfo := map[string]interface{}{ "$set": map[string]interface{}{ "mode": int(in.Mode)}, // 列表模式 0-精简列表 1-详细列表 } // 存在则更新 不存在则保存一条新数据 b := IC.Mgo.Update(entity.ListModeCollection, query, updateInfo, true, false) if !b { res.ErrCode = 1 err = errors.New("保存失败") } return res, err }