package models import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" ) // ChartPermissionSearchKeyWordMapping 权限相关 type ChartPermissionSearchKeyWordMapping struct { Id int `gorm:"primaryKey" json:"id"` //`description:"id" json:"-"` ChartPermissionId int `gorm:"column:chart_permission_id" json:"chart_permission_id"` //`description:"权限id"` KeyWord string `gorm:"column:key_word" json:"key_word"` //`description:"二级分类名称"` From string `gorm:"column:from" json:"-"` //`description:"类型标识" json:"-"` TacticType string `gorm:"column:tactic_type" json:"-"` //`description:"策略表type字段值" json:"-"` TeleconferenceSort int `gorm:"column:teleconference_sort" json:"-"` //`description:"电话会类型排序" json:"-"` ClassifyId int `gorm:"column:classify_id" json:"classify_id"` //`description:"分类ID"` } func GetPermission(classifyId int) (items []*ChartPermissionSearchKeyWordMapping, err error) { sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.source_from='rddp' AND a.classify_id = ? ` err = global.DmSQL["rddp"].Raw(sql, classifyId).Find(&items).Error return } func GetAllPermissionMapping() (items []*ChartPermissionSearchKeyWordMapping, err error) { sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.source_from='rddp'` err = global.DmSQL["rddp"].Raw(sql).Find(&items).Error return } // EditChartPermissionSearchKeyWordMappingMulti 修改报告报告权限(先删除原有的权限,再添加新的权限) func EditChartPermissionSearchKeyWordMappingMulti(keyword string, permissionIdList []int, classifyId int) (err error) { to := global.DmSQL["rddp"].Begin() defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := "DELETE FROM chart_permission_search_key_word_mapping WHERE source_from= 'rddp' AND classify_id = ?" err = to.Exec(sql, classifyId).Error 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.CreateInBatches(chartPermissionSearchKeyWordMappingList, utils.MultiAddNum).Error } 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(?,?,?)` err = global.DmSQL["rddp"].Exec(sql, chartPermissionId, reportId, "rddp").Error return } func RemoveChartPermissionChapterMapping(reportId int64) (err error) { sql := ` DELETE FROM chart_permission_chapter_mapping WHERE research_type=? AND report_chapter_type_id=? ` err = global.DmSQL["rddp"].Exec(sql, "rddp", reportId).Error return } type ChartPermissionMappingIdName struct { PermissionId int `gorm:"column:permission_id" json:"permission_id"` PermissionName string `gorm:"column:permission_name" json:"permission_name"` } func GetChartPermissionNameFromMappingByKeyword(source string, classifyId int) (list []*ChartPermissionMappingIdName, err error) { 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.source_from = ? AND a.classify_id = ? " err = global.DmSQL["rddp"].Raw(sql, source, classifyId).Find(&list).Error return } // UpdateChartPermissionNameFromMappingByKeyword 根据关键词及来源更新新关键词 func UpdateChartPermissionNameFromMappingByKeyword(newKeyword string, classifyId int, source string) (err error) { sql := " UPDATE chart_permission_search_key_word_mapping SET key_word = ? WHERE classify_id = ? AND source_from = ? " err = global.DmSQL["rddp"].Exec(sql, newKeyword, classifyId, source).Error return } // ChartPermissionSearchKeyWordMappingAndPermissionName // @Description: 分类关联品种 type ChartPermissionSearchKeyWordMappingAndPermissionName struct { ChartPermissionId int `gorm:"column:chart_permission_id" json:"chart_permission_id"` //`description:"权限id"` ChartPermissionName string `gorm:"column:chart_permission_name" json:"chart_permission_name"` //`description:"权限名称"` PermissionName string `gorm:"column:permission_name" json:"permission_name"` //`description:"权限名称"` KeyWord string `gorm:"column:key_word"` //`description:"二级分类名称"` ClassifyId int `gorm:"column:classify_id"` // `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) { 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.source_from='rddp' AND b.classify_id = ? ` err = global.DmSQL["rddp"].Raw(sql, classifyId).Find(&items).Error return }