Browse Source

fix:报告权限调整

Roc 3 years ago
parent
commit
0151a540f8
3 changed files with 33 additions and 3 deletions
  1. 3 2
      logic/report/research_report.go
  2. 3 1
      main.go
  3. 27 0
      utils/common.go

+ 3 - 2
logic/report/research_report.go

@@ -3,7 +3,7 @@ package report
 import (
 	"hongze/hongze_yb/models/tables/company_report_permission"
 	"hongze/hongze_yb/models/tables/research_report"
-	"strings"
+	"hongze/hongze_yb/utils"
 )
 
 func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchReportInfo, hasPermission bool, err error) {
@@ -14,7 +14,8 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 	}
 	reportType := reportInfo.Type
 	//这些个报告需要做权限校验
-	if strings.Contains("month,two_week,other", reportInfo.Type) {
+
+	if utils.InArray(reportInfo.Type, []string{"month", "two_week", "other"}) {
 		list, tmpErr := company_report_permission.GetReportVarietyList(userId, reportType)
 		if tmpErr != nil {
 			err = tmpErr

+ 3 - 1
main.go

@@ -1,6 +1,8 @@
 package main
 
-import "hongze/hongze_yb/core"
+import (
+	"hongze/hongze_yb/core"
+)
 
 // @title 弘则研报API接口文档
 // @version 1.0

+ 27 - 0
utils/common.go

@@ -933,3 +933,30 @@ func getMonthDay(year, month int) (days int) {
 	}
 	return
 }
+
+// InArray 是否在切片(数组/map)中含有该值,目前只支持:string、int 、 int64,其他都是返回false
+func InArray(needle interface{}, hyStack interface{}) bool {
+	switch key := needle.(type) {
+	case string:
+		for _, item := range hyStack.([]string) {
+			if key == item {
+				return true
+			}
+		}
+	case int:
+		for _, item := range hyStack.([]int) {
+			if key == item {
+				return true
+			}
+		}
+	case int64:
+		for _, item := range hyStack.([]int64) {
+			if key == item {
+				return true
+			}
+		}
+	default:
+		return false
+	}
+	return false
+}