2021-07-17 14:18:52 +08:00
|
|
|
package system
|
2020-06-29 21:58:53 +08:00
|
|
|
|
|
|
|
import (
|
2021-08-23 23:13:24 +08:00
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
|
|
|
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
|
2020-06-29 21:58:53 +08:00
|
|
|
)
|
|
|
|
|
2020-11-08 13:30:12 +08:00
|
|
|
//@author: [granty1](https://github.com/granty1)
|
|
|
|
//@function: CreateSysOperationRecord
|
|
|
|
//@description: 创建记录
|
|
|
|
//@param: sysOperationRecord model.SysOperationRecord
|
|
|
|
//@return: err error
|
2020-06-29 21:58:53 +08:00
|
|
|
|
2021-12-06 12:44:26 +08:00
|
|
|
type OperationRecordService struct{}
|
2021-07-17 14:18:52 +08:00
|
|
|
|
|
|
|
func (operationRecordService *OperationRecordService) CreateSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
|
2020-11-23 12:02:18 +08:00
|
|
|
err = global.GVA_DB.Create(&sysOperationRecord).Error
|
2020-06-29 21:58:53 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-08 13:30:12 +08:00
|
|
|
//@author: [granty1](https://github.com/granty1)
|
|
|
|
//@author: [piexlmax](https://github.com/piexlmax)
|
|
|
|
//@function: DeleteSysOperationRecordByIds
|
|
|
|
//@description: 批量删除记录
|
|
|
|
//@param: ids request.IdsReq
|
|
|
|
//@return: err error
|
2020-07-07 16:39:36 +08:00
|
|
|
|
2021-07-17 14:18:52 +08:00
|
|
|
func (operationRecordService *OperationRecordService) DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
|
2021-07-16 20:08:11 +08:00
|
|
|
err = global.GVA_DB.Delete(&[]system.SysOperationRecord{}, "id in (?)", ids.Ids).Error
|
2020-07-07 16:39:36 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-08 13:30:12 +08:00
|
|
|
//@author: [granty1](https://github.com/granty1)
|
|
|
|
//@function: DeleteSysOperationRecord
|
|
|
|
//@description: 删除操作记录
|
|
|
|
//@param: sysOperationRecord model.SysOperationRecord
|
|
|
|
//@return: err error
|
2020-06-29 21:58:53 +08:00
|
|
|
|
2021-07-17 14:18:52 +08:00
|
|
|
func (operationRecordService *OperationRecordService) DeleteSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
|
2020-12-27 17:20:54 +08:00
|
|
|
err = global.GVA_DB.Delete(&sysOperationRecord).Error
|
2020-06-29 21:58:53 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-08 13:30:12 +08:00
|
|
|
//@author: [granty1](https://github.com/granty1)
|
|
|
|
//@function: DeleteSysOperationRecord
|
|
|
|
//@description: 根据id获取单条操作记录
|
|
|
|
//@param: id uint
|
2022-05-28 19:22:23 +08:00
|
|
|
//@return: sysOperationRecord system.SysOperationRecord, err error
|
2020-06-29 21:58:53 +08:00
|
|
|
|
2022-05-28 19:22:23 +08:00
|
|
|
func (operationRecordService *OperationRecordService) GetSysOperationRecord(id uint) (sysOperationRecord system.SysOperationRecord, err error) {
|
2020-06-29 21:58:53 +08:00
|
|
|
err = global.GVA_DB.Where("id = ?", id).First(&sysOperationRecord).Error
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-08 13:30:12 +08:00
|
|
|
//@author: [granty1](https://github.com/granty1)
|
|
|
|
//@author: [piexlmax](https://github.com/piexlmax)
|
|
|
|
//@function: GetSysOperationRecordInfoList
|
|
|
|
//@description: 分页获取操作记录列表
|
2021-07-17 14:18:52 +08:00
|
|
|
//@param: info systemReq.SysOperationRecordSearch
|
2022-05-28 19:22:23 +08:00
|
|
|
//@return: list interface{}, total int64, err error
|
2020-06-29 21:58:53 +08:00
|
|
|
|
2022-05-28 19:22:23 +08:00
|
|
|
func (operationRecordService *OperationRecordService) GetSysOperationRecordInfoList(info systemReq.SysOperationRecordSearch) (list interface{}, total int64, err error) {
|
2020-06-29 21:58:53 +08:00
|
|
|
limit := info.PageSize
|
|
|
|
offset := info.PageSize * (info.Page - 1)
|
|
|
|
// 创建db
|
2021-07-16 20:08:11 +08:00
|
|
|
db := global.GVA_DB.Model(&system.SysOperationRecord{})
|
|
|
|
var sysOperationRecords []system.SysOperationRecord
|
2020-06-29 21:58:53 +08:00
|
|
|
// 如果有条件搜索 下方会自动创建搜索语句
|
|
|
|
if info.Method != "" {
|
|
|
|
db = db.Where("method = ?", info.Method)
|
|
|
|
}
|
|
|
|
if info.Path != "" {
|
|
|
|
db = db.Where("path LIKE ?", "%"+info.Path+"%")
|
|
|
|
}
|
|
|
|
if info.Status != 0 {
|
|
|
|
db = db.Where("status = ?", info.Status)
|
|
|
|
}
|
|
|
|
err = db.Count(&total).Error
|
2021-09-16 10:19:54 +08:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2020-07-05 14:45:05 +08:00
|
|
|
err = db.Order("id desc").Limit(limit).Offset(offset).Preload("User").Find(&sysOperationRecords).Error
|
2022-05-28 19:22:23 +08:00
|
|
|
return sysOperationRecords, total, err
|
2020-06-29 21:58:53 +08:00
|
|
|
}
|