Browse Source

no message

xingzai 5 months ago
parent
commit
2bc60ef9f1
6 changed files with 404 additions and 5 deletions
  1. 25 0
      models/article.go
  2. 16 0
      models/ficc_report/report.go
  3. 1 0
      models/resource_data.go
  4. 162 4
      services/ficc_report.go
  5. 199 1
      services/resource_data.go
  6. 1 0
      utils/constants.go

+ 25 - 0
models/article.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_cygx/utils"
 	"strings"
 	"time"
 )
@@ -49,6 +50,7 @@ type CygxArticle struct {
 	ModifyTimeByCl   string `description:"策略平台报告更新时间"`
 	CeLueFieldId     int    `description:"策略平台领域ID"`
 	Cover            string `description:"封面图片"`
+	ReportId         int    `description:"FICC研报ID"`
 }
 
 type CygxArticleEs struct {
@@ -121,6 +123,7 @@ type HomeArticle struct {
 	Cover               string               `description:"封面图片"`
 	BodyHighlight       []string             `description:"搜索高亮展示结果"`
 	ArticleTypeId       int                  `description:"文章类型ID"`
+	ReportId            int                  `description:"FICC研报ID"`
 	List                []*IndustrialManagementIdInt
 }
 
@@ -201,6 +204,13 @@ func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
 	return
 }
 
