1
This commit is contained in:
69
service/data_service.go
Normal file
69
service/data_service.go
Normal file
@@ -0,0 +1,69 @@
|
||||
// Package service - 对话数据服务
|
||||
// 功能:对话记录查询、导出Excel
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"customer-server/dao"
|
||||
"customer-server/model/dto"
|
||||
"customer-server/model/entity"
|
||||
|
||||
"gitea.com/red-future/common/utils"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
var Data = new(data)
|
||||
|
||||
type data struct{}
|
||||
|
||||
// Add 添加数据
|
||||
// 参数: ctx - 上下文,req - 添加数据请求
|
||||
// 返回: res - 添加成功后的数据ID,err - 错误信息
|
||||
// 功能: 创建新的数据记录
|
||||
func (s *data) Add(ctx context.Context, req *dto.AddDataReq) (res *dto.AddDataRes, err error) {
|
||||
data := &entity.Data{}
|
||||
if err = utils.Struct(req, data); err != nil {
|
||||
return
|
||||
}
|
||||
// 设置基础字段
|
||||
now := gtime.Now().Time
|
||||
data.CreatedAt = &now // 取地址赋值给指针类型
|
||||
data.UpdatedAt = &now // 取地址赋值给指针类型
|
||||
data.IsDeleted = false
|
||||
// 注意:Creator、Updater、TenantId 保持零值,不设置
|
||||
|
||||
if err = dao.Data.Insert(ctx, data); err != nil {
|
||||
return
|
||||
}
|
||||
res = &dto.AddDataRes{Id: data.Id.Hex()}
|
||||
return
|
||||
}
|
||||
|
||||
// Update 更新数据
|
||||
// 参数: ctx - 上下文,req - 更新数据请求
|
||||
// 返回: err - 错误信息
|
||||
// 功能: 更新数据记录内容
|
||||
func (s *data) Update(ctx context.Context, req *dto.UpdateDataReq) (err error) {
|
||||
return dao.Data.Update(ctx, req)
|
||||
}
|
||||
|
||||
// // Delete 删除数据
|
||||
// func (s *data) Delete(ctx context.Context, req *dto.DeleteDataReq) (err error) {
|
||||
// return dao.Data.Delete(ctx, req)
|
||||
// }
|
||||
|
||||
// List 获取数据列表
|
||||
// 参数: ctx - 上下文,req - 列表查询请求
|
||||
// 返回: res - 数据列表及分页信息,err - 错误信息
|
||||
// 功能: 分页查询数据记录
|
||||
func (s *data) List(ctx context.Context, req *dto.ListDataReq) (res *dto.ListDataRes, err error) {
|
||||
list, total, err := dao.Data.List(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = &dto.ListDataRes{
|
||||
List: list,
|
||||
Total: int(total),
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user