|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type AdminRoleDb struct {
- Db *xorm.Engine `json:"db"`
- }
-
- func (adminRoleDb *AdminRoleDb) Set() { // set方法
- adminRoleDb.Db = Db
- }
-
- func (adminRoleDb *AdminRoleDb) FindAdminRole(id int) (*[]model.AdminRole, error) {
- var m []model.AdminRole
- if err := adminRoleDb.Db.Where("adm_id =?", id).Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (adminRoleDb *AdminRoleDb) FindAdminRoleByRoleId(id int) (*[]model.AdminRole, error) {
- var m []model.AdminRole
- if err := adminRoleDb.Db.Where("role_id =?", id).Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (adminRoleDb *AdminRoleDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) {
- if reflect.TypeOf(admId).Kind() == reflect.Slice {
- return session.In("adm_id", admId).Delete(model.AdminRole{})
- } else {
- return session.Where("adm_id = ?", admId).Delete(model.AdminRole{})
- }
- }
-
- func (adminRoleDb *AdminRoleDb) GetAdminRoleByRole(id int) (m *model.AdminRole, err error) {
- m = new(model.AdminRole)
- has, err := adminRoleDb.Db.Where("role_id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (adminRoleDb *AdminRoleDb) AdminRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) {
- if reflect.TypeOf(roleId).Kind() == reflect.Slice {
- return session.In("role_id", roleId).Delete(model.AdminRole{})
- } else {
- return session.Where("role_id = ?", roleId).Delete(model.AdminRole{})
- }
- }
-
- func (adminRoleDb *AdminRoleDb) AdminRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return session.In("id", id).Delete(model.AdminRole{})
- } else {
- return session.Where("adm_id = ?", id).Delete(model.AdminRole{})
- }
- }
-
- func (adminRoleDb *AdminRoleDb) BatchAddAdminRoleBySession(session *xorm.Session, mm []*model.AdminRole) (int64, error) {
- affected, err := session.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- type AdminRole struct {
- model.Admin `xorm:"extends"`
- model.AdminRole `xorm:"extends"`
- }
-
- func (AdminRole) TableName() string {
- return "admin_role"
- }
|