From a491f294f782c2e932bb3a7c0fe44d583018c9ec Mon Sep 17 00:00:00 2001 From: dengbiao Date: Fri, 16 Aug 2024 23:18:18 +0800 Subject: [PATCH] update --- src/dao/agent_dao.go | 30 +++++++++++++ src/dao/agent_role_dao.go | 2 +- src/dao/agent_with_role_dao.go | 2 +- src/dao/medium_dao.go | 30 +++++++++++++ src/dao/medium_role_dao.go | 2 +- src/dao/medium_with_role_dao.go | 2 +- src/implement/admin_role_implement.go | 7 +-- src/implement/agent_implement.go | 47 +++++++++++++++++++++ src/implement/agent_role_implement.go | 4 +- src/implement/agent_with_role_implement.go | 8 ++-- src/implement/medium_implement.go | 47 +++++++++++++++++++++ src/implement/medium_role_implement.go | 4 +- src/implement/medium_with_role_implement.go | 8 ++-- 13 files changed, 174 insertions(+), 19 deletions(-) diff --git a/src/dao/agent_dao.go b/src/dao/agent_dao.go index 739d419..ae3b6aa 100644 --- a/src/dao/agent_dao.go +++ b/src/dao/agent_dao.go @@ -10,4 +10,34 @@ type AgentDao interface { AgentInsert(m *model.Agent) (int64, error) AgentDeleteBySession(session *xorm.Session, id interface{}) (int64, error) UpdateAgent(m *model.Agent, columns ...string) (int64, error) + GetAgentRolePermission(id int) (list []*AgentWithRolePermission, total int64, err error) + FindAdmin(username string, state, page, limit int) (list []model.Agent, total int64, err error) + GetAgent(id int) (m *model.Agent, err error) + FindAgentRolePermissionGroup(id int) (list []*AgentWithRolePermissionGroup, total int64, err error) +} + +type AgentWithRolePermissionGroup struct { + model.Agent `xorm:"extends"` + model.AgentWithRole `xorm:"extends"` + model.AgentRole `xorm:"extends"` + model.AgentRolePermissionGroup `xorm:"extends"` + model.AgentPermissionGroup `xorm:"extends"` +} + +func (AgentWithRolePermissionGroup) TableName() string { + return "agent" +} + +type AgentWithRolePermission struct { + model.Agent `xorm:"extends"` + model.AgentWithRole `xorm:"extends"` + model.AgentRole `xorm:"extends"` + model.AgentRolePermissionGroup `xorm:"extends"` + model.AgentPermissionGroup `xorm:"extends"` + model.AgentPermissionGroupPermission `xorm:"extends"` + model.AgentPermission `xorm:"extends"` +} + +func (AgentWithRolePermission) TableName() string { + return "agent" } diff --git a/src/dao/agent_role_dao.go b/src/dao/agent_role_dao.go index 264e7f2..46bf998 100644 --- a/src/dao/agent_role_dao.go +++ b/src/dao/agent_role_dao.go @@ -7,7 +7,7 @@ import ( type AgentRoleDao interface { FindAgentRole() (*[]model.AgentRole, error) - GetAgentRole() (m *model.AgentRole, err error) + GetAgentRole(id int) (m *model.AgentRole, err error) UpdateAgentRole(m *model.AgentRole, columns ...string) (int64, error) AgentRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) AgentRoleInsert(m *model.AgentRole) (int, error) diff --git a/src/dao/agent_with_role_dao.go b/src/dao/agent_with_role_dao.go index 719c7c5..2c046d8 100644 --- a/src/dao/agent_with_role_dao.go +++ b/src/dao/agent_with_role_dao.go @@ -8,7 +8,7 @@ import ( type AgentWithRoleDao interface { FindAgentWithRole(id int) (*[]model.AgentWithRole, error) FindAgentWithRoleByRoleId(id int) (*[]model.AgentWithRole, error) - AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) + AgentDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) GetAgentWithRoleByRole(id int) (m *model.AgentWithRole, err error) AgentWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) AgentWithRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) diff --git a/src/dao/medium_dao.go b/src/dao/medium_dao.go index 4bfae62..4127afa 100644 --- a/src/dao/medium_dao.go +++ b/src/dao/medium_dao.go @@ -10,4 +10,34 @@ type MediumDao interface { MediumInsert(m *model.Medium) (int64, error) MediumDeleteBySession(session *xorm.Session, id interface{}) (int64, error) UpdateMedium(m *model.Medium, columns ...string) (int64, error) + GetMediumRolePermission(id int) (list []*MediumWithRolePermission, total int64, err error) + FindAdmin(username string, state, page, limit int) (list []model.Medium, total int64, err error) + GetMedium(id int) (m *model.Medium, err error) + FindMediumRolePermissionGroup(id int) (list []*MediumWithRolePermissionGroup, total int64, err error) +} + +type MediumWithRolePermissionGroup struct { + model.Medium `xorm:"extends"` + model.MediumWithRole `xorm:"extends"` + model.MediumRole `xorm:"extends"` + model.MediumRolePermissionGroup `xorm:"extends"` + model.MediumPermissionGroup `xorm:"extends"` +} + +func (MediumWithRolePermissionGroup) TableName() string { + return "medium" +} + +type MediumWithRolePermission struct { + model.Medium `xorm:"extends"` + model.MediumWithRole `xorm:"extends"` + model.MediumRole `xorm:"extends"` + model.MediumRolePermissionGroup `xorm:"extends"` + model.MediumPermissionGroup `xorm:"extends"` + model.MediumPermissionGroupPermission `xorm:"extends"` + model.MediumPermission `xorm:"extends"` +} + +func (MediumWithRolePermission) TableName() string { + return "medium" } diff --git a/src/dao/medium_role_dao.go b/src/dao/medium_role_dao.go index 7cc20f7..25b325b 100644 --- a/src/dao/medium_role_dao.go +++ b/src/dao/medium_role_dao.go @@ -7,7 +7,7 @@ import ( type MediumRoleDao interface { FindMediumRole() (*[]model.MediumRole, error) - GetMediumRole() (m *model.MediumRole, err error) + GetMediumRole(id int) (m *model.MediumRole, err error) UpdateMediumRole(m *model.MediumRole, columns ...string) (int64, error) MediumRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) MediumRoleInsert(m *model.MediumRole) (int, error) diff --git a/src/dao/medium_with_role_dao.go b/src/dao/medium_with_role_dao.go index 31c4102..cdfff88 100644 --- a/src/dao/medium_with_role_dao.go +++ b/src/dao/medium_with_role_dao.go @@ -8,7 +8,7 @@ import ( type MediumWithRoleDao interface { FindMediumWithRole(id int) (*[]model.MediumWithRole, error) FindMediumWithRoleByRoleId(id int) (*[]model.MediumWithRole, error) - AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) + MediumDeleteBySessionForAdmId(session *xorm.Session, id interface{}) (int64, error) GetMediumWithRoleByRole(id int) (m *model.MediumWithRole, err error) MediumWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) MediumWithRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) diff --git a/src/implement/admin_role_implement.go b/src/implement/admin_role_implement.go index 91ea914..d2b5b64 100644 --- a/src/implement/admin_role_implement.go +++ b/src/implement/admin_role_implement.go @@ -3,6 +3,7 @@ import ( "code.fnuoos.com/zhimeng/model.git/src/dao" "code.fnuoos.com/zhimeng/model.git/src/model" + zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" "reflect" "xorm.io/xorm" ) @@ -18,7 +19,7 @@ type AdminRoleDb struct { func (a AdminRoleDb) FindAdminRole(id int) (*[]model.AdminRole, error) { var m []model.AdminRole if err := a.Db.Where("adm_id =?", id).Find(&m); err != nil { - return nil, logx.Error(err) + return nil, zhios_order_relate_logx.Error(err) } return &m, nil } @@ -26,7 +27,7 @@ func (a AdminRoleDb) FindAdminRole(id int) (*[]model.AdminRole, error) { func (a AdminRoleDb) FindAdminRoleByRoleId(id int) (*[]model.AdminRole, error) { var m []model.AdminRole if err := a.Db.Where("role_id =?", id).Find(&m); err != nil { - return nil, logx.Error(err) + return nil, zhios_order_relate_logx.Error(err) } return &m, nil } @@ -43,7 +44,7 @@ func (a AdminRoleDb) GetAdminRoleByRole(id int) (m *model.AdminRole, err error) m = new(model.AdminRole) has, err := a.Db.Where("role_id =?", id).Get(m) if err != nil { - return nil, logx.Error(err) + return nil, zhios_order_relate_logx.Error(err) } if has == false { return nil, nil diff --git a/src/implement/agent_implement.go b/src/implement/agent_implement.go index 31741eb..7fbb2ad 100644 --- a/src/implement/agent_implement.go +++ b/src/implement/agent_implement.go @@ -51,3 +51,50 @@ func (a AgentDb) UpdateAgent(m *model.Agent, columns ...string) (int64, error) { } return affected, nil } + +func (a AgentDb) GetAgentRolePermission(id int) (list []*dao.AgentWithRolePermission, total int64, err error) { + total, err = a.Db.Where("agent.id =?", id). + Join("LEFT", "agent_with_role", "agent.id = agent_with_role.agent_id"). + Join("LEFT", "agent_role", "admin_with_role.role_id = agent_role.id"). + Join("LEFT", "agent_role_permission_group", "agent_role.id = agent_role_permission_group.role_id"). + Join("LEFT", "agent_permission_group", "agent_role_permission_group.group_id = agent_permission_group.id"). + Join("LEFT", "agent_permission_group_permission", "agent_permission_group.id = agent_permission_group_permission.group_id"). + Join("LEFT", "agent_permission", "agent_permission_group_permission.permission_id = agent_permission.id"). + FindAndCount(&list) + return +} + +func (a AgentDb) FindAdmin(username string, state, page, limit int) (list []model.Agent, total int64, err error) { + sess := a.Db.Desc("id").Limit(limit, (page-1)*limit) + if username != "" { + sess.And("username like ?", "%"+username+"%") + } + if state != 0 { + sess.And("state = ?", state) + } + total, err = sess.FindAndCount(&list) + if err != nil { + return nil, 0, err + } + return +} + +func (a AgentDb) GetAgent(id int) (m *model.Agent, err error) { + m = new(model.Agent) + has, err := a.Db.Where("id =?", id).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (a AgentDb) FindAgentRolePermissionGroup(id int) (list []*dao.AgentWithRolePermissionGroup, total int64, err error) { + total, err = a.Db.Where("agent.id =?", id). + Join("LEFT", "agent_with_role", "agent.id = agent_with_role.agent_id"). + Join("LEFT", "agent_role", "agent_with_role.role_id = agent_role.id"). + FindAndCount(&list) + return +} diff --git a/src/implement/agent_role_implement.go b/src/implement/agent_role_implement.go index ea2049c..31d1910 100644 --- a/src/implement/agent_role_implement.go +++ b/src/implement/agent_role_implement.go @@ -24,9 +24,9 @@ func (a AgentRoleDb) FindAgentRole() (*[]model.AgentRole, error) { return &mm, nil } -func (a AgentRoleDb) GetAgentRole() (m *model.AgentRole, err error) { +func (a AgentRoleDb) GetAgentRole(id int) (m *model.AgentRole, err error) { m = new(model.AgentRole) - has, err := a.Db.Where("id = ?", m.Id).Get(m) + has, err := a.Db.Where("id = ?", id).Get(m) if err != nil { return nil, zhios_order_relate_logx.Error(err) } diff --git a/src/implement/agent_with_role_implement.go b/src/implement/agent_with_role_implement.go index 0a78de9..06bdc57 100644 --- a/src/implement/agent_with_role_implement.go +++ b/src/implement/agent_with_role_implement.go @@ -32,11 +32,11 @@ func (a AgentWithRoleDb) FindAgentWithRoleByRoleId(id int) (*[]model.AgentWithRo return &mm, nil } -func (a AgentWithRoleDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) { - if reflect.TypeOf(admId).Kind() == reflect.Slice { - return session.In("adm_id", admId).Delete(model.AgentWithRole{}) +func (a AgentWithRoleDb) AgentDeleteBySessionForAdmId(session *xorm.Session, id interface{}) (int64, error) { + if reflect.TypeOf(id).Kind() == reflect.Slice { + return session.In("id", id).Delete(model.AgentWithRole{}) } else { - return session.Where("adm_id = ?", admId).Delete(model.AgentWithRole{}) + return session.Where("id = ?", id).Delete(model.AgentWithRole{}) } } diff --git a/src/implement/medium_implement.go b/src/implement/medium_implement.go index ae1bdf8..980ae1f 100644 --- a/src/implement/medium_implement.go +++ b/src/implement/medium_implement.go @@ -51,3 +51,50 @@ func (m MediumDb) MediumDeleteBySession(session *xorm.Session, id interface{}) ( return session.Where("id = ?", id).Delete(model.Admin{}) } } + +func (m MediumDb) GetMediumRolePermission(id int) (list []*dao.MediumWithRolePermission, total int64, err error) { + total, err = m.Db.Where("medium.id =?", id). + Join("LEFT", "medium_with_role", "medium.id = medium_with_role.medium_id"). + Join("LEFT", "medium_role", "admin_with_role.role_id = medium_role.id"). + Join("LEFT", "medium_role_permission_group", "medium_role.id = medium_role_permission_group.role_id"). + Join("LEFT", "medium_permission_group", "medium_role_permission_group.group_id = medium_permission_group.id"). + Join("LEFT", "medium_permission_group_permission", "medium_permission_group.id = medium_permission_group_permission.group_id"). + Join("LEFT", "medium_permission", "medium_permission_group_permission.permission_id = medium_permission.id"). + FindAndCount(&list) + return +} + +func (m MediumDb) FindAdmin(username string, state, page, limit int) (list []model.Medium, total int64, err error) { + sess := m.Db.Desc("id").Limit(limit, (page-1)*limit) + if username != "" { + sess.And("username like ?", "%"+username+"%") + } + if state != 0 { + sess.And("state = ?", state) + } + total, err = sess.FindAndCount(&list) + if err != nil { + return nil, 0, err + } + return +} + +func (m MediumDb) GetMedium(id int) (mm *model.Medium, err error) { + mm = new(model.Medium) + has, err := m.Db.Where("id =?", id).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return mm, nil +} + +func (m MediumDb) FindMediumRolePermissionGroup(id int) (list []*dao.MediumWithRolePermissionGroup, total int64, err error) { + total, err = m.Db.Where("medium.id =?", id). + Join("LEFT", "medium_with_role", "medium.id = medium_with_role.medium_id"). + Join("LEFT", "medium_role", "medium_with_role.role_id = medium_role.id"). + FindAndCount(&list) + return +} diff --git a/src/implement/medium_role_implement.go b/src/implement/medium_role_implement.go index 25e50d3..8aa9cf2 100644 --- a/src/implement/medium_role_implement.go +++ b/src/implement/medium_role_implement.go @@ -24,9 +24,9 @@ func (m MediumRoleDb) FindMediumRole() (*[]model.MediumRole, error) { return &mm, nil } -func (m MediumRoleDb) GetMediumRole() (mm *model.MediumRole, err error) { +func (m MediumRoleDb) GetMediumRole(id int) (mm *model.MediumRole, err error) { mm = new(model.MediumRole) - has, err := m.Db.Where("id = ?", mm.Id).Get(mm) + has, err := m.Db.Where("id = ?", id).Get(mm) if err != nil { return nil, zhios_order_relate_logx.Error(err) } diff --git a/src/implement/medium_with_role_implement.go b/src/implement/medium_with_role_implement.go index 9a50081..835da46 100644 --- a/src/implement/medium_with_role_implement.go +++ b/src/implement/medium_with_role_implement.go @@ -32,11 +32,11 @@ func (m MediumWithRoleDb) FindMediumWithRoleByRoleId(id int) (*[]model.MediumWit return &mm, nil } -func (m MediumWithRoleDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) { - if reflect.TypeOf(admId).Kind() == reflect.Slice { - return session.In("adm_id", admId).Delete(model.MediumWithRole{}) +func (m MediumWithRoleDb) MediumDeleteBySessionForAdmId(session *xorm.Session, id interface{}) (int64, error) { + if reflect.TypeOf(id).Kind() == reflect.Slice { + return session.In("medium_id", id).Delete(model.MediumWithRole{}) } else { - return session.Where("adm_id = ?", admId).Delete(model.MediumWithRole{}) + return session.Where("medium_id = ?", id).Delete(model.MediumWithRole{}) } }