智慧食堂
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

db_nursing_home_package_with_day.go 2.6 KiB

1 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "xorm.io/xorm"
  6. )
  7. type NursingHomePackageWithDayDb struct {
  8. Db *xorm.Engine `json:"db"`
  9. PackageId int `json:"package_id"`
  10. }
  11. func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) Set(packageId int) { // set方法
  12. nursingHomePackageWithDayDb.Db = Db
  13. nursingHomePackageWithDayDb.PackageId = packageId
  14. }
  15. func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) GetNursingHomePackageWithDay(id int) (m *model.NursingHomePackageWithDay, err error) {
  16. m = new(model.NursingHomePackageWithDay)
  17. has, err := nursingHomePackageWithDayDb.Db.Where("id =?", id).Get(m)
  18. if err != nil {
  19. return nil, logx.Error(err)
  20. }
  21. if has == false {
  22. return nil, nil
  23. }
  24. return m, nil
  25. }
  26. func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) FindNursingHomePackageWithDay() (*[]model.NursingHomePackageWithDay, error) {
  27. var m []model.NursingHomePackageWithDay
  28. if err := nursingHomePackageWithDayDb.Db.Where("package_id =?", nursingHomePackageWithDayDb.PackageId).Asc("id").Find(&m); err != nil {
  29. return nil, logx.Error(err)
  30. }
  31. return &m, nil
  32. }
  33. func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) NursingHomePackageWithDayInsert(m *model.NursingHomePackageWithDay) (int, error) {
  34. _, err := nursingHomePackageWithDayDb.Db.InsertOne(m)
  35. if err != nil {
  36. return 0, err
  37. }
  38. return m.Id, nil
  39. }
  40. func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) BatchAddNursingHomePackageWithDaysBySession(session *xorm.Session, mm []*model.NursingHomePackageWithDay) (int64, error) {
  41. affected, err := session.Insert(mm)
  42. if err != nil {
  43. return 0, err
  44. }
  45. return affected, nil
  46. }
  47. func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) BatchAddNursingHomePackageWithDays(mm []*model.NursingHomePackageWithDay) (int64, error) {
  48. affected, err := nursingHomePackageWithDayDb.Db.Insert(mm)
  49. if err != nil {
  50. return 0, err
  51. }
  52. return affected, nil
  53. }
  54. func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) NursingHomePackageWithDayDeleteBySession(session *xorm.Session) (int64, error) {
  55. return Db.Where("package_id = ?", nursingHomePackageWithDayDb.PackageId).Delete(model.NursingHomePackageWithDay{})
  56. }
  57. func (nursingHomePackageWithDayDb *NursingHomePackageWithDayDb) NursingHomePackageWithDayUpdate(Db *xorm.Engine, id interface{}, m *model.NursingHomePackageWithDay, forceColums ...string) (int64, error) {
  58. var (
  59. affected int64
  60. err error
  61. )
  62. if forceColums != nil {
  63. affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(m)
  64. } else {
  65. affected, err = Db.Where("id=?", id).Update(m)
  66. }
  67. if err != nil {
  68. return 0, err
  69. }
  70. return affected, nil
  71. }