123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package logic
- import (
- "context"
- "errors"
- 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) {
- // todo 待测试
- res = new(bxbase.CommonRes)
- query := map[string]interface{}{
- "userId": in.UserId,
- "type": in.Type,
- }
- if IC.Mgo.Count("list_mode", query) > 0 {
- // 存在则更新
- b := IC.Mgo.Update("list_mode", query, map[string]interface{}{
- "$set": map[string]interface{}{
- "mode": in.Mode},
- }, false, false)
- if !b {
- res.ErrCode = 1
- err = errors.New("更新失败")
- }
- } else {
- // 保存
- saveData := map[string]interface{}{
- "type": in.Type,
- "mode": in.Mode,
- "userId": in.UserId,
- }
- rs := IC.Mgo.Save("list_mode", saveData)
- if rs == "" {
- res.ErrCode = 1
- err = errors.New("保存失败")
- }
- }
- return res, nil
- }
|