|
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type SchemeEnterpriseDb struct {
- Db *xorm.Engine `json:"db"`
- }
-
- func (adminRoleDb *SchemeEnterpriseDb) Set() { // set方法
- adminRoleDb.Db = Db
- }
-
- func (adminRoleDb *SchemeEnterpriseDb) FindSchemeEnterprise(schemeId int) (*[]model.SchemeWithEnterprise, error) {
- var m []model.SchemeWithEnterprise
- if err := adminRoleDb.Db.Where("scheme_id =?", schemeId).Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (adminRoleDb *SchemeEnterpriseDb) FindSchemeEnterpriseByEnterpriseId(id int) (*[]model.SchemeWithEnterprise, error) {
- var m []model.SchemeWithEnterprise
- if err := adminRoleDb.Db.Where("role_id =?", id).Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (adminRoleDb *SchemeEnterpriseDb) GetSchemeEnterpriseByEnterpriseId(enterpriseId int) (m *model.SchemeWithEnterprise, err error) {
- m = new(model.SchemeWithEnterprise)
- has, err := adminRoleDb.Db.Where("enterprise_id =?", enterpriseId).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (adminRoleDb *SchemeEnterpriseDb) GetSchemeEnterprise(id int) (m *model.SchemeWithEnterprise, err error) {
- m = new(model.SchemeWithEnterprise)
- has, err := adminRoleDb.Db.Where("id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (adminRoleDb *SchemeEnterpriseDb) SchemeEnterpriseDeleteForEnterpriseBySession(session *xorm.Session, enterpriseId interface{}) (int64, error) {
- if reflect.TypeOf(enterpriseId).Kind() == reflect.Slice {
- return session.In("enterprise_id", enterpriseId).Delete(model.SchemeWithEnterprise{})
- } else {
- return session.Where("enterprise_id = ?", enterpriseId).Delete(model.SchemeWithEnterprise{})
- }
- }
-
- func (adminRoleDb *SchemeEnterpriseDb) SchemeEnterpriseDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return session.In("scheme_id", id).Delete(model.SchemeWithEnterprise{})
- } else {
- return session.Where("scheme_id = ?", id).Delete(model.SchemeWithEnterprise{})
- }
- }
-
- func (adminRoleDb *SchemeEnterpriseDb) BatchAddSchemeEnterpriseBySession(session *xorm.Session, mm []*model.SchemeWithEnterprise) (int64, error) {
- affected, err := session.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- type SchemeEnterprise struct {
- model.Enterprise `xorm:"extends"`
- model.SchemeWithEnterprise `xorm:"extends"`
- }
-
- func (SchemeEnterprise) TableName() string {
- return "scheme_with_enterprise"
- }
|