智慧食堂
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

72 行
2.0 KiB

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