package service import ( cDto "Medical_OAuth/common/dto" "Medical_OAuth/common/global" "errors" "gogs.baozhida.cn/zoie/OAuth-core/service" "gorm.io/gorm" "Medical_OAuth/app/admin/model" "Medical_OAuth/app/admin/service/dto" ) type SysDictDataService struct { service.Service } // GetPage 获取列表 func (e *SysDictDataService) GetPage(c *dto.SysDictDataGetPageReq, list *[]model.SysDictData, count *int64) error { var err error var data model.SysDictData err = e.Orm.Model(&data). Scopes( cDto.MakeCondition(c.GetNeedSearch()), cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), ). Find(list).Limit(-1).Offset(-1). Count(count).Error if err != nil { e.Log.Errorf("db error: %s", err) return global.GetFailedErr } return nil } // Get 获取对象 func (e *SysDictDataService) Get(d *dto.SysDictDataGetReq, sysDictModel *model.SysDictData) error { err := e.Orm.First(sysDictModel, d.GetId()).Error if err != nil { e.Log.Errorf("db error: %s", err) if errors.Is(err, gorm.ErrRecordNotFound) { return global.GetNotFoundOrNoPermissionErr } return global.GetFailedErr } return nil } // Insert 创建对象 func (e *SysDictDataService) Insert(c *dto.SysDictDataInsertReq) error { var err error var data = new(model.SysDictData) c.Generate(data) err = e.Orm.Create(data).Error if err != nil { e.Log.Errorf("db error: %s", err) return global.CreateFailedErr } return nil } // Update 修改对象 func (e *SysDictDataService) Update(c *dto.SysDictDataUpdateReq) error { var err error var dictDataModel = model.SysDictData{} err = e.Orm.First(&dictDataModel, c.GetId()).Error if err != nil { e.Log.Errorf("db error: %s", err) if errors.Is(err, gorm.ErrRecordNotFound) { return global.UpdateNotFoundOrNoPermissionErr } return global.UpdateFailedErr } c.Generate(&dictDataModel) err = e.Orm.Save(dictDataModel).Error if err != nil { e.Log.Errorf("db error: %s", err) return global.UpdateFailedErr } return nil } // Remove 删除 func (e *SysDictDataService) Remove(c *dto.SysDictDataDeleteReq) error { var err error var data model.SysDictData db := e.Orm.Delete(&data, c.GetId()) if err = db.Error; err != nil { e.Log.Errorf("Delete error: %s", err) return global.DeleteFailedErr } if db.RowsAffected == 0 { return global.DeleteNotFoundOrNoPermissionErr } return nil } // GetAll 获取所有 func (e *SysDictDataService) GetAll(c *dto.SysDictDataGetPageReq, list *[]model.SysDictData) error { var err error var data model.SysDictData err = e.Orm.Model(&data). Scopes( cDto.MakeCondition(c.GetNeedSearch()), ). Find(list).Error if err != nil { e.Log.Errorf("db error: %s", err) return global.GetFailedErr } return nil }