Compare commits

...

7 Commits

Author SHA1 Message Date
alick-liming
4cd40716b6 fix: postgres bool int 2023-08-24 19:32:36 +08:00
alick-liming
10d7be26ca Merge branch 'main' of github.com:ccfos/nightingale into lm_main 2023-08-24 17:06:50 +08:00
alick-liming
1bfd55969e Merge branch 'main' of github.com:ccfos/nightingale into lm_main 2023-08-24 14:51:37 +08:00
alick-liming
7ee4811720 Merge branch 'main' of github.com:ccfos/nightingale into lm_main 2023-08-19 21:26:04 +08:00
alick-liming
5e0328ce65 Merge branch 'main' of github.com:ccfos/nightingale into lm_main 2023-08-16 07:27:51 +08:00
alick-liming
69ff3fc3eb Merge branch 'main' of github.com:ccfos/nightingale into lm_main 2023-08-02 11:22:16 +08:00
alick-liming
c86ac06e9a fix: post err process 2023-08-01 11:52:49 +08:00
2 changed files with 80 additions and 14 deletions

View File

@@ -11,7 +11,7 @@ import (
// 创建 ES Index Pattern
func (rt *Router) esIndexPatternAdd(c *gin.Context) {
var f models.EsIndexPattern
var f models.EsIndexPatternFe
ginx.BindJSON(c, &f)
username := c.MustGet("username").(string)
@@ -27,7 +27,7 @@ func (rt *Router) esIndexPatternAdd(c *gin.Context) {
// 更新 ES Index Pattern
func (rt *Router) esIndexPatternPut(c *gin.Context) {
var f models.EsIndexPattern
var f models.EsIndexPatternFe
ginx.BindJSON(c, &f)
id := ginx.QueryInt64(c, "id")
@@ -40,7 +40,8 @@ func (rt *Router) esIndexPatternPut(c *gin.Context) {
return
}
f.UpdateBy = c.MustGet("username").(string)
// f.UpdateBy = c.MustGet("username").(string)
ginx.NewRender(c).Message(esIndexPattern.Update(rt.Ctx, f))
}
@@ -60,7 +61,7 @@ func (rt *Router) esIndexPatternDel(c *gin.Context) {
func (rt *Router) esIndexPatternGetList(c *gin.Context) {
datasourceId := ginx.QueryInt64(c, "datasource_id", 0)
var lst []*models.EsIndexPattern
var lst []*models.EsIndexPatternFe
var err error
if datasourceId != 0 {
lst, err = models.EsIndexPatternGets(rt.Ctx, "datasource_id = ?", datasourceId)

View File

@@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
)
type EsIndexPattern struct {
type EsIndexPatternFe struct {
Id int64 `json:"id" gorm:"primaryKey"`
DatasourceId int64 `json:"datasource_id"`
Name string `json:"name"`
@@ -21,11 +21,24 @@ type EsIndexPattern struct {
UpdateBy string `json:"update_by"`
}
type EsIndexPattern struct {
Id int64 `json:"id" gorm:"primaryKey"`
DatasourceId int64 `json:"datasource_id"`
Name string `json:"name"`
TimeField string `json:"time_field"`
AllowHideSystemIndices int `json:"allow_hide_system_indices"`
FieldsFormat string `json:"fields_format"`
CreateAt int64 `json:"create_at"`
CreateBy string `json:"create_by"`
UpdateAt int64 `json:"update_at"`
UpdateBy string `json:"update_by"`
}
func (t *EsIndexPattern) TableName() string {
return "es_index_pattern"
}
func (r *EsIndexPattern) Add(ctx *ctx.Context) error {
func (r *EsIndexPatternFe) Add(ctx *ctx.Context) error {
esIndexPattern, err := EsIndexPatternGet(ctx, "datasource_id = ? and name = ?", r.DatasourceId, r.Name)
if err != nil {
return errors.WithMessage(err, "failed to query es index pattern")
@@ -35,7 +48,9 @@ func (r *EsIndexPattern) Add(ctx *ctx.Context) error {
return errors.New("es index pattern datasource and name already exists")
}
return DB(ctx).Create(r).Error
dbIndexPattern := r.FE2DB()
return DB(ctx).Create(dbIndexPattern).Error
}
func EsIndexPatternDel(ctx *ctx.Context, ids []int64) error {
@@ -45,7 +60,7 @@ func EsIndexPatternDel(ctx *ctx.Context, ids []int64) error {
return DB(ctx).Where("id in ?", ids).Delete(new(EsIndexPattern)).Error
}
func (ei *EsIndexPattern) Update(ctx *ctx.Context, eip EsIndexPattern) error {
func (ei *EsIndexPatternFe) Update(ctx *ctx.Context, eip EsIndexPatternFe) error {
if ei.Name != eip.Name || ei.DatasourceId != eip.DatasourceId {
exists, err := EsIndexPatternExists(ctx, ei.Id, eip.DatasourceId, eip.Name)
if err != nil {
@@ -62,19 +77,69 @@ func (ei *EsIndexPattern) Update(ctx *ctx.Context, eip EsIndexPattern) error {
eip.CreateBy = ei.CreateBy
eip.UpdateAt = time.Now().Unix()
return DB(ctx).Model(ei).Select("*").Updates(eip).Error
dbIndexPattern := eip.FE2DB()
return DB(ctx).Model(dbIndexPattern).Select("*").Updates(dbIndexPattern).Error
}
func EsIndexPatternGets(ctx *ctx.Context, where string, args ...interface{}) ([]*EsIndexPattern, error) {
func (dbIndexPatten *EsIndexPattern) DB2FE() *EsIndexPatternFe {
feIndexPattern := new(EsIndexPatternFe)
feIndexPattern.Id = dbIndexPatten.Id
feIndexPattern.DatasourceId = dbIndexPatten.DatasourceId
feIndexPattern.Name = dbIndexPatten.Name
feIndexPattern.TimeField = dbIndexPatten.TimeField
allowHideSystemIndices := false
if dbIndexPatten.AllowHideSystemIndices != 0 {
allowHideSystemIndices = true
}
feIndexPattern.AllowHideSystemIndices = allowHideSystemIndices
feIndexPattern.FieldsFormat = dbIndexPatten.FieldsFormat
feIndexPattern.CreateAt = dbIndexPatten.CreateAt
feIndexPattern.UpdateAt = dbIndexPatten.UpdateAt
feIndexPattern.UpdateBy = dbIndexPatten.UpdateBy
return feIndexPattern
}
func (feIndexPatten *EsIndexPatternFe) FE2DB() *EsIndexPattern {
dbIndexPattern := new(EsIndexPattern)
dbIndexPattern.Id = feIndexPatten.Id
dbIndexPattern.DatasourceId = feIndexPatten.DatasourceId
dbIndexPattern.Name = feIndexPatten.Name
dbIndexPattern.TimeField = feIndexPatten.TimeField
allowHideSystemIndices := 0
if !feIndexPatten.AllowHideSystemIndices {
allowHideSystemIndices = 1
}
dbIndexPattern.AllowHideSystemIndices = allowHideSystemIndices
dbIndexPattern.FieldsFormat = feIndexPatten.FieldsFormat
dbIndexPattern.CreateAt = feIndexPatten.CreateAt
dbIndexPattern.UpdateAt = feIndexPatten.UpdateAt
dbIndexPattern.UpdateBy = feIndexPatten.UpdateBy
return dbIndexPattern
}
func EsIndexPatternGets(ctx *ctx.Context, where string, args ...interface{}) ([]*EsIndexPatternFe, error) {
var objs []*EsIndexPattern
err := DB(ctx).Where(where, args...).Find(&objs).Error
if err != nil {
return nil, errors.WithMessage(err, "failed to query es index pattern")
}
return objs, nil
var finals []*EsIndexPatternFe
for _, i := range objs {
dbIndexPattern := i.DB2FE()
finals = append(finals, dbIndexPattern)
}
return finals, nil
}
func EsIndexPatternGet(ctx *ctx.Context, where string, args ...interface{}) (*EsIndexPattern, error) {
func EsIndexPatternGet(ctx *ctx.Context, where string, args ...interface{}) (*EsIndexPatternFe, error) {
var lst []*EsIndexPattern
err := DB(ctx).Where(where, args...).Find(&lst).Error
if err != nil {
@@ -85,10 +150,10 @@ func EsIndexPatternGet(ctx *ctx.Context, where string, args ...interface{}) (*Es
return nil, nil
}
return lst[0], nil
return lst[0].DB2FE(), nil
}
func EsIndexPatternGetById(ctx *ctx.Context, id int64) (*EsIndexPattern, error) {
func EsIndexPatternGetById(ctx *ctx.Context, id int64) (*EsIndexPatternFe, error) {
return EsIndexPatternGet(ctx, "id=?", id)
}