refactor: reorganize modules and add Linux build tooling
This commit is contained in:
75
module/base/feedback/internal/logic/method/add.go
Normal file
75
module/base/feedback/internal/logic/method/add.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Package method 业务逻辑方法包,实现反馈相关的业务操作
|
||||
package method
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/service"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// Add 添加新的反馈记录
|
||||
// ctx: 上下文,包含用户认证信息
|
||||
// in: 添加请求参数
|
||||
// 返回: 添加结果,包含新创建的记录ID
|
||||
func Add(ctx context.Context, in *pb.AddRequest) (reply *pb.AddReply, err error) {
|
||||
// 解析用户认证信息
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 构建反馈记录
|
||||
record := &models.FeedbackItem{
|
||||
Std_IICUDS: types.Std_IICUDS{
|
||||
Identity: utils.UUID(), // 生成唯一标识
|
||||
},
|
||||
Std_Passport: types.Std_Passport{
|
||||
PassportID: auth.ID, // 用户ID
|
||||
PassportIdentity: auth.Identity, // 用户身份标识
|
||||
},
|
||||
UserName: in.GetUserName(), // 用户名
|
||||
Status: in.GetStatus(), // 状态
|
||||
Email: in.GetEmail(), // 邮箱
|
||||
Phone: in.GetPhone(), // 手机号
|
||||
Title: in.GetTitle(), // 标题
|
||||
Content: in.GetContent(), // 内容
|
||||
Images: make([]models.FeedbackImage, 0, len(in.GetImages())), // 图片列表
|
||||
Accessories: make([]models.FeedbackAccessory, 0, len(in.GetAccessories())), // 附件列表
|
||||
}
|
||||
|
||||
// 处理图片信息
|
||||
for _, v := range in.GetImages() {
|
||||
record.Images = append(record.Images, models.FeedbackImage{
|
||||
Std_IICUDS: types.Std_IICUDS{
|
||||
Identity: utils.UUID(), // 生成图片唯一标识
|
||||
},
|
||||
ItemIdentity: record.Identity, // 关联的反馈记录ID
|
||||
URL: v.GetUrl(), // 图片URL
|
||||
})
|
||||
}
|
||||
|
||||
// 处理附件信息
|
||||
for _, v := range in.GetAccessories() {
|
||||
record.Accessories = append(record.Accessories, models.FeedbackAccessory{
|
||||
Std_IICUDS: types.Std_IICUDS{
|
||||
Identity: utils.UUID(), // 生成附件唯一标识
|
||||
},
|
||||
ItemIdentity: record.Identity, // 关联的反馈记录ID
|
||||
Title: v.Title, // 附件标题
|
||||
FilePath: v.FilePath, // 附件文件路径
|
||||
})
|
||||
}
|
||||
|
||||
// 保存到数据库
|
||||
err = impl.DBService.Create(record).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.AddReply{Identity: record.Identity}, nil
|
||||
}
|
||||
35
module/base/feedback/internal/logic/method/delete.go
Normal file
35
module/base/feedback/internal/logic/method/delete.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Package method 业务逻辑方法包,实现反馈相关的业务操作
|
||||
package method
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"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/vars"
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
)
|
||||
|
||||
// Delete 删除反馈记录
|
||||
// ctx: 上下文
|
||||
// in: 删除请求参数,包含记录ID
|
||||
// 返回: 删除操作结果
|
||||
func Delete(ctx context.Context, in *pb.DeleteRequest) (reply *pb.StatusReply, err error) {
|
||||
// 验证请求参数
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, exception.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 删除记录(GORM会自动处理关联的图片和附件删除)
|
||||
err = impl.DBService.Where("identity = ?", in.GetIdentity()).Delete(new(models.FeedbackItem)).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Message: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
}
|
||||
42
module/base/feedback/internal/logic/method/get.go
Normal file
42
module/base/feedback/internal/logic/method/get.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// 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/engine/exception"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Get 根据ID获取反馈记录详情
|
||||
// ctx: 上下文
|
||||
// in: 查询请求参数,包含记录ID
|
||||
// 返回: 反馈记录详情
|
||||
func Get(ctx context.Context, in *pb.GetRequest) (reply *pb.GetReply, err error) {
|
||||
// 验证请求参数
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, exception.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, exception.ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 转换为响应格式
|
||||
item := convert(*record)
|
||||
out.Record = item
|
||||
out.Exists = true
|
||||
return out, nil
|
||||
}
|
||||
87
module/base/feedback/internal/logic/method/list.go
Normal file
87
module/base/feedback/internal/logic/method/list.go
Normal file
@@ -0,0 +1,87 @@
|
||||
// Package method 业务逻辑方法包,实现反馈相关的业务操作
|
||||
package method
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/service"
|
||||
)
|
||||
|
||||
// List 获取反馈记录列表
|
||||
// ctx: 上下文,包含用户认证信息
|
||||
// in: 查询请求参数,包含分页、筛选条件等
|
||||
// 返回: 反馈记录列表和总数
|
||||
func List(ctx context.Context, in *pb.ListRequest) (reply *pb.ListReply, err error) {
|
||||
// 解析用户认证信息
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 分页参数校验和设置
|
||||
if in.GetPage() < 1 {
|
||||
in.Page = 1
|
||||
}
|
||||
size := in.GetSize()
|
||||
if size < 1 || size > 50 {
|
||||
in.Size = 10
|
||||
}
|
||||
offset := (in.Page - 1) * in.GetSize()
|
||||
|
||||
// 构建查询会话,预加载图片信息
|
||||
sess := impl.DBService.Preload("Images")
|
||||
|
||||
// 根据机构筛选或用户身份筛选
|
||||
if in.GetAgency() != "" {
|
||||
sess = sess.Where("agency = ?", in.GetAgency())
|
||||
} else {
|
||||
userIdentity := auth.Identity
|
||||
if userIdentity != "" {
|
||||
sess = sess.Where("passport_identity = ?", userIdentity)
|
||||
}
|
||||
}
|
||||
|
||||
// 用户名筛选
|
||||
username := in.GetUserName()
|
||||
if username != "" {
|
||||
sess = sess.Where("username = ?", username)
|
||||
}
|
||||
|
||||
// 状态筛选
|
||||
status := in.GetStatus()
|
||||
if status != 0 {
|
||||
sess = sess.Where("status = ?", status)
|
||||
}
|
||||
|
||||
// 分类筛选
|
||||
category := in.GetCategory()
|
||||
if category != "" {
|
||||
sess = sess.Where("category = ?", category)
|
||||
}
|
||||
|
||||
var (
|
||||
list []models.FeedbackItem
|
||||
count int64
|
||||
)
|
||||
|
||||
// 执行查询,按创建时间倒序排列
|
||||
if err := sess.Limit(int(in.GetSize())).Offset(int(offset)).Order("created_at desc").Find(&list).Count(&count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 构建响应结果
|
||||
out := &pb.ListReply{
|
||||
Count: count,
|
||||
List: make([]*pb.FeedbackItem, 0, len(list)),
|
||||
}
|
||||
|
||||
// 转换数据格式
|
||||
for _, v := range list {
|
||||
item := convert(v)
|
||||
out.List = append(out.List, item)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
112
module/base/feedback/internal/logic/method/modify.go
Normal file
112
module/base/feedback/internal/logic/method/modify.go
Normal file
@@ -0,0 +1,112 @@
|
||||
// Package method 业务逻辑方法包,实现反馈相关的业务操作
|
||||
package method
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"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/service"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
)
|
||||
|
||||
// Modify 修改反馈记录
|
||||
// ctx: 上下文,包含用户认证信息
|
||||
// in: 修改请求参数,包含记录ID和要修改的字段
|
||||
// 返回: 修改操作结果
|
||||
func Modify(ctx context.Context, in *pb.ModifyRequest) (reply *pb.StatusReply, err error) {
|
||||
// 解析用户认证信息
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 验证请求参数
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, exception.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 构建更新记录
|
||||
record := &models.FeedbackItem{
|
||||
Std_IICUDS: types.Std_IICUDS{
|
||||
Identity: utils.UUID(),
|
||||
},
|
||||
Std_Passport: types.Std_Passport{
|
||||
PassportID: auth.ID, // 用户ID
|
||||
PassportIdentity: auth.Identity, // 用户身份标识
|
||||
},
|
||||
UserName: in.GetUserName(), // 用户名
|
||||
Email: in.GetEmail(), // 邮箱
|
||||
Phone: in.GetPhone(), // 手机号
|
||||
Status: in.GetStatus(), // 状态
|
||||
Title: in.GetTitle(), // 标题
|
||||
Content: in.GetContent(), // 内容
|
||||
Category: in.GetCategory(), // 分类
|
||||
Images: make([]models.FeedbackImage, 0, len(in.GetImages())), // 图片列表
|
||||
Accessories: make([]models.FeedbackAccessory, 0, len(in.GetAccessories())), // 附件列表
|
||||
}
|
||||
|
||||
// 处理图片信息
|
||||
for _, v := range in.GetImages() {
|
||||
identity := v.GetIdentity()
|
||||
if identity == "" {
|
||||
identity = utils.UUID() // 生成新的图片ID
|
||||
}
|
||||
record.Images = append(record.Images, models.FeedbackImage{
|
||||
Std_IICUDS: types.Std_IICUDS{
|
||||
Identity: identity,
|
||||
},
|
||||
ItemIdentity: in.GetIdentity(), // 关联的反馈记录ID
|
||||
URL: v.GetUrl(), // 图片URL
|
||||
})
|
||||
}
|
||||
|
||||
// 处理附件信息
|
||||
for _, v := range in.GetAccessories() {
|
||||
record.Accessories = append(record.Accessories, models.FeedbackAccessory{
|
||||
ItemIdentity: in.GetIdentity(), // 关联的反馈记录ID
|
||||
Title: v.Title, // 附件标题
|
||||
FilePath: v.FilePath, // 附件文件路径
|
||||
})
|
||||
}
|
||||
|
||||
// 先删除关联的图片和附件
|
||||
err = impl.DBService.Where("item_identity = ?", in.GetIdentity()).Delete(&models.FeedbackImage{}).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = impl.DBService.Where("item_identity = ?", in.GetIdentity()).Delete(&models.FeedbackAccessory{}).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 更新主记录
|
||||
err = impl.DBService.Where("identity = ?", in.GetIdentity()).Updates(record).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 重新创建关联的图片和附件
|
||||
if len(record.Images) > 0 {
|
||||
err = impl.DBService.Create(&record.Images).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if len(record.Accessories) > 0 {
|
||||
err = impl.DBService.Create(&record.Accessories).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Message: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
}
|
||||
48
module/base/feedback/internal/logic/method/ref.go
Normal file
48
module/base/feedback/internal/logic/method/ref.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// Package method 业务逻辑方法包,实现反馈相关的业务操作
|
||||
package method
|
||||
|
||||
import (
|
||||
"bsm/full/module/base/feedback/internal/models"
|
||||
pb "bsm/full/module/base/feedback/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
// convert 将数据库模型转换为protobuf响应格式
|
||||
// item: 数据库中的反馈记录模型
|
||||
// 返回: protobuf格式的反馈记录指针
|
||||
func convert(item models.FeedbackItem) *pb.FeedbackItem {
|
||||
reply := &pb.FeedbackItem{
|
||||
Identity: item.Identity, // 记录唯一标识
|
||||
UserName: item.UserName, // 用户名
|
||||
Email: item.Email, // 邮箱
|
||||
Phone: item.Phone, // 手机号
|
||||
Status: item.Status, // 状态
|
||||
Title: item.Title, // 标题
|
||||
Content: item.Content, // 内容
|
||||
Remark: item.Remark, // 备注
|
||||
Category: item.Category, // 分类
|
||||
CreatedAt: item.CreatedAt.Format(vars.YYYY_MM_DD_HH_MM_SS), // 创建时间
|
||||
UpdatedAt: item.UpdatedAt.Format(vars.YYYY_MM_DD_HH_MM_SS), // 更新时间
|
||||
}
|
||||
|
||||
// 转换图片信息
|
||||
for _, image := range item.Images {
|
||||
reply.Images = append(reply.Images, &pb.FeedbackImage{
|
||||
Identity: image.Identity, // 图片唯一标识
|
||||
ItemIdentity: image.ItemIdentity, // 关联的反馈记录ID
|
||||
Url: image.URL, // 图片URL
|
||||
})
|
||||
}
|
||||
|
||||
// 转换附件信息
|
||||
for _, accessory := range item.Accessories {
|
||||
reply.Accessories = append(reply.Accessories, &pb.FeedbackAccessory{
|
||||
Identity: accessory.Identity, // 附件唯一标识
|
||||
ItemIdentity: accessory.ItemIdentity, // 关联的反馈记录ID
|
||||
Title: accessory.Title, // 附件标题
|
||||
FilePath: accessory.FilePath, // 附件文件路径
|
||||
})
|
||||
}
|
||||
|
||||
return reply
|
||||
}
|
||||
41
module/base/feedback/internal/logic/method/remark.go
Normal file
41
module/base/feedback/internal/logic/method/remark.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Package method 业务逻辑方法包,实现反馈相关的业务操作
|
||||
package method
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"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/vars"
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
)
|
||||
|
||||
// Remark 添加或更新反馈记录的备注和状态
|
||||
// ctx: 上下文
|
||||
// in: 备注请求参数,包含记录ID、备注内容和状态
|
||||
// 返回: 操作结果
|
||||
func Remark(ctx context.Context, in *pb.RemarkRequest) (reply *pb.StatusReply, err error) {
|
||||
// 验证请求参数
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, exception.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 构建更新记录
|
||||
record := &models.FeedbackItem{
|
||||
Remark: in.GetRemark(), // 备注内容
|
||||
Status: in.GetStatus(), // 状态
|
||||
}
|
||||
|
||||
// 更新记录的备注和状态
|
||||
err = impl.DBService.Where("identity = ?", in.GetIdentity()).Updates(record).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Message: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user