Parcourir la source

首页权限列表,首页报告汇总

xiexiaoyuan il y a 3 ans
Parent
commit
997741bbe0

+ 18 - 0
controller/company/company_permission.go

@@ -4,6 +4,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"hongze/hongze_yb/controller/response"
 	"hongze/hongze_yb/services/company"
+	userService "hongze/hongze_yb/services/user"
 )
 
 // GetPermissionList 获取FICC品种权限列表
@@ -34,3 +35,20 @@ func GetPermissionList(c *gin.Context)  {
 
 	response.OkData("获取成功", list, c)
 }
+
+
+func GetHomeFiccPermissions(c *gin.Context) {
+	userinfo := userService.GetInfoByClaims(c)
+	// 判断用户是否有已购权限
+	if userinfo.CompanyID == 0 {
+		response.Fail("无权操作", c)
+		return
+	}
+	list, err := company.GetHomeFiccPermissions(userinfo)
+	if err !=nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+
+	response.OkData("获取成功", list, c)
+}

+ 13 - 0
controller/report/classify.go

@@ -115,4 +115,17 @@ func ClassifySimpleList(c *gin.Context)  {
 	}
 	response.OkData("查询成功", classList, c )
 	return
+}
+
+
+func ClassifyFirstList(c *gin.Context)  {
+	userinfo := userService.GetInfoByClaims(c)
+
+	classList, err := reportService.GetClassifyFirstList(userinfo)
+	if err != nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+	response.OkData("查询成功", classList, c )
+	return
 }

+ 11 - 3
models/response/classify.go

@@ -1,7 +1,6 @@
 package response
 
 import (
-	"hongze/hongze_yb/services/company"
 	"time"
 )
 
@@ -21,7 +20,7 @@ type ClassifyDetail struct {
 	AvatarImgUrl     string     `json:"avatar_img_url"`
 	Abstract         string		`json:"abstract"`
 	Descript         string     `json:"descript"`
-	PermissionCheck     *company.PermissionCheckInfo    `json:"permission_check"`
+	PermissionCheck     *PermissionCheckInfo    `json:"permission_check"`
 	AuthOk              bool `json:"auth_ok"`
 	IsVip           int       `json:"is_vip"'`
 }
@@ -42,7 +41,7 @@ type ClassReportListItem struct {
 }
 type ClassReportList struct {
 	List    []*ClassReportListItem   	`json:"list"`
-	PermissionCheck     *company.PermissionCheckInfo    `json:"permission_check"`
+	PermissionCheck     *PermissionCheckInfo    `json:"permission_check"`
 	AuthOk              bool `json:"auth_ok"`
 	Paging         *PagingItem `json:"paging"`
 }
@@ -51,4 +50,13 @@ type ClassifySimpleListItem struct {
 	ClassifyIdSecond        int     `json:"classify_id_second"`
 	ClassifyNameSecond     	string  `json:"classify_name_second"`
 	ClassifySecondNameSimple     	string  `json:"classify_second_simple"`
+}
+
+type ClassifyFirstListItem struct {
+	ClassifyIdFirst    int    `description:"一级分类id" json:"classify_id_first"`
+	ClassifyIdSecond   int     `json:"classify_id_second"`
+	ClassifyNameFirst  string `description:"一级分类名称" json:"classify_name_first"`
+	ClassifyNameSecond     	string  `json:"classify_name_second"`
+	IconImgUrl         string	`json:"icon_img_url"`
+	RedirectPage        string     `json:"redirect_page"`
 }

+ 67 - 0
models/response/permission.go

