智慧食堂
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

75 wiersze
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 NursingHomeSetDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. EnterpriseId int `json:"enterprise_id"`
  11. }
  12. func (nursingHomeSetDb *NursingHomeSetDb) Set(enterpriseId int) { // set方法
  13. nursingHomeSetDb.Db = Db
  14. nursingHomeSetDb.EnterpriseId = enterpriseId
  15. }
  16. func (nursingHomeSetDb *NursingHomeSetDb) GetNursingHomeSet() (m *model.NursingHomeSet, err error) {
  17. m = new(model.NursingHomeSet)
  18. has, err := nursingHomeSetDb.Db.Where("enterprise_id =?", nursingHomeSetDb.EnterpriseId).Get(m)
  19. if err != nil {
  20. return nil, logx.Error(err)
  21. }
  22. if has == false {
  23. return nil, nil
  24. }
  25. return m, nil
  26. }
  27. func (nursingHomeSetDb *NursingHomeSetDb) NursingHomeSetInsert(m *model.NursingHomeSet) (int, error) {
  28. _, err := nursingHomeSetDb.Db.InsertOne(m)
  29. if err != nil {
  30. return 0, err
  31. }
  32. return m.Id, nil
  33. }
  34. func (nursingHomeSetDb *NursingHomeSetDb) BatchAddNursingHomeSets(mm []*model.NursingHomeSet) (int64, error) {
  35. affected, err := nursingHomeSetDb.Db.Insert(mm)
  36. if err != nil {
  37. return 0, err
  38. }
  39. return affected, nil
  40. }
  41. func (nursingHomeSetDb *NursingHomeSetDb) NursingHomeSetDeleteById(id interface{}) (int64, error) {
  42. if reflect.TypeOf(id).Kind() == reflect.Slice {
  43. return Db.In("id", id).Delete(model.NursingHomeSet{})
  44. } else {
  45. return Db.Where("id = ?", id).Delete(model.NursingHomeSet{})
  46. }
  47. }
  48. func (nursingHomeSetDb *NursingHomeSetDb) NursingHomeSetDelete() (int64, error) {
  49. return Db.Where("enterprise_id = ?", nursingHomeSetDb.EnterpriseId).Delete(model.NursingHomeSet{})
  50. }
  51. func (nursingHomeSetDb *NursingHomeSetDb) NursingHomeSetUpdate(id interface{}, m *model.NursingHomeSet, forceColums ...string) (int64, error) {
  52. var (
  53. affected int64
  54. err error
  55. )
  56. if forceColums != nil {
  57. affected, err = nursingHomeSetDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
  58. } else {
  59. affected, err = nursingHomeSetDb.Db.Where("id=?", id).Update(m)
  60. }
  61. if err != nil {
  62. return 0, err
  63. }
  64. return affected, nil
  65. }