广告平台(站长下代理使用)
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.
 
 
 
 
 
 

78 lines
2.0 KiB

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