package chart_permission_search_key_word_mapping

import (
	"github.com/beego/beego/v2/client/orm"
)

type ChartPermissionSearchKeyWordMapping struct {
	Id                 int    `orm:"column(id);pk" json:"id"`
	ChartPermissionId  int    `json:"chart_permission_id"`
	KeyWord            string `json:"key_word"`
	From               string `json:"from"`
	TacticType         string `json:"tactic_type"`
	TeleconferenceSort int    ` json:"teleconference_sort"`
}

// GetChartPermissionIdsByKeyWord 查询二级分类中的权限
func GetChartPermissionIdsByKeyWord(keyWord string) (ids []int, err error) {
	o := orm.NewOrm()
	var list []*ChartPermissionSearchKeyWordMapping
	sql := "SELECT * from chart_permission_search_key_word_mapping WHERE key_word = ? and `from` = 'rddp'"
	_, err = o.Raw(sql, keyWord).QueryRows(&list)
	if err != nil {
		return
	}

	if len(list) > 0 {
		for _, item := range list {
			ids = append(ids, item.ChartPermissionId)
		}
	}
	return
}
