智慧食堂
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

72 rindas
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. }