瀏覽代碼

Merge branch 'feature/eta1.7.6_permission' into debug

xyxie 1 年之前
父節點
當前提交
72304cf1f8

+ 5 - 1
controller/public.go

@@ -41,7 +41,11 @@ import (
 // @failure 400 {string} string "获取失败"
 // @Router /public/get_apply_variety_list [get]
 func GetApplyVarietyList(c *gin.Context) {
-	list := logic.GetApplyVarietyList()
+	list, err := logic.GetApplyVarietyList()
+	if err != nil {
+		response.FailData("获取品种失败", "获取品种失败,Err:"+err.Error(), c)
+		return
+	}
 	response.OkData("获取成功", list, c)
 }
 

+ 48 - 3
logic/public.go

@@ -1,5 +1,11 @@
 package logic
 
+import (
+	"fmt"
+	"hongze/hongze_yb/models/tables/chart_permission"
+	"hongze/hongze_yb/utils"
+)
+
 type ApplyVariety struct {
 	PermissionName string `json:"permission_name" description:"权限名称"`
 	Name           string `json:"name" description:"品种名称"`
@@ -7,8 +13,47 @@ type ApplyVariety struct {
 }
 
 // GetApplyVarietyList 获取所有可以申请的品种权限
-func GetApplyVarietyList() (list []ApplyVariety) {
-	list = append(list, ApplyVariety{PermissionName: "宏观经济", Name: "宏观经济", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/宏观经济.png"})
+func GetApplyVarietyList() (list []ApplyVariety, err error) {
+	// 查询所有的二级品种,按照顺序排序,
+	permissionImgMap := make(map[string]string, 0)
+	permissionImgMap["宏观经济"] = "https://hzstatic.hzinsights.com/static/yb_variety/宏观经济.png"
+	permissionImgMap["利率债"] = "https://hzstatic.hzinsights.com/static/yb_variety/利率债.png"
+	permissionImgMap["原油"] = "https://hzstatic.hzinsights.com/static/yb_variety/原油.png"
+	permissionImgMap["PTA"] = "https://hzstatic.hzinsights.com/static/yb_variety/PTA.png"
+	permissionImgMap["MEG"] = "https://hzstatic.hzinsights.com/static/yb_variety/MEG.png"
+	permissionImgMap["织造终端"] = "https://hzstatic.hzinsights.com/static/yb_variety/织造终端.png"
+	permissionImgMap["甲醇"] = "https://hzstatic.hzinsights.com/static/yb_variety/甲醇.png"
+	permissionImgMap["聚烯烃"] = "https://hzstatic.hzinsights.com/static/yb_variety/聚烯烃.png"
+	permissionImgMap["沥青"] = "https://hzstatic.hzinsights.com/static/yb_variety/沥青.png"
+	permissionImgMap["苯乙烯"] = "https://hzstatic.hzinsights.com/static/yb_variety/苯乙烯.png"
+	permissionImgMap["PVC"] = "https://hzstatic.hzinsights.com/static/yb_variety/PVC.png"
+	permissionImgMap["聚酯"] = "https://hzstatic.hzinsights.com/static/yb_variety/聚酯.png"
+	permissionImgMap["钢材"] = "https://hzstatic.hzinsights.com/static/yb_variety/钢材.png"
+	permissionImgMap["铁矿"] = "https://hzstatic.hzinsights.com/static/yb_variety/铁矿.png"
+	permissionImgMap["玻璃纯碱"] = "https://hzstatic.hzinsights.com/static/yb_variety/玻璃纯碱.png"
+	permissionImgMap["双焦"] = "https://hzstatic.hzinsights.com/static/yb_variety/双焦(焦煤、焦炭).png"
+	permissionImgMap["铜"] = "https://hzstatic.hzinsights.com/static/yb_variety/有色(铜、铝).png"
+	permissionImgMap["铝"] = "https://hzstatic.hzinsights.com/static/yb_variety/有色(铜、铝).png"
+	permissionImgMap["镍/不锈钢"] = "https://hzstatic.hzinsights.com/static/yb_variety/镍2不锈钢.png"
+	permissionImgMap["锌"] = "https://hzstatic.hzinsights.com/static/yb_variety/有色锌.png"
+	permissionImgMap["钴锂"] = "https://hzstatic.hzinsights.com/static/yb_variety/钴锂.png"
+	allFiccPermissions, e := chart_permission.GetListByProductIdAndPermissionType(1)
+	if e != nil {
+		err = fmt.Errorf("获取品种权限失败 Err:%s", e.Error())
+		return
+	}
+
+	for _, v := range allFiccPermissions {
+		if v.ParentId > 0 {
+			tmp := ApplyVariety{PermissionName: v.PermissionName, Name: v.PermissionName, PicUrl: utils.APPLY_VARIETY_IMG_DEFAULT}
+			img, ok := permissionImgMap[v.PermissionName]
+			if ok {
+				tmp.PicUrl = img
+			}
+			list = append(list, tmp)
+		}
+	}
+	/*list = append(list, ApplyVariety{PermissionName: "宏观经济", Name: "宏观经济", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/宏观经济.png"})
 	list = append(list, ApplyVariety{PermissionName: "利率债", Name: "利率债", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/利率债.png"})
 	list = append(list, ApplyVariety{PermissionName: "原油", Name: "原油", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/原油.png"})
 	list = append(list, ApplyVariety{PermissionName: "PTA", Name: "PTA", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/PTA.png"})
@@ -27,7 +72,7 @@ func GetApplyVarietyList() (list []ApplyVariety) {
 	list = append(list, ApplyVariety{PermissionName: "有色(铜、铝)", Name: "有色(铜、铝)", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/有色(铜、铝).png"})
 	list = append(list, ApplyVariety{PermissionName: "镍+不锈钢", Name: "镍+不锈钢", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/镍2不锈钢.png"})
 	list = append(list, ApplyVariety{PermissionName: "有色(锌)", Name: "有色(锌)", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/有色锌.png"})
-	list = append(list, ApplyVariety{PermissionName: "钴锂", Name: "钴锂", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/钴锂.png"})
+	list = append(list, ApplyVariety{PermissionName: "钴锂", Name: "钴锂", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/钴锂.png"})*/
 	//list = append(list, ApplyVariety{PermissionName: "苯乙烯", Name: "苯乙烯", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/苯乙烯.png"})
 	//list = append(list, ApplyVariety{PermissionName: "橡胶", Name: "橡胶", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/橡胶.png"})
 	//list = append(list, ApplyVariety{PermissionName: "策略", Name: "市场策略", PicUrl: "https://hzstatic.hzinsights.com/static/yb_variety/市场策略.png"})

+ 6 - 0
models/tables/chart_permission/chart_permission.go

@@ -23,6 +23,8 @@ type ChartPermission struct {
 	CygxAuth            int8      `gorm:"column:cygx_auth;type:tinyint(4);not null;default:0" json:"cygxAuth"`                    // 是否是权限,用于查研观向小程序前台权限校验
 	YbImgUrl            string    `gorm:"column:yb_img_url;type:varchar(255)" json:"yb_img_url"`                                  // 研报小程序报告列表icon
 	PriceDrivenState    int       `gorm:"column:price_driven_state;type:tinyint(4);not null;default:0" json:"price_driven_state"` // 品种价格驱动状态:0-关闭 1-开启
+	ParentId            int       `gorm:"column:parent_id;default:0;NOT NULL;comment:'父级权限id'" json:"parent_id"`
+	IsPublic            int       `gorm:"column:is_public;default:0;NOT NULL;comment:'是否是公有权限1:公有权限,0私有权限'" json:"is_public"`
 }
 
 // TableName get sql table name.获取数据库表名
@@ -49,6 +51,8 @@ var ChartPermissionColumns = struct {
 	IsOther             string
 	IsReport            string
 	CygxAuth            string
+	ParentId            string
+	IsPublic            string
 }{
 	ChartPermissionID:   "chart_permission_id",
 	ChartPermissionName: "chart_permission_name",
@@ -67,4 +71,6 @@ var ChartPermissionColumns = struct {
 	IsOther:             "is_other",
 	IsReport:            "is_report",
 	CygxAuth:            "cygx_auth",
+	ParentId:            "parent_id",
+	IsPublic:            "is_public",
 }

+ 13 - 13
models/tables/chart_permission/query.go

@@ -13,17 +13,11 @@ func GetListByProductId(productId int64) (list []*ChartPermission, err error) {
 }
 
 // GetFiccListExceptTacticByProductId 获取ficc 除了市场策略的所有权限
-func GetFiccListExceptTacticByProductId() (list []*ChartPermission, err error)  {
-	err = global.DEFAULT_MYSQL.Where(" enabled = 1 AND permission_type = 0 AND product_id = 1 and classify_name != '市场策略'").Find(&list).Error
+func GetFiccListExceptTacticByProductId() (list []*ChartPermission, err error) {
+	err = global.DEFAULT_MYSQL.Where(" enabled = 1 AND permission_type = 0 AND product_id = 1 and parent_id >0 and classify_name != '市场策略'").Order("sort asc").Find(&list).Error
 	return
 }
 
-// GetFiccListExceptTacticByProductIdOrderSort 获取ficc 除了市场策略的所有权限
-func GetFiccListExceptTacticByProductIdOrderSort() (list []*ChartPermission, err error)  {
-	err = global.DEFAULT_MYSQL.Where(" enabled = 1 AND permission_type = 0 AND product_id = 1 and classify_name != '市场策略'").
-	Order("sort asc").Find(&list).Error
-	return
-}
 // GetClassNameListByProductId 根据权限id获取权限分类
 func GetClassNameListByProductId(productId int64) (list []*ChartPermission, err error) {
 	err = global.DEFAULT_MYSQL.Where(" product_id = ?", productId).Group("classify_name").Find(&list).Error
@@ -47,17 +41,23 @@ func GetListByIds(permissionIds []int) (list []*ChartPermission, err error) {
 	return
 }
 
-// GetListByProductIdAndClassifyName 根据product及classify_name获取集合
-func GetListByProductIdAndClassifyName(productId int, classifyName string) (items []*ChartPermission, err error) {
-	err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("enabled = 1 AND permission_type = 0 AND product_id = ? AND classify_name = ?", productId, classifyName).Order("sort ASC").Scan(&items).Error
+// GetListByProductIdAndPermissionType 根据product及classify_name获取集合
+func GetListByProductIdAndPermissionType(productId int) (items []*ChartPermission, err error) {
+	err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("enabled = 1 AND permission_type = 0 AND product_id = ? ", productId).Order("sort ASC").Scan(&items).Error
 	return
 }
 
 // GetByChartPermissionId 根据chartPermissionId 查找权限基本信息
-func GetByChartPermissionId(chartPermissionId int) (item *ChartPermission, err error)  {
+func GetByChartPermissionId(chartPermissionId int) (item *ChartPermission, err error) {
 	err = global.DEFAULT_MYSQL.Model(ChartPermission{}).Where("chart_permission_id = ?", chartPermissionId).First(&item).Error
 	if err == utils.ErrNoRow {
 		err = nil
 	}
 	return
-}
+}
+
+// GetFiccFirstListExceptTacticByProductId 获取ficc 除了市场策略的所有父级
+func GetFiccFirstListExceptTacticByProductId() (list []*ChartPermission, err error) {
+	err = global.DEFAULT_MYSQL.Where(" enabled = 1 AND permission_type = 0 AND product_id = 1 and classify_name != '市场策略' AND parent_id = 0").Order("sort asc").Find(&list).Error
+	return
+}

+ 76 - 63
services/company/permission.go

@@ -8,7 +8,6 @@ import (
 	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/tables/admin"
 	"hongze/hongze_yb/models/tables/chart_permission"
-	"hongze/hongze_yb/models/tables/chart_permission_first"
 	"hongze/hongze_yb/models/tables/company"
 	"hongze/hongze_yb/models/tables/company_product"
 	"hongze/hongze_yb/models/tables/company_report_permission"
@@ -628,23 +627,33 @@ type PermissionItem struct {
 func GetFiccPermissionList() (list []*FiccPermissionList, err error) {
 	productId := 1
 	list = make([]*FiccPermissionList, 0)
-	for _, v := range utils.PermissionFiccClassifyArr {
-		classify := new(FiccPermissionList)
-		classify.ClassifyName = v
-		items, e := chart_permission.GetListByProductIdAndClassifyName(productId, v)
-		if e != nil {
-			err = errors.New("获取品种权限失败 Err:" + e.Error())
-			return
+	allFiccPermissions, e := chart_permission.GetListByProductIdAndPermissionType(productId)
+	if e != nil {
+		err = errors.New("获取品种权限失败 Err:" + e.Error())
+		return
+	}
+	permissionMap := make(map[int][]*chart_permission.ChartPermission, 0)
+	for _, v := range allFiccPermissions {
+		if v.ParentId > 0 {
+			permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
 		}
-		tmpItems := make([]*PermissionItem, 0)
-		for _, iv := range items {
-			item := new(PermissionItem)
-			item.PermissionId = int(iv.ChartPermissionID)
-			item.PermissionName = iv.PermissionName
-			tmpItems = append(tmpItems, item)
+	}
+	for _, v := range allFiccPermissions {
+		if v.ParentId == 0 {
+			classify := new(FiccPermissionList)
+			classify.ClassifyName = v.PermissionName
+			classify.Items = make([]*PermissionItem, 0)
+			items, ok := permissionMap[int(v.ChartPermissionID)]
+			if ok {
+				for _, iv := range items {
+					item := new(PermissionItem)
+					item.PermissionId = int(iv.ChartPermissionID)
+					item.PermissionName = iv.PermissionName
+					classify.Items = append(classify.Items, item)
+				}
+			}
+			list = append(list, classify)
 		}
-		classify.Items = tmpItems
-		list = append(list, classify)
 	}
 	return
 }
@@ -669,50 +678,54 @@ func GetHomeFiccPermissions(user user.UserInfo) (ret response.PermissionFiccResp
 		return
 	}
 	permissionMap := make(map[uint64]bool)
-	permissionFirstMap := make(map[string]*response.PermissionFirstItem)
+	permissionFirstMap := make(map[int]*response.PermissionFirstItem)
 
 	//查询首页展示的图标
-	permissionFirstList, err := chart_permission_first.GetIndexShowList()
+	permissionFirstList, err := chart_permission.GetFiccFirstListExceptTacticByProductId()
 	if err != nil {
 		return
 	}
 	for _, v := range permissionFirstList {
-		permissionFirstMap[v.ClassifyName] = &response.PermissionFirstItem{
-			Id:          int(v.Id),
-			Sort:        v.YbIndexSort + 1000,
-			YbIndexName: v.YbIndexName,
-			YbIndexIcon: v.YbIndexIcon,
+		permissionFirstMap[int(v.ChartPermissionID)] = &response.PermissionFirstItem{
+			Id:          int(v.ChartPermissionID),
+			Sort:        v.Sort + 1000,
+			YbIndexName: v.PermissionName,
+			YbIndexIcon: "",
 		}
 	}
 
 	for k, v := range permissionList {
-		permissionMap[v.ChartPermissionID] = false
-		for _, myPerId := range validPermissionIds {
-			if int(v.ChartPermissionID) == myPerId {
-				permissionMap[v.ChartPermissionID] = true
-				permissionList[k].Sort = v.Sort - 1000
-				if _, ok := permissionFirstMap[v.ClassifyName]; ok && !permissionFirstMap[v.ClassifyName].IsCheck {
-					permissionFirstMap[v.ClassifyName].AuthOk = true
-					permissionFirstMap[v.ClassifyName].Sort -= 1000
-					permissionFirstMap[v.ClassifyName].IsCheck = true
+		if v.ParentId > 0 {
+			permissionMap[v.ChartPermissionID] = false
+			for _, myPerId := range validPermissionIds {
+				if int(v.ChartPermissionID) == myPerId {
+					permissionMap[v.ChartPermissionID] = true
+					permissionList[k].Sort = v.Sort - 1000
+					if _, ok := permissionFirstMap[v.ParentId]; ok && !permissionFirstMap[v.ParentId].IsCheck {
+						permissionFirstMap[v.ParentId].AuthOk = true
+						permissionFirstMap[v.ParentId].Sort -= 1000
+						permissionFirstMap[v.ParentId].IsCheck = true
+					}
+					break
 				}
-				break
 			}
 		}
 	}
 
 	for _, v := range permissionList {
-		temp := new(response.PermissionFiccSecondItem)
-		temp.Sort = v.Sort
-		temp.ChartPermissionID = int(v.ChartPermissionID)
-		temp.ChartPermissionName = v.PermissionName
-		temp.AuthOk = permissionMap[v.ChartPermissionID]
-		temp.PirceDrivenState = v.PriceDrivenState
-		if _, ok := permissionFirstMap[v.ClassifyName]; ok {
-			permissionFirstMap[v.ClassifyName].List = append(permissionFirstMap[v.ClassifyName].List, temp)
-		} else {
-			permissionFirstMap[v.ClassifyName] = &response.PermissionFirstItem{
-				List: []*response.PermissionFiccSecondItem{temp},
+		if v.ParentId > 0 {
+			temp := new(response.PermissionFiccSecondItem)
+			temp.Sort = v.Sort
+			temp.ChartPermissionID = int(v.ChartPermissionID)
+			temp.ChartPermissionName = v.PermissionName
+			temp.AuthOk = permissionMap[v.ChartPermissionID]
+			temp.PirceDrivenState = v.PriceDrivenState
+			if _, ok := permissionFirstMap[v.ParentId]; ok {
+				permissionFirstMap[v.ParentId].List = append(permissionFirstMap[v.ParentId].List, temp)
+			} else {
+				permissionFirstMap[v.ParentId] = &response.PermissionFirstItem{
+					List: []*response.PermissionFiccSecondItem{temp},
+				}
 			}
 		}
 	}
@@ -948,22 +961,22 @@ func GetBindFiccPermissions(user user.UserInfo) (ret response.BindPermissionFicc
 	for _, item := range validPermissionList {
 		validPermissionIds = append(validPermissionIds, item.ChartPermissionID)
 	}
-	permissionList, err := chart_permission.GetFiccListExceptTacticByProductIdOrderSort()
+	permissionList, err := chart_permission.GetFiccListExceptTacticByProductId()
 	if err != nil {
 		return
 	}
 	permissionMap := make(map[uint64]bool)
-	permissionFirstMap := make(map[string]*response.BindPermissionFiccItem)
+	permissionFirstMap := make(map[int]*response.BindPermissionFiccItem)
 
 	//查询首页展示的图标
-	permissionFirstList, err := chart_permission_first.GetIndexShowListOrderSort()
+	permissionFirstList, err := chart_permission.GetFiccFirstListExceptTacticByProductId()
 	if err != nil {
 		return
 	}
 	for _, v := range permissionFirstList {
-		permissionFirstMap[v.ClassifyName] = &response.BindPermissionFiccItem{
-			Id:           int(v.Id),
-			ClassifyName: v.YbIndexName,
+		permissionFirstMap[int(v.ChartPermissionID)] = &response.BindPermissionFiccItem{
+			Id:           int(v.ChartPermissionID),
+			ClassifyName: v.ChartPermissionName,
 		}
 	}
 
@@ -981,14 +994,14 @@ func GetBindFiccPermissions(user user.UserInfo) (ret response.BindPermissionFicc
 		temp := new(response.BindPermissionFiccSecondItem)
 		temp.ChartPermissionID = int(v.ChartPermissionID)
 		temp.ChartPermissionName = v.PermissionName
-		if _, ok := permissionFirstMap[v.ClassifyName]; ok && permissionMap[v.ChartPermissionID] {
-			permissionFirstMap[v.ClassifyName].List = append(permissionFirstMap[v.ClassifyName].List, temp)
+		if _, ok := permissionFirstMap[v.ParentId]; ok && permissionMap[v.ChartPermissionID] {
+			permissionFirstMap[v.ParentId].List = append(permissionFirstMap[v.ParentId].List, temp)
 		}
 	}
 
 	var list []*response.BindPermissionFiccItem
 	for _, v := range permissionFirstList {
-		item := permissionFirstMap[v.ClassifyName]
+		item := permissionFirstMap[int(v.ChartPermissionID)]
 		if len(item.List) > 0 {
 			temp := new(response.BindPermissionFiccItem)
 			temp.Id = item.Id
@@ -1041,22 +1054,22 @@ func GetCommoditiesBindFiccPermissions(user user.UserInfo) (ret response.BindPer
 	for _, item := range validPermissionList {
 		validPermissionIds = append(validPermissionIds, item.ChartPermissionID)
 	}
-	permissionList, err := chart_permission.GetFiccListExceptTacticByProductIdOrderSort()
+	permissionList, err := chart_permission.GetFiccListExceptTacticByProductId()
 	if err != nil {
 		return
 	}
 	permissionMap := make(map[uint64]bool)
-	permissionFirstMap := make(map[string]*response.BindPermissionFiccItem)
+	permissionFirstMap := make(map[int]*response.BindPermissionFiccItem)
 
 	//查询首页展示的图标
-	permissionFirstList, err := chart_permission_first.GetIndexShowListOrderSort()
+	permissionFirstList, err := chart_permission.GetFiccFirstListExceptTacticByProductId()
 	if err != nil {
 		return
 	}
 	for _, v := range permissionFirstList {
-		permissionFirstMap[v.ClassifyName] = &response.BindPermissionFiccItem{
-			Id:           int(v.Id),
-			ClassifyName: v.YbIndexName,
+		permissionFirstMap[int(v.ChartPermissionID)] = &response.BindPermissionFiccItem{
+			Id:           int(v.ChartPermissionID),
+			ClassifyName: v.ChartPermissionName,
 		}
 	}
 
@@ -1074,22 +1087,22 @@ func GetCommoditiesBindFiccPermissions(user user.UserInfo) (ret response.BindPer
 		temp := new(response.BindPermissionFiccSecondItem)
 		temp.ChartPermissionID = int(v.ChartPermissionID)
 		temp.ChartPermissionName = v.PermissionName
-		if _, ok := permissionFirstMap[v.ClassifyName]; ok && permissionMap[v.ChartPermissionID] {
-			permissionFirstMap[v.ClassifyName].List = append(permissionFirstMap[v.ClassifyName].List, temp)
+		if _, ok := permissionFirstMap[v.ParentId]; ok && permissionMap[v.ChartPermissionID] {
+			permissionFirstMap[v.ParentId].List = append(permissionFirstMap[v.ParentId].List, temp)
 		}
 	}
 
 	var list []*response.BindPermissionFiccItem
 LOOP:
 	for _, v := range permissionFirstList {
-		item := permissionFirstMap[v.ClassifyName]
+		item := permissionFirstMap[int(v.ChartPermissionID)]
 		if len(item.List) > 0 {
 			temp := new(response.BindPermissionFiccItem)
 			temp.Id = item.Id
 			temp.ClassifyName = item.ClassifyName
 			temp.List = item.List
 			//大宗商品分类内合并PTA&MEG
-			if temp.ClassifyName == "化工" {
+			if temp.ClassifyName == "化工产业" {
 				count := 0
 				for i, secondItem := range temp.List {
 					if secondItem.ChartPermissionName == "PTA" || secondItem.ChartPermissionName == "MEG" {

+ 3 - 0
utils/constants.go

@@ -367,3 +367,6 @@ const (
 	DATA_SUB_SOURCE_EDB  = iota //经济数据库
 	DATA_SUB_SOURCE_DATE        //日期序列
 )
+
+// 默认的品种图片
+const APPLY_VARIETY_IMG_DEFAULT = "https://hzstatic.hzinsights.com/static/yb_variety/宏观经济.png"