|
@@ -0,0 +1,206 @@
|
|
|
+package report
|
|
|
+
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "hongze/hongze_yb/global"
|
|
|
+ "hongze/hongze_yb/models/response"
|
|
|
+ "hongze/hongze_yb/models/tables/chart_permission_search_key_word_mapping"
|
|
|
+ "hongze/hongze_yb/models/tables/rddp/classify"
|
|
|
+ "hongze/hongze_yb/models/tables/rddp/report"
|
|
|
+ "hongze/hongze_yb/services/company"
|
|
|
+ "hongze/hongze_yb/services/user"
|
|
|
+ "hongze/hongze_yb/utils"
|
|
|
+ "log"
|
|
|
+)
|
|
|
+
|
|
|
+// GetClassListByClassifyName 查询二级分类列表
|
|
|
+func GetClassListByClassifyName(user user.UserInfo, classifyName string) (list []*response.ClassifyListItem, err error) {
|
|
|
+ var errMsg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Critical(fmt.Sprintf("GetClassListByClassifyName: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ classifyInfo, err := classify.GetByClassifyName(classifyName)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("分类查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if classifyInfo.Id == 0 {
|
|
|
+ err = errors.New("分类不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if classifyInfo.ParentId != 0 {
|
|
|
+ err = errors.New("不允许查询二级分类")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ classifyList, err := classify.GetListByPid(classifyInfo.Id)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("二级分类查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询二级分类中最新的报告ID
|
|
|
+ reportList, err := report.GetLatestReportsByClassifyNameFirst(classifyName)
|
|
|
+ if err != nil && err != utils.ErrNoRow {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("报告查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ reportMap := make(map[int]*report.Report)
|
|
|
+ for _, v := range reportList {
|
|
|
+ reportMap[v.ClassifyIdSecond] = v
|
|
|
+ }
|
|
|
+ for _, item := range classifyList {
|
|
|
+ temp := new(response.ClassifyListItem)
|
|
|
+ temp.ClassifySecondId = item.Id
|
|
|
+ temp.ParentId = item.ParentId
|
|
|
+ temp.AuthorDescript = item.AuthorDescript
|
|
|
+ temp.ReportAuthor = item.ReportAuthor
|
|
|
+ temp.HomeImgUrl = item.HomeImgUrl
|
|
|
+ temp.ClassifySecondName = item.ClassifyName
|
|
|
+ if _, ok := reportMap[item.Id]; ok {
|
|
|
+ temp.Stage = reportMap[item.Id].Stage
|
|
|
+ }
|
|
|
+ if classifyName == "权益研报" {
|
|
|
+ temp.ProductName = "权益"
|
|
|
+ } else {
|
|
|
+ temp.ProductName = "FICC"
|
|
|
+ }
|
|
|
+
|
|
|
+ list = append(list, temp)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetClassifyDetail(user user.UserInfo, classifySecondName string) (detail *response.ClassifyDetail, err error) {
|
|
|
+ var errMsg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Critical(fmt.Sprintf("GetClassifyDetail: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ classifyInfo, err := classify.GetByClassifyName(classifySecondName)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("分类查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if classifyInfo.Id == 0 {
|
|
|
+ err = errors.New("分类不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if classifyInfo.ParentId == 0 {
|
|
|
+ err = errors.New("只允许查询二级分类")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //查询权限, 查询当前分类下的最新的报告,
|
|
|
+ permissionIds, err := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(classifyInfo.ClassifyName)
|
|
|
+ log.Println(permissionIds)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("分类权限查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ authOk, permissionCheckInfo, err := company.GetCheckPermission(user.CompanyID, int(user.UserID), permissionIds)
|
|
|
+ if err != nil && err != utils.ErrNoRow {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("权限查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ detail = new(response.ClassifyDetail)
|
|
|
+ detail.ClassifySecondId = classifyInfo.Id
|
|
|
+ detail.ParentId = classifyInfo.ParentId
|
|
|
+ detail.AuthorDescript = classifyInfo.AuthorDescript
|
|
|
+ detail.ReportAuthor = classifyInfo.ReportAuthor
|
|
|
+ detail.AvatarImgUrl = classifyInfo.AvatarImgUrl
|
|
|
+ detail.ClassifySecondName = classifyInfo.ClassifyName
|
|
|
+ detail.Abstract = classifyInfo.Abstract
|
|
|
+ detail.Descript = classifyInfo.Descript
|
|
|
+ detail.IsVip = classifyInfo.IsVip
|
|
|
+ detail.PermissionCheck = &permissionCheckInfo
|
|
|
+ detail.AuthOk = authOk
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetClassifyReportList 查询二级分类下的报告列表
|
|
|
+func GetClassifyReportList(user user.UserInfo, classifySecondName string, page, limit int) (list *response.ClassReportList, err error) {
|
|
|
+ var errMsg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Critical(fmt.Sprintf("GetClassifyDetail: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ classifyInfo, err := classify.GetByClassifyName(classifySecondName)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("分类查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if classifyInfo.Id == 0 {
|
|
|
+ err = errors.New("分类不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if classifyInfo.ParentId == 0 {
|
|
|
+ err = errors.New("只允许查询二级分类")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //查询权限, 查询当前分类下的最新的报告,
|
|
|
+ permissionIds, err := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(classifyInfo.ClassifyName)
|
|
|
+ log.Println(permissionIds)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("分类权限查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ authOk, permissionCheckInfo, err := company.GetCheckPermission(user.CompanyID, int(user.UserID), permissionIds)
|
|
|
+ if err != nil && err != utils.ErrNoRow {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("权限查询出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //查询 report列表
|
|
|
+ offset := (page - 1) * limit
|
|
|
+ reportList, err := report.GetListByClassSecond(classifySecondName, offset, limit)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询报告列表出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var newList []*response.ClassReportListItem
|
|
|
+ if len(reportList) > 0 {
|
|
|
+ for _, reportInfo := range reportList {
|
|
|
+ reportItem := new(response.ClassReportListItem)
|
|
|
+ reportItem.ReportId = reportInfo.Id
|
|
|
+ reportItem.Title = reportInfo.Title
|
|
|
+ reportItem.PublishTime = reportInfo.PublishTime
|
|
|
+ reportItem.ClassifyNameFirst = reportInfo.ClassifyNameFirst
|
|
|
+ reportItem.ClassifyNameSecond = reportInfo.ClassifyNameSecond
|
|
|
+ reportItem.Stage = reportInfo.Stage
|
|
|
+ reportItem.Abstract = reportInfo.Abstract
|
|
|
+ reportItem.Author = reportInfo.Author
|
|
|
+ if authOk {
|
|
|
+ reportItem.VideoUrl = reportInfo.VideoUrl
|
|
|
+ }
|
|
|
+ newList = append(newList, reportItem)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list = new(response.ClassReportList)
|
|
|
+ list.List = newList
|
|
|
+ list.PermissionCheck = &permissionCheckInfo
|
|
|
+ list.AuthOk = authOk
|
|
|
+
|
|
|
+ return
|
|
|
+}
|