package chart_permission

import (
	"errors"
	"hongze/hongze_yb/global"
	"hongze/hongze_yb/utils"
)

// GetListByProductId 根据产品id获取所有权限列表
func GetListByProductId(productId int64) (list []*ChartPermission, err error) {
	err = global.DEFAULT_MYSQL.Where(" product_id = ?", productId).Find(&list).Error
	return
}

// GetClassNameListByProductId 根据权限id获取权限分类
func GetClassNameListByProductId(productId int64) (list []*ChartPermission, err error) {
	err = global.DEFAULT_MYSQL.Where(" product_id = ?", productId).Group("classify_name").Find(&list).Error
	return
}

// GetByWhereMap 根据查询条件map获取信息
func GetByWhereMap(where map[string]interface{}) (list []*ChartPermission, err error) {
	cond, whereVal, buildErr := utils.WhereBuild(where)
	if buildErr != nil {
		err = errors.New("系统异常,生成查询语句失败")
		return
	}
	err = global.DEFAULT_MYSQL.Where(cond, whereVal...).Find(&list).Error
	return
}

// GetListByIds 通过IDs获取图表权限集合
func GetListByIds(permissionIds []int) (list []*ChartPermission, err error) {
	err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("chart_permission_id IN (?)", permissionIds).Scan(&list).Error
	return
}