Browse Source

新增指标数据表头信息,优化已购列表接口

xiexiaoyuan 3 years ago
parent
commit
265419d5d8

+ 1 - 11
logic/user/user.go

@@ -355,17 +355,7 @@ func GetUserTabBar(userInfo user.UserInfo) (list []string, err error) {
 	}
 	// 已购仅付费用户可见
 	if strings.Contains("永续,正式", companyProduct.Status) {
-		//判断是否除了权益研报以外的权限
-		permissionIds, tErr := companyService.GetPurchasePermissionIdsByCompany2ProductId(userInfo.CompanyID, 1)
-		if tErr != nil {
-			if err == utils.ErrNoRow {
-				err = nil
-			}
-			return
-		}
-		if len(permissionIds) > 0{
-			list = append(list, "buy")
-		}
+		list = append(list, "buy")
 	}
 
 	return

+ 10 - 0
models/response/report.go

@@ -155,6 +155,16 @@ type TickerDataItem struct {
 	WwValue          float64       `json:"ww_value"`
 	MmValue          float64       `json:"mm_value"`
 }
+type TickerTitleData struct {
+	TickerTitle      string      `json:"ticker_title"`
+	ReportChapterTypeId  int     `json:"report_chapter_type_id"`
+	ReportChapterTypeName string `json:"report_chapter_type_name"`
+	DataTableImage string   `json:"data_table_image"`
+}
+type TickerData struct {
+	List []*TickerDataItem `json:"list"`
+	TickerTitle *TickerTitleData `json:"ticker_title"`
+}
 
 type ReportCollectListResp []*ReportCollectList
 

+ 2 - 4
models/tables/report_chapter_type/query.go

@@ -47,15 +47,13 @@ func GetTypeIDByReportChapterTypeName(name string) (chapterIds []int, err error
 }
 
 // GetTickerTitleByTypeId 根据类型获取指标标题
