智慧食堂
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_admin_role.go 2.1 KiB

1 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "reflect"
  6. "xorm.io/xorm"
  7. )
  8. type AdminRoleDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. }
  11. func (adminRoleDb *AdminRoleDb) Set() { // set方法
  12. adminRoleDb.Db = Db
  13. }
  14. func (adminRoleDb *AdminRoleDb) GetAdminRole(id int) (m *model.AdminRole, err error) {
  15. m = new(model.AdminRole)
  16. has, err := adminRoleDb.Db.Where("adm_id =?", id).Get(m)
  17. if err != nil {
  18. return nil, logx.Error(err)
  19. }
  20. if has == false {
  21. return nil, nil
  22. }
  23. return m, nil
  24. }
  25. func (adminRoleDb *AdminRoleDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) {
  26. if reflect.TypeOf(admId).Kind() == reflect.Slice {
  27. return session.In("adm_id", admId).Delete(model.AdminRole{})
  28. } else {
  29. return session.Where("adm_id = ?", admId).Delete(model.AdminRole{})
  30. }
  31. }
  32. func (adminRoleDb *AdminRoleDb) GetAdminRoleByRole(id int) (m *model.AdminRole, err error) {
  33. m = new(model.AdminRole)
  34. has, err := adminRoleDb.Db.Where("role_id =?", id).Get(m)
  35. if err != nil {
  36. return nil, logx.Error(err)
  37. }
  38. if has == false {
  39. return nil, nil
  40. }
  41. return m, nil
  42. }
  43. func (adminRoleDb *AdminRoleDb) AdminRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) {
  44. if reflect.TypeOf(roleId).Kind() == reflect.Slice {
  45. return session.In("role_id", roleId).Delete(model.AdminRole{})
  46. } else {
  47. return session.Where("role_id = ?", roleId).Delete(model.AdminRole{})
  48. }
  49. }
  50. func (adminRoleDb *AdminRoleDb) AdminRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  51. if reflect.TypeOf(id).Kind() == reflect.Slice {
  52. return session.In("id", id).Delete(model.AdminRole{})
  53. } else {
  54. return session.Where("adm_id = ?", id).Delete(model.AdminRole{})
  55. }
  56. }
  57. func (adminRoleDb *AdminRoleDb) BatchAddAdminRoleBySession(session *xorm.Session, mm []*model.AdminRole) (int64, error) {
  58. affected, err := session.Insert(mm)
  59. if err != nil {
  60. return 0, err
  61. }
  62. return affected, nil
  63. }
  64. type AdminRole struct {
  65. model.Admin `xorm:"extends"`
  66. model.AdminRole `xorm:"extends"`
  67. }
  68. func (AdminRole) TableName() string {
  69. return "admin_role"
  70. }