report_mapping_category_group.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/utils"
  7. "strings"
  8. "time"
  9. )
  10. //func init() {
  11. // var condition string
  12. // var pars []interface{}
  13. // condition += ` AND publish_status = 1 `
  14. //
  15. // list, err := models.GetArticleList(condition, pars)
  16. // fmt.Println(err)
  17. // for _, v := range list {
  18. // AddCygxReportMappingCategoryGroupByArticleId(v.ArticleId)
  19. // }
  20. //}
  21. // AddCygxReportMappingCategoryGroupByArticleId 根据文章ID建立分类分组,主客观权限分组
  22. func AddCygxReportMappingCategoryGroupByArticleId(articleId int) {
  23. fmt.Println(articleId)
  24. time.Sleep(5 * time.Second)
  25. var err error
  26. defer func() {
  27. if err != nil {
  28. go utils.SendAlarmMsg("根据文章ID建立分类分组,主客观权限分组,失败"+err.Error(), 2)
  29. }
  30. }()
  31. detail, e := models.GetArticleDetailById(articleId)
  32. if e != nil {
  33. err = errors.New("GetArticleDetailById, Err: " + e.Error())
  34. return
  35. }
  36. categoryId := detail.CategoryId
  37. var condition string
  38. var pars []interface{}
  39. condition += ` AND category_id_celue = ? `
  40. pars = append(pars, categoryId)
  41. list, e := models.GetCygxReportMappingGroupList(condition, pars)
  42. if e != nil {
  43. err = errors.New("GetCygxReportMappingGroupList, Err: " + e.Error())
  44. return
  45. }
  46. pars = make([]interface{}, 0)
  47. var idCygxs []int
  48. for _, v := range list {
  49. idCygxs = append(idCygxs, v.IdCygx)
  50. fmt.Println(v)
  51. }
  52. condition = ` AND id IN (` + utils.GetOrmInReplace(len(idCygxs)) + `)`
  53. pars = append(pars, idCygxs)
  54. cygxlist, e := models.GetCygxReportMappingCygxByCon(condition, pars)
  55. if e != nil {
  56. err = errors.New("GetCygxReportMappingCygxByCon, Err: " + e.Error())
  57. return
  58. }
  59. var items []*models.CygxReportMappingCategoryGroup
  60. for _, v := range cygxlist {
  61. item := new(models.CygxReportMappingCategoryGroup)
  62. item.IdCygx = v.Id
  63. item.ChartPermissionId = v.ChartPermissionId
  64. //如果类型是报告就是主观,类型是纪要就是客观
  65. if detail.TypeName == "报告" {
  66. item.PermissionType = 1
  67. }
  68. if detail.TypeName == "纪要" {
  69. item.PermissionType = 2
  70. }
  71. item.ArticleId = articleId
  72. item.CreateTime = time.Now()
  73. item.ModifyTime = time.Now()
  74. items = append(items, item)
  75. }
  76. e = models.AddCygxReportMappingCategoryGroupMulti(items, articleId)
  77. fmt.Println(items)
  78. return
  79. }
  80. // 校验文章主客观权限
  81. func CheckArticlePermissionType(articleId int, user *models.WxUserItem) (checkPermissionType bool) {
  82. var err error
  83. defer func() {
  84. if err != nil {
  85. go utils.SendAlarmMsg("记录用户文章浏览记录,失败"+err.Error(), 2)
  86. }
  87. }()
  88. permissionStr, e := models.GetCompanyPermissionByUser(user.CompanyId)
  89. if e != nil {
  90. err = errors.New("GetCompanyPermissionByUser, Err: " + e.Error())
  91. return
  92. }
  93. var condition string
  94. var pars []interface{}
  95. condition += ` AND article_id = ? `
  96. pars = append(pars, articleId)
  97. list, e := models.GetCygxReportMappingCategoryGroupList(condition, pars)
  98. if e != nil {
  99. err = errors.New("GetCygxReportMappingCategoryGroupList, Err: " + e.Error())
  100. return
  101. }
  102. if len(list) == 0 {
  103. checkPermissionType = true
  104. return
  105. }
  106. var chartPermissionId int
  107. var chartPermissionName string
  108. var permissionTypeZg bool
  109. var permissionTypeKg bool
  110. for _, v := range list {
  111. chartPermissionId = v.ChartPermissionId
  112. if v.PermissionType == 1 || v.PermissionType == 0 {
  113. permissionTypeZg = true
  114. }
  115. if v.PermissionType == 2 || v.PermissionType == 0 {
  116. permissionTypeKg = true
  117. }
  118. }
  119. categoryinfo, e := models.GetChartPermissionById(chartPermissionId)
  120. if e != nil {
  121. err = errors.New("GetChartPermissionById, Err: " + e.Error())
  122. return
  123. }
  124. if permissionTypeZg {
  125. chartPermissionName = categoryinfo.PermissionName + "(主观)"
  126. }
  127. if permissionTypeKg {
  128. chartPermissionName = categoryinfo.PermissionName + "(客观)"
  129. }
  130. if permissionTypeKg && permissionTypeZg {
  131. chartPermissionName = categoryinfo.PermissionName
  132. }
  133. if strings.Contains(permissionStr, chartPermissionName) {
  134. checkPermissionType = true
  135. }
  136. return
  137. }