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

db_nursing_home_package.go 3.0 KiB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package db
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/db/model"
  5. "applet/app/utils/logx"
  6. "reflect"
  7. "xorm.io/xorm"
  8. )
  9. type NursingHomePackageDb struct {
  10. Db *xorm.Engine `json:"db"`
  11. }
  12. func (nursingHomePackageDb *NursingHomePackageDb) Set() { // set方法
  13. nursingHomePackageDb.Db = Db
  14. }
  15. func (nursingHomePackageDb *NursingHomePackageDb) GetNursingHomePackage(id int) (m *model.NursingHomePackage, err error) {
  16. m = new(model.NursingHomePackage)
  17. has, err := nursingHomePackageDb.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 (nursingHomePackageDb *NursingHomePackageDb) GetNursingHomePackageByMonth(enterpriseId int, year, month string) (m *model.NursingHomePackage, err error) {
  27. m = new(model.NursingHomePackage)
  28. has, err := nursingHomePackageDb.Db.Where("enterprise_id =?", enterpriseId).And("year =? and month =? and is_delete = 0", year, month).Get(m)
  29. if err != nil {
  30. return nil, logx.Error(err)
  31. }
  32. if has == false {
  33. return nil, nil
  34. }
  35. return m, nil
  36. }
  37. func (nursingHomePackageDb *NursingHomePackageDb) FindNursingHomePackage() (*[]model.NursingHomePackage, error) {
  38. var m []model.NursingHomePackage
  39. if err := nursingHomePackageDb.Db.Desc("id").Find(&m); err != nil {
  40. return nil, logx.Error(err)
  41. }
  42. return &m, nil
  43. }
  44. func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageInsert(m *model.NursingHomePackage) (int, error) {
  45. _, err := nursingHomePackageDb.Db.InsertOne(m)
  46. if err != nil {
  47. return 0, err
  48. }
  49. return m.Id, nil
  50. }
  51. func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageInsertBySession(session *xorm.Session, m *model.NursingHomePackage) (int, error) {
  52. _, err := session.InsertOne(m)
  53. if err != nil {
  54. return 0, err
  55. }
  56. return m.Id, nil
  57. }
  58. func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageDelete(id interface{}) (int64, error) {
  59. if reflect.TypeOf(id).Kind() == reflect.Slice {
  60. return Db.In("id", id).Delete(model.NursingHomePackage{})
  61. } else {
  62. return Db.Where("id = ?", id).Delete(model.NursingHomePackage{})
  63. }
  64. }
  65. func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageUpdateBySession(session *xorm.Session, id interface{}, m *model.NursingHomePackage, forceColums ...string) (int64, error) {
  66. var (
  67. affected int64
  68. err error
  69. )
  70. if forceColums != nil {
  71. affected, err = session.Where("id=?", id).Cols(forceColums...).Update(m)
  72. } else {
  73. affected, err = session.Where("id=?", id).Update(m)
  74. }
  75. if err != nil {
  76. return 0, err
  77. }
  78. return affected, nil
  79. }
  80. func (nursingHomePackageDb *NursingHomePackageDb) NursingHomePackageList(req md.ListNursingHomePackageReq) (m []model.NursingHomePackage, total int64, err error) {
  81. sess := nursingHomePackageDb.Db.Where("enterprise_id =?", req.EnterpriseId).Desc("id").Limit(req.Limit, (req.Page-1)*req.Limit)
  82. if req.Year != "" {
  83. sess.And("year = ?", req.Year)
  84. }
  85. if req.Month != "" {
  86. sess.And("month = ?", req.Month)
  87. }
  88. total, err = sess.And("is_delete = 0").FindAndCount(&m)
  89. if err != nil {
  90. return
  91. }
  92. return
  93. }