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

преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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) 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.AdminRole{})
  24. } else {
  25. return session.Where("adm_id = ?", admId).Delete(model.AdminRole{})
  26. }
  27. }
  28. func (adminRoleDb *AdminRoleDb) GetAdminRoleByRole(id int) (m *model.AdminRole, err error) {
  29. m = new(model.AdminRole)
  30. has, err := adminRoleDb.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 (adminRoleDb *AdminRoleDb) AdminRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) {
  40. if reflect.TypeOf(roleId).Kind() == reflect.Slice {
  41. return session.In("role_id", roleId).Delete(model.AdminRole{})
  42. } else {
  43. return session.Where("role_id = ?", roleId).Delete(model.AdminRole{})
  44. }
  45. }
  46. func (adminRoleDb *AdminRoleDb) AdminRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  47. if reflect.TypeOf(id).Kind() == reflect.Slice {
  48. return session.In("id", id).Delete(model.AdminRole{})
  49. } else {
  50. return session.Where("adm_id = ?", id).Delete(model.AdminRole{})
  51. }
  52. }
  53. func (adminRoleDb *AdminRoleDb) BatchAddAdminRoleBySession(session *xorm.Session, mm []*model.AdminRole) (int64, error) {
  54. affected, err := session.Insert(mm)
  55. if err != nil {
  56. return 0, err
  57. }
  58. return affected, nil
  59. }
  60. type AdminRole struct {
  61. model.Admin `xorm:"extends"`
  62. model.AdminRole `xorm:"extends"`
  63. }
  64. func (AdminRole) TableName() string {
  65. return "admin_role"
  66. }