dengbiao преди 1 ден
родител
ревизия
5798c11232
променени са 11 файла, в които са добавени 761 реда и са изтрити 578 реда
  1. +20
    -24
      config/config.go
  2. +9
    -12
      internal/business/api/business_ext.go
  3. +10
    -1
      internal/logic/api/logic_ext.go
  4. +2
    -2
      internal/logic/domain/group/repo/group_cache.go
  5. +48
    -0
      internal/logic/domain/group/repo/group_notice_cache.go
  6. +15
    -8
      internal/logic/domain/group/repo/group_notice_dao.go
  7. +1
    -1
      internal/logic/domain/group/repo/group_notice_with_like_records_dao.go
  8. +21
    -0
      internal/logic/domain/group/repo/group_repo.go
  9. +623
    -527
      pkg/pb/logic.ext.pb.go
  10. +9
    -0
      pkg/proto/logic.ext.proto
  11. +3
    -3
      pkg/rpc/rpc.go

+ 20
- 24
config/config.go Целия файл

@@ -1,13 +1,9 @@
package config

import (
"context"
"egg-im/pkg/k8sutil"
"egg-im/pkg/logger"
"go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"strconv"
)

const (
@@ -31,26 +27,26 @@ var (
)

func Init() {
k8sClient, err := k8sutil.GetK8sClient()
if err != nil {
panic(err)
}
configmap, err := k8sClient.CoreV1().ConfigMaps(NameSpace).Get(context.TODO(), "config", metav1.GetOptions{})
if err != nil {
panic(err)
}
MySQL = configmap.Data["mysql"]
RedisIP = configmap.Data["redisIP"]
RedisPassword = configmap.Data["redisPassword"]
PushRoomSubscribeNum, _ = strconv.Atoi(configmap.Data["pushRoomSubscribeNum"])
if PushRoomSubscribeNum == 0 {
panic("PushRoomSubscribeNum == 0")
}
PushAllSubscribeNum, _ = strconv.Atoi(configmap.Data["pushAllSubscribeNum"])
if PushRoomSubscribeNum == 0 {
panic("PushAllSubscribeNum == 0")
}
//k8sClient, err := k8sutil.GetK8sClient()
//if err != nil {
// panic(err)
//}
//configmap, err := k8sClient.CoreV1().ConfigMaps(NameSpace).Get(context.TODO(), "config", metav1.GetOptions{})
//if err != nil {
// panic(err)
//}
//
//MySQL = configmap.Data["mysql"]
//RedisIP = configmap.Data["redisIP"]
//RedisPassword = configmap.Data["redisPassword"]
//PushRoomSubscribeNum, _ = strconv.Atoi(configmap.Data["pushRoomSubscribeNum"])
//if PushRoomSubscribeNum == 0 {
// panic("PushRoomSubscribeNum == 0")
//}
//PushAllSubscribeNum, _ = strconv.Atoi(configmap.Data["pushAllSubscribeNum"])
//if PushRoomSubscribeNum == 0 {
// panic("PushAllSubscribeNum == 0")
//}

LocalAddr = os.Getenv("POD_IP") + RPCListenAddr



+ 9
- 12
internal/business/api/business_ext.go Целия файл

@@ -41,6 +41,11 @@ func (s *BusinessExtServer) ViewGroupNotice(ctx context.Context, req *pb.ViewGro
IsLike: false,
}, nil
}
groupNotice.ReadNums++
err = repo2.GroupNoticeDao.Save(groupNotice, false)
if err != nil {
return nil, err
}
groupNoticeWithLikeRecords, err := repo2.GroupNoticeWithLikeRecordsDao.Get(userId, req.GroupId)
if err != nil {
return nil, err
@@ -53,7 +58,7 @@ func (s *BusinessExtServer) ViewGroupNotice(ctx context.Context, req *pb.ViewGro
LikeNums: int64(groupNotice.LikeNums),
ReadNums: int64(groupNotice.ReadNums),
PublishType: pb.GroupNoticePublishType(groupNotice.PublishType),
PublishTime: groupNotice.CreateTime.Format("2006-01-02 15:04:05"),
PublishTime: groupNotice.UpdateTime.Format("2006-01-02 15:04:05"),
IsLike: func() bool {
if groupNoticeWithLikeRecords == nil {
return false
@@ -93,7 +98,7 @@ func (s *BusinessExtServer) LikeGroupNotice(ctx context.Context, req *pb.LikeGro
}

groupNotice.LikeNums++
return new(pb.Empty), repo2.GroupNoticeDao.Save(groupNotice)
return new(pb.Empty), repo2.GroupNoticeDao.Save(groupNotice, false)
}

func (s *BusinessExtServer) CancelLikeGroupNotice(ctx context.Context, req *pb.CancelLikeGroupNoticeReq) (*pb.Empty, error) {
@@ -122,16 +127,8 @@ func (s *BusinessExtServer) CancelLikeGroupNotice(ctx context.Context, req *pb.C
return nil, err
}

err = repo2.GroupNoticeWithLikeRecordsDao.Save(&model.GroupNoticeWithLikeRecords{
GroupId: req.GroupId,
UserId: userId,
})
if err != nil {
return nil, err
}

groupNotice.LikeNums--
return new(pb.Empty), repo2.GroupNoticeDao.Save(groupNotice)
return new(pb.Empty), repo2.GroupNoticeDao.Save(groupNotice, false)
}

func (s *BusinessExtServer) PublishGroupNotice(ctx context.Context, req *pb.PublishGroupNoticeReq) (*pb.Empty, error) {
@@ -156,7 +153,7 @@ func (s *BusinessExtServer) PublishGroupNotice(ctx context.Context, req *pb.Publ
UpdateTime: now,
}

return new(pb.Empty), repo2.GroupNoticeDao.Save(&groupComplain)
return new(pb.Empty), repo2.GroupNoticeDao.Save(&groupComplain, true)
}

func (s *BusinessExtServer) ComplainGroup(ctx context.Context, req *pb.ComplainGroupReq) (*pb.Empty, error) {


+ 10
- 1
internal/logic/api/logic_ext.go Целия файл

@@ -4,6 +4,7 @@ import (
"context"
"egg-im/internal/business/comm/utils"
"egg-im/internal/logic/app"
"egg-im/internal/logic/domain/group/repo"
"egg-im/pkg/grpclib"
"egg-im/pkg/pb"
"google.golang.org/protobuf/proto"
@@ -243,7 +244,15 @@ func (*LogicExtServer) UpdateGroup(ctx context.Context, in *pb.UpdateGroupReq) (
// GetGroup 获取群组信息
func (*LogicExtServer) GetGroup(ctx context.Context, in *pb.GetGroupReq) (*pb.GetGroupResp, error) {
group, memberType, userStatusType, err := app.GroupApp.GetGroup(ctx, in.GroupId)
return &pb.GetGroupResp{Group: group, MemberType: memberType, GroupUserStatusType: userStatusType}, err
if err != nil {
return &pb.GetGroupResp{Group: group, MemberType: memberType, GroupUserStatusType: userStatusType}, err
}
groupNotice, err := repo.GroupRepo.GetGroupNotice(in.GroupId)
return &pb.GetGroupResp{Group: group, MemberType: memberType, GroupUserStatusType: userStatusType, GroupNotice: &pb.GroupNotice{
Content: groupNotice.Content,
PublishType: pb.GroupNoticePublishType(groupNotice.PublishType),
PublishTime: groupNotice.UpdateTime.Format("2006-01-02 15:04:05"),
}}, err
}

// GetGroups 获取用户加入的所有群组


+ 2
- 2
internal/logic/domain/group/repo/group_cache.go Целия файл

@@ -44,7 +44,7 @@ func (c *groupCache) GetLimit(limit string, groupId int64) (*model.Group, error)

// Set 设置群组缓存
func (c *groupCache) Set(group *model.Group) error {
err := db.RedisUtil.Set(GroupKey+strconv.FormatInt(group.Id, 10), group, 4*time.Hour)
err := db.RedisUtil.Set(GroupKey+strconv.FormatInt(group.Id, 10), group, 2*time.Hour)
if err != nil {
return gerrors.WrapError(err)
}
@@ -53,7 +53,7 @@ func (c *groupCache) Set(group *model.Group) error {

// SetLimit 设置群组缓存
func (c *groupCache) SetLimit(limit string, group *model.Group) error {
err := db.RedisUtil.Set(GroupKey+limit+":"+strconv.FormatInt(group.Id, 10), group, 4*time.Hour)
err := db.RedisUtil.Set(GroupKey+limit+":"+strconv.FormatInt(group.Id, 10), group, 2*time.Hour)
if err != nil {
return gerrors.WrapError(err)
}


+ 48
- 0
internal/logic/domain/group/repo/group_notice_cache.go Целия файл

@@ -0,0 +1,48 @@
package repo

import (
"egg-im/internal/logic/domain/group/model"
"egg-im/pkg/db"
"egg-im/pkg/gerrors"
"strconv"
"time"

"github.com/go-redis/redis"
)

const GroupNoticeKey = "group:notice:"

type groupNoticeCache struct{}

var GroupNoticeCache = new(groupNoticeCache)

// Get 获取群组缓存
func (c *groupNoticeCache) Get(groupId int64) (*model.GroupNotice, error) {
var user model.GroupNotice
err := db.RedisUtil.Get(GroupNoticeKey+strconv.FormatInt(groupId, 10), &user)
if err != nil && err != redis.Nil {
return nil, gerrors.WrapError(err)
}
if err == redis.Nil {
return nil, nil
}
return &user, nil
}

// Set 设置群组缓存
func (c *groupNoticeCache) Set(group *model.GroupNotice) error {
err := db.RedisUtil.Set(GroupNoticeKey+strconv.FormatInt(group.Id, 10), group, 1*time.Hour)
if err != nil {
return gerrors.WrapError(err)
}
return nil
}

// Del 删除群组缓存
func (c *groupNoticeCache) Del(groupId int64) error {
_, err := db.RedisCli.Del(GroupNoticeKey + strconv.FormatInt(groupId, 10)).Result()
if err != nil {
return gerrors.WrapError(err)
}
return nil
}

+ 15
- 8
internal/logic/domain/group/repo/group_notice_dao.go Целия файл

@@ -26,15 +26,15 @@ func (*groupNoticeDao) Get(groupId int64) (*model.GroupNotice, error) {
}

// Save 插入一条群组
func (g *groupNoticeDao) Save(groupNotice *model.GroupNotice) error {
func (g *groupNoticeDao) Save(groupNotice *model.GroupNotice, isPublish bool) error {
mm, err := g.Get(groupNotice.GroupId)
if err != nil {
return err
}
if mm != nil {
if mm != nil && isPublish {
mm.Content = groupNotice.Content
mm.LikeNums = groupNotice.LikeNums
mm.ReadNums = groupNotice.ReadNums
mm.LikeNums = 0
mm.ReadNums = 0
mm.PublishType = groupNotice.PublishType
mm.UpdateTime = groupNotice.UpdateTime

@@ -43,10 +43,17 @@ func (g *groupNoticeDao) Save(groupNotice *model.GroupNotice) error {
if err != nil {
return err
}
}
err = db.DB.Save(&groupNotice).Error
if err != nil {
return gerrors.WrapError(err)
err = db.DB.Save(&mm).Error
if err != nil {
return gerrors.WrapError(err)
}
//删除缓存
GroupCache.Del(groupNotice.GroupId)
} else {
err = db.DB.Save(&groupNotice).Error
if err != nil {
return gerrors.WrapError(err)
}
}
return nil
}

+ 1
- 1
internal/logic/domain/group/repo/group_notice_with_like_records_dao.go Целия файл

@@ -27,7 +27,7 @@ func (*groupNoticeWithLikeRecords) Get(userId, groupId int64) (*model.GroupNotic

// Save 插入一条群组
func (*groupNoticeWithLikeRecords) Save(groupNoticeWithLikeRecords *model.GroupNoticeWithLikeRecords) error {
err := db.DB.Save(&groupNoticeWithLikeRecords).Error
err := db.DB.Create(&groupNoticeWithLikeRecords).Error
if err != nil {
return gerrors.WrapError(err)
}


+ 21
- 0
internal/logic/domain/group/repo/group_repo.go Целия файл

@@ -42,6 +42,27 @@ func (*groupRepo) Get(groupId int64) (*model.Group, error) {
return group, nil
}

// GetGroupNotice 获取群组公告信息
func (*groupRepo) GetGroupNotice(groupId int64) (*model.GroupNotice, error) {
group, err := GroupNoticeCache.Get(groupId)
if err != nil {
return nil, err
}
if group != nil {
return group, nil
}

group, err = GroupNoticeDao.Get(groupId)
if err != nil {
return nil, err
}
err = GroupNoticeCache.Set(group)
if err != nil {
return nil, err
}
return group, nil
}

// GetLimit 获取群组信息(限量)
func (*groupRepo) GetLimit(groupId, limit int64) (*model.Group, error) {
group, err := GroupCache.GetLimit(strconv.FormatInt(limit, 10), groupId)


+ 623
- 527
pkg/pb/logic.ext.pb.go
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 9
- 0
pkg/proto/logic.ext.proto Целия файл

@@ -2,6 +2,7 @@ syntax = "proto3";
package pb;
option go_package = "egg-im/pkg/pb/";

import "business.ext.proto";
import "common.ext.proto";
import "connect.ext.proto";

@@ -186,8 +187,16 @@ message GetGroupResp {
Group group = 1;
MemberType member_type = 2;
GroupUserStatusType group_user_status_type = 3;
GroupNotice group_notice = 4; //群公告
}

message GroupNotice {
string content = 1; //公告内容
GroupNoticePublishType publish_type = 2; // 发布方式
string publish_time = 3; // 发布时间
}


message Group {
int64 group_id = 1; // 群组id
string name = 2; // 名称


+ 3
- 3
pkg/rpc/rpc.go Целия файл

@@ -58,10 +58,10 @@ func initConnectIntClient() {
}

func initBusinessIntClient() {
//conn, err := grpc.DialContext(context.TODO(), "127.0.0.1:8000", grpc.WithInsecure(),
// grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)))
conn, err := grpc.DialContext(context.TODO(), k8s.GetK8STarget("egg-im", "business", "8000"), grpc.WithInsecure(),
conn, err := grpc.DialContext(context.TODO(), "127.0.0.1:8000", grpc.WithInsecure(),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)))
//conn, err := grpc.DialContext(context.TODO(), k8s.GetK8STarget("egg-im", "business", "8000"), grpc.WithInsecure(),
// grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)))
if err != nil {
panic(err)
}


Зареждане…
Отказ
Запис