permission.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. )
  6. // ChartPermissionSearchKeyWordMapping 权限相关
  7. type ChartPermissionSearchKeyWordMapping struct {
  8. Id int `gorm:"primaryKey" json:"id"` //`description:"id" json:"-"`
  9. ChartPermissionId int `gorm:"column:chart_permission_id" json:"chart_permission_id"` //`description:"权限id"`
  10. KeyWord string `gorm:"column:key_word" json:"key_word"` //`description:"二级分类名称"`
  11. From string `gorm:"column:from" json:"-"` //`description:"类型标识" json:"-"`
  12. TacticType string `gorm:"column:tactic_type" json:"-"` //`description:"策略表type字段值" json:"-"`
  13. TeleconferenceSort int `gorm:"column:teleconference_sort" json:"-"` //`description:"电话会类型排序" json:"-"`
  14. ClassifyId int `gorm:"column:classify_id" json:"classify_id"` //`description:"分类ID"`
  15. }
  16. func GetPermission(classifyId int) (items []*ChartPermissionSearchKeyWordMapping, err error) {
  17. sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.source_from='rddp' AND a.classify_id = ? `
  18. err = global.DmSQL["rddp"].Raw(sql, classifyId).Find(&items).Error
  19. return
  20. }
  21. func GetAllPermissionMapping() (items []*ChartPermissionSearchKeyWordMapping, err error) {
  22. sql := `SELECT * FROM chart_permission_search_key_word_mapping AS a WHERE a.source_from='rddp'`
  23. err = global.DmSQL["rddp"].Raw(sql).Find(&items).Error
  24. return
  25. }
  26. // EditChartPermissionSearchKeyWordMappingMulti 修改报告报告权限(先删除原有的权限,再添加新的权限)
  27. func EditChartPermissionSearchKeyWordMappingMulti(keyword string, permissionIdList []int, classifyId int) (err error) {
  28. to := global.DmSQL["rddp"].Begin()
  29. defer func() {
  30. if err != nil {
  31. _ = to.Rollback()
  32. } else {
  33. _ = to.Commit()
  34. }
  35. }()
  36. sql := "DELETE FROM chart_permission_search_key_word_mapping WHERE source_from= 'rddp' AND classify_id = ?"
  37. err = to.Exec(sql, classifyId).Error
  38. if err != nil {
  39. return
  40. }
  41. if len(permissionIdList) > 0 {
  42. chartPermissionSearchKeyWordMappingList := make([]*ChartPermissionSearchKeyWordMapping, 0)
  43. for _, permissionId := range permissionIdList {
  44. tmpChartPermissionSearchKeyWordMapping := &ChartPermissionSearchKeyWordMapping{
  45. ChartPermissionId: permissionId,
  46. KeyWord: keyword,
  47. From: "rddp",
  48. TacticType: "",
  49. TeleconferenceSort: 0,
  50. ClassifyId: classifyId,
  51. }
  52. chartPermissionSearchKeyWordMappingList = append(chartPermissionSearchKeyWordMappingList, tmpChartPermissionSearchKeyWordMapping)
  53. }
  54. err = to.CreateInBatches(chartPermissionSearchKeyWordMappingList, utils.MultiAddNum).Error
  55. }
  56. return
  57. }
  58. func AddChartPermissionChapterMapping(chartPermissionId int, reportId int64) (err error) {
  59. sql := `INSERT INTO chart_permission_chapter_mapping (chart_permission_id, report_chapter_type_id,research_type)
  60. VALUES(?,?,?)`
  61. err = global.DmSQL["rddp"].Exec(sql, chartPermissionId, reportId, "rddp").Error
  62. return
  63. }
  64. func RemoveChartPermissionChapterMapping(reportId int64) (err error) {
  65. sql := ` DELETE FROM chart_permission_chapter_mapping WHERE research_type=? AND report_chapter_type_id=? `
  66. err = global.DmSQL["rddp"].Exec(sql, "rddp", reportId).Error
  67. return
  68. }
  69. type ChartPermissionMappingIdName struct {
  70. PermissionId int `gorm:"column:permission_id" json:"permission_id"`
  71. PermissionName string `gorm:"column:permission_name" json:"permission_name"`
  72. }
  73. func GetChartPermissionNameFromMappingByKeyword(source string, classifyId int) (list []*ChartPermissionMappingIdName, err error) {
  74. 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 = ? "
  75. err = global.DmSQL["rddp"].Raw(sql, source, classifyId).Find(&list).Error
  76. return
  77. }
  78. // UpdateChartPermissionNameFromMappingByKeyword 根据关键词及来源更新新关键词
  79. func UpdateChartPermissionNameFromMappingByKeyword(newKeyword string, classifyId int, source string) (err error) {
  80. sql := " UPDATE chart_permission_search_key_word_mapping SET key_word = ? WHERE classify_id = ? AND source_from = ? "
  81. err = global.DmSQL["rddp"].Exec(sql, newKeyword, classifyId, source).Error
  82. return
  83. }
  84. // ChartPermissionSearchKeyWordMappingAndPermissionName
  85. // @Description: 分类关联品种
  86. type ChartPermissionSearchKeyWordMappingAndPermissionName struct {
  87. ChartPermissionId int `gorm:"column:chart_permission_id" json:"chart_permission_id"` //`description:"权限id"`
  88. ChartPermissionName string `gorm:"column:chart_permission_name" json:"chart_permission_name"` //`description:"权限名称"`
  89. PermissionName string `gorm:"column:permission_name" json:"permission_name"` //`description:"权限名称"`
  90. KeyWord string `gorm:"column:key_word"` //`description:"二级分类名称"`
  91. ClassifyId int `gorm:"column:classify_id"` // `description:"分类ID"`
  92. }
  93. // GetPermissionByClassifyId
  94. // @Description: 根据分类id获取关联的报告权限
  95. // @author: Roc
  96. // @datetime 2024-06-19 14:56:44
  97. // @param classifyId int
  98. // @return items []*ChartPermissionSearchKeyWordMappingAndPermissionName
  99. // @return err error
  100. func GetPermissionByClassifyId(classifyId int) (items []*ChartPermissionSearchKeyWordMappingAndPermissionName, err error) {
  101. sql := `SELECT a.chart_permission_name,a.permission_name,b.chart_permission_id,b.key_word,b.classify_id FROM chart_permission AS a
  102. 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 = ? `
  103. err = global.DmSQL["rddp"].Raw(sql, classifyId).Find(&items).Error
  104. return
  105. }