assignment.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package autocode
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
  5. autoCodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  7. )
  8. type AssignmentService struct {
  9. }
  10. // CreateAssignment 创建Assignment记录
  11. // Author [piexlmax](https://github.com/piexlmax)
  12. func (assignmentService *AssignmentService) CreateAssignment(assignment autocode.Assignment) (err error) {
  13. err = global.GVA_DB.Create(&assignment).Error
  14. return err
  15. }
  16. // DeleteAssignment 删除Assignment记录
  17. // Author [piexlmax](https://github.com/piexlmax)
  18. func (assignmentService *AssignmentService) DeleteAssignment(assignment autocode.Assignment) (err error) {
  19. err = global.GVA_DB.Delete(&assignment).Error
  20. return err
  21. }
  22. // DeleteAssignmentByIds 批量删除Assignment记录
  23. // Author [piexlmax](https://github.com/piexlmax)
  24. func (assignmentService *AssignmentService) DeleteAssignmentByIds(ids request.IdsReq) (err error) {
  25. err = global.GVA_DB.Delete(&[]autocode.Assignment{}, "id in ?", ids.Ids).Error
  26. return err
  27. }
  28. // UpdateAssignment 更新Assignment记录
  29. // Author [piexlmax](https://github.com/piexlmax)
  30. func (assignmentService *AssignmentService) UpdateAssignment(assignment autocode.Assignment) (err error) {
  31. err = global.GVA_DB.Save(&assignment).Error
  32. return err
  33. }
  34. // GetAssignment 根据id获取Assignment记录
  35. // Author [piexlmax](https://github.com/piexlmax)
  36. func (assignmentService *AssignmentService) GetAssignment(id uint) (err error, assignment autocode.Assignment) {
  37. err = global.GVA_DB.Where("id = ?", id).First(&assignment).Error
  38. return
  39. }
  40. // GetAssignmentInfoList 分页获取Assignment记录
  41. // Author [piexlmax](https://github.com/piexlmax)
  42. func (assignmentService *AssignmentService) GetAssignmentInfoList(info autoCodeReq.AssignmentSearch) (err error, list interface{}, total int64) {
  43. limit := info.PageSize
  44. offset := info.PageSize * (info.Page - 1)
  45. // 创建db
  46. db := global.GVA_DB.Model(&autocode.Assignment{})
  47. var assignments []autocode.Assignment
  48. // 如果有条件搜索 下方会自动创建搜索语句
  49. err = db.Count(&total).Error
  50. err = db.Limit(limit).Offset(offset).Find(&assignments).Error
  51. return err, assignments, total
  52. }