fix version 1

This commit is contained in:
2026-09-22 21:15:34 +08:00
parent 9f86366638
commit d63d7e8b3a
277 changed files with 9959 additions and 1514 deletions

View File

@@ -2,18 +2,23 @@ package basic
import (
"context"
"errors"
"time"
"bsm/full/module/social/group/internal/impl"
"bsm/full/module/social/group/internal/models"
pb "bsm/full/module/social/group/pb"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/vars"
"time"
"gorm.io/gorm"
)
// 解散群组
func Disband(ctx context.Context, in *pb.IdentRequest) (reply *pb.DataStatusReply, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
@@ -22,8 +27,37 @@ func Disband(ctx context.Context, in *pb.IdentRequest) (reply *pb.DataStatusRepl
if in.Id == 0 && in.Identity == "" {
return nil, errcode.ErrInvalidArgument
}
if in.Identity == "" {
return nil, errcode.ErrInvalidArgument
}
// TODO: add your logic code & delete this line.
// 校验群组存在,且仅群主可解散
var group models.GroupBasic
if err = impl.DBService.Where("identity=?", in.Identity).First(&group).Error; err != nil {
printer.Error(err.Error())
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errcode.ErrRecordNotFound
}
return nil, errcode.ErrDB
}
if group.PassportID != auth.ID {
return nil, errcode.ErrPermissionDenied
}
// 软删除群组及其成员记录
err = impl.DBService.Transaction(func(tx *gorm.DB) error {
if e := tx.Where("identity=?", in.Identity).Delete(&models.GroupBasic{}).Error; e != nil {
return e
}
if e := tx.Where("group_identity=?", in.Identity).Delete(&models.GroupMember{}).Error; e != nil {
return e
}
return nil
})
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.DataStatusReply{
Data: vars.OK,

View File

@@ -25,6 +25,7 @@ func Fetch(ctx context.Context, in *pb.Empty) (reply *pb.GroupsReply, err error)
}
return &pb.GroupsReply{
Total: int32(len(groups)),
Total: int32(len(groups)),
Groups: groups,
}, nil
}

View File

@@ -2,12 +2,15 @@ package basic
import (
"context"
"errors"
"bsm/full/module/social/group/internal/impl"
"bsm/full/module/social/group/internal/models"
pb "bsm/full/module/social/group/pb"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"gorm.io/gorm"
)
// 获取群组信息
@@ -17,10 +20,17 @@ func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.GroupItem, err err
if err != nil {
return nil, err
}
err = impl.DBService.Where("identity=?", in.Identity).First(&reply).Error
if err != nil {
if in.GetIdentity() == "" {
return nil, errcode.ErrInvalidArgument
}
var group models.GroupBasic
if err = impl.DBService.Where("identity=?", in.Identity).First(&group).Error; err != nil {
printer.Error(err.Error())
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errcode.ErrRecordNotFound
}
return nil, errcode.ErrDB
}
return &pb.GroupItem{}, nil
return models.ToGroupItem(&group), nil
}

View File

@@ -10,7 +10,6 @@ import (
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-sdk/core/vars"
)
@@ -20,22 +19,49 @@ func Modify(ctx context.Context, in *pb.GroupItem) (reply *pb.DataStatusReply, e
if err != nil {
return nil, err
}
record := &models.GroupBasic{
Name: in.GetName(),
Introduce: in.GetIntroduce(),
Avatar: in.GetAvatar(),
Background: in.GetBackground(),
Notice: in.GetNotice(),
EnableSearchByNumber: in.GetEnableSearchByNumber(),
EnableSearchByName: in.GetEnableSearchByName(),
if in.GetIdentity() == "" {
return nil, errcode.ErrInvalidArgument
}
record.Identity = utils.UUID()
err = impl.DBService.Where("identity=? and creator_id=?", in.Identity, auth.ID).UpdateColumns(record).Error
if err != nil {
// 校验群组存在,且操作者必须是创建者
var group models.GroupBasic
if err = impl.DBService.Where("identity=?", in.Identity).First(&group).Error; err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
return nil, errcode.ErrRecordNotFound
}
if group.PassportID != auth.ID {
return nil, errcode.ErrPermissionDenied
}
// 仅更新请求中确实提供的字段,避免零值覆盖;同时不再改写群 identity
updates := map[string]any{}
if v := in.GetName(); v != "" {
updates["name"] = v
}
if v := in.GetIntroduce(); v != "" {
updates["introduce"] = v
}
if v := in.GetAvatar(); v != "" {
updates["avatar"] = v
}
if v := in.GetBackground(); v != "" {
updates["background"] = v
}
if v := in.GetNotice(); v != "" {
updates["notice"] = v
}
// 布尔字段无法区分「未传」与「false」仅在为 true 时更新,避免误清空已有开关
if in.GetEnableSearchByNumber() {
updates["enable_search_by_number"] = true
}
if in.GetEnableSearchByName() {
updates["enable_search_by_name"] = true
}
if len(updates) > 0 {
if err = impl.DBService.Model(&models.GroupBasic{}).Where("identity=?", in.Identity).Updates(updates).Error; err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
}
return &pb.DataStatusReply{