|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package implement
-
- import (
- "applet/app/db/dao"
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- func NewAgentWithRoleDb(engine *xorm.Engine) dao.AgentWithRoleDao {
- return &AgentWithRoleDb{Db: engine}
- }
-
- type AgentWithRoleDb struct {
- Db *xorm.Engine
- }
-
- func (a AgentWithRoleDb) FindAgentWithRole(id int) (*[]model.AgentWithRole, error) {
- var mm []model.AgentWithRole
- if err := a.Db.Where("adm_id =?", id).Find(&mm); err != nil {
- return nil, logx.Error(err)
- }
- return &mm, nil
- }
-
- func (a AgentWithRoleDb) FindAgentWithRoleByRoleId(id int) (*[]model.AgentWithRole, error) {
- var mm []model.AgentWithRole
- if err := a.Db.Where("role_id =?", id).Find(&mm); err != nil {
- return nil, logx.Error(err)
- }
- 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{})
- } else {
- return session.Where("adm_id = ?", admId).Delete(model.AgentWithRole{})
- }
- }
-
- func (a AgentWithRoleDb) GetAgentWithRoleByRole(id int) (mm *model.AgentWithRole, err error) {
- mm = new(model.AgentWithRole)
- has, err := a.Db.Where("role_id =?", id).Get(mm)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return mm, nil
- }
-
- func (a AgentWithRoleDb) AgentWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) {
- if reflect.TypeOf(roleId).Kind() == reflect.Slice {
- return session.In("role_id", roleId).Delete(model.AgentWithRole{})
- } else {
- return session.Where("role_id = ?", roleId).Delete(model.AgentWithRole{})
- }
- }
-
- func (a AgentWithRoleDb) AgentWithRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return session.In("agent_id", id).Delete(model.AgentWithRole{})
- } else {
- return session.Where("agent_id = ?", id).Delete(model.AgentWithRole{})
- }
- }
-
- func (a AgentWithRoleDb) BatchAddAgentWithRoleBySession(session *xorm.Session, mm []*model.AgentWithRole) (int64, error) {
- affected, err := session.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
|