problem_info.go 2.5 KB

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