@@ -0,0 +1,67 @@
+package response
+
+type PermissionFirstItem struct {
+	AuthOk     bool
+	Sort       int
+	IsCheck    bool
+	List       PermissionFiccSecondList
+}
+
+type PermissionFiccItem struct {
+	ClassifyName    string   `json:"classify_name"`
+	List  PermissionFiccSecondList   `json:"list"`
+	Sort           int       `json:"sort"`
+}
+
+type PermissionFiccSecondItem struct {
+	ChartPermissionName string    `json:"chart_permission_name"`
+	ChartPermissionID   int    `json:"chart_permission_id"`
+	Sort           int 	`json:"sort"`
+	AuthOk     bool   `json:"auth_ok"`
+}
+
+type PermissionFiccList []*PermissionFiccItem
+
+func (p PermissionFiccList) Len() int {
+	return len(p)
+}
+
+func (p PermissionFiccList) Less(i, j int) bool {
+	return p[i].Sort < p[j].Sort
+}
+
+func (p PermissionFiccList) Swap(i, j int) {
+	p[i], p[j] = p[j], p[i]
+}
+
+type PermissionFiccSecondList []*PermissionFiccSecondItem
+
+func (ps PermissionFiccSecondList) Len() int {
+	return len(ps)
+}
+
+func (ps PermissionFiccSecondList) Less(i, j int) bool {
+	return ps[i].Sort < ps[j].Sort
+}
+
+func (ps PermissionFiccSecondList) Swap(i, j int) {
+	ps[i], ps[j] = ps[j], ps[i]
+}
+
+// PermissionCheckInfo 权限校验完成后的结果
+type PermissionCheckInfo struct {
+	Name         string       `json:"name" description:"销售名称"`
+	Mobile       string       `json:"mobile" description:"手机号"`
+	Type         string       `json:"type" description:"校验失败,没有权限,需要让前端处理的类型,枚举值:apply,contact"`
+	CustomerInfo CustomerInfo `json:"customer_info" description:"客户信息"`
+}
+
+// CustomerInfo 客户信息
+type CustomerInfo struct {
+	CompanyName string `json:"company_name" description:"客户(公司)名称"`
+	Name        string `json:"name" description:"联系人名称"`
+	Mobile      string `json:"mobile" description:"手机号"`
+	Status      string `json:"status" description:"状态"`
+	IsSuspend   int8   `json:"is_suspend" description:"启用与否字段:1:暂停,0:启用"`
+	HasApply    bool   `json:"has_apply" description:"是否有申请过"`
+}

+ 2 - 3
models/response/report.go

@@ -1,14 +1,13 @@
 package response
 
 import (
-	"hongze/hongze_yb/services/company"
 	"time"
 )
 
 type ReportDetail struct {
 	ReportInfo          *ReportItem  `json:"report_info"`
 	ReportChapterList        []*ReportChapterListItem `json:"report_chapter_list"`
-	PermissionCheck     *company.PermissionCheckInfo    `json:"permission_check"`
+	PermissionCheck     *PermissionCheckInfo    `json:"permission_check"`
 	AuthOk              bool `json:"auth_ok"`
 }
 
