operationHisDao.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "time"
  4. )
  5. // OperationHis 操作记录
  6. type OperationHis struct {
  7. ID int `gorm:"primary_key" json:"id"` //编号
  8. OperationType int `gorm:"type:int" json:"operationType"` //操作类型
  9. ModuleType int `gorm:"type:int" json:"moduleType"` //操作模块
  10. HandleContent string `gorm:"type:varchar(1000)" json:"handleContent"` //操作内容
  11. HandleUserId int64 `gorm:"type:bigint" json:"handleUserId"` //操作用户ID
  12. HandleTime time.Time `gorm:"type:timestamp;default CURRENT_TIMESTAMP" json:"handleTime"` //操作时间
  13. TenantId int `gorm:"type:int" json:"tenantId"` //租户ID
  14. }
  15. func (OperationHis) TableName() string {
  16. return "t_sys_handle_his"
  17. }
  18. func (c *OperationHis) Create() error {
  19. return Db.Debug().Model(&c).Save(&c).Error
  20. }
  21. func (c OperationHis) GetHistories(offset, limit int) ([]OperationHis, error) {
  22. var list []OperationHis
  23. db := Db.Debug().Model(&c)
  24. if c.OperationType > 0 {
  25. db = db.Where("operation_type = ?", c.OperationType)
  26. }
  27. if c.ModuleType > 0 {
  28. db = db.Where("module_type = ?", c.ModuleType)
  29. }
  30. if c.HandleContent != "" {
  31. db = db.Where("handle_content like ?", "%"+c.HandleContent+"%")
  32. }
  33. err := Db.Debug().Model(&c).Offset(offset).Limit(limit).Find(&list).Error
  34. return list, err
  35. }