Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修改通知功能,实现系统通知 #8

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions biz/adaptor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ type SystemServerImpl struct {
SystemService service.SystemService
}

func (s *SystemServerImpl) InsertNotificationCount(ctx context.Context, req *system.InsertNotificationCountReq) (res *system.InsertNotificationCountResp, err error) {
return s.SystemService.InsertNotificationCount(ctx, req)
}

// func (s *SystemServerImpl) UpdateNotifications(ctx context.Context, req *system.UpdateNotificationsReq) (resp *system.UpdateNotificationsResp, err error) {
// return s.SystemService.UpdateNotifications(ctx, req)
// }
func (s *SystemServerImpl) ReadNotifications(ctx context.Context, req *system.ReadNotificationsReq) (resp *system.ReadNotificationsResp, err error) {
return s.SystemService.ReadNotifications(ctx, req)
}

func (s *SystemServerImpl) GetSliders(ctx context.Context, req *system.GetSlidersReq) (resp *system.GetSlidersResp, err error) {
return s.SystemService.GetSliders(ctx, req)
Expand Down
63 changes: 7 additions & 56 deletions biz/application/service/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package service

import (
"context"
"fmt"
"github.com/CloudStriver/cloudmind-system/biz/infrastructure/consts"
"github.com/CloudStriver/cloudmind-system/biz/infrastructure/convertor"
notificationmapper "github.com/CloudStriver/cloudmind-system/biz/infrastructure/mapper/notification"
notificationcountmapper "github.com/CloudStriver/cloudmind-system/biz/infrastructure/mapper/notificationCount"
slidermapper "github.com/CloudStriver/cloudmind-system/biz/infrastructure/mapper/slider"
"github.com/CloudStriver/go-pkg/utils/pagination/mongop"
"github.com/CloudStriver/go-pkg/utils/pconvertor"
Expand All @@ -15,7 +13,6 @@ import (
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/stores/redis"
"go.mongodb.org/mongo-driver/bson/primitive"
"strconv"
)

type SystemService interface {
Expand All @@ -26,38 +23,12 @@ type SystemService interface {
GetNotifications(ctx context.Context, req *gensystem.GetNotificationsReq) (resp *gensystem.GetNotificationsResp, err error)
GetNotificationCount(ctx context.Context, req *gensystem.GetNotificationCountReq) (resp *gensystem.GetNotificationCountResp, err error)
CreateNotifications(ctx context.Context, req *gensystem.CreateNotificationsReq) (resp *gensystem.CreateNotificationsResp, err error)
ReadNotifications(ctx context.Context, req *gensystem.ReadNotificationsReq) (resp *gensystem.ReadNotificationsResp, err error)
InsertNotificationCount(ctx context.Context, req *gensystem.InsertNotificationCountReq) (resp *gensystem.InsertNotificationCountResp, err error)
//UpdateNotifications(ctx context.Context, req *gensystem.UpdateNotificationsReq) (resp *gensystem.UpdateNotificationsResp, err error)
}

type SystemServiceImpl struct {
NotificationMongoMapper notificationmapper.INotificationMongoMapper
NotificationCountMongoMapper notificationcountmapper.INotificationCountMongoMapper
SliderMongoMapper slidermapper.ISliderMongoMapper
Redis *redis.Redis
}

func (s *SystemServiceImpl) InsertNotificationCount(ctx context.Context, req *gensystem.InsertNotificationCountReq) (resp *gensystem.InsertNotificationCountResp, err error) {
uid, _ := primitive.ObjectIDFromHex(req.UserId)
if err = s.NotificationCountMongoMapper.InsertCount(ctx, &notificationcountmapper.NotificationCount{
ID: uid,
Sum: 0,
Read: 0,
}); err != nil {
return resp, err
}
return resp, nil
}
func (s *SystemServiceImpl) ReadNotifications(ctx context.Context, req *gensystem.ReadNotificationsReq) (resp *gensystem.ReadNotificationsResp, err error) {
uid, _ := primitive.ObjectIDFromHex(req.UserId)
if err = s.NotificationCountMongoMapper.AddCount(ctx, &notificationcountmapper.NotificationCount{
ID: uid,
Read: req.ReadCount,
}); err != nil {
return resp, err
}
return resp, nil
NotificationMongoMapper notificationmapper.INotificationMongoMapper
SliderMongoMapper slidermapper.ISliderMongoMapper
Redis *redis.Redis
}

func (s *SystemServiceImpl) DeleteSlider(ctx context.Context, req *gensystem.DeleteSliderReq) (resp *gensystem.DeleteSliderResp, err error) {
Expand Down Expand Up @@ -137,22 +108,15 @@ func (s *SystemServiceImpl) GetNotifications(ctx context.Context, req *gensystem
}

func (s *SystemServiceImpl) GetNotificationCount(ctx context.Context, req *gensystem.GetNotificationCountReq) (resp *gensystem.GetNotificationCountResp, err error) {

userCount, err := s.NotificationCountMongoMapper.GetCount(ctx, req.UserId)
cnt, err := s.NotificationMongoMapper.Count(ctx, &notificationmapper.FilterOptions{
OnlyUserIds: []string{consts.NotificationSystemKey, req.UserId},
})
if err != nil {
fmt.Println(err)
return resp, err
}

system, err := s.Redis.GetCtx(ctx, fmt.Sprintf("%s:%s", consts.NotificationCount, consts.NotificationSystemKey))
if err != nil {
return resp, err
}

systemCount, _ := strconv.ParseInt(system, 10, 64)

return &gensystem.GetNotificationCountResp{
Total: systemCount + userCount.Sum - userCount.Read,
Total: cnt,
}, nil
}

Expand All @@ -168,19 +132,6 @@ func (s *SystemServiceImpl) CreateNotifications(ctx context.Context, req *gensys
return resp, err
}

if req.TargetUserId == consts.NotificationSystemKey {
if _, err = s.Redis.IncrCtx(ctx, fmt.Sprintf("%s:%s", consts.NotificationCount, consts.NotificationSystemKey)); err != nil {
return resp, err
}
} else {
uid, _ := primitive.ObjectIDFromHex(req.TargetUserId)
if err = s.NotificationCountMongoMapper.AddCount(ctx, &notificationcountmapper.NotificationCount{
ID: uid,
Sum: 1,
}); err != nil {
return resp, err
}
}
return resp, nil
}

Expand Down
13 changes: 11 additions & 2 deletions biz/infrastructure/mapper/notification/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
)

type FilterOptions struct {
OnlyUserId *string
OnlyType *int64
OnlyUserId *string
OnlyUserIds []string
OnlyType *int64
}

type MongoFilter struct {
Expand Down Expand Up @@ -39,3 +40,11 @@ func (f *MongoFilter) CheckOnlyType() {
f.m[consts.Type] = *f.OnlyType
}
}

func (f *MongoFilter) CheckOnlyUserIds() {
if f.OnlyUserIds != nil {
f.m[consts.TargetUserId] = bson.M{
"in": f.OnlyUserIds,
}
}
}
68 changes: 0 additions & 68 deletions biz/infrastructure/mapper/notificationCount/mongo.go

This file was deleted.

6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/CloudStriver/go-pkg v0.0.0-20240117111745-b4ba57a38f44
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312013508-fed7c5ed3e2c
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312020955-691e500d8edb
github.com/cloudwego/kitex v0.8.0
github.com/google/wire v0.5.0
github.com/kitex-contrib/obs-opentelemetry v0.2.5
Expand All @@ -14,9 +14,7 @@ require (
google.golang.org/grpc v1.61.0
)

//replace (
// github.com/CloudStriver/service-idl-gen-go => ../service-idl-gen-go
//)
//replace github.com/CloudStriver/service-idl-gen-go => ../service-idl-gen-go

require (
github.com/apache/thrift v0.16.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CloudStriver/go-pkg v0.0.0-20240117111745-b4ba57a38f44 h1:7exnHSz2LCeghuVDVD8IS+JaPB/bxDJWFEL7xH5L2Tg=
github.com/CloudStriver/go-pkg v0.0.0-20240117111745-b4ba57a38f44/go.mod h1:SsAxWs5EIcaDE/0e5buoFOWsM4lTvFZhySkV68+RT3g=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312012247-c0e2c8143766 h1:rhL+eapoLlEERFy31AMPVK7mhoMCyHeaKT00Fob50u4=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312012247-c0e2c8143766/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312013508-fed7c5ed3e2c h1:xTv+HbCgCNjoXpPlPtYzQuzGXDaWcN/g/ncWmL2OuHU=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312013508-fed7c5ed3e2c/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312020023-d19062f3547f h1:pJDpY40HnUruaQcpSokQwHucExnzYUHTFxDRQXI56To=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312020023-d19062f3547f/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312020955-691e500d8edb h1:YRJbAIyNLuWVDqCa9/4z4Qf5lfEA413o4B66DgHaIA4=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240312020955-691e500d8edb/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
Expand Down
2 changes: 0 additions & 2 deletions provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package provider

import (
notificationcountmapper "github.com/CloudStriver/cloudmind-system/biz/infrastructure/mapper/notificationCount"
slidermapper "github.com/CloudStriver/cloudmind-system/biz/infrastructure/mapper/slider"
"github.com/CloudStriver/cloudmind-system/biz/infrastructure/store/redis"
"github.com/google/wire"
Expand All @@ -28,6 +27,5 @@ var InfrastructureSet = wire.NewSet(

var MapperSet = wire.NewSet(
notificationmapper.NewNotificationModel,
notificationcountmapper.NewNotificationCountModel,
slidermapper.NewSliderModel,
)
9 changes: 3 additions & 6 deletions provider/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading