recordService.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package service
  2. import (
  3. "AIT/common"
  4. "AIT/global"
  5. "AIT/models"
  6. )
  7. type RecordService struct {
  8. }
  9. func (f *RecordService) CreateRecord(record models.Record) int64 {
  10. affected := global.Db.Create(&record).RowsAffected
  11. return affected
  12. }
  13. func (f *RecordService) UpdateRecordById(recordId string, recordResult string) models.Record {
  14. record := models.Record{
  15. Id: recordId,
  16. Result: recordResult,
  17. UpdateTime: common.NowTime(),
  18. }
  19. global.Db.Model(&record).Updates(record)
  20. return record
  21. }
  22. func (f *RecordService) GetRecordList(param models.RecordListParam) ([]models.Record, int64) {
  23. query := models.Record{}
  24. if len(param.UserName) > 0 {
  25. query.UserName = param.UserName
  26. }
  27. page := models.Page{
  28. PageNum: param.PageNum,
  29. PageSize: param.PageSize,
  30. }
  31. recordList := make([]models.Record, 0)
  32. rows := common.RestPage(page, "record", query, " create_time desc", &recordList, &[]models.User{})
  33. return recordList, rows
  34. }
  35. func (f *RecordService) FindById(recordId string) (models.Record, int64) {
  36. var record models.Record
  37. count := global.Db.Where("id = ?", recordId).First(&record).RowsAffected
  38. return record, count
  39. }