package implement import ( "applet/app/db/dao" "applet/app/db/model" "applet/app/utils/logx" "reflect" "xorm.io/xorm" ) func NewMediumWithRoleDb(engine *xorm.Engine) dao.MediumWithRoleDao { return &MediumWithRoleDb{Db: engine} } type MediumWithRoleDb struct { Db *xorm.Engine } func (m MediumWithRoleDb) FindMediumWithRole(id int) (*[]model.MediumWithRole, error) { var mm []model.MediumWithRole if err := m.Db.Where("adm_id =?", id).Find(&mm); err != nil { return nil, logx.Error(err) } return &mm, nil } func (m MediumWithRoleDb) FindMediumWithRoleByRoleId(id int) (*[]model.MediumWithRole, error) { var mm []model.MediumWithRole if err := m.Db.Where("role_id =?", id).Find(&mm); err != nil { return nil, logx.Error(err) } 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{}) } else { return session.Where("adm_id = ?", admId).Delete(model.MediumWithRole{}) } } func (m MediumWithRoleDb) GetMediumWithRoleByRole(id int) (mm *model.MediumWithRole, err error) { mm = new(model.MediumWithRole) has, err := m.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 (m MediumWithRoleDb) MediumWithRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) { if reflect.TypeOf(roleId).Kind() == reflect.Slice { return session.In("role_id", roleId).Delete(model.MediumWithRole{}) } else { return session.Where("role_id = ?", roleId).Delete(model.MediumWithRole{}) } } func (m MediumWithRoleDb) MediumWithRoleDeleteBySession(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("medium_id = ?", id).Delete(model.MediumWithRole{}) } } func (m MediumWithRoleDb) BatchAddMediumWithRoleBySession(session *xorm.Session, mm []*model.MediumWithRole) (int64, error) { affected, err := session.Insert(mm) if err != nil { return 0, err } return affected, nil }