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

db_nursing_home_set.go 2.0 KiB

pirms 1 gada
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }