123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package service
- import (
- "Medical_OAuth/common/actions"
- 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 SysPost struct {
- service.Service
- }
- // GetPage 获取SysPost列表
- func (e *SysPost) GetPage(c *dto.SysPostPageReq, list *[]model.SysPost, count *int64, p *actions.DataPermission) error {
- var err error
- var data model.SysPost
- 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("db error: %s \r", err)
- return global.GetFailedErr
- }
- return nil
- }
- // Get 获取SysPost对象
- func (e *SysPost) Get(d *dto.SysPostGetReq, postModel *model.SysPost, p *actions.DataPermission) error {
- err := e.Orm.
- Scopes(actions.Permission(postModel.TableName(), p)).
- First(postModel, 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 创建SysPost对象
- func (e *SysPost) Insert(c *dto.SysPostInsertReq) error {
- var err error
- var data model.SysPost
- 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 修改SysPost对象
- func (e *SysPost) Update(c *dto.SysPostUpdateReq) error {
- var postModel = model.SysPost{}
- err := e.Orm.First(&postModel, 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(&postModel)
- err = e.Orm.Save(&postModel).Error
- if err != nil {
- e.Log.Errorf("db error: %s", err)
- return global.UpdateFailedErr
- }
- return nil
- }
- // Remove 删除SysPost
- func (e *SysPost) Remove(d *dto.SysPostDeleteReq) error {
- var err error
- var data model.SysPost
- db := e.Orm.Model(&data).Delete(&data, d.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
- }
|