report_mapping.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/utils"
  6. "strconv"
  7. "time"
  8. )
  9. func GetReportMappingMap() (mapResp map[int]bool, err error) {
  10. defer func() {
  11. if err != nil {
  12. go utils.SendAlarmMsg("GetReportMappingMap, ErrMsg: "+err.Error(), 3)
  13. }
  14. }()
  15. mapResp = make(map[int]bool, 0)
  16. list, err := models.GetReportMappingByPermissionName(utils.CE_LUE_NAME)
  17. if err != nil && err.Error() != utils.ErrNoRow() {
  18. return
  19. }
  20. if len(list) > 0 {
  21. for _, v := range list {
  22. mapResp[v.CategoryId] = true
  23. }
  24. }
  25. return
  26. }
  27. // 生成查研观向的报告匹配类型
  28. func init111() {
  29. list, err := models.GetReportMapping()
  30. if err != nil {
  31. fmt.Print(err)
  32. }
  33. var condition string
  34. for _, v := range list {
  35. if v.MatchTypeName == "" {
  36. continue
  37. }
  38. item := new(models.CygxReportMappingCygx)
  39. item.ChartPermissionId = v.ChartPermissionId
  40. item.ChartPermissionName = v.ChartPermissionName
  41. item.MatchTypeName = v.MatchTypeName
  42. item.ReportType = v.ReportType
  43. item.Sort = v.Sort
  44. item.IsCustom = v.IsCustom
  45. item.IsSummary = v.IsSummary
  46. item.IsReport = v.IsReport
  47. item.PermissionType = v.PermissionType
  48. condition = ` AND match_type_name = '` + v.MatchTypeName + `' AND chart_permission_id = ` + strconv.Itoa(v.ChartPermissionId)
  49. total, err := models.GetCygxReportMappingCygxCount(condition)
  50. if err != nil {
  51. fmt.Print(err)
  52. }
  53. if total == 0 {
  54. _, err = models.AddCygxReportMappingCygx(item)
  55. if err != nil {
  56. fmt.Print(err)
  57. }
  58. }
  59. }
  60. }
  61. // 生成多对多关系表
  62. func init1232() {
  63. list, err := models.GetCygxReportMappingCygx()
  64. if err != nil {
  65. fmt.Print(err)
  66. }
  67. var condition string
  68. for _, v := range list {
  69. if v.MatchTypeName == "" {
  70. continue
  71. }
  72. condition = ` AND match_type_name = '` + v.MatchTypeName + `' AND chart_permission_id = ` + strconv.Itoa(v.ChartPermissionId)
  73. listCelue, err := models.GetCygxReportMappingcelue(condition)
  74. if err != nil {
  75. fmt.Print(err)
  76. }
  77. for _, vC := range listCelue {
  78. item := new(models.CygxReportMappingGroup)
  79. item.IdCygx = v.Id
  80. item.CategoryIdCelue = vC.CategoryId
  81. item.CreateTime = time.Now()
  82. item.ModifyTime = time.Now()
  83. fmt.Println(item)
  84. _, err = models.AddCygxReportMappingGroup(item)
  85. if err != nil {
  86. fmt.Print(err)
  87. }
  88. }
  89. }
  90. }