面包店
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.3 KiB

9 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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) FindAdminRole(id int) (*[]model.AdminRole, error) {
  15. var m []model.AdminRole
  16. if err := adminRoleDb.Db.Where("adm_id =?", id).Find(&m); err != nil {
  17. return nil, logx.Error(err)
  18. }
  19. return &m, nil
  20. }
  21. func (adminRoleDb *AdminRoleDb) FindAdminRoleByRoleId(id int) (*[]model.AdminRole, error) {
  22. var m []model.AdminRole
  23. if err := adminRoleDb.Db.Where("role_id =?", id).Find(&m); err != nil {
  24. return nil, logx.Error(err)
  25. }
  26. return &m, nil
  27. }
  28. func (adminRoleDb *AdminRoleDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) {
  29. if reflect.TypeOf(admId).Kind() == reflect.Slice {
  30. return session.In("adm_id", admId).Delete(model.AdminRole{})
  31. } else {
  32. return session.Where("adm_id = ?", admId).Delete(model.AdminRole{})
  33. }
  34. }
  35. func (adminRoleDb *AdminRoleDb) GetAdminRoleByRole(id int) (m *model.AdminRole, err error) {
  36. m = new(model.AdminRole)
  37. has, err := adminRoleDb.Db.Where("role_id =?", id).Get(m)
  38. if err != nil {
  39. return nil, logx.Error(err)
  40. }
  41. if has == false {
  42. return nil, nil
  43. }
  44. return m, nil
  45. }
  46. func (adminRoleDb *AdminRoleDb) AdminRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) {
  47. if reflect.TypeOf(roleId).Kind() == reflect.Slice {
  48. return session.In("role_id", roleId).Delete(model.AdminRole{})
  49. } else {
  50. return session.Where("role_id = ?", roleId).Delete(model.AdminRole{})
  51. }
  52. }
  53. func (adminRoleDb *AdminRoleDb) AdminRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  54. if reflect.TypeOf(id).Kind() == reflect.Slice {
  55. return session.In("id", id).Delete(model.AdminRole{})
  56. } else {
  57. return session.Where("adm_id = ?", id).Delete(model.AdminRole{})
  58. }
  59. }
  60. func (adminRoleDb *AdminRoleDb) BatchAddAdminRoleBySession(session *xorm.Session, mm []*model.AdminRole) (int64, error) {
  61. affected, err := session.Insert(mm)
  62. if err != nil {
  63. return 0, err
  64. }
  65. return affected, nil
  66. }
  67. type AdminRole struct {
  68. model.Admin `xorm:"extends"`
  69. model.AdminRole `xorm:"extends"`
  70. }
  71. func (AdminRole) TableName() string {
  72. return "admin_role"
  73. }