+func GetArticleDetailByReportId(reportId int) (item *ArticleDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article WHERE report_id = ?  AND publish_status = 1  `
+	err = o.Raw(sql, reportId).QueryRow(&item)
+	return
+}
+
 func GetSellerList(articleId int) (items []*SellerRep, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
@@ -1015,3 +1025,18 @@ WHERE
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+// 列表
+func GetCygxCygxArticleListByReportIds(reportIds []int) (items []*CygxArticle, err error) {
+	lenArr := len(reportIds)
+	if lenArr == 0 {
+		return
+	}
+	var pars []interface{}
+	o := orm.NewOrm()
+	sql := `SELECT article_id ,report_id FROM cygx_article as art WHERE report_id IN  (` + utils.GetOrmInReplace(lenArr) + `) `
+	pars = append(pars, reportIds)
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, 0, lenArr).QueryRows(&items)
+	return
+}

+ 16 - 0
models/ficc_report/report.go

@@ -15,6 +15,10 @@ type ReportDetail struct {
 	CollectionId         int                      `description:"收藏ID: 大于0则表示已收藏" json:"collection_id"`
 	RoadVideoId          int                      `json:"road_video_id" description:"绑定的路演视频ID"`
 	ReportDetailShowType int                      `description:"报告详情的展示类型:1-拼接;2:目录" json:"report_detail_show_type"`
+	HasPermission        int                      `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
+	Mobile               string                   `description:"用户手机号"`
+	SellerMobile         string                   `description:"销售电话"`
+	SellerName           string                   `description:"销售姓名"`
 }
 
 type ReportChapterListItem struct {
@@ -127,3 +131,15 @@ func GetByReportId(reportId int) (item *Report, err error) {
 	err = o.Raw(sql, reportId).QueryRow(&item)
 	return
 }
+
+func GetFiccRreportToCygxArticle(condition string, pars []interface{}) (items []*Report, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT	* FROM report WHERE state = 2
+			AND classify_name_first IN ('宏观报告','晨会纪要','调研纪要')
+			AND classify_name_second IN ('大类资产周报','晨会纪要','黑色调研')
+			AND IF ( classify_name_first = '宏观报告' , classify_name_second = '大类资产周报' ,1=1 )
+			AND IF ( classify_name_first = '晨会纪要' , classify_name_second = '晨会纪要' ,1=1 )
+			AND IF ( classify_name_first = '调研纪要' , classify_name_second = '黑色调研' ,1=1 ) ` + condition + ` ORDER BY  modify_time	 DESC   `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 1 - 0
models/resource_data.go

@@ -44,6 +44,7 @@ type CygxResourceDataResp struct {
 	ReportSelection    *CygxReportSelectionRep                 `description:"重点公司(原报告精选)"`
 	YanxuanSpecial     *CygxYanxuanSpecialCenterResp           `description:"研选专栏"`
 	AskserieVideo      *MicroRoadShowPageList                  `description:"活动音频"`
+	FiccReport         *HomeArticle                            `description:"FICC研报"`
 }
 
 // Source      string    `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`

+ 162 - 4
services/ficc_report.go

@@ -8,6 +8,9 @@ import (
 	"hongze/hongze_cygx/models/ficc_report"
 	"hongze/hongze_cygx/utils"
 	"html"
+	"strconv"
+	"strings"
+	"time"
 )
 
 // GetMinClassify
@@ -87,21 +90,77 @@ func GetReportDetail(userinfo *models.WxUserItem, reportId int) (reportDetail fi
 			return
 		}
 	}
+	//判断是否已经申请过
+	applyCount, e := models.GetApplyRecordCount(userinfo.UserId)
+	if e != nil {
+		err = errors.New("判断是否已申请过试用失败")
+		return
+	}
+	var hasPermission int
+	if userinfo.CompanyId > 1 {
+		companyPermission, e := models.GetCompanyPermission(userinfo.CompanyId)
+		if e != nil {
+			err = errors.New("获取用户权限信息失败")
+			return
+		}
+		if companyPermission == "" {
+			if applyCount > 0 {
+				hasPermission = 5
+			} else {
+				hasPermission = 2
+			}
+		} else {
+			var articlePermissionName string
+			var hasPersion bool
+			slice := strings.Split(articlePermissionName, ",")
+			if utils.InArrayByStr(slice, "周期") {
+				hasPersion = true
+			}
+			if hasPersion {
+				hasPermission = 1
+			} else { //无该行业权限
+				companyDetail, e := models.GetCompanyDetailById(userinfo.CompanyId)
+				if e == nil && companyDetail.ProductId == 1 {
+					hasPermission = 2
+				} else {
+					hasPermission = 3
+				}
+			}
+		}
+		//获取销售手机号
+		sellerItem, e := models.GetSellerByCompanyId(userinfo.CompanyId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("获取销售数据失败")
+			return
+		}
+		if sellerItem != nil {
+			reportDetail.SellerMobile = sellerItem.Mobile
+			reportDetail.SellerName = sellerItem.RealName
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 5
+		} else {
+			hasPermission = 4
+		}
+	}
+	reportDetail.HasPermission = hasPermission
 
 	//判断权限
 
 	var authOk bool
+
 	var reportChapterIdList []int
 	if reportInfo.HasChapter == 1 {
 		if reportInfo.ClassifyNameFirst == "晨报" {
 			//authOk, permissionCheckInfo, err = CheckDayReportPermission(userinfo, productAuthOk)
 		} else {
-			authOk, _, _, reportChapterIdList, err = CheckWeekReportPermission(userinfo, reportId, true)
+			_, _, _, reportChapterIdList, err = CheckWeekReportPermission(userinfo, reportId, true)
 		}
 	}
-
-	authOk = true
-	fmt.Println("reportChapterIdList", reportChapterIdList)
+	if hasPermission == 1 {
+		authOk = true
+	}
 
 	reportItem := new(ficc_report.ReportItem)
 	reportItem.ReportId = reportInfo.Id
@@ -377,3 +436,102 @@ func GetChapterListByReportChapterIdList(classifyNameFirst string, reportId int,
 	//}
 	return
 }
+
+//func init() {
+//	//GetFiccRreportToCygxArticle()
+//	UpdateFICCReportResourceData(5542)
+//}
+
+// 获取FICC研报到查研观向数据库中
+func GetFiccRreportToCygxArticle() (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("自动取消十分钟之内没有付款的的订单 CancelCygxOrder ,err:", err.Error()), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	//modifyTime := time.Now().Add(-10 * time.Minute)
+	//condition = `  AND modify_time >= ?   `
+	//pars = append(pars, modifyTime)
+	reportList, e := ficc_report.GetFiccRreportToCygxArticle(condition, pars)
+	if e != nil {
+		err = errors.New("GetFiccRreportToCygxArticle, Err: " + e.Error())
+		return
+	}
+	fmt.Println(len(reportList))
+	if len(reportList) == 0 {
+		return
+	}
+
+	var reportIds []int
+	for _, v := range reportList {
+		reportIds = append(reportIds, v.Id)
+	}
+	listaFiccReport, e := models.GetCygxCygxArticleListByReportIds(reportIds)
+	if e != nil {
+		err = errors.New("GetCygxCygxArticleListByReportIds, Err: " + e.Error())
+		return
+	}
+	mapFiccReport := make(map[int]bool)
+	for _, v := range listaFiccReport {
+		mapFiccReport[v.IsReport] = true
+	}
+	//量不大,先这么写吧
+	for _, v := range reportList {
+		time.Sleep(1 * time.Millisecond) // 延时一秒
+		item := new(models.CygxArticle)
+		item.ReportId = v.Id
+		item.PublishDate = v.PublishTime.Format(utils.FormatDateTime)
+		item.Title = v.Title
+		item.Body = v.Content
+		item.Abstract = v.Abstract
+		item.PublishStatus = 1
+		if (v.ClassifyNameFirst == "宏观报告" && v.ClassifyNameSecond == "大类资产周报") || (v.ClassifyNameFirst == "晨会纪要" && v.ClassifyNameSecond == "晨会纪要") {
+			item.SubCategoryName = "产业跟踪"
+			item.MatchTypeName = "产业跟踪"
+
+			if utils.RunMode == "release" {
+				item.CategoryId = 10091
+				item.CategoryIdTwo = 10091
+			} else {
+				//item.CategoryId = 10091
+				//item.CategoryIdTwo = 10091
+			}
+		} else if v.ClassifyNameFirst == "调研纪要" && v.ClassifyNameSecond == "调研纪要" {
+			item.SubCategoryName = "调研纪要"
+			item.MatchTypeName = "调研纪要"
+			if utils.RunMode == "release" {
+				item.CategoryId = 10090
+				item.CategoryIdTwo = 10090
+			} else {
+				//item.CategoryId = 10091
+				//item.CategoryIdTwo = 10091
+			}
+		} else {
+			continue
+		}
+		var articleIdMax int
+		maxArticleIdArticleInfo, e := models.GetMaxArticleIdInfo()
+		if e != nil {
+			err = errors.New("GetMaxArticleIdInfo, Err: " + e.Error())
+			return
+		}
+		articleIdMax = maxArticleIdArticleInfo.ArticleId + 1
+		item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdMax))
+		item.ArticleId = articleIdMax
+
+		//如果不存在就新增
+		if !mapFiccReport[v.Id] {
+			_, e = models.AddCygxArticles(item)
+			if e != nil {
+				err = errors.New("AddCygxArticles, Err: " + e.Error())
+				return
+			}
+		}
+		UpdateFICCReportResourceData(v.Id)
+		fmt.Println(v)
+	}
+	return
+}

+ 199 - 1
services/resource_data.go

@@ -43,6 +43,7 @@ func GetResourceDataList(condition string, pars []interface{}, startSize, pageSi
 	var reportselectionIds []int  // 报告精选
 	var yanxuanSpecialIds []int   // 研选专栏
 	var askserieVideoIds []string //问答系列视频
+	var ficcreporrtIds []string   //FICC研报
 	//Source      string    `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt "`
 	for _, v := range list {
 		if v.Source == "article" {
@@ -73,6 +74,8 @@ func GetResourceDataList(condition string, pars []interface{}, startSize, pageSi
 			yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
 		} else if v.Source == utils.CYGX_OBJ_ASKSERIEVIDEO {
 			askserieVideoIds = append(askserieVideoIds, strconv.Itoa(v.SourceId))
+		} else if v.Source == utils.CYGX_OBJ_FICC_REPORT {
+			ficcreporrtIds = append(ficcreporrtIds, strconv.Itoa(v.SourceId))
 		}
 
 	}
@@ -447,10 +450,49 @@ func GetResourceDataList(condition string, pars []interface{}, startSize, pageSi
 		}
 	}
 
+	//处理FICC研报
+	if len(ficcreporrtIds) > 0 {
+		pars = make([]interface{}, 0)
+		condition = ` AND a.report_id IN (` + utils.GetOrmInReplace(len(ficcreporrtIds)) + `)`
+		pars = append(pars, ficcreporrtIds)
+
+		listArticle, e := models.GetHomeList(condition, pars, 0, len(ficcreporrtIds))
+		if e != nil {
+			err = errors.New("GetHomeList, Err: " + e.Error())
+			return
+		}
+
+		//listArticle, e = HandleArticleCategoryImg(listArticle)
+		//if e != nil {
+		//	err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
+		//	return
+		//}
+		for _, v := range listArticle {
+			//fmt.Println(v.ArticleId)
+			v.Body = ""
+			v.BodyHtml = ""
+			mapItems[fmt.Sprint("ficcreport", v.ReportId)].FiccReport = v
+		}
+
+		//listArticle, e = HandleArticleCategoryImg(listArticle)
+		//if e != nil {
+		//	err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
+		//	return
+		//}
+		//for _, v := range listArticle {
+		//	//reportInfoItem := new(ficc_report.ReportDetail)
+		//	//reportInfoItem.ReportInfo.ReportId = v.ReportId
+		//	//reportInfoItem.ReportInfo.PublishTime = utils.StrTimeToTime(v.PublishDate)
+		//	//reportInfoItem.ReportInfo.Title = v.Title
+		//	mapItems[fmt.Sprint("ficcreport", v.ArticleId)].FiccReport = v
+		//
+		//}
+	}
+
 	for _, vList := range list {
 		for _, v := range mapItems {
 			//如果这些类型都为空,那么就不合并
-			if v.Article == nil && v.Newchart == nil && v.Roadshow == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.Activityspecial == nil && v.Researchsummary == nil && v.Minutessummary == nil && v.Meetingreviewchapt == nil && v.ProductInterior == nil && v.IndustrialResource == nil && v.ReportSelection == nil && v.YanxuanSpecial == nil && v.AskserieVideo == nil {
+			if v.Article == nil && v.Newchart == nil && v.Roadshow == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.Activityspecial == nil && v.Researchsummary == nil && v.Minutessummary == nil && v.Meetingreviewchapt == nil && v.ProductInterior == nil && v.IndustrialResource == nil && v.ReportSelection == nil && v.YanxuanSpecial == nil && v.AskserieVideo == nil && v.FiccReport == nil {
 				continue
 			}
 			if v.SourceId == vList.SourceId && v.Source == vList.Source {
@@ -904,3 +946,159 @@ func initsql12_17() {
 	}
 	return
 }
+
+// 更新FICC研报
+func UpdateFICCReportResourceData(sourceId int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go utils.SendAlarmMsg("更新文章 失败,UpdateArticleResourceData Err:"+err.Error()+"资源ID"+strconv.Itoa(sourceId), 3)
+		}
+	}()
+	var source = utils.CYGX_OBJ_FICC_REPORT
+	var condition string
+	var pars []interface{}
+	condition = ` AND publish_status = 1  AND  report_id = ?  `
+	pars = append(pars, sourceId)
+	total, e := models.GetCygxArticleCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxArticleCount, Err: " + err.Error())
+		return
+	}
+	//如果取消发布了就做删除处理
+	if total == 0 {
+		e = models.DeleteResourceData(sourceId, source)
+		if e != nil {
+			err = errors.New("DeleteResourceData, Err: " + e.Error())
+			return
+		}
+		//删除 cygx_resource_data 表关联的产业ID,标的ID
+		e = models.DeleteCygxResourceDataGroup(sourceId, source)
+		if e != nil {
+			err = errors.New("DeleteCygxResourceDataGroup, Err: " + e.Error())
+			return
+		}
+	} else {
+		//判断是否存在,如果不存在就新增,存在就更新
+		totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
+		if e != nil {
+			err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
+			return
+		}
+		detail, e := models.GetArticleDetailByReportId(sourceId)
+		if e != nil {
+			err = errors.New("GetArticleDetailByReportId, Err: " + e.Error())
+			return
+		}
+		var resourceDataId int
+		publishDate := time.Now().Format(utils.FormatDateTime)
+		item := new(models.CygxResourceData)
+		if detail.ArticleTypeId > 0 {
+			item.SearchTag = detail.ArticleTypeName // 研选类型名称
+		} else {
+			item.SearchTag = detail.MatchTypeName
+			if detail.SubCategoryName == "产业跟踪" && detail.MatchTypeName == "行业深度" { //需求池973:查研观向首页标签【深度】下,过滤【产业跟踪】系列的报告。新报告不再写入此标签下,存量报告也去掉
+				item.SearchTag = ""
+			}
+			//获取文章分类详情
+			detailCategory, _ := models.GetCygxReportMappingCelueMaxDetailByCategoryId(detail.CategoryId)
+			if detailCategory != nil {
+				item.ChartPermissionId = detailCategory.ChartPermissionId
+			}
+		}
+		var industrialName string
+		var subjectName string
+		//建立首页资源表,与产业的关系
+		industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+			return
+		}
+
+		for _, v := range industrialList {
+			industrialName += v.IndustryName
+		}
+
+		//建立首页资源表,与标的 的关系
+		subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetSubjectArticleGroupManagementList, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+			return
+		}
+
+		for _, v := range subjectList {
+			subjectName += v.SubjectName
+		}
+		item.SourceId = sourceId
+		item.Source = source
+		item.PublishDate = publishDate
+		item.CreateTime = time.Now()
+		item.SearchTitle = detail.Title
+		annotation, e := utils.GetHtmlContentText(detail.Annotation)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+			return
+		}
+		abstract, e := utils.GetHtmlContentText(detail.Abstract)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetHtmlContentText, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+			return
+		}
+		item.SearchContent = annotation + abstract + detail.FieldName + detail.Stock + industrialName + subjectName
+		item.SearchOrderTime = detail.PublishDate
+
+		if totalData == 0 {
+			newId, e := models.AddCygxResourceData(item)
+			if e != nil {
+				err = errors.New("AddCygxResourceData, Err: " + e.Error())
+				return
+			}
+			resourceDataId = int(newId)
+		} else {
+			e = models.UpdateResourceDataByItem(item)
+			if e != nil {
+				err = errors.New("UpdateResourceData, Err: " + e.Error())
+				return
+			}
+			sourceDetail, e := models.GetCygxResourceDataByIdAndSource(sourceId, source)
+			if e != nil {
+				err = errors.New("UpdateResourceData, Err: " + e.Error())
+				return
+			}
+			resourceDataId = sourceDetail.Id
+		}
+
+		//建立首页资源表,与产业的关系
+		var industrialItems []*models.CygxResourceDataIndustrialGroupManagement
+		for _, v := range industrialList {
+			var industrialItem = new(models.CygxResourceDataIndustrialGroupManagement)
+			industrialItem.SourceId = sourceId
+			industrialItem.Source = source
+			industrialItem.IndustrialManagementId = v.IndustrialManagementId
+			industrialItem.ResourceDataId = resourceDataId
+			industrialItem.CreateTime = time.Now()
+			industrialItems = append(industrialItems, industrialItem)
+		}
+
+		//建立首页资源表,与标的 的关系
+		var subjectItems []*models.CygxResourceDataIndustrialGroupSubject
+		for _, v := range subjectList {
+			var subjectItem = new(models.CygxResourceDataIndustrialGroupSubject)
+			subjectItem.SourceId = sourceId
+			subjectItem.Source = source
+			subjectItem.IndustrialSubjectId = v.IndustrialSubjectId
+			subjectItem.ResourceDataId = resourceDataId
+			subjectItem.CreateTime = time.Now()
+			subjectItems = append(subjectItems, subjectItem)
+		}
+
+		//插入关联信息
+		e = models.AddCygxResourceDataGroup(sourceId, source, industrialItems, subjectItems)
+		if e != nil {
+			err = errors.New("AddCygxResourceDataGroup, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}

+ 1 - 0
utils/constants.go

@@ -265,6 +265,7 @@ const (
 	CYGX_OBJ_INDUSTRIALSOURCE_YX string = "industrialsourceYx" // 对象类型:研选资源包
 	CYGX_OBJ_RS_CALENDAR         string = "rscalendar"         // 对象类型:研究员日历安排
 	CYGX_OBJ_USER_FEEDBACK       string = "userfeedback"       // 对象类型:用户交流反馈
+	CYGX_OBJ_FICC_REPORT         string = "ficcreport"         // 对象类型:FICC研报
 )
 
 const (