permission.go 5.3 KB

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