广告平台(总站长使用)
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 NewAgentRoleDb(engine *xorm.Engine) dao.AgentRoleDao {
  10. return &AgentRoleDb{Db: engine}
  11. }
  12. type AgentRoleDb struct {
  13. Db *xorm.Engine
  14. }
  15. func (a AgentRoleDb) FindAgentRole() (*[]model.AgentRole, error) {
  16. var mm []model.AgentRole
  17. if err := a.Db.Desc("id").Find(&mm); err != nil {
  18. return nil, logx.Error(err)
  19. }
  20. return &mm, nil
  21. }
  22. func (a AgentRoleDb) GetAgentRole() (m *model.AgentRole, err error) {
  23. m = new(model.AgentRole)
  24. has, err := a.Db.Where("id = ?", m.Id).Get(m)
  25. if err != nil {
  26. return nil, logx.Error(err)
  27. }
  28. if has == false {
  29. return nil, nil
  30. }
  31. return m, nil
  32. }
  33. func (a AgentRoleDb) UpdateAgentRole(m *model.AgentRole, columns ...string) (int64, error) {
  34. affected, err := a.Db.Where("id =?", m.Id).Cols(columns...).Update(m)
  35. if err != nil {
  36. return 0, err
  37. }
  38. return affected, nil
  39. }
  40. func (a AgentRoleDb) AgentRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  41. if reflect.TypeOf(id).Kind() == reflect.Slice {
  42. return session.In("id", id).Delete(model.Role{})
  43. } else {
  44. return session.Where("id = ?", id).Delete(model.Role{})
  45. }
  46. }
  47. func (a AgentRoleDb) AgentRoleInsert(m *model.AgentRole) (int, error) {
  48. _, err := a.Db.InsertOne(m)
  49. if err != nil {
  50. return 0, err
  51. }
  52. return m.Id, nil
  53. }
  54. func (a AgentRoleDb) FindPermissionGroupByAgentRole(roleId int) (list []*dao.AgentRolePermissionGroup, total int64, err error) {
  55. total, err = a.Db.Where("agent_role.id =?", roleId).
  56. Join("LEFT", "agent_role_permission_group", "agent_role_permission_group.role_id = agent_role.id").
  57. Join("LEFT", "agent_permission_group", "agent_permission_group.id = agent_role_permission_group.group_id").
  58. FindAndCount(&list)
  59. return
  60. }