智慧食堂
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.

87 lines
2.5 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 NursingHomeWithSpec struct {
  9. Db *xorm.Engine `json:"db"`
  10. EnterpriseId int `json:"enterprise_id"`
  11. }
  12. func (nursingHomeWithSpecDb *NursingHomeWithSpec) Set(enterpriseId int) { // set方法
  13. nursingHomeWithSpecDb.Db = Db
  14. nursingHomeWithSpecDb.EnterpriseId = enterpriseId
  15. }
  16. func (nursingHomeWithSpecDb *NursingHomeWithSpec) GetNursingHomeWithSpecById(id int) (m *model.NursingHomeWithSpec, err error) {
  17. m = new(model.NursingHomeWithSpec)
  18. has, err := nursingHomeWithSpecDb.Db.Where("id =?", id).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 (nursingHomeWithSpecDb *NursingHomeWithSpec) GetNursingHomeWithSpec() (m *model.NursingHomeWithSpec, err error) {
  28. m = new(model.NursingHomeWithSpec)
  29. has, err := nursingHomeWithSpecDb.Db.Where("enterprise_id =?", nursingHomeWithSpecDb.EnterpriseId).Get(m)
  30. if err != nil {
  31. return nil, logx.Error(err)
  32. }
  33. if has == false {
  34. return nil, nil
  35. }
  36. return m, nil
  37. }
  38. func (nursingHomeWithSpecDb *NursingHomeWithSpec) NursingHomeWithSpecInsert(m *model.NursingHomeWithSpec) (int, error) {
  39. _, err := nursingHomeWithSpecDb.Db.InsertOne(m)
  40. if err != nil {
  41. return 0, err
  42. }
  43. return m.Id, nil
  44. }
  45. func (nursingHomeWithSpecDb *NursingHomeWithSpec) BatchAddNursingHomeWithSpecs(mm []*model.NursingHomeWithSpec) (int64, error) {
  46. affected, err := nursingHomeWithSpecDb.Db.Insert(mm)
  47. if err != nil {
  48. return 0, err
  49. }
  50. return affected, nil
  51. }
  52. func (nursingHomeWithSpecDb *NursingHomeWithSpec) NursingHomeWithSpecDeleteById(id interface{}) (int64, error) {
  53. if reflect.TypeOf(id).Kind() == reflect.Slice {
  54. return Db.In("id", id).Delete(model.NursingHomeWithSpec{})
  55. } else {
  56. return Db.Where("id = ?", id).Delete(model.NursingHomeWithSpec{})
  57. }
  58. }
  59. func (nursingHomeWithSpecDb *NursingHomeWithSpec) NursingHomeWithSpecDelete() (int64, error) {
  60. return Db.Where("enterprise_id = ?", nursingHomeWithSpecDb.EnterpriseId).Delete(model.NursingHomeWithSpec{})
  61. }
  62. func (nursingHomeWithSpecDb *NursingHomeWithSpec) NursingHomeWithSpecUpdate(id interface{}, m *model.NursingHomeWithSpec, forceColums ...string) (int64, error) {
  63. var (
  64. affected int64
  65. err error
  66. )
  67. if forceColums != nil {
  68. affected, err = nursingHomeWithSpecDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
  69. } else {
  70. affected, err = nursingHomeWithSpecDb.Db.Where("id=?", id).Update(m)
  71. }
  72. if err != nil {
  73. return 0, err
  74. }
  75. return affected, nil
  76. }