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

70 lines
1.8 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 NewMediumRoleDb(engine *xorm.Engine) dao.MediumRoleDao {
  10. return &MediumRoleDb{Db: engine}
  11. }
  12. type MediumRoleDb struct {
  13. Db *xorm.Engine
  14. }
  15. func (m MediumRoleDb) FindMediumRole() (*[]model.MediumRole, error) {
  16. var mm []model.MediumRole
  17. if err := m.Db.Desc("id").Find(&mm); err != nil {
  18. return nil, logx.Error(err)
  19. }
  20. return &mm, nil
  21. }
  22. func (m MediumRoleDb) GetMediumRole() (mm *model.MediumRole, err error) {
  23. mm = new(model.MediumRole)
  24. has, err := m.Db.Where("id = ?", mm.Id).Get(mm)
  25. if err != nil {
  26. return nil, logx.Error(err)
  27. }
  28. if has == false {
  29. return nil, nil
  30. }
  31. return mm, nil
  32. }
  33. func (m MediumRoleDb) UpdateMediumRole(mm *model.MediumRole, columns ...string) (int64, error) {
  34. affected, err := m.Db.Where("id =?", mm.Id).Cols(columns...).Update(m)
  35. if err != nil {
  36. return 0, err
  37. }
  38. return affected, nil
  39. }
  40. func (m MediumRoleDb) MediumRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  41. if reflect.TypeOf(id).Kind() == reflect.Slice {
  42. return session.In("id", id).Delete(model.MediumRole{})
  43. } else {
  44. return session.Where("id = ?", id).Delete(model.MediumRole{})
  45. }
  46. }
  47. func (m MediumRoleDb) MediumRoleInsert(mm *model.MediumRole) (int, error) {
  48. _, err := m.Db.InsertOne(mm)
  49. if err != nil {
  50. return 0, err
  51. }
  52. return mm.Id, nil
  53. }
  54. func (m MediumRoleDb) FindPermissionGroupByMediumRole(roleId int) (list []*dao.MediumRolePermissionGroup, total int64, err error) {
  55. total, err = m.Db.Where("medium_role.id =?", roleId).
  56. Join("LEFT", "medium_role_permission_group", "medium_role_permission_group.role_id = medium_role.id").
  57. Join("LEFT", "medium_permission_group", "medium_permission_group.id = medium_role_permission_group.group_id").
  58. FindAndCount(&list)
  59. return
  60. }