-func GetTickerTitleByTypeId(id int) (title string, err error)  {
-	var chapterType *ReportChapterType
-	err = global.DEFAULT_MYSQL.Model(ReportChapterType{}).Select("ticker_title").Where("report_chapter_type_id=?", id).First(&chapterType).Error
+func GetTickerTitleByTypeId(id int) (chapterType *ReportChapterType , err error)  {
+	err = global.DEFAULT_MYSQL.Model(ReportChapterType{}).Select("ticker_title, report_chapter_type_id, report_chapter_type_name, report_chapter_type_key").Where("report_chapter_type_id=?", id).First(&chapterType).Error
 	if err != nil {
 		if err == utils.ErrNoRow {
 			err = nil
 		}
 		return
 	}
-	title = chapterType.TickerTitle
 	return
 }

+ 16 - 1
services/activity/activity.go

@@ -1,8 +1,10 @@
 package activity
 
 import (
+	"errors"
 	"fmt"
 	"gorm.io/gorm"
+	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/response/purchase"
 	"hongze/hongze_yb/models/tables/company_product"
@@ -202,6 +204,16 @@ func GetUserAuthActivityIds(userInfo user.UserInfo) (acrivityIds []int, err erro
 
 // GetLatestActivity 从用户有权限参与的活动中,筛选出最新的活动
 func GetLatestActivity(permissionIds []int, userId uint64) (purchaseItem *purchase.PurchaseListItem, err error)  {
+	var errMsg string
+	defer func() {
+		if sysErr := recover(); sysErr != nil {
+			err = errors.New("系统错误")
+			global.LOG.Critical(fmt.Sprintf("GetLatestClassReport: userId=%d, err:%s,sysErr:%s", userId, err.Error(), sysErr))
+		}
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("GetLatestClassReport: userId=%d, err:%s, errMsg:%s", userId, err.Error(), errMsg))
+		}
+	}()
 	// 获取用户权限可参与的活动ID
 	var activityIds []int
 	permissions, err := yb_activity_permission.GetPermissionsByPermissionIds(permissionIds)
@@ -214,11 +226,15 @@ func GetLatestActivity(permissionIds []int, userId uint64) (purchaseItem *purcha
 
 	activityItem, err := yb_activity.GetLatestByIds(activityIds)
 	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("查询活动错误")
 		return
 	}
 	//统计未读数
 	unRead, err := GetUnRead(activityIds, userId)
 	if err != nil{
+		errMsg = err.Error()
+		err = errors.New("查询活动未读数错误")
 		return
 	}
 	purchaseItem = new(purchase.PurchaseListItem)
@@ -231,7 +247,6 @@ func GetLatestActivity(permissionIds []int, userId uint64) (purchaseItem *purcha
 		// 添加活动icon
 		purchaseItem.ImgUrl = utils.ALIYUN_YBIMG_HOST + "purchase_icon_xj_two_week.png"
 	}
-
 	return
 }
 

+ 0 - 1
services/company/permission.go

@@ -47,7 +47,6 @@ func GetPurchasePermissionIdsByCompany2ProductId(companyId, productId int64) (pe
 	where["company_id ="] = companyId
 	where["product_id ="] = productId
 	where["status in"] = []string{"正式", "永续"}
-	where["chart_permission_id !="] = 33       //过滤策略的权限
 	list, err := company_report_permission.GetByWhereMap(where)
 	if err != nil {
 		return

+ 21 - 4
services/purchase/purchase.go

@@ -8,6 +8,7 @@ import (
 	"hongze/hongze_yb/services/report"
 	"hongze/hongze_yb/services/user"
 	"sort"
+	"sync"
 )
 
 func GetLatestReportAndActivity(user user.UserInfo) (list purchase.PurchaseList, err error)  {
@@ -19,13 +20,29 @@ func GetLatestReportAndActivity(user user.UserInfo) (list purchase.PurchaseList,
 		err = errors.New("用户无权限")
 		return
 	}
-	list, err = report.GetLatestClassReport(permissionIds, user.UserID)
+
+	w := sync.WaitGroup{}
+	//查找最新的报告
+	w.Add(1)
+	go func() {
+		defer w.Done()
+		list, err = report.GetLatestClassReport(permissionIds, user.UserID)
+	}()
+	//查找最新的活动
+	w.Add(1)
+	var purItem *purchase.PurchaseListItem
+	var err2 error
+	go func() {
+		defer w.Done()
+		purItem, err2 = activity2.GetLatestActivity(permissionIds, user.UserID)
+	}()
+	w.Wait()
+
 	if err != nil {
 		return
 	}
-
-	purItem, err := activity2.GetLatestActivity(permissionIds, user.UserID)
-	if err != nil {
+	if err2 != nil {
+		err = err2
 		return
 	}
 

+ 22 - 4
services/report/report.go

@@ -32,11 +32,14 @@ import (
 func GetLatestClassReport(permissionIds []int, userId uint64) (purchaseList []*purchase.PurchaseListItem, err error)  {
 	var errMsg string
 	defer func() {
+		if sysErr := recover(); sysErr != nil {
+			err = errors.New("系统错误")
+			global.LOG.Critical(fmt.Sprintf("GetLatestClassReport: userId=%d, err:%s,sysErr:%s", userId, err.Error(), sysErr))
+		}
 		if err != nil {
 			global.LOG.Critical(fmt.Sprintf("GetLatestClassReport: userId=%d, err:%s, errMsg:%s", userId, err.Error(), errMsg))
 		}
 	}()
-
 	//获取所有分类信息
 	classifys, err := classify.GetSimpleAll()
 	if err != nil {
@@ -396,7 +399,7 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 	}
 	//如果有权限则展示content
 	if authOk  {
-		_ = AddViewRecord(userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0)
+		task.Task(AddViewRecord, userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0)
 		reportItem.Content = html.UnescapeString(reportInfo.Content)
 		reportItem.VideoUrl = reportInfo.VideoUrl
 	}
@@ -826,7 +829,7 @@ func SearchReport(user user.UserInfo, keyWord string, pageIndex, pageSize int)(r
 }
 
 // GetTickerData 获取指标数据
-func GetTickerData(user user.UserInfo, reportChapterId int) (list []*response.TickerDataItem, err error) {
+func GetTickerData(user user.UserInfo, reportChapterId int) (ret response.TickerData, err error) {
 	var errMsg string
 	defer func() {
 		if err != nil {
@@ -854,6 +857,7 @@ func GetTickerData(user user.UserInfo, reportChapterId int) (list []*response.Ti
 		return
 	}
 
+	var list []*response.TickerDataItem
 	if len(tickers) > 0 {
 		var tickerNames []string
 		for _, v := range tickers {
@@ -865,12 +869,18 @@ func GetTickerData(user user.UserInfo, reportChapterId int) (list []*response.Ti
 		}else{
 			dataList, err = daily_base_column.GetDataByBaseColumnTickers(tickerNames)
 		}
+
 		if err != nil {
 			errMsg = err.Error()
 			err = errors.New("查询指标数据失败")
 			return
 		}
-
+		chapterTypeInfo, tErr := report_chapter_type.GetTickerTitleByTypeId(chapter.TypeId)
+		if tErr != nil {
+			errMsg = tErr.Error()
+			err = errors.New("查询章节类型失败")
+			return
+		}
 		if len(dataList) >= 0 {
 			for _, v := range dataList {
 				temp := new(response.TickerDataItem)
@@ -886,6 +896,14 @@ func GetTickerData(user user.UserInfo, reportChapterId int) (list []*response.Ti
 				list = append(list, temp)
 			}
 		}
+
+		tickerTitle := new(response.TickerTitleData)
+		tickerTitle.TickerTitle = chapterTypeInfo.TickerTitle
+		tickerTitle.ReportChapterTypeId = int(chapterTypeInfo.ReportChapterTypeId)
+		tickerTitle.ReportChapterTypeName = chapterTypeInfo.ReportChapterTypeName
+		tickerTitle.DataTableImage = fmt.Sprintf("http://hongze.oss-cn-shanghai.aliyuncs.com/data_table/%s.png", chapterTypeInfo.ReportChapterTypeKey)
+		ret.List = list
+		ret.TickerTitle = tickerTitle
 	}
 	return
 }

+ 2 - 1
services/report/report_chapter.go

@@ -11,6 +11,7 @@ import (
 	"hongze/hongze_yb/models/tables/report_chapter_type"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/task"
 	"hongze/hongze_yb/utils"
 	"html"
 )
@@ -248,7 +249,7 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 			chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst)
 		}
 
-		_ = AddViewRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
+		task.Task(AddViewRecord, user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
 	}else{
 		reportChapterItem.ContentSub = html.UnescapeString(reportChapter.ContentSub)
 	}

+ 26 - 7
services/report/report_view_record.go

@@ -1,23 +1,42 @@
 package report
 
 import (
+	"errors"
+	"fmt"
+	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/tables/company"
 	"hongze/hongze_yb/models/tables/rddp/report_view_record"
 	"hongze/hongze_yb/services/user"
 	"time"
 )
 
-func AddViewRecord(user user.UserInfo, reportId int, classifyName string, reportChapterId int) (err error) {
-	companyInfo, err := company.GetByCompanyId(user.CompanyID)
+func AddViewRecord(params ...interface{}) {
+	var err error
+	userInter  := params[0]
+	userInfo, ok := (userInter).(user.UserInfo)
+	if !ok {
+		err = errors.New("格式换转失败")
+		return
+	}
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("Task BatchInsertReportView: userId=%d, err:%s", userInfo.UserID, err.Error()))
+		}
+	}()
+
+	reportId := params[1].(int)
+	classifyName := params[2]
+	reportChapterId := params[3].(int)
+	companyInfo, err := company.GetByCompanyId(userInfo.CompanyID)
 	if err != nil {
 		return
 	}
 	record := new(report_view_record.ReportViewRecord)
-	record.UserId = int(user.UserID)
+	record.UserId = int(userInfo.UserID)
 	record.ReportId = reportId
-	record.Mobile = user.Mobile
-	record.Email = user.Email
-	record.RealName = user.RealName
+	record.Mobile = userInfo.Mobile
+	record.Email = userInfo.Email
+	record.RealName = userInfo.RealName
 	record.CompanyName = companyInfo.CompanyName
 	record.CreateTime = time.Now()
 	if classifyName == "晨报" || classifyName == "周报" {
@@ -28,6 +47,6 @@ func AddViewRecord(user user.UserInfo, reportId int, classifyName string, report
 		return
 	}
 	//修改联系人最后一次阅读报告时间
-	err = user.WxUser.SetWxUserReportLastViewTime()
+	err = userInfo.WxUser.SetWxUserReportLastViewTime()
 	return
 }