123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package service
- import (
- "errors"
- "time"
- "github.com/go-admin-team/go-admin-core/sdk/service"
- "gorm.io/gorm"
- "go-admin/app/admin/models"
- "go-admin/app/admin/service/dto"
- "go-admin/common/actions"
- cDto "go-admin/common/dto"
- )
- type OtFireEvents struct {
- service.Service
- }
- // GetPage 获取OtFireEvents列表
- func (e *OtFireEvents) GetPage(c *dto.OtFireEventsGetPageReq, p *actions.DataPermission, list *[]models.OtFireEvents, count *int64) error {
- var err error
- var data models.OtFireEvents
- c.CheckFilling(time.Hour)
- start, end := time.Unix(c.StartTime, 0).Format(time.DateTime), time.Unix(c.EndTime, 0).Format(time.DateTime)
- db := e.Orm.Model(&data).
- Scopes(
- // cDto.MakeCondition(c.GetNeedSearch()),
- cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
- // actions.Permission(data.TableName(), p),
- ).
- Where("is_know = 0 AND is_resolve = 0 AND is_ignore = 0").
- Where("created_at>=? and created_at<?", start, end)
- if c.AppAlias != "" {
- db.Where("app_alias=?", c.AppAlias)
- }
- if c.RuleId > 0 {
- db.Where("rule_id=?", c.RuleId)
- }
- if c.AlertStatus > 0 {
- db.Where("alert_status=?", c.AlertStatus)
- }
- if c.ExceptionName != "" {
- db.Where("exception_name", c.ExceptionName)
- }
- err = db.Order("append_time DESC").Find(list).Limit(-1).Offset(-1).
- Count(count).Error
- if err != nil {
- e.Log.Errorf("OtFireEventsService GetPage error:%s \r\n", err)
- return err
- }
- return nil
- }
- // Get 获取OtFireEvents对象
- func (e *OtFireEvents) Get(d *dto.OtFireEventsGetReq, p *actions.DataPermission, model *models.OtFireEvents) error {
- var data models.OtFireEvents
- err := e.Orm.Model(&data).
- Scopes(
- actions.Permission(data.TableName(), p),
- ).
- First(model, d.GetId()).Error
- if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
- err = errors.New("查看对象不存在或无权查看")
- e.Log.Errorf("Service GetOtFireEvents error:%s \r\n", err)
- return err
- }
- if err != nil {
- e.Log.Errorf("db error:%s", err)
- return err
- }
- return nil
- }
- // Insert 创建OtFireEvents对象
- func (e *OtFireEvents) Insert(c *dto.OtFireEventsInsertReq) error {
- var err error
- var data models.OtFireEvents
- c.Generate(&data)
- err = e.Orm.Create(&data).Error
- if err != nil {
- e.Log.Errorf("OtFireEventsService Insert error:%s \r\n", err)
- return err
- }
- return nil
- }
- // Update 修改OtFireEvents对象
- func (e *OtFireEvents) Update(c *dto.OtFireEventsUpdateReq, p *actions.DataPermission) error {
- var err error
- var data = models.OtFireEvents{}
- e.Orm.Scopes(
- actions.Permission(data.TableName(), p),
- ).First(&data, c.GetId())
- c.Generate(&data)
- db := e.Orm.Save(&data)
- if err = db.Error; err != nil {
- e.Log.Errorf("OtFireEventsService Save error:%s \r\n", err)
- return err
- }
- if db.RowsAffected == 0 {
- return errors.New("无权更新该数据")
- }
- return nil
- }
- // Remove 删除OtFireEvents
- func (e *OtFireEvents) Remove(d *dto.OtFireEventsDeleteReq, p *actions.DataPermission) error {
- var data models.OtFireEvents
- db := e.Orm.Model(&data).
- Scopes(
- actions.Permission(data.TableName(), p),
- ).Delete(&data, d.GetId())
- if err := db.Error; err != nil {
- e.Log.Errorf("Service RemoveOtFireEvents error:%s \r\n", err)
- return err
- }
- if db.RowsAffected == 0 {
- return errors.New("无权删除该数据")
- }
- return nil
- }
- // Notate 修改OtFireEvents对象
- func (e *OtFireEvents) Notate(c *dto.OtFireEventsUpdateReq, p *actions.DataPermission) error {
- var err error
- var data = models.OtFireEvents{}
- e.Orm.Scopes(
- actions.Permission(data.TableName(), p),
- ).First(&data, c.GetId())
- data.IsIgnore = c.IsIgnore
- data.IsKnow = c.IsKnow
- data.IsResolve = c.IsResolve
- db := e.Orm.Save(&data)
- if err = db.Error; err != nil {
- e.Log.Errorf("OtFireEventsService Notate error:%s \r\n", err)
- return err
- }
- if db.RowsAffected == 0 {
- return errors.New("无权更新该数据")
- }
- return nil
- }
|