Selaa lähdekoodia

update

master
dengbiao 4 päivää sitten
vanhempi
commit
4c43960cd0
9 muutettua tiedostoa jossa 1108 lisäystä ja 285 poistoa
  1. +1
    -1
      Dockerfile_business
  2. +1
    -1
      Dockerfile_connect
  3. +1
    -1
      Dockerfile_logic
  4. +139
    -0
      internal/business/api/business_ext.go
  5. +10
    -10
      internal/logic/domain/group/model/group_notice.go
  6. +4
    -14
      internal/logic/domain/group/model/group_notice_with_like_records.go
  7. +24
    -7
      internal/logic/domain/group/repo/group_notice_dao.go
  8. +29
    -9
      internal/logic/domain/group/repo/group_notice_with_like_records_dao.go
  9. +899
    -242
      pkg/pb/business.ext.pb.go

+ 1
- 1
Dockerfile_business Näytä tiedosto

@@ -1,6 +1,6 @@
# 多重构建,减少镜像大小
# 构建:使用golang:1.18版本
FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.18.4 as build
FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.19 as build

# 容器环境变量添加,会覆盖默认的变量值
ENV GO111MODULE=on


+ 1
- 1
Dockerfile_connect Näytä tiedosto

@@ -1,6 +1,6 @@
# 多重构建,减少镜像大小
# 构建:使用golang:1.18版本
FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.18.4 as build
FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.19 as build

# 容器环境变量添加,会覆盖默认的变量值
ENV GO111MODULE=on


+ 1
- 1
Dockerfile_logic Näytä tiedosto

@@ -1,6 +1,6 @@
# 多重构建,减少镜像大小
# 构建:使用golang:1.18版本
FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.18.4 as build
FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.19 as build

# 容器环境变量添加,会覆盖默认的变量值
ENV GO111MODULE=on


+ 139
- 0
internal/business/api/business_ext.go Näytä tiedosto

@@ -20,6 +20,145 @@ import (

type BusinessExtServer struct{}

func (s *BusinessExtServer) ViewGroupNotice(ctx context.Context, req *pb.ViewGroupNoticeReq) (*pb.ViewGroupNoticeResp, error) {
userId, _, err := grpclib.GetCtxData(ctx)
if err != nil {
return nil, err
}
groupNotice, err := repo2.GroupNoticeDao.Get(req.GroupId)
if err != nil {
return nil, err
}
if groupNotice == nil {
return &pb.ViewGroupNoticeResp{
GroupId: 0,
UserId: 0,
Content: "",
LikeNums: 0,
ReadNums: 0,
PublishType: 0,
PublishTime: "",
IsLike: false,
}, nil
}
groupNoticeWithLikeRecords, err := repo2.GroupNoticeWithLikeRecordsDao.Get(userId, req.GroupId)
if err != nil {
return nil, err
}

return &pb.ViewGroupNoticeResp{
GroupId: groupNotice.GroupId,
UserId: groupNotice.UserId,
Content: groupNotice.Content,
LikeNums: int64(groupNotice.LikeNums),
ReadNums: int64(groupNotice.ReadNums),
PublishType: pb.GroupNoticePublishType(groupNotice.PublishType),
PublishTime: groupNotice.CreateTime.Format("2006-01-02 15:04:05"),
IsLike: func() bool {
if groupNoticeWithLikeRecords == nil {
return false
}
return true
}(),
}, nil
}

func (s *BusinessExtServer) LikeGroupNotice(ctx context.Context, req *pb.LikeGroupNoticeReq) (*pb.Empty, error) {
userId, _, err := grpclib.GetCtxData(ctx)
if err != nil {
return nil, err
}
groupNoticeWithLikeRecords, err := repo2.GroupNoticeWithLikeRecordsDao.Get(userId, req.GroupId)
if err != nil {
return nil, err
}
if groupNoticeWithLikeRecords != nil {
return nil, errors.New("请勿重复点赞!")
}

groupNotice, err := repo2.GroupNoticeDao.Get(req.GroupId)
if err != nil {
return nil, err
}
if groupNotice == nil {
return nil, errors.New("群公告记录不存在!")
}

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)
}

func (s *BusinessExtServer) CancelLikeGroupNotice(ctx context.Context, req *pb.CancelLikeGroupNoticeReq) (*pb.Empty, error) {
userId, _, err := grpclib.GetCtxData(ctx)
if err != nil {
return nil, err
}
groupNoticeWithLikeRecords, err := repo2.GroupNoticeWithLikeRecordsDao.Get(userId, req.GroupId)
if err != nil {
return nil, err
}
if groupNoticeWithLikeRecords == nil {
return nil, errors.New("不存在的点赞记录!")
}

groupNotice, err := repo2.GroupNoticeDao.Get(req.GroupId)
if err != nil {
return nil, err
}
if groupNotice == nil {
return nil, errors.New("群公告记录不存在!")
}

err = repo2.GroupNoticeWithLikeRecordsDao.Delete(userId, req.GroupId)
if err != nil {
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)
}

