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

69 lines
2.2 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 AdminWithEnterpriseDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. }
  11. func (adminWithEnterpriseDb *AdminWithEnterpriseDb) Set() { // set方法
  12. adminWithEnterpriseDb.Db = Db
  13. }
  14. func (adminWithEnterpriseDb *AdminWithEnterpriseDb) FindAdminWithEnterprise(id int) (*[]model.AdminWithEnterprise, error) {
  15. var m []model.AdminWithEnterprise
  16. if err := adminWithEnterpriseDb.Db.Where("adm_id =?", id).Find(&m); err != nil {
  17. return nil, logx.Error(err)
  18. }
  19. return &m, nil
  20. }
  21. func (adminWithEnterpriseDb *AdminWithEnterpriseDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) {
  22. if reflect.TypeOf(admId).Kind() == reflect.Slice {
  23. return session.In("adm_id", admId).Delete(model.AdminWithEnterprise{})
  24. } else {
  25. return session.Where("adm_id = ?", admId).Delete(model.AdminWithEnterprise{})
  26. }
  27. }
  28. func (adminWithEnterpriseDb *AdminWithEnterpriseDb) GetAdminWithEnterpriseByWithEnterprise(id int) (m *model.AdminWithEnterprise, err error) {
  29. m = new(model.AdminWithEnterprise)
  30. has, err := adminWithEnterpriseDb.Db.Where("role_id =?", id).Get(m)
  31. if err != nil {
  32. return nil, logx.Error(err)
  33. }
  34. if has == false {
  35. return nil, nil
  36. }
  37. return m, nil
  38. }
  39. func (adminWithEnterpriseDb *AdminWithEnterpriseDb) AdminWithEnterpriseDeleteForWithEnterpriseBySession(session *xorm.Session, roleId interface{}) (int64, error) {
  40. if reflect.TypeOf(roleId).Kind() == reflect.Slice {
  41. return session.In("role_id", roleId).Delete(model.AdminWithEnterprise{})
  42. } else {
  43. return session.Where("role_id = ?", roleId).Delete(model.AdminWithEnterprise{})
  44. }
  45. }
  46. func (adminWithEnterpriseDb *AdminWithEnterpriseDb) AdminWithEnterpriseDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  47. if reflect.TypeOf(id).Kind() == reflect.Slice {
  48. return session.In("id", id).Delete(model.AdminWithEnterprise{})
  49. } else {
  50. return session.Where("adm_id = ?", id).Delete(model.AdminWithEnterprise{})
  51. }
  52. }
  53. func (adminWithEnterpriseDb *AdminWithEnterpriseDb) BatchAddAdminWithEnterpriseBySession(session *xorm.Session, mm []*model.AdminWithEnterprise) (int64, error) {
  54. affected, err := session.Insert(mm)
  55. if err != nil {
  56. return 0, err
  57. }
  58. return affected, nil
  59. }