@@ -10,4 +10,34 @@ type AgentDao interface { | |||||
AgentInsert(m *model.Agent) (int64, error) | AgentInsert(m *model.Agent) (int64, error) | ||||
AgentDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | AgentDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | ||||
UpdateAgent(m *model.Agent, columns ...string) (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" | |||||
} | } |
@@ -7,7 +7,7 @@ import ( | |||||
type AgentRoleDao interface { | type AgentRoleDao interface { | ||||
FindAgentRole() (*[]model.AgentRole, error) | 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) | UpdateAgentRole(m *model.AgentRole, columns ...string) (int64, error) | ||||
AgentRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | AgentRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | ||||
AgentRoleInsert(m *model.AgentRole) (int, error) | AgentRoleInsert(m *model.AgentRole) (int, error) | ||||
@@ -8,7 +8,7 @@ import ( | |||||
type AgentWithRoleDao interface { | type AgentWithRoleDao interface { | ||||
FindAgentWithRole(id int) (*[]model.AgentWithRole, error) | FindAgentWithRole(id int) (*[]model.AgentWithRole, error) | ||||
FindAgentWithRoleByRoleId(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) | GetAgentWithRoleByRole(id int) (m *model.AgentWithRole, err error) | ||||
AgentWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) | AgentWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) | ||||
AgentWithRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | AgentWithRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | ||||
@@ -10,4 +10,34 @@ type MediumDao interface { | |||||
MediumInsert(m *model.Medium) (int64, error) | MediumInsert(m *model.Medium) (int64, error) | ||||
MediumDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | MediumDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | ||||
UpdateMedium(m *model.Medium, columns ...string) (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" | |||||
} | } |
@@ -7,7 +7,7 @@ import ( | |||||
type MediumRoleDao interface { | type MediumRoleDao interface { | ||||
FindMediumRole() (*[]model.MediumRole, error) | 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) | UpdateMediumRole(m *model.MediumRole, columns ...string) (int64, error) | ||||
MediumRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | MediumRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | ||||
MediumRoleInsert(m *model.MediumRole) (int, error) | MediumRoleInsert(m *model.MediumRole) (int, error) | ||||
@@ -8,7 +8,7 @@ import ( | |||||
type MediumWithRoleDao interface { | type MediumWithRoleDao interface { | ||||
FindMediumWithRole(id int) (*[]model.MediumWithRole, error) | FindMediumWithRole(id int) (*[]model.MediumWithRole, error) | ||||
FindMediumWithRoleByRoleId(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) | GetMediumWithRoleByRole(id int) (m *model.MediumWithRole, err error) | ||||
MediumWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) | MediumWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) | ||||
MediumWithRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | MediumWithRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) | ||||
@@ -3,6 +3,7 @@ | |||||
import ( | import ( | ||||
"code.fnuoos.com/zhimeng/model.git/src/dao" | "code.fnuoos.com/zhimeng/model.git/src/dao" | ||||
"code.fnuoos.com/zhimeng/model.git/src/model" | "code.fnuoos.com/zhimeng/model.git/src/model" | ||||
zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" | |||||
"reflect" | "reflect" | ||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
@@ -18,7 +19,7 @@ type AdminRoleDb struct { | |||||
func (a AdminRoleDb) FindAdminRole(id int) (*[]model.AdminRole, error) { | func (a AdminRoleDb) FindAdminRole(id int) (*[]model.AdminRole, error) { | ||||
var m []model.AdminRole | var m []model.AdminRole | ||||
if err := a.Db.Where("adm_id =?", id).Find(&m); err != nil { | 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 | 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) { | func (a AdminRoleDb) FindAdminRoleByRoleId(id int) (*[]model.AdminRole, error) { | ||||
var m []model.AdminRole | var m []model.AdminRole | ||||
if err := a.Db.Where("role_id =?", id).Find(&m); err != nil { | 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 | return &m, nil | ||||
} | } | ||||
@@ -43,7 +44,7 @@ func (a AdminRoleDb) GetAdminRoleByRole(id int) (m *model.AdminRole, err error) | |||||
m = new(model.AdminRole) | m = new(model.AdminRole) | ||||
has, err := a.Db.Where("role_id =?", id).Get(m) | has, err := a.Db.Where("role_id =?", id).Get(m) | ||||
if err != nil { | if err != nil { | ||||
return nil, logx.Error(err) | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | } | ||||
if has == false { | if has == false { | ||||
return nil, nil | return nil, nil | ||||
@@ -51,3 +51,50 @@ func (a AgentDb) UpdateAgent(m *model.Agent, columns ...string) (int64, error) { | |||||
} | } | ||||
return affected, nil | 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 | |||||
} |
@@ -24,9 +24,9 @@ func (a AgentRoleDb) FindAgentRole() (*[]model.AgentRole, error) { | |||||
return &mm, nil | 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) | 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 { | if err != nil { | ||||
return nil, zhios_order_relate_logx.Error(err) | return nil, zhios_order_relate_logx.Error(err) | ||||
} | } | ||||
@@ -32,11 +32,11 @@ func (a AgentWithRoleDb) FindAgentWithRoleByRoleId(id int) (*[]model.AgentWithRo | |||||
return &mm, nil | 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 { | } else { | ||||
return session.Where("adm_id = ?", admId).Delete(model.AgentWithRole{}) | |||||
return session.Where("id = ?", id).Delete(model.AgentWithRole{}) | |||||
} | } | ||||
} | } | ||||
@@ -51,3 +51,50 @@ func (m MediumDb) MediumDeleteBySession(session *xorm.Session, id interface{}) ( | |||||
return session.Where("id = ?", id).Delete(model.Admin{}) | 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 | |||||
} |
@@ -24,9 +24,9 @@ func (m MediumRoleDb) FindMediumRole() (*[]model.MediumRole, error) { | |||||
return &mm, nil | 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) | 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 { | if err != nil { | ||||
return nil, zhios_order_relate_logx.Error(err) | return nil, zhios_order_relate_logx.Error(err) | ||||
} | } | ||||
@@ -32,11 +32,11 @@ func (m MediumWithRoleDb) FindMediumWithRoleByRoleId(id int) (*[]model.MediumWit | |||||
return &mm, nil | 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 { | } else { | ||||
return session.Where("adm_id = ?", admId).Delete(model.MediumWithRole{}) | |||||
return session.Where("medium_id = ?", id).Delete(model.MediumWithRole{}) | |||||
} | } | ||||
} | } | ||||