@@ -68,7 +67,7 @@ type ReportChapterItem struct {
 
 type ReportChapterDetail struct {
 	ReportChapterItem  * ReportChapterItem  `json:"report_chapter_item"`
-	PermissionCheck     *company.PermissionCheckInfo    `json:"permission_check"`
+	PermissionCheck     *PermissionCheckInfo    `json:"permission_check"`
 	ReportChapterMenuList        []*ReportChapterMenu `json:"report_chapter_menu_list""`
 	AuthOk              bool `json:"auth_ok"`
 }

+ 5 - 0
models/tables/chart_permission/query.go

@@ -12,6 +12,11 @@ func GetListByProductId(productId int64) (list []*ChartPermission, err error) {
 	return
 }
 
+// GetFiccListExceptTacticByProductId 获取ficc 除了市场策略的所有权限
+func GetFiccListExceptTacticByProductId() (list []*ChartPermission, err error)  {
+	err = global.DEFAULT_MYSQL.Where(" product_id = 1 and classify_name != '市场策略'").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

+ 12 - 27
models/tables/rddp/classify/query.go

@@ -19,53 +19,38 @@ func GetByClassifyName(classifyName string) (item *Classify, err error) {
 	return
 }
 
-// GetByClassifyId 根据分类ID查询分类详情
-func GetByClassifyId(id int) (item *Classify, err error) {
-	err = global.MYSQL["rddp"].Model(Classify{}).Where("id = ?", id).First(&item).Error
+// GetParentList 查询所有一级分类
+func GetParentList() (list []*Classify, err error) {
+	err = global.MYSQL["rddp"].Model(Classify{}).Where("parent_id = 0").Order("sort asc, id asc").Scan(&list).Error
 	if err == utils.ErrNoRow {
 		err = nil
 	}
 	return
 }
 
-// GetListByPid 根据分类名称查找专栏列表
-func GetListByPid(pid int) (list []*Classify, err error) {
-	err = global.MYSQL["rddp"].Model(Classify{}).Where("parent_id = ? ", pid).Order("sort asc, id asc").Scan(&list).Error
+// GetByClassifyId 根据分类ID查询分类详情
+func GetByClassifyId(id int) (item *Classify, err error) {
+	err = global.MYSQL["rddp"].Model(Classify{}).Where("id = ?", id).First(&item).Error
 	if err == utils.ErrNoRow {
 		err = nil
 	}
 	return
 }
 
-
-// GetIdsByClassifyName 根据分类名称查找id
-func GetIdsByClassifyName(names []string) (ids []int, err error) {
-	var list []*Classify
-	err = global.MYSQL["rddp"].Model(Classify{}).Select("id").Where("classify_name in (?) ", names).Scan(&list).Error
+// GetListByPid 根据分类名称查找专栏列表
+func GetListByPid(pid int) (list []*Classify, err error) {
+	err = global.MYSQL["rddp"].Model(Classify{}).Where("parent_id = ? ", pid).Order("sort asc, id asc").Scan(&list).Error
 	if err == utils.ErrNoRow {
 		err = nil
 	}
-	if err != nil {
-		return
-	}
-	for _, v := range list {
-		ids = append(ids, v.Id)
-	}
 	return
 }
 
-// GetIdsByClassifyNameAndParentId 查询
-func GetIdsByClassifyNameAndParentId(names []string, parentId int) (ids []int, err error) {
-	var list []*Classify
-	err = global.MYSQL["rddp"].Model(Classify{}).Select("id").Where("classify_name in (?) and parent_id = ?", names, parentId).Scan(&list).Error
+// GetFirstByPid 根据一级分类查找二级分类
+func GetFirstByPid(pid int) (item *Classify, err error) {
+	err = global.MYSQL["rddp"].Model(Classify{}).Where("parent_id = ? ", pid).First(&item).Error
 	if err == utils.ErrNoRow {
 		err = nil
 	}
-	if err != nil {
-		return
-	}
-	for _, v := range list {
-		ids = append(ids, v.Id)
-	}
 	return
 }

+ 3 - 2
routers/company.go

@@ -7,8 +7,9 @@ import (
 )
 
 func InitCompany(r *gin.Engine) {
-	rGroup := r.Group("company").Use(middleware.Token())
+	rGroup := r.Group("api/company").Use(middleware.Token())
 	{
-		rGroup.GET("/getPermissionList", company.GetPermissionList)
+	//	rGroup.GET("/getPermissionList", company.GetPermissionList)
+		rGroup.GET("/getPermissionList", company.GetHomeFiccPermissions)
 	}
 }

+ 1 - 0
routers/report.go

@@ -13,6 +13,7 @@ func InitReport(r *gin.Engine)  {
 	rGroup.GET("/list", report.List)
 
 	rGroup2 := r.Group("api/classify").Use(middleware.Token())
+	rGroup2.GET("/", report.ClassifyFirstList)
 	rGroup2.GET("/list", report.ClassifyList)
 	rGroup2.GET("/simple/list", report.ClassifySimpleList)
 	rGroup2.GET("/detail", report.ClassifyDetail)

+ 79 - 2
services/company/permission.go

@@ -2,6 +2,7 @@ package company
 
 import (
 	"fmt"
+	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/tables/admin"
 	"hongze/hongze_yb/models/tables/chart_permission"
 	"hongze/hongze_yb/models/tables/company"
@@ -10,7 +11,9 @@ import (
 	"hongze/hongze_yb/models/tables/company_user_chart_classify_permission"
 	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/models/tables/yb_apply_record"
+	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
+	"sort"
 	"time"
 )
 
@@ -258,7 +261,7 @@ func CheckPermissionByPermissionIdList2Ficc(companyId int64, userId int, permiss
 	return
 }
 
-func GetCheckPermission(companyId int64, userId int, permissionIdList []int) (ok bool, permissionCheckInfo PermissionCheckInfo, err error) {
+func GetCheckPermission(companyId int64, userId int, permissionIdList []int) (ok bool, permissionCheckInfo response.PermissionCheckInfo, err error) {
 	defer func() {
 		// 如果无权限,那么就去查询是否申请过
 		if ok == false {
@@ -319,7 +322,7 @@ func GetCheckPermission(companyId int64, userId int, permissionIdList []int) (ok
 			err = tmpErr
 			return
 		}
-		customerInfo := CustomerInfo{
+		customerInfo := response.CustomerInfo{
 			CompanyName: companyInfo.CompanyName,
 			Status:      companyProductInfo.Status,
 			Name:        wxUser.RealName,
@@ -578,5 +581,79 @@ func GetFiccPermissionList() (list []*FiccPermissionList, err error) {
 		list = append(list, classify)
 	}
 
+	return
+}
+
+func GetHomeFiccPermissions(user user.UserInfo) (list response.PermissionFiccList, err error){
+	validPermissionIds, err := GetPurchasePermissionIdsByCompany2ProductId(user.CompanyID, 1)
+	if err != nil {
+		return
+	}
+	permissionList, err := chart_permission.GetFiccListExceptTacticByProductId()
+	if err != nil {
+		return
+	}
+	permissionMap := make(map[uint64]bool)
+	permissionFirstMap := make(map[string]*response.PermissionFirstItem)
+	permissionFirstMap["宏观经济"] = &response.PermissionFirstItem{
+		Sort: 1001,
+	}
+	permissionFirstMap["化工产业"] = &response.PermissionFirstItem{
+		Sort: 1002,
+	}
+	permissionFirstMap["黑色产业"] = &response.PermissionFirstItem{
+		Sort: 1003,
+	}
+	permissionFirstMap["有色产业"] = &response.PermissionFirstItem{
+		Sort: 1004,
+	}
+
+	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
+				}
+				break
+			}
+		}
+	}
+
+	for _, v := range permissionList {
+		temp := new(response.PermissionFiccSecondItem)
+		temp.Sort = v.Sort
+		temp.ChartPermissionID = int(v.ChartPermissionID)
+		temp.ChartPermissionName = v.ChartPermissionName
+		temp.AuthOk = permissionMap[v.ChartPermissionID]
+		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},
+			}
+		}
+
+
+	}
+
+	for k, v := range permissionFirstMap {
+		temp := new(response.PermissionFiccItem)
+		temp.Sort = v.Sort
+		temp.ClassifyName = k
+		if len(v.List) > 0 {
+			temp.List = v.List
+			sort.Sort(temp.List)
+		}
+		list = append(list, temp)
+	}
+
+	if len(list) > 0 {
+		sort.Sort(list)
+	}
 	return
 }

+ 54 - 0
services/report/classify.go

@@ -261,4 +261,58 @@ func GetClassifySecondSimpleList(user user.UserInfo, classifyIdFirst int) (list
 }
 
 
+// GetClassifyFirstList 获取一级分类列表
+func GetClassifyFirstList(user user.UserInfo) (list []*response.ClassifyFirstListItem, err error) {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("GetClassifyFirstList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+
+	classifyParents, err := classify.GetParentList()
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("分类查询出错")
+		return
+	}
+	if len(classifyParents) == 0 {
+		err = errors.New("分类不存在")
+		return
+	}
+	classifyMap := make(map[string]bool)
+	classifyMap["需求报告"] = true
+	classifyMap["宏观报告"] = true
+	classifyMap["日度点评"] = true
+	classifyMap["数据点评"] = true
+	classifyMap["行业调研"] = true
+	classifyMap["碳市场价格周报"] = true
+	classifyMap["海外视角"] = true
+	classifyMap["百家谈"] = true
+	for _, item := range classifyParents {
+		temp := new(response.ClassifyFirstListItem)
+		temp.ClassifyIdFirst = item.Id
+		temp.ClassifyNameFirst = item.ClassifyName
+		temp.IconImgUrl = ""
+		if _, ok := classifyMap[item.ClassifyName]; ok {
+			if item.ClassifyName == "需求报告" || item.ClassifyName == "宏观报告" {
+				classifySecond, tErr := classify.GetFirstByPid(item.Id)
+				if tErr == nil && classifySecond.Id > 0 {
+					temp.ClassifyIdSecond = classifySecond.Id
+					temp.ClassifyNameSecond = classifySecond.ClassifyName
+					temp.RedirectPage = "/api/classify/detail"
+				}
+			}else{
+				temp.RedirectPage = "/api/classify/list"
+			}
+		}else{
+			temp.RedirectPage = "/api/report/list"
+		}
+
+		list = append(list, temp)
+	}
+
+	return
+}
+
 

+ 2 - 2
services/report/report.go

@@ -236,7 +236,7 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 
 	//判断权限
 	var authOk bool
-	var permissionCheckInfo company.PermissionCheckInfo
+	var permissionCheckInfo response.PermissionCheckInfo
 	if reportInfo.ClassifyNameFirst == "晨报"{
 		authOk, permissionCheckInfo, err = CheckDayReportPermission(userinfo)
 	}else if reportInfo.ClassifyNameFirst == "周报"{
@@ -283,7 +283,7 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 }
 
 // CheckReportPermission 验证用户查看报告的权限
-func CheckReportPermission(userInfo user.UserInfo, reportId int) (authOk bool, permissionCheckInfo company.PermissionCheckInfo, err error) {
+func CheckReportPermission(userInfo user.UserInfo, reportId int) (authOk bool, permissionCheckInfo response.PermissionCheckInfo, err error) {
 	permissionIds, err := chart_permission_chapter_mapping.GetPermissionIdsByReportId(reportId, "rddp")
 	if err != nil && err != utils.ErrNoRow {
 		return

+ 3 - 3
services/report/report_chapter.go

@@ -173,7 +173,7 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 
 	var authOk bool
 	var chapterAuthOk bool
-	var permissionCheckInfo company.PermissionCheckInfo
+	var permissionCheckInfo response.PermissionCheckInfo
 
 	reportInfo, tErr := report.GetByReportId(reportChapter.ReportId)
 	if tErr != nil {
@@ -295,7 +295,7 @@ func GetMenuChapter(reportId int, typeIds []int, classifyNameFirst string) (repo
 }
 
 // CheckWeekReportPermission 验证周报的权限
-func CheckWeekReportPermission(userInfo user.UserInfo, reportId int) (authOk bool, permissionCheckInfo company.PermissionCheckInfo, err error) {
+func CheckWeekReportPermission(userInfo user.UserInfo, reportId int) (authOk bool, permissionCheckInfo response.PermissionCheckInfo, err error) {
 	permissionIds, err := chart_permission_chapter_mapping.GetPermissionIdsByReportId(reportId, "week")
 	if err != nil && err != utils.ErrNoRow {
 		return
@@ -305,7 +305,7 @@ func CheckWeekReportPermission(userInfo user.UserInfo, reportId int) (authOk boo
 }
 
 // CheckDayReportPermission 验证晨报的权限
-func CheckDayReportPermission(userInfo user.UserInfo) (authOk bool, permissionCheckInfo company.PermissionCheckInfo, err error) {
+func CheckDayReportPermission(userInfo user.UserInfo) (authOk bool, permissionCheckInfo response.PermissionCheckInfo, err error) {
 	permissions, err := company.GetValidPermissionByCompany2ProductId(userInfo.CompanyID, 1)
 	if err != nil && err != utils.ErrNoRow {
 		return