123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package models
- import (
- "eta/eta_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "strconv"
- )
- // ChartPermissionSearchKeyWordMapping 权限相关
- type ChartPermissionSearchKeyWordMapping struct {
- Id int `description:"id" json:"-"`
- ChartPermissionId int `description:"权限id"`
- KeyWord string `description:"二级分类名称"`
- From string `description:"类型标识" json:"-"`
- TacticType string `description:"策略表type字段值" json:"-"`
- TeleconferenceSort int `description:"电话会类型排序" json:"-"`
- ClassifyId int `description:"分类ID"`
- }
- func GetPermission(classifyId int) (items []*ChartPermissionSearchKeyWordMapping, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.from='rddp' AND a.classify_id = ? `
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
- func GetAllPermissionMapping() (items []*ChartPermissionSearchKeyWordMapping, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.from='rddp'`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // EditChartPermissionSearchKeyWordMappingMulti 修改报告报告权限(先删除原有的权限,再添加新的权限)
- func EditChartPermissionSearchKeyWordMappingMulti(keyword string, permissionIdList []int, classifyId int) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- sql := "DELETE FROM chart_permission_search_key_word_mapping WHERE `from` = 'rddp' AND classify_id = ?"
- _, err = to.Raw(sql, classifyId).Exec()
- if err != nil {
- return
- }
- if len(permissionIdList) > 0 {
- chartPermissionSearchKeyWordMappingList := make([]*ChartPermissionSearchKeyWordMapping, 0)
- for _, permissionId := range permissionIdList {
- tmpChartPermissionSearchKeyWordMapping := &ChartPermissionSearchKeyWordMapping{
- ChartPermissionId: permissionId,
- KeyWord: keyword,
- From: "rddp",
- TacticType: "",
- TeleconferenceSort: 0,
- ClassifyId: classifyId,
- }
- chartPermissionSearchKeyWordMappingList = append(chartPermissionSearchKeyWordMappingList, tmpChartPermissionSearchKeyWordMapping)
- }
- _, err = to.InsertMulti(len(chartPermissionSearchKeyWordMappingList), chartPermissionSearchKeyWordMappingList)
- }
- return
- }
- func AddChartPermissionChapterMapping(chartPermissionId int, reportId int64) (err error) {
- sql := `INSERT INTO chart_permission_chapter_mapping (chart_permission_id, report_chapter_type_id,research_type)
- VALUES(?,?,?)`
- o := orm.NewOrmUsingDB("rddp")
- _, err = o.Raw(sql, chartPermissionId, reportId, "rddp").Exec()
- return
- }
- func RemoveChartPermissionChapterMapping(reportId int64) (err error) {
- sql := ` DELETE FROM chart_permission_chapter_mapping WHERE research_type=? AND report_chapter_type_id=? `
- o := orm.NewOrmUsingDB("rddp")
- _, err = o.Raw(sql, "rddp", reportId).Exec()
- return
- }
- type ChartPermissionMappingIdName struct {
- PermissionId int
- PermissionName string
- }
- func GetChartPermissionNameFromMappingByKeyword(source string, classifyId int) (list []*ChartPermissionMappingIdName, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := " SELECT b.chart_permission_id AS permission_id,b.permission_name FROM chart_permission_search_key_word_mapping AS a INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id WHERE a.`from` = ? AND a.classify_id = ? "
- _, err = o.Raw(sql, source, classifyId).QueryRows(&list)
- return
- }
- // UpdateChartPermissionNameFromMappingByKeyword 根据关键词及来源更新新关键词
- func UpdateChartPermissionNameFromMappingByKeyword(newKeyword string, classifyId int, source string) (err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := " UPDATE chart_permission_search_key_word_mapping SET key_word = ? WHERE classify_id = ? AND `from` = ? "
- _, err = o.Raw(sql, newKeyword, classifyId, source).Exec()
- return
- }
- // ChartPermissionSearchKeyWordMappingAndPermissionName
- // @Description: 分类关联品种
- type ChartPermissionSearchKeyWordMappingAndPermissionName struct {
- ChartPermissionId int `description:"权限id"`
- ChartPermissionName string `description:"权限名称"`
- PermissionName string `description:"权限名称"`
- KeyWord string `description:"二级分类名称"`
- ClassifyId int `description:"分类ID"`
- }
- // GetPermissionByClassifyId
- // @Description: 根据分类id获取关联的报告权限
- // @author: Roc
- // @datetime 2024-06-19 14:56:44
- // @param classifyId int
- // @return items []*ChartPermissionSearchKeyWordMappingAndPermissionName
- // @return err error
- func GetPermissionByClassifyId(classifyId int) (items []*ChartPermissionSearchKeyWordMappingAndPermissionName, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT a.chart_permission_name,a.permission_name,b.chart_permission_id,b.key_word,b.classify_id FROM chart_permission AS a
- join chart_permission_search_key_word_mapping AS b ON a.chart_permission_id=b.chart_permission_id WHERE b.from='rddp' AND b.classify_id = ? `
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
- func GetClassifyIdsByPermissionId(chartPermissionIdList []string) (classifyIds []string, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT classify_id
- FROM chart_permission_search_key_word_mapping
- WHERE chart_permission_id IN (` + utils.GetOrmInReplace(len(chartPermissionIdList)) + `)
- GROUP BY classify_id
- HAVING COUNT(DISTINCT chart_permission_id) = ` + strconv.Itoa(len(chartPermissionIdList)) + ``
- _, err = o.Raw(sql, chartPermissionIdList).QueryRows(&classifyIds)
- return
- }
|