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

108 lines
3.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 NursingHomeUserWithDayDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. IdentityId int `json:"identity_id"`
  11. }
  12. func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) Set(identityId int) { // set方法
  13. nursingHomeUserWithDayDb.Db = Db
  14. nursingHomeUserWithDayDb.IdentityId = identityId
  15. }
  16. func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) GetNursingHomeUserWithDay(id int) (m *model.NursingHomeUserWithDay, err error) {
  17. m = new(model.NursingHomeUserWithDay)
  18. has, err := nursingHomeUserWithDayDb.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 (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) FindNursingHomeUserWithDayByDate(sDate, eDate string) (*[]model.NursingHomeUserWithDay, error) {
  28. var m []model.NursingHomeUserWithDay
  29. if err := nursingHomeUserWithDayDb.Db.Where("identity_id =?", nursingHomeUserWithDayDb.IdentityId).
  30. And("date >= ? And date <= ?", sDate, eDate).Asc("date").Find(&m); err != nil {
  31. return nil, logx.Error(err)
  32. }
  33. return &m, nil
  34. }
  35. func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) FindNursingHomeUserWithDayByOrdNo(ordNo string) (*[]model.NursingHomeUserWithDay, error) {
  36. var m []model.NursingHomeUserWithDay
  37. if err := nursingHomeUserWithDayDb.Db.Where("ord_no =?", ordNo).Desc("id").Find(&m); err != nil {
  38. return nil, logx.Error(err)
  39. }
  40. return &m, nil
  41. }
  42. func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) FindNursingHomeUserWithDayByOrdNoAndState(ordNo string, state int) (*[]model.NursingHomeUserWithDay, error) {
  43. var m []model.NursingHomeUserWithDay
  44. if err := nursingHomeUserWithDayDb.Db.Where("ord_no =?", ordNo).And("state =?", state).Desc("id").Find(&m); err != nil {
  45. return nil, logx.Error(err)
  46. }
  47. return &m, nil
  48. }
  49. func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) NursingHomeUserWithDayInsert(m *model.NursingHomeUserWithDay) (int, error) {
  50. _, err := nursingHomeUserWithDayDb.Db.InsertOne(m)
  51. if err != nil {
  52. return 0, err
  53. }
  54. return m.Id, nil
  55. }
  56. func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) BatchAddNursingHomeUserWithDays(mm []*model.NursingHomeUserWithDay) (int64, error) {
  57. affected, err := nursingHomeUserWithDayDb.Db.Insert(mm)
  58. if err != nil {
  59. return 0, err
  60. }
  61. return affected, nil
  62. }
  63. func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) NursingHomeUserWithDayDelete(id interface{}) (int64, error) {
  64. if reflect.TypeOf(id).Kind() == reflect.Slice {
  65. return Db.In("id", id).Delete(model.NursingHomeUserWithDay{})
  66. } else {
  67. return Db.Where("id = ?", id).Delete(model.NursingHomeUserWithDay{})
  68. }
  69. }
  70. func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) NursingHomeUserWithDayUpdate(id interface{}, m *model.NursingHomeUserWithDay, forceColums ...string) (int64, error) {
  71. var (
  72. affected int64
  73. err error
  74. )
  75. if forceColums != nil {
  76. affected, err = nursingHomeUserWithDayDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
  77. } else {
  78. affected, err = nursingHomeUserWithDayDb.Db.Where("id=?", id).Update(m)
  79. }
  80. if err != nil {
  81. return 0, err
  82. }
  83. return affected, nil
  84. }
  85. func (nursingHomeUserWithDayDb *NursingHomeUserWithDayDb) NursingHomeUserWithDayBatchUpdate(ids interface{}, m []*model.NursingHomeUserWithDay) (int64, error) {
  86. var (
  87. affected int64
  88. err error
  89. )
  90. affected, err = nursingHomeUserWithDayDb.Db.In("id", ids).Update(m)
  91. if err != nil {
  92. return 0, err
  93. }
  94. return affected, nil
  95. }