problem_reply.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ProblemReplyService struct {
  9. }
  10. // CreateProblemReply 创建ProblemReply记录
  11. // Author [piexlmax](https://github.com/piexlmax)
  12. func (problemReplyService *ProblemReplyService) CreateProblemReply(problemReply autocode.ProblemReply) (err error) {
  13. err = global.GVA_DB.Create(&problemReply).Error
  14. return err
  15. }
  16. // DeleteProblemReply 删除ProblemReply记录
  17. // Author [piexlmax](https://github.com/piexlmax)
  18. func (problemReplyService *ProblemReplyService) DeleteProblemReply(problemReply autocode.ProblemReply) (err error) {
  19. err = global.GVA_DB.Delete(&problemReply).Error
  20. return err
  21. }
  22. // DeleteProblemReplyByIds 批量删除ProblemReply记录
  23. // Author [piexlmax](https://github.com/piexlmax)
  24. func (problemReplyService *ProblemReplyService) DeleteProblemReplyByIds(ids request.IdsReq) (err error) {
  25. err = global.GVA_DB.Delete(&[]autocode.ProblemReply{}, "id in ?", ids.Ids).Error
  26. return err
  27. }
  28. // UpdateProblemReply 更新ProblemReply记录
  29. // Author [piexlmax](https://github.com/piexlmax)
  30. func (problemReplyService *ProblemReplyService) UpdateProblemReply(problemReply autocode.ProblemReply) (err error) {
  31. err = global.GVA_DB.Save(&problemReply).Error
  32. return err
  33. }
  34. // GetProblemReply 根据id获取ProblemReply记录
  35. // Author [piexlmax](https://github.com/piexlmax)
  36. func (problemReplyService *ProblemReplyService) GetProblemReply(id uint) (err error, problemReply autocode.ProblemReply) {
  37. err = global.GVA_DB.Where("id = ?", id).First(&problemReply).Error
  38. return
  39. }
  40. // GetProblemReplyInfoList 分页获取ProblemReply记录
  41. // Author [piexlmax](https://github.com/piexlmax)
  42. func (problemReplyService *ProblemReplyService) GetProblemReplyInfoList(info autoCodeReq.ProblemReplySearch) (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.ProblemReply{})
  47. var problemReplys []autocode.ProblemReply
  48. if info.ProblemId != nil && *info.ProblemId != 0 {
  49. db.Where("problem_id=?", info.ProblemId)
  50. }
  51. // 如果有条件搜索 下方会自动创建搜索语句
  52. err = db.Count(&total).Error
  53. err = db.Limit(limit).Offset(offset).Find(&problemReplys).Error
  54. return err, problemReplys, total
  55. }