report_mapping_category_group.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strings"
  8. )
  9. // 校验文章主客观权限
  10. func CheckArticlePermissionType(articleId int, user *models.WxUserItem) (checkPermissionType bool) {
  11. var err error
  12. defer func() {
  13. if err != nil {
  14. go utils.SendAlarmMsg("校验文章主客观权限,失败"+err.Error()+fmt.Sprint("uid:", user.UserId, "articleId", articleId), 2)
  15. }
  16. }()
  17. permissionStr, e := models.GetCompanyPermissionByUser(user.CompanyId)
  18. if e != nil {
  19. err = errors.New("GetCompanyPermissionByUser, Err: " + e.Error())
  20. return
  21. }
  22. var condition string
  23. var pars []interface{}
  24. condition += ` AND article_id = ? `
  25. pars = append(pars, articleId)
  26. list, e := models.GetCygxReportMappingCategoryGroupList(condition, pars)
  27. if e != nil {
  28. err = errors.New("GetCygxReportMappingCategoryGroupList, Err: " + e.Error())
  29. return
  30. }
  31. if len(list) == 0 {
  32. checkPermissionType = true
  33. return
  34. }
  35. var chartPermissionId int
  36. var chartPermissionName string
  37. var permissionTypeZg bool
  38. var permissionTypeKg bool
  39. for _, v := range list {
  40. chartPermissionId = v.ChartPermissionId
  41. if v.PermissionType == 1 || v.PermissionType == 0 {
  42. permissionTypeZg = true
  43. }
  44. if v.PermissionType == 2 || v.PermissionType == 0 {
  45. permissionTypeKg = true
  46. }
  47. }
  48. categoryinfo, e := models.GetChartPermissionById(chartPermissionId)
  49. if e != nil {
  50. err = errors.New("GetChartPermissionById, Err: " + e.Error())
  51. return
  52. }
  53. if permissionTypeZg {
  54. chartPermissionName = categoryinfo.PermissionName + "(主观)"
  55. }
  56. if permissionTypeKg {
  57. chartPermissionName = categoryinfo.PermissionName + "(客观)"
  58. }
  59. if permissionTypeKg && permissionTypeZg {
  60. chartPermissionName = categoryinfo.PermissionName
  61. }
  62. if strings.Contains(permissionStr, chartPermissionName) {
  63. checkPermissionType = true
  64. }
  65. return
  66. }