123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package service
- import (
- "Medical_OAuth/app/admin/model"
- "Medical_OAuth/app/admin/service/dto"
- cDto "Medical_OAuth/common/dto"
- "Medical_OAuth/common/global"
- "errors"
- "gorm.io/gorm"
- "gogs.baozhida.cn/zoie/OAuth-core/service"
- )
- type ServApi struct {
- service.Service
- }
- // GetPage 获取ServApi列表
- func (e *ServApi) GetPage(c *dto.ServApiGetPageReq, list *[]model.ServApi, count *int64) error {
- var err error
- var data model.ServApi
- 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 \r", err)
- return global.GetFailedErr
- }
- return nil
- }
- // Get 获取ServApi对象
- func (e *ServApi) Get(d *dto.ServApiGetReq, servApiModel *model.ServApi) error {
- err := e.Orm.First(servApiModel, 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 创建AppMenu对象
- func (e *ServApi) Insert(c *dto.ServApiInsertReq) error {
- var err error
- var data model.ServApi
- err = e.Orm.Where("service_id = ? and path = ? and action = ?", c.ServiceId, c.Path, c.Action).First(&data).Error
- if err == nil {
- return errors.New("数据已存在")
- }
- c.Generate(&data)
- err = e.Orm.Create(&data).Error
- if err != nil {
- e.Log.Errorf("db error: %s", err)
- return global.CreateFailedErr
- }
- c.Id = data.Id
- return nil
- }
- // Update 修改ServApi对象
- func (e *ServApi) Update(c *dto.ServApiUpdateReq) error {
- var servModel = model.ServApi{}
- err := e.Orm.First(&servModel, 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(&servModel)
- err = e.Orm.Save(&servModel).Error
- if err != nil {
- e.Log.Errorf("db error: %s", err)
- return global.UpdateFailedErr
- }
- return nil
- }
- // Remove 删除ServApi
- func (e *ServApi) Remove(d *dto.ServApiDeleteReq) error {
- var data model.ServApi
- db := e.Orm.Model(&data).Delete(&data, d.GetId())
- if err := db.Error; err != nil {
- e.Log.Errorf("Service RemoveServApi error: %s", err)
- return global.DeleteFailedErr
- }
- return nil
- }
- func (e *ServApi) GetList(c *dto.ServApiListByIds, list *[]model.ServApi) error {
- var err error
- var data model.ServApi
- err = e.Orm.Model(&data).
- Scopes(
- cDto.MakeCondition(c.GetNeedSearch()),
- ).
- Find(list).Limit(-1).Offset(-1).
- Error
- if err != nil {
- e.Log.Errorf("db error: %s \r", err)
- return global.GetFailedErr
- }
- return nil
- }
|