package service

import (
	"XT_New/models"
	"github.com/jinzhu/gorm"
)

func GetHomeData(adminUserId int64) (adminUser models.VMAdminUser, err error) {
	err = readUserDb.Model(&models.VMAdminUser{}).Where("status = 1 AND id = ?", adminUserId).
		Preload("Org", "status = 1").
		Preload("VMApp_Role", func(db *gorm.DB) *gorm.DB {
			return db.Preload("Org", "status = 1").Where("status = 1")
		}).Find(&adminUser).Error
	return
}

func GetCreator(id int64, orgid int64) (models.SgjUserAdminRole, error) {
	role := models.SgjUserAdminRole{}
	err := UserReadDB().Model(&role).Where("admin_user_id = ? and org_id = ? and status =1", id, orgid).Find(&role).Error
	return role, err
}

func GetAllApp(org_id int64) (apps []*models.OrgApp, err error) {
	err = readUserDb.Model(&models.OrgApp{}).Where("status = 1 AND pid > 0 AND org_id = ?", org_id).Order("number asc").Find(&apps).Error
	return
}

func GetSystemBanner() (banners []*models.VMAdminBanner, err error) {
	err = readUserDb.Model(&models.VMAdminBanner{}).Where("status = 1 ").Find(&banners).Error
	return
}
