refactor: reorganize modules and add Linux build tooling
This commit is contained in:
45
module/base/feedback/internal/config/config.go
Normal file
45
module/base/feedback/internal/config/config.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// Package config 配置管理包,负责服务的配置初始化和管理
|
||||
package config
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
"git.apinb.com/bsm-sdk/core/crypto/encipher"
|
||||
"git.apinb.com/bsm-sdk/core/env"
|
||||
)
|
||||
|
||||
var (
|
||||
Spec SrvConfig // 全局服务配置实例
|
||||
)
|
||||
|
||||
// SrvConfig 服务配置结构体
|
||||
type SrvConfig struct {
|
||||
conf.Base `yaml:",inline"` // 基础配置
|
||||
Databases *conf.DBConf `yaml:"Databases"` // 数据库配置
|
||||
MicroService *conf.MicroServiceConf `yaml:"MicroService"` // 微服务配置
|
||||
Rpc map[string]conf.RpcConf `yaml:"Rpc"` // RPC配置
|
||||
Gateway *conf.GatewayConf `yaml:"Gateway"` // 网关配置
|
||||
Apm *conf.ApmConf `yaml:"APM"` // APM监控配置
|
||||
Etcd *conf.EtcdConf `yaml:"Etcd"` // Etcd配置
|
||||
}
|
||||
|
||||
// New 初始化服务配置
|
||||
// srvKey: 服务标识符,用于配置文件的命名
|
||||
func New(srvKey string) {
|
||||
// 初始化配置 创建一个新的配置实例,用于服务配置
|
||||
conf.New(srvKey, &Spec)
|
||||
|
||||
// 配置校验 服务IP,端口; 端口如果不合规,则随机分配端口
|
||||
Spec.Port = conf.CheckPort(Spec.Port)
|
||||
Spec.BindIP = conf.CheckIP(Spec.BindIP)
|
||||
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
|
||||
|
||||
// 配置校验 服务名称地址及监听地址不能为空
|
||||
conf.NotNil(Spec.Service, Spec.Cache)
|
||||
|
||||
// 初始化加密SecretKey
|
||||
encipher.New(env.Runtime.JwtSecretKey)
|
||||
|
||||
conf.PrintInfo(Spec.Addr)
|
||||
}
|
||||
31
module/base/feedback/internal/impl/impl.go
Normal file
31
module/base/feedback/internal/impl/impl.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Package impl 实现层,负责初始化各种服务连接
|
||||
package impl
|
||||
|
||||
import (
|
||||
"bsm/full/module/base/feedback/internal/config"
|
||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||
"git.apinb.com/bsm-sdk/core/with"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
RedisService *redis.RedisClient // Redis缓存服务
|
||||
EtcdService *clientv3.Client // Etcd服务发现客户端
|
||||
DBService *gorm.DB // 数据库服务
|
||||
MemorySerice *cache.Cache // 内存缓存服务
|
||||
)
|
||||
|
||||
// NewImpl 初始化各种服务连接
|
||||
// 包括内存缓存、Redis缓存、数据库连接和Etcd服务发现
|
||||
func NewImpl() {
|
||||
// 初始化内存缓存服务
|
||||
MemorySerice = with.Memory(nil)
|
||||
// 初始化Redis缓存服务
|
||||
RedisService = with.RedisCache(config.Spec.Cache)
|
||||
// 初始化数据库连接
|
||||
DBService = with.Databases(config.Spec.Databases, nil)
|
||||
// 初始化Etcd服务发现客户端
|
||||
EtcdService = with.Etcd(config.Spec.Etcd)
|
||||
}
|
||||
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
|
||||
}
|
||||
26
module/base/feedback/internal/models/feedback_accessory.go
Normal file
26
module/base/feedback/internal/models/feedback_accessory.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Package models 数据模型包,定义反馈相关的数据库模型
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// FeedbackAccessory 反馈附件模型
|
||||
// 用于存储反馈记录关联的附件信息
|
||||
type FeedbackAccessory struct {
|
||||
types.Std_IICUDS // 标准IICUDS字段(ID、Identity、CreatedAt、UpdatedAt、Status)
|
||||
ItemIdentity string `gorm:"column:item_identity;type:varchar(36);default:'';" json:"item_identity"` // 关联的反馈记录ID
|
||||
Title string `gorm:"column:title;type:varchar(255);default:''" json:"title"` // 附件标题
|
||||
FilePath string `gorm:"column:file_path;type:varchar(500);not null" json:"file_path"` // 附件文件地址
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 注册模型到数据库迁移表
|
||||
database.MigrateTables = append(database.MigrateTables, &FeedbackAccessory{})
|
||||
}
|
||||
|
||||
// TableName 返回数据库表名
|
||||
func (c *FeedbackAccessory) TableName() string {
|
||||
return "feedback_accessory" // 对应数据库表名
|
||||
}
|
||||
25
module/base/feedback/internal/models/feedback_images.go
Normal file
25
module/base/feedback/internal/models/feedback_images.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Package models 数据模型包,定义反馈相关的数据库模型
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// FeedbackImage 反馈图片模型
|
||||
// 用于存储反馈记录关联的图片信息
|
||||
type FeedbackImage struct {
|
||||
types.Std_IICUDS // 标准IICUDS字段(ID、Identity、CreatedAt、UpdatedAt、Status)
|
||||
ItemIdentity string `gorm:"column:item_identity;type:varchar(36);default:'';" json:"item_identity"` // 关联的反馈记录ID
|
||||
URL string `gorm:"column:url;type:varchar(255);default:'';" json:"url"` // 图片URL地址
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 注册模型到数据库迁移表
|
||||
database.MigrateTables = append(database.MigrateTables, &FeedbackImage{})
|
||||
}
|
||||
|
||||
// TableName 返回数据库表名
|
||||
func (FeedbackImage) TableName() string {
|
||||
return "feedback_images" // 对应数据库表名
|
||||
}
|
||||
35
module/base/feedback/internal/models/feedback_item.go
Normal file
35
module/base/feedback/internal/models/feedback_item.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Package models 数据模型包,定义反馈相关的数据库模型
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// FeedbackItem 反馈记录模型
|
||||
// 用于存储用户反馈的基本信息和关联数据
|
||||
type FeedbackItem struct {
|
||||
types.Std_IICUDS // 标准IICUDS字段(ID、Identity、CreatedAt、UpdatedAt、Status)
|
||||
types.Std_Passport // 标准Passport字段(用户身份信息)
|
||||
Category string `gorm:"column:category;type:varchar(255);default:'';" json:"category"` // 分类
|
||||
UserName string `gorm:"column:user_name;type:varchar(20);default:'';" json:"user_name"` // 用户名
|
||||
Email string `gorm:"column:email;type:varchar(255);default:'';" json:"email"` // 邮箱
|
||||
Phone string `gorm:"column:phone;type:varchar(20);default:'';" json:"phone"` // 手机号码
|
||||
Status int32 `gorm:"column:status;default:1;" json:"status"` // 状态,1未处理,2已处理,也可以调用方自行设置,如果未设置则默认是1
|
||||
Title string `gorm:"column:title;type:varchar(255);default:'';" json:"title"` // 标题
|
||||
Content string `gorm:"column:content;type:varchar(500);" json:"content"` // 内容
|
||||
Remark string `gorm:"column:remark;type:varchar(500);" json:"remark"` // 备注
|
||||
Agency string `gorm:"column:agency;type:varchar(255);default:'';" json:"agency"` // 机构
|
||||
Images []FeedbackImage `gorm:"foreignKey:ItemIdentity;references:Identity" json:"images"` // 图片列表
|
||||
Accessories []FeedbackAccessory `gorm:"foreignKey:ItemIdentity;references:Identity" json:"accessories"` // 附件列表
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 注册模型到数据库迁移表
|
||||
database.MigrateTables = append(database.MigrateTables, &FeedbackItem{})
|
||||
}
|
||||
|
||||
// TableName 返回数据库表名
|
||||
func (FeedbackItem) TableName() string {
|
||||
return "feedback_item" // 对应数据库表名
|
||||
}
|
||||
40
module/base/feedback/internal/server/method_server.go
Normal file
40
module/base/feedback/internal/server/method_server.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/base/feedback/internal/logic/method"
|
||||
pb "bsm/full/module/base/feedback/pb"
|
||||
)
|
||||
|
||||
type MethodServer struct {
|
||||
pb.UnimplementedMethodServer
|
||||
}
|
||||
|
||||
func NewMethodServer() *MethodServer {
|
||||
return &MethodServer{}
|
||||
}
|
||||
|
||||
func (s *MethodServer) List(ctx context.Context, in *pb.ListRequest) (*pb.ListReply, error) {
|
||||
return method.List(ctx, in)
|
||||
}
|
||||
|
||||
func (s *MethodServer) Get(ctx context.Context, in *pb.GetRequest) (*pb.GetReply, error) {
|
||||
return method.Get(ctx, in)
|
||||
}
|
||||
|
||||
func (s *MethodServer) Add(ctx context.Context, in *pb.AddRequest) (*pb.AddReply, error) {
|
||||
return method.Add(ctx, in)
|
||||
}
|
||||
|
||||
func (s *MethodServer) Modify(ctx context.Context, in *pb.ModifyRequest) (*pb.StatusReply, error) {
|
||||
return method.Modify(ctx, in)
|
||||
}
|
||||
|
||||
func (s *MethodServer) Delete(ctx context.Context, in *pb.DeleteRequest) (*pb.StatusReply, error) {
|
||||
return method.Delete(ctx, in)
|
||||
}
|
||||
|
||||
func (s *MethodServer) Remark(ctx context.Context, in *pb.RemarkRequest) (*pb.StatusReply, error) {
|
||||
return method.Remark(ctx, in)
|
||||
}
|
||||
91
module/base/feedback/internal/server/new.go
Normal file
91
module/base/feedback/internal/server/new.go
Normal file
@@ -0,0 +1,91 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "bsm/full/module/base/feedback/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Grpc *grpc.Server
|
||||
Ctx context.Context
|
||||
Mux *gwRuntime.ServeMux
|
||||
grpcConns map[string]*grpc.ClientConn // 连接池
|
||||
}
|
||||
|
||||
func New(addr string) *Server {
|
||||
srv := &Server{
|
||||
Ctx: context.Background(),
|
||||
Grpc: grpc.NewServer(),
|
||||
Mux: gwRuntime.NewServeMux(gwRuntime.WithForwardResponseRewriter(responseEnvelope)),
|
||||
grpcConns: make(map[string]*grpc.ClientConn),
|
||||
}
|
||||
|
||||
// register service to grpc.Server
|
||||
pb.RegisterMethodServer(srv.Grpc, NewMethodServer())
|
||||
|
||||
reflection.Register(srv.Grpc)
|
||||
|
||||
// 连接池: 只创建一次连接并复用
|
||||
conn, ok := srv.grpcConns[addr]
|
||||
if !ok {
|
||||
var err error
|
||||
conn, err = grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
panic("failed to dial grpc server: " + err.Error())
|
||||
}
|
||||
srv.grpcConns[addr] = conn
|
||||
}
|
||||
|
||||
// 将服务注册到Gateway
|
||||
|
||||
if err := pb.RegisterMethodHandler(srv.Ctx, srv.Mux, conn); err != nil {
|
||||
panic("Failed to register Method handler: " + err.Error())
|
||||
}
|
||||
|
||||
// Register services swagger
|
||||
srv.RegisterSwagger()
|
||||
|
||||
return srv
|
||||
}
|
||||
|
||||
// RegisterSwagger 注册swagger
|
||||
func (s *Server) RegisterSwagger() {
|
||||
srvKey := strings.ToLower(vars.ServiceKey)
|
||||
s.Mux.HandlePath("GET", "/"+srvKey+".swagger.json", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
bytes, err := os.ReadFile("./swagger/" + srvKey + ".swagger.json")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.Write(bytes)
|
||||
return
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// response envelope
|
||||
func responseEnvelope(_ context.Context, response proto.Message) (interface{}, error) {
|
||||
name := string(response.ProtoReflect().Descriptor().Name())
|
||||
if name == "Status" || name == "Error" || name == "StatusReply" {
|
||||
return response, nil
|
||||
}
|
||||
return map[string]any{
|
||||
"code": 0,
|
||||
"message": vars.OK,
|
||||
"details": response,
|
||||
"timeseq": time.Now().Unix(),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user