智慧食堂
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

db_nursing_home_with_spec.go 2.5 KiB

před 1 rokem
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }