Dockerfile
This commit is contained in:
118
dao/data/api_interface_dao.go
Normal file
118
dao/data/api_interface_dao.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/data"
|
||||
entity "cid/model/entity/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var ApiInterface = new(apiInterfaceDao)
|
||||
|
||||
type apiInterfaceDao struct{}
|
||||
|
||||
// Insert 插入接口
|
||||
func (d *apiInterfaceDao) Insert(ctx context.Context, req *dto.CreateApiInterfaceReq) (id int64, err error) {
|
||||
var res *entity.ApiInterface
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新接口
|
||||
func (d *apiInterfaceDao) Update(ctx context.Context, req *dto.UpdateApiInterfaceReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Data(&req).OmitEmpty().Where(entity.ApiInterfaceCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除接口
|
||||
func (d *apiInterfaceDao) Delete(ctx context.Context, req *dto.DeleteApiInterfaceReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Where(entity.ApiInterfaceCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个接口
|
||||
func (d *apiInterfaceDao) GetOne(ctx context.Context, req *dto.GetApiInterfaceReq) (res *entity.ApiInterface, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Where(entity.ApiInterfaceCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取接口数量
|
||||
func (d *apiInterfaceDao) Count(ctx context.Context, req *dto.ListApiInterfaceReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取接口列表
|
||||
func (d *apiInterfaceDao) List(ctx context.Context, req *dto.ListApiInterfaceReq) (res []entity.ApiInterface, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.ApiInterfaceCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *apiInterfaceDao) buildListFilter(ctx context.Context, req *dto.ListApiInterfaceReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Model
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model.WhereLike(entity.ApiInterfaceCols.Name, "%"+req.Keyword+"%")
|
||||
model.WhereOrLike(entity.ApiInterfaceCols.Code, "%"+req.Keyword+"%")
|
||||
}
|
||||
model.Where(entity.ApiInterfaceCols.PlatformId, req.PlatformId)
|
||||
model.Where(entity.ApiInterfaceCols.Name, req.Name)
|
||||
model.Where(entity.ApiInterfaceCols.Code, req.Code)
|
||||
model.Where(entity.ApiInterfaceCols.Method, req.Method)
|
||||
model.Where(entity.ApiInterfaceCols.Status, req.Status)
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新接口状态
|
||||
func (d *apiInterfaceDao) UpdateStatus(ctx context.Context, id int64, status string) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).
|
||||
Data(map[string]interface{}{"status": status}).
|
||||
Where(entity.ApiInterfaceCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetByIds 根据ID列表获取接口列表
|
||||
func (d *apiInterfaceDao) GetByIds(ctx context.Context, ids []int64) (res []entity.ApiInterface, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).
|
||||
WhereIn(entity.ApiInterfaceCols.Id, ids).
|
||||
All()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
135
dao/data/data_fetch_log_dao.go
Normal file
135
dao/data/data_fetch_log_dao.go
Normal file
@@ -0,0 +1,135 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/data"
|
||||
entity "cid/model/entity/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
)
|
||||
|
||||
var DataFetchLog = new(dataFetchLogDao)
|
||||
|
||||
type dataFetchLogDao struct{}
|
||||
|
||||
// Insert 插入数据获取日志
|
||||
func (d *dataFetchLogDao) Insert(ctx context.Context, log *entity.DataFetchLog) (id int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).Data(&log).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新数据获取日志
|
||||
func (d *dataFetchLogDao) Update(ctx context.Context, id int64, data map[string]interface{}) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).
|
||||
Data(data).
|
||||
OmitEmpty().
|
||||
Where(entity.DataFetchLogCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个数据获取日志
|
||||
func (d *dataFetchLogDao) GetOne(ctx context.Context, req *dto.GetDataFetchLogReq) (res *entity.DataFetchLog, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).Where(entity.DataFetchLogCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取数据获取日志数量
|
||||
func (d *dataFetchLogDao) Count(ctx context.Context, req *dto.ListDataFetchLogReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取数据获取日志列表
|
||||
func (d *dataFetchLogDao) List(ctx context.Context, req *dto.ListDataFetchLogReq) (res []entity.DataFetchLog, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.DataFetchLogCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *dataFetchLogDao) buildListFilter(ctx context.Context, req *dto.ListDataFetchLogReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).Model
|
||||
model.Where(entity.DataFetchLogCols.PlatformId, req.PlatformId)
|
||||
model.Where(entity.DataFetchLogCols.InterfaceId, req.InterfaceId)
|
||||
model.Where(entity.DataFetchLogCols.RequestId, req.RequestId)
|
||||
model.Where(entity.DataFetchLogCols.Status, req.Status)
|
||||
if req.StartTime > 0 {
|
||||
model.WhereGTE(entity.DataFetchLogCols.StartTime, req.StartTime)
|
||||
}
|
||||
if req.EndTime > 0 {
|
||||
model.WhereLTE(entity.DataFetchLogCols.StartTime, req.EndTime)
|
||||
}
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// GetByRequestId 根据请求ID获取日志
|
||||
func (d *dataFetchLogDao) GetByRequestId(ctx context.Context, requestId string) (res *entity.DataFetchLog, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).
|
||||
Where(entity.DataFetchLogCols.RequestId, requestId).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新日志状态
|
||||
func (d *dataFetchLogDao) UpdateStatus(ctx context.Context, id int64, status string, endTime int64, duration int, responseData, errorMessage string) (rows int64, err error) {
|
||||
updateData := map[string]interface{}{
|
||||
"status": status,
|
||||
}
|
||||
if endTime > 0 {
|
||||
updateData["end_time"] = endTime
|
||||
}
|
||||
if duration > 0 {
|
||||
updateData["duration"] = duration
|
||||
}
|
||||
if responseData != "" {
|
||||
updateData["response_data"] = responseData
|
||||
}
|
||||
if errorMessage != "" {
|
||||
updateData["error_message"] = errorMessage
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).
|
||||
Data(updateData).
|
||||
Where(entity.DataFetchLogCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// IncrementRetryCount 增加重试次数
|
||||
func (d *dataFetchLogDao) IncrementRetryCount(ctx context.Context, id int64) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DataFetchLogTable).
|
||||
Where(entity.DataFetchLogCols.Id, id).
|
||||
Data(gdb.Raw(entity.DataFetchLogCols.RetryCount + " + 1")).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
115
dao/data/platform_dao.go
Normal file
115
dao/data/platform_dao.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/data"
|
||||
entity "cid/model/entity/data"
|
||||
"context"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var Platform = new(platformDao)
|
||||
|
||||
type platformDao struct{}
|
||||
|
||||
// Insert 插入平台
|
||||
func (d *platformDao) Insert(ctx context.Context, req *dto.CreatePlatformReq) (id int64, err error) {
|
||||
var res *entity.Platform
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新平台
|
||||
func (d *platformDao) Update(ctx context.Context, req *dto.UpdatePlatformReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Data(&req).OmitEmpty().Where(entity.PlatformCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除平台
|
||||
func (d *platformDao) Delete(ctx context.Context, req *dto.DeletePlatformReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Where(entity.PlatformCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个平台
|
||||
func (d *platformDao) GetOne(ctx context.Context, req *dto.GetPlatformReq) (res *entity.Platform, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Where(entity.PlatformCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取平台数量
|
||||
func (d *platformDao) Count(ctx context.Context, req *dto.ListPlatformReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取平台列表
|
||||
func (d *platformDao) List(ctx context.Context, req *dto.ListPlatformReq) (res []entity.Platform, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.PlatformCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *platformDao) buildListFilter(ctx context.Context, req *dto.ListPlatformReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).Model
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model.WhereLike(entity.PlatformCols.Name, "%"+req.Keyword+"%")
|
||||
}
|
||||
model.Where(entity.PlatformCols.Name, req.Name)
|
||||
model.Where(entity.PlatformCols.Type, req.Type)
|
||||
model.Where(entity.PlatformCols.Status, req.Status)
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新平台状态
|
||||
func (d *platformDao) UpdateStatus(ctx context.Context, id int64, status string) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).
|
||||
Data(map[string]interface{}{"status": status}).
|
||||
Where(entity.PlatformCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetByType 根据类型获取平台
|
||||
func (d *platformDao) GetByType(ctx context.Context, platformType string) (res *entity.Platform, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PlatformTable).
|
||||
Where(entity.PlatformCols.Type, platformType).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user