Files
full/module/base/feedback/internal/logic/method/get.go

56 lines
1.4 KiB
Go
Raw Normal View History

// Package method 业务逻辑方法包,实现反馈相关的业务操作
package method
import (
"context"
"errors"
"bsm/full/module/base/feedback/internal/impl"
"bsm/full/module/base/feedback/internal/models"
pb "bsm/full/module/base/feedback/pb"
"git.apinb.com/bsm-sdk/core/errcode"
2026-09-22 21:15:34 +08:00
"git.apinb.com/bsm-sdk/core/service"
"gorm.io/gorm"
)
// Get 根据ID获取反馈记录详情
// ctx: 上下文
// in: 查询请求参数包含记录ID
// 返回: 反馈记录详情
func Get(ctx context.Context, in *pb.GetRequest) (reply *pb.GetReply, err error) {
2026-09-22 21:15:34 +08:00
// 解析用户认证信息
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// 验证请求参数
if in.GetIdentity() == "" {
return nil, errcode.ErrInvalidArgument
}
out := new(pb.GetReply)
record := new(models.FeedbackItem)
// 查询记录,预加载关联的图片信息
err = impl.DBService.Preload("Images").Where("identity = ?", in.GetIdentity()).First(record).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errcode.ErrRecordNotFound
}
return nil, err
}
2026-09-22 21:15:34 +08:00
// 归属校验:仅本人或管理端可查看
allowed := canAccess(auth, record.PassportIdentity)
if !allowed {
return nil, errcode.ErrPermissionDenied
}
// 转换为响应格式
2026-09-22 21:15:34 +08:00
item := convert(*record, !allowed)
out.Record = item
out.Exists = true
return out, nil
}