func (s *BusinessExtServer) PublishGroupNotice(ctx context.Context, req *pb.PublishGroupNoticeReq) (*pb.Empty, error) {
now := time.Now()
userId, _, err := grpclib.GetCtxData(ctx)
if err != nil {
return nil, err
}
//1、判断是否可以进行发布群公告
groupUser, err := repo2.GroupUserRepo.Get(req.GroupId, userId)
if groupUser.MemberType == int(pb.MemberType_GMT_MEMBER) {
return nil, errors.New("普通成员不能发布群公告")
}
groupComplain := model.GroupNotice{
GroupId: req.GroupId,
UserId: userId,
PublishType: int32(req.PublishType),
Content: req.Content,
LikeNums: 0,
ReadNums: 0,
CreateTime: now,
UpdateTime: now,
}

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

func (s *BusinessExtServer) ComplainGroup(ctx context.Context, req *pb.ComplainGroupReq) (*pb.Empty, error) {
now := time.Now()
userId, _, err := grpclib.GetCtxData(ctx)


+ 10
- 10
internal/logic/domain/group/model/group_notice.go Näytä tiedosto

@@ -4,14 +4,14 @@ import (
"time"
)

type GroupComplain struct {
Id int64 // 自增主键
GroupId int64 // 群组id
UserId int64 // 用户id
ComplainType int // 投诉类型(1:存在赌博行为 2:存在骗钱行为 3:不当信息骚扰 4:传播谣言 5:发布假冒商品信息 6:侵犯未成年人权益 7:其他)
Text string // 投诉内容
ImageList string // 图片
Status int // 状态
CreateTime time.Time // 创建时间
UpdateTime time.Time // 更新时间
type GroupNotice struct {
Id int64 // 自增主键
GroupId int64 // 群组id
UserId int64 // 发布用户id
Content string // 公告内容
LikeNums int // 点赞数量
ReadNums int // 阅读数量
PublishType int32 // 发布方式(1:仅发布 2:发布并通知 3:通知并置顶)
CreateTime time.Time // 创建时间
UpdateTime time.Time // 更新时间
}

+ 4
- 14
internal/logic/domain/group/model/group_notice_with_like_records.go Näytä tiedosto

@@ -1,17 +1,7 @@
package model

import (
"time"
)

type GroupNotice struct {
Id int64 // 自增主键
GroupId int64 // 群组id
UserId int64 // 用户id
Content string // 公告内容
LikeNums int // 点赞数量
ReadNums int // 阅读数量
PublishType int32 // 发布方式(1:仅发布 2:发布并通知 3:通知并置顶)
CreateTime time.Time // 创建时间
UpdateTime time.Time // 更新时间
type GroupNoticeWithLikeRecords struct {
Id int64 // 自增主键
GroupId int64 // 群组id
UserId int64 // 点赞用户id
}

+ 24
- 7
internal/logic/domain/group/repo/group_notice_dao.go Näytä tiedosto

@@ -8,13 +8,13 @@ import (
"github.com/jinzhu/gorm"
)

type groupComplainDao struct{}
type groupNoticeDao struct{}

var GroupComplainDao = new(groupComplainDao)
var GroupNoticeDao = new(groupNoticeDao)

// Get 获取群组信息
func (*groupComplainDao) Get(id int64) (*model.GroupComplain, error) {
var group = model.GroupComplain{Id: id}
// Get 获取群组公告信息
func (*groupNoticeDao) Get(groupId int64) (*model.GroupNotice, error) {
var group = model.GroupNotice{GroupId: groupId}
err := db.DB.First(&group).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, gerrors.WrapError(err)
@@ -26,8 +26,25 @@ func (*groupComplainDao) Get(id int64) (*model.GroupComplain, error) {
}

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

//清除群组点赞记录
err = GroupNoticeWithLikeRecordsDao.Clean(groupNotice.GroupId)
if err != nil {
return err
}
}
err = db.DB.Save(&groupNotice).Error
if err != nil {
return gerrors.WrapError(err)
}


+ 29
- 9
internal/logic/domain/group/repo/group_notice_with_like_records_dao.go Näytä tiedosto

@@ -8,16 +8,16 @@ import (
"github.com/jinzhu/gorm"
)

type groupNoticeDao struct{}
type groupNoticeWithLikeRecords struct{}

var GroupNoticeDao = new(groupNoticeDao)
var GroupNoticeWithLikeRecordsDao = new(groupNoticeWithLikeRecords)

// Get 获取群组公告信息
func (*groupNoticeDao) Get(groupId int64) (*model.GroupNotice, error) {
var group = model.GroupNotice{GroupId: groupId}
err := db.DB.First(&group).Error
// Get 获取用户点赞信息
func (*groupNoticeWithLikeRecords) Get(userId, groupId int64) (*model.GroupNoticeWithLikeRecords, error) {
group := model.GroupNoticeWithLikeRecords{}
err := db.DB.First(&group, "user_id = ? and group_id = ?", userId, groupId).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, gerrors.WrapError(err)
return nil, err
}
if err == gorm.ErrRecordNotFound {
return nil, nil
@@ -26,10 +26,30 @@ func (*groupNoticeDao) Get(groupId int64) (*model.GroupNotice, error) {
}

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

// Delete 取消点赞
func (*groupNoticeWithLikeRecords) Delete(userId, groupId int64) (err error) {
group := model.GroupNoticeWithLikeRecords{}
err = gerrors.WrapError(db.DB.Where("user_id = ? and group_id = ?", userId, groupId).Delete(&group).Error)
if err != nil {
return err
}
return nil
}

// Clean 清除群组点赞记录
func (*groupNoticeWithLikeRecords) Clean(groupId int64) (err error) {
group := model.GroupNoticeWithLikeRecords{}
err = gerrors.WrapError(db.DB.Where("group_id = ?", groupId).Delete(&group).Error)
if err != nil {
return err
}
return nil
}

+ 899
- 242
pkg/pb/business.ext.pb.go
File diff suppressed because it is too large
Näytä tiedosto


Ladataan…
Peruuta
Tallenna