mirror of
https://github.com/lejianwen/rustdesk-api.git
synced 2026-05-02 04:26:45 +00:00
style(service): refactor global dependencies to use local variables
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/lejianwen/rustdesk-api/v2/global"
|
||||
"github.com/lejianwen/rustdesk-api/v2/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -13,7 +12,7 @@ func (as *AuditService) AuditConnList(page, pageSize uint, where func(tx *gorm.D
|
||||
res = &model.AuditConnList{}
|
||||
res.Page = int64(page)
|
||||
res.PageSize = int64(pageSize)
|
||||
tx := global.DB.Model(&model.AuditConn{})
|
||||
tx := DB.Model(&model.AuditConn{})
|
||||
if where != nil {
|
||||
where(tx)
|
||||
}
|
||||
@@ -25,36 +24,36 @@ func (as *AuditService) AuditConnList(page, pageSize uint, where func(tx *gorm.D
|
||||
|
||||
// Create 创建
|
||||
func (as *AuditService) CreateAuditConn(u *model.AuditConn) error {
|
||||
res := global.DB.Create(u).Error
|
||||
res := DB.Create(u).Error
|
||||
return res
|
||||
}
|
||||
func (as *AuditService) DeleteAuditConn(u *model.AuditConn) error {
|
||||
return global.DB.Delete(u).Error
|
||||
return DB.Delete(u).Error
|
||||
}
|
||||
|
||||
// Update 更新
|
||||
func (as *AuditService) UpdateAuditConn(u *model.AuditConn) error {
|
||||
return global.DB.Model(u).Updates(u).Error
|
||||
return DB.Model(u).Updates(u).Error
|
||||
}
|
||||
|
||||
// InfoByPeerIdAndConnId
|
||||
func (as *AuditService) InfoByPeerIdAndConnId(peerId string, connId int64) (res *model.AuditConn) {
|
||||
res = &model.AuditConn{}
|
||||
global.DB.Where("peer_id = ? and conn_id = ?", peerId, connId).First(res)
|
||||
DB.Where("peer_id = ? and conn_id = ?", peerId, connId).First(res)
|
||||
return
|
||||
}
|
||||
|
||||
// ConnInfoById
|
||||
func (as *AuditService) ConnInfoById(id uint) (res *model.AuditConn) {
|
||||
res = &model.AuditConn{}
|
||||
global.DB.Where("id = ?", id).First(res)
|
||||
DB.Where("id = ?", id).First(res)
|
||||
return
|
||||
}
|
||||
|
||||
// FileInfoById
|
||||
func (as *AuditService) FileInfoById(id uint) (res *model.AuditFile) {
|
||||
res = &model.AuditFile{}
|
||||
global.DB.Where("id = ?", id).First(res)
|
||||
DB.Where("id = ?", id).First(res)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -62,7 +61,7 @@ func (as *AuditService) AuditFileList(page, pageSize uint, where func(tx *gorm.D
|
||||
res = &model.AuditFileList{}
|
||||
res.Page = int64(page)
|
||||
res.PageSize = int64(pageSize)
|
||||
tx := global.DB.Model(&model.AuditFile{})
|
||||
tx := DB.Model(&model.AuditFile{})
|
||||
if where != nil {
|
||||
where(tx)
|
||||
}
|
||||
@@ -74,22 +73,22 @@ func (as *AuditService) AuditFileList(page, pageSize uint, where func(tx *gorm.D
|
||||
|
||||
// CreateAuditFile
|
||||
func (as *AuditService) CreateAuditFile(u *model.AuditFile) error {
|
||||
res := global.DB.Create(u).Error
|
||||
res := DB.Create(u).Error
|
||||
return res
|
||||
}
|
||||
func (as *AuditService) DeleteAuditFile(u *model.AuditFile) error {
|
||||
return global.DB.Delete(u).Error
|
||||
return DB.Delete(u).Error
|
||||
}
|
||||
|
||||
// Update 更新
|
||||
func (as *AuditService) UpdateAuditFile(u *model.AuditFile) error {
|
||||
return global.DB.Model(u).Updates(u).Error
|
||||
return DB.Model(u).Updates(u).Error
|
||||
}
|
||||
|
||||
func (as *AuditService) BatchDeleteAuditConn(ids []uint) error {
|
||||
return global.DB.Where("id in (?)", ids).Delete(&model.AuditConn{}).Error
|
||||
return DB.Where("id in (?)", ids).Delete(&model.AuditConn{}).Error
|
||||
}
|
||||
|
||||
func (as *AuditService) BatchDeleteAuditFile(ids []uint) error {
|
||||
return global.DB.Where("id in (?)", ids).Delete(&model.AuditFile{}).Error
|
||||
return DB.Where("id in (?)", ids).Delete(&model.AuditFile{}).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user