1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package system
- import (
- "lc-base-frame/global"
- "lc-base-frame/model/common/request"
- "lc-base-frame/model/system"
- systemReq "lc-base-frame/model/system/request"
- )
- //@author: [granty1](https://github.com/granty1)
- //@function: CreateSysOperationRecord
- //@description: 创建记录
- //@param: sysOperationRecord model.SysOperationRecord
- //@return: err error
- type OperationRecordService struct{}
- func (operationRecordService *OperationRecordService) CreateSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
- err = global.Db.Create(&sysOperationRecord).Error
- return err
- }
- //@author: [granty1](https://github.com/granty1)
- //@author: [piexlmax](https://github.com/piexlmax)
- //@function: DeleteSysOperationRecordByIds
- //@description: 批量删除记录
- //@param: ids request.IdsReq
- //@return: err error
- func (operationRecordService *OperationRecordService) DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
- err = global.Db.Delete(&[]system.SysOperationRecord{}, "id in (?)", ids.Ids).Error
- return err
- }
- //@author: [granty1](https://github.com/granty1)
- //@function: DeleteSysOperationRecord
- //@description: 删除操作记录
- //@param: sysOperationRecord model.SysOperationRecord
- //@return: err error
- func (operationRecordService *OperationRecordService) DeleteSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
- err = global.Db.Delete(&sysOperationRecord).Error
- return err
- }
- //@author: [granty1](https://github.com/granty1)
- //@function: DeleteSysOperationRecord
- //@description: 根据id获取单条操作记录
- //@param: id uint
- //@return: sysOperationRecord system.SysOperationRecord, err error
- func (operationRecordService *OperationRecordService) GetSysOperationRecord(id uint) (sysOperationRecord system.SysOperationRecord, err error) {
- err = global.Db.Where("id = ?", id).First(&sysOperationRecord).Error
- return
- }
- //@author: [granty1](https://github.com/granty1)
- //@author: [piexlmax](https://github.com/piexlmax)
- //@function: GetSysOperationRecordInfoList
- //@description: 分页获取操作记录列表
- //@param: info systemReq.SysOperationRecordSearch
- //@return: list interface{}, total int64, err error
- func (operationRecordService *OperationRecordService) GetSysOperationRecordInfoList(info systemReq.SysOperationRecordSearch) (list interface{}, total int64, err error) {
- limit := info.PageSize
- offset := info.PageSize * (info.Page - 1)
- // 创建db
- db := global.Db.Model(&system.SysOperationRecord{})
- var sysOperationRecords []system.SysOperationRecord
- // 如果有条件搜索 下方会自动创建搜索语句
- 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
- if err != nil {
- return
- }
- err = db.Order("id desc").Limit(limit).Offset(offset).Preload("User").Find(&sysOperationRecords).Error
- return sysOperationRecords, total, err
- }
|