123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package service
- import (
- "errors"
- "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 OtIfram struct {
- service.Service
- }
- // GetPage 获取OtIfram列表
- func (e *OtIfram) GetPage(c *dto.OtIframGetPageReq, p *actions.DataPermission, list *[]models.OtIfram, count *int64) error {
- var err error
- var data models.OtIfram
- err = e.Orm.Model(&data).
- Scopes(
- cDto.MakeCondition(c.GetNeedSearch()),
- cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
- actions.Permission(data.TableName(), p),
- ).
- Find(list).Limit(-1).Offset(-1).
- Count(count).Error
- if err != nil {
- e.Log.Errorf("OtIframService GetPage error:%s \r\n", err)
- return err
- }
- return nil
- }
- // Get 获取OtIfram对象
- func (e *OtIfram) Get(d *dto.OtIframGetReq, p *actions.DataPermission, model *models.OtIfram) error {
- var data models.OtIfram
- 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 GetOtIfram error:%s \r\n", err)
- return err
- }
- if err != nil {
- e.Log.Errorf("db error:%s", err)
- return err
- }
- return nil
- }
- // Insert 创建OtIfram对象
- func (e *OtIfram) Insert(c *dto.OtIframInsertReq) error {
- var err error
- var data models.OtIfram
- c.Generate(&data)
- err = e.Orm.Create(&data).Error
- if err != nil {
- e.Log.Errorf("OtIframService Insert error:%s \r\n", err)
- return err
- }
- return nil
- }
- // Update 修改OtIfram对象
- func (e *OtIfram) Update(c *dto.OtIframUpdateReq, p *actions.DataPermission) error {
- var err error
- var data = models.OtIfram{}
- 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("OtIframService Save error:%s \r\n", err)
- return err
- }
- if db.RowsAffected == 0 {
- return errors.New("无权更新该数据")
- }
- return nil
- }
- // Remove 删除OtIfram
- func (e *OtIfram) Remove(d *dto.OtIframDeleteReq, p *actions.DataPermission) error {
- var data models.OtIfram
- 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 RemoveOtIfram error:%s \r\n", err)
- return err
- }
- if db.RowsAffected == 0 {
- return errors.New("无权删除该数据")
- }
- return nil
- }
|