problem_info.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. "gorm.io/gorm"
  8. )
  9. type ProblemInfoService struct {
  10. }
  11. // CreateProblemInfo 创建ProblemInfo记录
  12. // Author [piexlmax](https://github.com/piexlmax)
  13. func (problemInfoService *ProblemInfoService) CreateProblemInfo(problemInfo autocode.ProblemInfo) (err error) {
  14. err = global.GVA_DB.Create(&problemInfo).Error
  15. return err
  16. }
  17. // DeleteProblemInfo 删除ProblemInfo记录
  18. // Author [piexlmax](https://github.com/piexlmax)
  19. func (problemInfoService *ProblemInfoService) DeleteProblemInfo(problemInfo autocode.ProblemInfo) (err error) {
  20. err = global.GVA_DB.Delete(&problemInfo).Error
  21. return err
  22. }
  23. // DeleteProblemInfoByIds 批量删除ProblemInfo记录
  24. // Author [piexlmax](https://github.com/piexlmax)
  25. func (problemInfoService *ProblemInfoService) DeleteProblemInfoByIds(ids request.IdsReq) (err error) {
  26. err = global.GVA_DB.Delete(&[]autocode.ProblemInfo{}, "id in ?", ids.Ids).Error
  27. return err
  28. }
  29. // UpdateProblemInfo 更新ProblemInfo记录
  30. // Author [piexlmax](https://github.com/piexlmax)
  31. func (problemInfoService *ProblemInfoService) UpdateProblemInfo(problemInfo autocode.ProblemInfo) (err error) {
  32. err = global.GVA_DB.Where("id=?", problemInfo.ID).Save(problemInfo).Error
  33. return err
  34. }
  35. func (problemInfoService *ProblemInfoService) UpdateProblemInfoCount(id uint) (err error) {
  36. err = global.GVA_DB.Model(&autocode.ProblemInfo{}).Where("id=?", id).Update("count", gorm.Expr("count+1")).Error
  37. return err
  38. }
  39. // GetProblemInfo 根据id获取ProblemInfo记录
  40. // Author [piexlmax](https://github.com/piexlmax)
  41. func (problemInfoService *ProblemInfoService) GetProblemInfo(id uint) (err error, problemInfo autocode.ProblemInfo) {
  42. err = global.GVA_DB.Where("id = ?", id).First(&problemInfo).Error
  43. return
  44. }
  45. // GetProblemInfoInfoList 分页获取ProblemInfo记录
  46. // Author [piexlmax](https://github.com/piexlmax)
  47. func (problemInfoService *ProblemInfoService) GetProblemInfoInfoList(info autoCodeReq.ProblemInfoSearch) (err error, infoList []autocode.ProblemInfo, total int64) {
  48. limit := info.PageSize
  49. offset := info.PageSize * (info.Page - 1)
  50. // 创建db
  51. db := global.GVA_DB.Model(&autocode.ProblemInfo{})
  52. if info.SiteType != "" {
  53. db.Where("site_type=?", info.SiteType)
  54. }
  55. if info.UnitId != nil && *info.UnitId != 0 {
  56. db.Where("unit_id=?", info.UnitId)
  57. }
  58. if info.Status != "" {
  59. db.Where("status=?", info.Status)
  60. }
  61. if info.Oper != 0 {
  62. db.Where("oper=?", info.Oper)
  63. }
  64. if !info.CreatedAtStart.IsZero() && !info.CreatedAtEnd.IsZero() {
  65. db.Where("created_at between ? and ?", info.CreatedAtStart, info.CreatedAtEnd)
  66. }
  67. var problemInfos []autocode.ProblemInfo
  68. // 如果有条件搜索 下方会自动创建搜索语句
  69. err = db.Count(&total).Error
  70. err = db.Limit(limit).Offset(offset).Order("created_at desc").Find(&problemInfos).Error
  71. return err, problemInfos, total
  72. }