智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 1 година
пре 1 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "reflect"
  6. "xorm.io/xorm"
  7. )
  8. type GradeDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. EnterpriseId int `json:"enterprise_id"`
  11. }
  12. func (gradeDb *GradeDb) Set(enterpriseId int) { // set方法
  13. gradeDb.Db = Db
  14. gradeDb.EnterpriseId = enterpriseId
  15. }
  16. func (gradeDb *GradeDb) FindGrade() (*[]model.Grade, error) {
  17. var m []model.Grade
  18. if err := gradeDb.Db.Desc("id").Where("enterprise_id =?", gradeDb.EnterpriseId).Find(&m); err != nil {
  19. return nil, logx.Error(err)
  20. }
  21. return &m, nil
  22. }
  23. func (gradeDb *GradeDb) GradeDeleteBySession(id interface{}) (int64, error) {
  24. if reflect.TypeOf(id).Kind() == reflect.Slice {
  25. return gradeDb.Db.In("id", id).Delete(model.Grade{})
  26. } else {
  27. return gradeDb.Db.Where("id = ?", id).Delete(model.Grade{})
  28. }
  29. }
  30. func (gradeDb *GradeDb) ClassDeleteBySessionForEnterprise(session *xorm.Session, enterpriseId interface{}) (int64, error) {
  31. if reflect.TypeOf(enterpriseId).Kind() == reflect.Slice {
  32. return session.In("enterprise_id", enterpriseId).Delete(model.Grade{})
  33. } else {
  34. return session.Where("enterprise_id = ?", enterpriseId).Delete(model.Grade{})
  35. }
  36. }
  37. func (gradeDb *GradeDb) GradeInsert(m *model.Grade) (int, error) {
  38. _, err := gradeDb.Db.InsertOne(m)
  39. if err != nil {
  40. return 0, err
  41. }
  42. return m.Id, nil
  43. }
  44. func (gradeDb *GradeDb) GradeUpdate(m *model.Grade, columns ...string) (int64, error) {
  45. affected, err := gradeDb.Db.Where("id =?", m.Id).Cols(columns...).Update(m)
  46. if err != nil {
  47. return 0, err
  48. }
  49. return affected, nil
  50. }
  51. func (gradeDb *GradeDb) GetGrade(id int) (m *model.Grade, err error) {
  52. m = new(model.Grade)
  53. has, err := gradeDb.Db.Where("id =?", id).Get(m)
  54. if err != nil {
  55. return nil, logx.Error(err)
  56. }
  57. if has == false {
  58. return nil, nil
  59. }
  60. return m, nil
  61. }