智慧食堂
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

db_suggested_feedback.go 2.7 KiB

hace 10 meses
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "reflect"
  6. "xorm.io/xorm"
  7. )
  8. type SuggestedFeedbackDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. }
  11. func (suggestedFeedbackDb *SuggestedFeedbackDb) Set() { // set方法
  12. suggestedFeedbackDb.Db = Db
  13. }
  14. func (suggestedFeedbackDb *SuggestedFeedbackDb) GetSuggestedFeedback(id int) (m *model.SuggestedFeedback, err error) {
  15. m = new(model.SuggestedFeedback)
  16. has, err := suggestedFeedbackDb.Db.Where("id =?", id).Get(m)
  17. if err != nil {
  18. return nil, logx.Error(err)
  19. }
  20. if has == false {
  21. return nil, nil
  22. }
  23. return m, nil
  24. }
  25. func (suggestedFeedbackDb *SuggestedFeedbackDb) FindSuggestedFeedbackById(ids interface{}) (*[]model.SuggestedFeedback, error) {
  26. var m []model.SuggestedFeedback
  27. if err := suggestedFeedbackDb.Db.In("id", ids).Desc("sort").Find(&m); err != nil {
  28. return nil, logx.Error(err)
  29. }
  30. return &m, nil
  31. }
  32. func (suggestedFeedbackDb *SuggestedFeedbackDb) FindSuggestedFeedback(limit, start int) (*[]model.SuggestedFeedback, error) {
  33. var m []model.SuggestedFeedback
  34. if limit == 0 || start == 0 {
  35. if err := suggestedFeedbackDb.Db.Asc("sort").Find(&m); err != nil {
  36. return nil, logx.Error(err)
  37. }
  38. } else {
  39. if err := suggestedFeedbackDb.Db.Asc("sort").Limit(limit, start).Find(m); err != nil {
  40. return nil, logx.Error(err)
  41. }
  42. }
  43. return &m, nil
  44. }
  45. func (suggestedFeedbackDb *SuggestedFeedbackDb) GetSuggestedFeedbackByName(name string) (m *model.SuggestedFeedback, err error) {
  46. m = new(model.SuggestedFeedback)
  47. has, err := suggestedFeedbackDb.Db.Where("name =?", name).Get(m)
  48. if err != nil {
  49. return nil, logx.Error(err)
  50. }
  51. if has == false {
  52. return nil, nil
  53. }
  54. return m, nil
  55. }
  56. func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackInsert(m *model.SuggestedFeedback) (int, error) {
  57. _, err := suggestedFeedbackDb.Db.InsertOne(m)
  58. if err != nil {
  59. return 0, err
  60. }
  61. return m.Id, nil
  62. }
  63. func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackUpdate(m *model.SuggestedFeedback, columns ...string) (int64, error) {
  64. affected, err := suggestedFeedbackDb.Db.Where("id =?", m.Id).Cols(columns...).Update(m)
  65. if err != nil {
  66. return 0, err
  67. }
  68. return affected, nil
  69. }
  70. func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackDelete(id interface{}) (int64, error) {
  71. if reflect.TypeOf(id).Kind() == reflect.Slice {
  72. return Db.In("id", id).Delete(model.SuggestedFeedback{})
  73. } else {
  74. return Db.Where("id = ?", id).Delete(model.SuggestedFeedback{})
  75. }
  76. }
  77. type SuggestedFeedbackWithUserIdentity struct {
  78. model.SuggestedFeedback `xorm:"extends"`
  79. model.UserIdentity `xorm:"extends"`
  80. model.Enterprise `xorm:"extends"`
  81. model.User `xorm:"extends"`
  82. }
  83. func (SuggestedFeedbackWithUserIdentity) TableName() string {
  84. return "suggested_feedback"
  85. }