Selaa lähdekoodia

Merge branch 'cygx7.5' into debug

# Conflicts:
#	models/db.go
ziwen 2 vuotta sitten
vanhempi
commit
0e25d4b898

+ 60 - 0
models/data_manage/cygx_article.go

@@ -0,0 +1,60 @@
+package data_manage
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxArticle struct {
+	SummaryManageId    int       `orm:"column(id);pk"`
+	CategoryName       string    `description:"行业分类名称"`
+	CategoryId         int       `description:"行业分类ID"`
+	CategoryIdTwo      int       `description:"分类id用作修改匹配类型使用"`
+	ArticleId          int       `description:"文章ID"`
+	Title              string    `description:"标题"`
+	Abstract           string    `description:"摘要"`
+	Body               string    `description:"内容"`
+	BodyText           string    `description:"内容"`
+	PublishStatus      int       `description:"发布状态,0未发布 ,1已发布"`
+	PublishDate        time.Time `description:"发布时间"`
+	CreateDate         time.Time `description:"创建时间"`
+	LastUpdatedTime    time.Time `description:"更新时间"`
+	IsSummary          int       `description:"是否属于纪要库 1是、0否"`
+	IsReport           int       `description:"是否属于报告 1是、0否"`
+	ReportType         int       `description:"'报告类型,1行业报告,2产业报告'"`
+	Source             int       `description:"来源 0策略平台同步,1小程序后台添加"`
+	ArticleIdMd5       string    `description:"ID,md5值"`
+	UpdateFrequency    string    `description:"更新周期"`
+	SellerAndMobile    string    `description:"销售和手机号"`
+	Department         string    `description:"作者"`
+	ExpertBackground   string    `description:"专家背景"`
+	ExpertNumber       string    `description:"专家编号"`
+	InterviewDate      string    `description:"访谈日期"`
+	FileLink           string    `description:"下载预览链接"`
+	ChartPermissionIds string    `description:"行业ID ,多个用 , 隔开"`
+	DepartmentId       int       `description:"作者ID"`
+	Periods            string    `description:"期数"`
+	ReportLink         string    `description:"报告链接"`
+	ArticleType        string    `description:"文章类型 文章类型,lyjh:路演精华 "`
+	HavePublish        int       `description:"是否发布过,1是 ,0 否"`
+	IsClass            int       `description:"是否归类过,1是 ,0 否"`
+	SubCategoryName    string    `description:"主题名称"`
+	LinkArticleId      int       `description:"报告ID链接"`
+	AdminId            int       `description:"销售/管理员ID"`
+	AdminName          string    `description:"销售/管理员姓名"`
+	ArticleTypeId      int       `description:"文章类型ID"`
+	ArticleTypeName    string    `description:"文章类型名称"`
+	Annotation         string    `description:"核心观点"`
+	Stock              string    `description:"个股标签"`
+	//NickName           string    `description:"作者昵称"`
+}
+
+func GetReportArticleList(condition string, pars []interface{}) (list []*CygxArticle, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article WHERE 1=1 AND publish_status = 1`
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&list)
+	return
+}

+ 15 - 0
models/data_manage/cygx_article_type.go

@@ -0,0 +1,15 @@
+package data_manage
+
+import "github.com/beego/beego/v2/client/orm"
+
+type CygxArticleType struct {
+	ArticleTypeId int `description:"表cygx_article_type中id"`
+	YanxPermissionId        int `description:"研选类型所对应的ID"`
+}
+
+func CygxArticleTypeMappingList() (items []*CygxArticleType, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT article_type_id, yanx_permission_id FROM cygx_article_type `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 52 - 0
models/data_manage/cygx_minutes_summary.go

@@ -0,0 +1,52 @@
+package data_manage
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxMinutesSummary struct {
+	ArticleId       int       `orm:"column(article_id);pk"description:"报告id"`
+	Title           string    `description:"标题"`
+	Department      string    `description:"作者"`
+	Abstract        string    `description:"摘要"`
+	PublishStatus   int       `description:"发布状态,1已发布,0未发布"`
+	PublishDate     time.Time `description:"发布时间"`
+	CreateTime      time.Time `description:"创建时间"`
+	LastUpdatedTime time.Time `description:"最后一次更新时间"`
+	Periods         string    `description:"期数"`
+	HavePublish     int       `description:"是否发布过,1是,0否"`
+	AdminId         int       `description:"销售/管理员ID"`
+	AdminName       string    `description:"销售/管理员姓名"`
+}
+
+type CygxMinutesSummaryLog struct {
+	ArticleSunId        int       `orm:"column(article_sun_id);pk"description:"子级报告id"`
+	ArticleId           int       `description:"父级报告Id"`
+	Type                string    `description:"类型'SSGS:上市公司调研纪要,’CYDYJY:产业调研纪要’,’YANX:研选"`
+	Sort                string    `description:"排序"`
+	ChartPermissionId   int       `description:"行业ID"`
+	ChartPermissionSort string    `description:"行业排序"`
+	CreateTime          time.Time `description:"创建时间"`
+	Body                string    `description:"内容"`
+	ReportLink          string    `description:"报告链接"`
+	LinkArticleId       int       `description:"报告ID链接"`
+}
+
+func AddCygxMinutesSummaryOrm(item *CygxMinutesSummary) (newArtId int64, err error) {
+	o := orm.NewOrm()
+	newArtId, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+	return
+}
+
+func AddCygxMinutesSummaryLogOrm(items []*CygxMinutesSummaryLog) (newArtId int64, err error) {
+	o := orm.NewOrm()
+	newArtId, err = o.InsertMulti(1, items)
+	if err != nil {
+		return
+	}
+	return
+}

+ 15 - 0
models/data_manage/cygx_report_mapping.go

@@ -0,0 +1,15 @@
+package data_manage
+
+import "github.com/beego/beego/v2/client/orm"
+
+type CygxReportMapping struct {
+	ChartPermissionId int `description:"表chart_permission中id"`
+	CategoryId        int `description:"权益文章对应分类,cygx_article"`
+}
+
+func CygxReportMappingist() (items []*CygxReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT chart_permission_id, category_id FROM cygx_report_mapping `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 71 - 0
models/data_manage/cygx_research_summary.go

@@ -0,0 +1,71 @@
+package data_manage
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// GetLatestContractListByProductId 获取最新的续约合同ids
+func GetLatestContractListByProductId(productId int) (contractIds []string, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT article_id FROM cygx_research_summary WHERE product_id=? AND contract_type="续约合同" GROUP BY create_time DESC,company_id `
+	_, err = o.Raw(sql, productId).QueryRows(&contractIds)
+	return
+}
+
+type CygxResearchSummaryLog struct {
+	ArticleSunId        int       `orm:"column(article_sun_id);pk"description:"子级报告id"`
+	ArticleId           int       `description:"父级报告Id"`
+	Type                string    `description:"类型'SDBG:深度报告片篇,’CYDYJY:产业调研纪要’,’SJDP:事件点评,’BZCHJH:本周晨会精华’"`
+	Sort                string    `description:"排序"`
+	ChartPermissionId   int       `description:"行业ID"`
+	ChartPermissionSort string    `description:"行业排序"`
+	CreateTime          time.Time `description:"创建时间"`
+	Body                string    `description:"内容"`
+	ReportLink          string    `description:"报告链接"`
+	LinkArticleId       int       `description:"报告ID链接"`
+}
+
+type CygxResearchSummary struct {
+	ArticleId       int       `orm:"column(article_id);pk"description:"报告id"`
+	Title           string    `description:"标题"`
+	Department      string    `description:"作者"`
+	Abstract        string    `description:"摘要"`
+	PublishStatus   int       `description:"发布状态,1已发布,0未发布"`
+	PublishDate     time.Time `description:"发布时间"`
+	CreateTime      time.Time `description:"创建时间"`
+	LastUpdatedTime time.Time `description:"最后一次更新时间"`
+	Periods         string    `description:"期数"`
+	HavePublish     int       `description:"是否发布过,1是,0否"`
+	AdminId         int       `description:"销售/管理员ID"`
+	AdminName       string    `description:"销售/管理员姓名"`
+}
+
+func AddCygxResearchSummaryOrm(item *CygxResearchSummary) (newArtId int64, err error) {
+	o := orm.NewOrm()
+	newArtId, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+	return
+}
+
+func AddCygxResearchSummaryLogOrm(items []*CygxResearchSummaryLog) (newArtId int64, err error) {
+	o := orm.NewOrm()
+	newArtId, err = o.InsertMulti(1, items)
+	if err != nil {
+		return
+	}
+	return
+}
+type CygxRSlChartPermission struct {
+	ChartPermissionId   int    `description:"行业ID"`
+	ChartPermissionSort string `description:"行业排序"`
+	List                []*AddCygxResearchSummaryLog
+}
+
+type AddCygxResearchSummaryLog struct {
+	Body                string `description:"内容"`
+	ReportLink          string `description:"报告链接"`
+	ChartPermissionSort string `description:"行业排序"`
+}

+ 17 - 0
models/db.go

@@ -77,6 +77,9 @@ func init() {
 
 	// 注册研报 数据表
 	initYbTable()
+
+	// 注册查研观向 数据表
+	initCygx()
 }
 
 // initCompany 注册客户信息 数据表
@@ -150,3 +153,17 @@ func initEdb() {
 		new(data_manage.TableInfo),
 	)
 }
+
+// initCygx 注册查研观向 数据表
+func initCygx()  {
+	//注册对象
+	orm.RegisterModel(
+		new(data_manage.CygxReportMapping),
+		new(data_manage.CygxResearchSummary),
+		new(data_manage.CygxResearchSummaryLog),
+		new(data_manage.CygxMinutesSummary),
+		new(data_manage.CygxMinutesSummaryLog),
+		new(data_manage.CygxArticle),
+		new(data_manage.CygxArticleType),
+	)
+}

+ 858 - 0
services/cygx_research_summary.go

@@ -0,0 +1,858 @@
+package services
+
+import (
+	"context"
+	"fmt"
+	"hongze/hongze_task/models/data_manage"
+	"hongze/hongze_task/services/alarm_msg"
+	"hongze/hongze_task/utils"
+	"regexp"
+	"strconv"
+	"strings"
+	"time"
+)
+
+func CygxResearchSummary(cont context.Context) (err error) {
+	defer func() {
+		if err != nil {
+			go alarm_msg.SendAlarmMsg("CygxResearchSummary-定时本周生成研究汇总失败, ErrMsg:\n"+err.Error(), 3)
+			fmt.Println(err)
+		}
+	}()
+	//content := "本周研究汇总"
+	friday := utils.GetNowWeekThursday().Add(9 * time.Hour)
+	lastfriday := utils.GetLastWeekThursday().Add(9 * time.Hour)
+	lastMonth := int(lastfriday.Month())
+	month := int(friday.Month())
+	lastDay := lastfriday.Day()
+	day := friday.Day()
+	//friday, _ = time.Parse(utils.FormatDateTime, "2022-09-02 15:00:00")
+	//lastfriday, _ = time.Parse(utils.FormatDateTime, "2022-08-26 15:00:00")
+
+	itemCrs := new(data_manage.CygxResearchSummary)
+	itemCrs.AdminId = 11
+	itemCrs.AdminName = "admin"
+	itemCrs.Title = fmt.Sprintf("本周研究汇总(%d月%d日至%d月%d日)", lastMonth, lastDay, month, day)
+	itemCrs.Department = "弘则产品组"
+	itemCrs.Abstract = ""
+	itemCrs.PublishStatus = 0
+	//itemCrs.Periods = strconv.Itoa(total + 1)
+	itemCrs.CreateTime = time.Now()
+	itemCrs.LastUpdatedTime = time.Now()
+	itemCrs.PublishDate = time.Now()
+
+	articleId, e := data_manage.AddCygxResearchSummaryOrm(itemCrs)
+	if e != nil {
+		err = e
+		return
+	}
+	mappingList, err := data_manage.CygxReportMappingist()
+	if err != nil {
+		return
+	}
+	CategoryChartPermissionIdMap := make(map[int]int)
+	for _, item := range mappingList {
+		CategoryChartPermissionIdMap[item.CategoryId] = item.ChartPermissionId
+	}
+	yanxMappingList, err := data_manage.CygxArticleTypeMappingList()
+	if err != nil {
+		return
+	}
+	articleTypeChartPermissionIdMap := make(map[int]int)
+	for _, item := range yanxMappingList {
+		articleTypeChartPermissionIdMap[item.ArticleTypeId] = item.YanxPermissionId
+	}
+	//深度报告
+	{
+		var condition string
+		var pars []interface{}
+		condition += ` AND publish_date < ?  AND publish_date >= ? `
+		pars = append(pars, friday, lastfriday)
+		sdbgList := make([]*data_manage.CygxArticle, 0)
+
+		//医药
+		{
+			newCondition := condition + ` AND category_id_two IN(65,102)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				sdbgList = append(sdbgList, article)
+			}
+		}
+
+		//消费
+		{
+			newCondition := condition + ` AND category_id_two IN(62,67,1008)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				sdbgList = append(sdbgList, article)
+			}
+		}
+
+		//科技
+		{
+			newCondition := condition + ` AND category_id_two IN(57,69,1009)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				sdbgList = append(sdbgList, article)
+			}
+		}
+
+		//智造
+		{
+			newCondition := condition + ` AND category_id_two IN(66,85)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				sdbgList = append(sdbgList, article)
+			}
+		}
+
+		var logItems []*data_manage.CygxResearchSummaryLog
+		for _, article := range sdbgList {
+			head := "<div class=\"title-content\">\n<strong> 【" + article.Title + "】</strong>\n    "
+			sliceSubjects := strings.Split(article.Stock, "/")
+			var company string
+			if sliceSubjects[0] != "" {
+				for _, vSubject := range sliceSubjects {
+					sliceKuohao := strings.Split(vSubject, "(")           //过滤括号
+					sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
+					subject := sliceXiahuaxian[0]
+					company += "#" + subject
+				}
+				company = "    <span style=\"color: #ff1720\">" + company + "</span>"
+			}
+			annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
+			annotation = strings.ReplaceAll(annotation, "</strong>", "")
+			re, _ := regexp.Compile("<strong.*?>")
+			annotation = re.ReplaceAllString(annotation, "")
+			logItem := data_manage.CygxResearchSummaryLog{
+				ArticleId:         int(articleId),
+				Type:              "SDBG",
+				ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
+				CreateTime:        time.Now(),
+				Body:              head + company + annotation,
+				ReportLink:        "https://vmp.hzinsights.com/v2/articles/" + strconv.Itoa(article.ArticleId),
+				LinkArticleId:     article.LinkArticleId,
+			}
+			logItems = append(logItems, &logItem)
+		}
+		if len(logItems) > 0 {
+			_, e := data_manage.AddCygxResearchSummaryLogOrm(logItems)
+			if e != nil {
+				err = e
+				return
+			}
+		}
+	}
+
+	//产业调研纪要
+	{
+		var condition string
+		var pars []interface{}
+		condition += ` AND publish_date < ?  AND publish_date >= ? `
+		pars = append(pars, friday, lastfriday)
+		cydyjyList := make([]*data_manage.CygxArticle, 0)
+
+		//医药
+		{
+			newCondition := condition + ` AND category_id_two IN(28,93,301,71)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				cydyjyList = append(cydyjyList, article)
+			}
+		}
+
+		//消费
+		{
+			newCondition := condition + ` AND category_id_two IN(32,58)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				cydyjyList = append(cydyjyList, article)
+			}
+		}
+
+		//科技
+		{
+			newCondition := condition + ` AND category_id_two IN(79)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				cydyjyList = append(cydyjyList, article)
+			}
+		}
+
+		//智造
+		{
+			newCondition := condition + ` AND category_id_two IN(84)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				cydyjyList = append(cydyjyList, article)
+			}
+		}
+
+		var logItems []*data_manage.CygxResearchSummaryLog
+		for _, article := range cydyjyList {
+			head := "<div class=\"title-content\">\n<strong> 【" + article.Title + "】</strong>\n    "
+			sliceSubjects := strings.Split(article.Stock, "/")
+			var company string
+			if sliceSubjects[0] != "" {
+				for _, vSubject := range sliceSubjects {
+					sliceKuohao := strings.Split(vSubject, "(")           //过滤括号
+					sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
+					subject := sliceXiahuaxian[0]
+					company += "#" + subject
+				}
+				company = "    <span style=\"color: #ff1720\">" + company + "</span>"
+			}
+			annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
+			annotation = strings.ReplaceAll(annotation, "</strong>", "")
+			re, _ := regexp.Compile("<strong.*?>")
+			annotation = re.ReplaceAllString(annotation, "")
+			logItem := data_manage.CygxResearchSummaryLog{
+				ArticleId:         int(articleId),
+				Type:              "CYDYJY",
+				ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
+				CreateTime:        time.Now(),
+				Body:              head + company + annotation,
+				ReportLink:        "https://vmp.hzinsights.com/v2/articles/" + strconv.Itoa(article.ArticleId),
+				LinkArticleId:     article.LinkArticleId,
+			}
+			logItems = append(logItems, &logItem)
+		}
+		if len(logItems) > 0 {
+			_, e := data_manage.AddCygxResearchSummaryLogOrm(logItems)
+			if e != nil {
+				err = e
+				return
+			}
+		}
+
+	}
+
+	//上市公司调研纪要
+	{
+		var condition string
+		var pars []interface{}
+		condition += ` AND publish_date < ?  AND publish_date >= ? `
+		pars = append(pars, friday, lastfriday)
+		ssgsdyjyList := make([]*data_manage.CygxArticle, 0)
+
+		//医药
+		{
+			newCondition := condition + ` AND category_id_two IN(74,96)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				ssgsdyjyList = append(ssgsdyjyList, article)
+			}
+		}
+
+		//消费
+		{
+			newCondition := condition + ` AND category_id_two IN(88)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				ssgsdyjyList = append(ssgsdyjyList, article)
+			}
+		}
+
+		//科技
+		{
+			newCondition := condition + ` AND category_id_two IN(45)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				ssgsdyjyList = append(ssgsdyjyList, article)
+			}
+		}
+
+		//智造
+		{
+			newCondition := condition + ` AND category_id_two IN(86)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				ssgsdyjyList = append(ssgsdyjyList, article)
+			}
+		}
+
+		var logItems []*data_manage.CygxResearchSummaryLog
+		for _, article := range ssgsdyjyList {
+			head := "<div class=\"title-content\">\n<strong> 【" + article.Title + "】</strong>\n    "
+			sliceSubjects := strings.Split(article.Stock, "/")
+			var company string
+			if sliceSubjects[0] != "" {
+				for _, vSubject := range sliceSubjects {
+					sliceKuohao := strings.Split(vSubject, "(")           //过滤括号
+					sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
+					subject := sliceXiahuaxian[0]
+					company += "#" + subject
+				}
+				company = "    <span style=\"color: #ff1720\">" + company + "</span>"
+			}
+			annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
+			annotation = strings.ReplaceAll(annotation, "</strong>", "")
+			re, _ := regexp.Compile("<strong.*?>")
+			annotation = re.ReplaceAllString(annotation, "")
+			logItem := data_manage.CygxResearchSummaryLog{
+				ArticleId:         int(articleId),
+				Type:              "SSGS",
+				ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
+				CreateTime:        time.Now(),
+				Body:              head + company + annotation,
+				ReportLink:        "https://vmp.hzinsights.com/v2/articles/" + strconv.Itoa(article.ArticleId),
+				LinkArticleId:     article.LinkArticleId,
+			}
+			logItems = append(logItems, &logItem)
+		}
+		if len(logItems) > 0 {
+			_, e := data_manage.AddCygxResearchSummaryLogOrm(logItems)
+			if e != nil {
+				err = e
+				return
+			}
+		}
+	}
+
+	//买方研选
+	{
+		var condition string
+		var pars []interface{}
+		condition += ` AND publish_date < ?  AND publish_date >= ? `
+		pars = append(pars, friday, lastfriday)
+		mfyxList := make([]*data_manage.CygxArticle, 0)
+
+		//纪要
+		{
+			newCondition := condition + ` AND article_type_id = 1 `
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				mfyxList = append(mfyxList, article)
+			}
+		}
+		//观点
+		{
+			newCondition := condition + ` AND article_type_id = 2 `
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				mfyxList = append(mfyxList, article)
+			}
+		}
+		//沙龙
+		{
+			newCondition := condition + ` AND article_type_id = 13 `
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				mfyxList = append(mfyxList, article)
+			}
+		}
+		fmt.Println("mfyxList:", len(mfyxList))
+		var logItems []*data_manage.CygxResearchSummaryLog
+		for _, article := range mfyxList {
+			head := "<div class=\"title-content\">\n<strong> 【" + article.Title + "】</strong>\n    "
+			body := strings.ReplaceAll(article.Body, "<strong>", "")
+			body = strings.ReplaceAll(body, "</strong>", "")
+			re, _ := regexp.Compile("<strong.*?>")
+			body = re.ReplaceAllString(body, "")
+			sliceSubjects := strings.Split(article.Stock, "/")
+			var company string
+			if sliceSubjects[0] != "" {
+				for _, vSubject := range sliceSubjects {
+					sliceKuohao := strings.Split(vSubject, "(")           //过滤括号
+					sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
+					subject := sliceXiahuaxian[0]
+					company += "#" + subject
+				}
+				company = "    <span style=\"color: #ff1720\">" + company + "</span>"
+			}
+			var plus int
+			coreIndex := strings.Index(body, "核心观点:")
+			plus = 15
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心观点:")
+				plus = 13
+			}
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心观点")
+				plus = 12
+			}
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心结论:")
+				plus = 15
+			}
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心结论:")
+				plus = 13
+			}
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心结论")
+				plus = 12
+			}
+			endIndex := strings.Index(body, "<hr")
+			fmt.Println("ID:",article.ArticleId)
+			fmt.Println("coreIndex:", coreIndex, endIndex)
+			if coreIndex != -1 && endIndex != -1 {
+				body = body[coreIndex+plus : endIndex]
+				logItem := data_manage.CygxResearchSummaryLog{
+					ArticleId:         int(articleId),
+					Type:              "YANX",
+					ChartPermissionId: articleTypeChartPermissionIdMap[article.ArticleTypeId],
+					CreateTime:        time.Now(),
+					Body:              head + company + body,
+					ReportLink:        "https://details.hzinsights.com/cygx/report?id=" + article.ArticleIdMd5,
+					LinkArticleId:     article.LinkArticleId,
+				}
+				logItems = append(logItems, &logItem)
+			}
+		}
+		if len(logItems) > 0 {
+			_, e := data_manage.AddCygxResearchSummaryLogOrm(logItems)
+			if e != nil {
+				err = e
+				return
+			}
+		}
+
+	}
+
+	return
+}
+
+func CygxLastWeekSummary(cont context.Context) (err error) {
+	defer func() {
+		if err != nil {
+			go alarm_msg.SendAlarmMsg("CygxLastWeekSummary-定时生成上周纪要汇总失败, ErrMsg:\n"+err.Error(), 3)
+			fmt.Println(err)
+		}
+	}()
+	tuesday := utils.GetNowWeekThursday().Add(8 * time.Hour)
+	lastTuesday := utils.GetLastWeekThursday().Add(8 * time.Hour)
+	lastMonth := int(lastTuesday.Month())
+	month := int(tuesday.Month())
+	lastDay := lastTuesday.Day()
+	day := tuesday.Day()
+
+	itemCrs := new(data_manage.CygxMinutesSummary)
+	itemCrs.AdminId = 11
+	itemCrs.AdminName = "admin"
+	itemCrs.Title = fmt.Sprintf("上周纪要汇总(%d月%d日至%d月%d日)", lastMonth, lastDay, month, day)
+	itemCrs.Department = "弘则产品组"
+	itemCrs.Abstract = ""
+	itemCrs.PublishStatus = 0
+	//itemCrs.Periods = strconv.Itoa(total + 1)
+	itemCrs.CreateTime = time.Now()
+	itemCrs.LastUpdatedTime = time.Now()
+	itemCrs.PublishDate = time.Now()
+
+	articleId, e := data_manage.AddCygxMinutesSummaryOrm(itemCrs)
+	if e != nil {
+		err = e
+		return
+	}
+	mappingList, err := data_manage.CygxReportMappingist()
+	if err != nil {
+		return
+	}
+	CategoryChartPermissionIdMap := make(map[int]int)
+	for _, item := range mappingList {
+		CategoryChartPermissionIdMap[item.CategoryId] = item.ChartPermissionId
+	}
+	yanxMappingList, err := data_manage.CygxArticleTypeMappingList()
+	if err != nil {
+		return
+	}
+	articleTypeChartPermissionIdMap := make(map[int]int)
+	for _, item := range yanxMappingList {
+		articleTypeChartPermissionIdMap[item.ArticleTypeId] = item.YanxPermissionId
+	}
+	//产业调研纪要
+	{
+		var condition string
+		var pars []interface{}
+		condition += ` AND publish_date < ?  AND publish_date >= ? `
+		pars = append(pars, tuesday, lastTuesday)
+		cydyjyList := make([]*data_manage.CygxArticle, 0)
+
+		//医药
+		{
+			newCondition := condition + ` AND category_id_two IN(28,93,301,71)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				cydyjyList = append(cydyjyList, article)
+			}
+		}
+
+		//消费
+		{
+			newCondition := condition + ` AND category_id_two IN(32,58)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				cydyjyList = append(cydyjyList, article)
+			}
+		}
+
+		//科技
+		{
+			newCondition := condition + ` AND category_id_two IN(79)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				cydyjyList = append(cydyjyList, article)
+			}
+		}
+
+		//智造
+		{
+			newCondition := condition + ` AND category_id_two IN(84)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				cydyjyList = append(cydyjyList, article)
+			}
+		}
+
+		var logItems []*data_manage.CygxMinutesSummaryLog
+		for _, article := range cydyjyList {
+			head := "<div class=\"title-content\">\n<strong> 【" + article.Title + "】</strong>\n    "
+			sliceSubjects := strings.Split(article.Stock, "/")
+			var company string
+			if sliceSubjects[0] != "" {
+				for _, vSubject := range sliceSubjects {
+					sliceKuohao := strings.Split(vSubject, "(")           //过滤括号
+					sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
+					subject := sliceXiahuaxian[0]
+					company += "#" + subject
+				}
+				company = "    <span style=\"color: #ff1720\">" + company + "</span>"
+			}
+			annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
+			annotation = strings.ReplaceAll(annotation, "</strong>", "")
+			re, _ := regexp.Compile("<strong.*?>")
+			annotation = re.ReplaceAllString(annotation, "")
+			logItem := data_manage.CygxMinutesSummaryLog{
+				ArticleId:         int(articleId),
+				Type:              "CYDYJY",
+				ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
+				CreateTime:        time.Now(),
+				Body:              head + company + annotation,
+				ReportLink:        "https://vmp.hzinsights.com/v2/articles/" + strconv.Itoa(article.ArticleId),
+				LinkArticleId:     article.LinkArticleId,
+			}
+			logItems = append(logItems, &logItem)
+		}
+		if len(logItems) > 0 {
+			_, e := data_manage.AddCygxMinutesSummaryLogOrm(logItems)
+			if e != nil {
+				err = e
+				return
+			}
+		}
+
+	}
+
+	//上市公司调研纪要
+	{
+		var condition string
+		var pars []interface{}
+		condition += ` AND publish_date < ?  AND publish_date >= ? `
+		pars = append(pars, tuesday, lastTuesday)
+		ssgsdyjyList := make([]*data_manage.CygxArticle, 0)
+
+		//医药
+		{
+			newCondition := condition + ` AND category_id_two IN(74,96)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				ssgsdyjyList = append(ssgsdyjyList, article)
+			}
+		}
+
+		//消费
+		{
+			newCondition := condition + ` AND category_id_two IN(88)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				ssgsdyjyList = append(ssgsdyjyList, article)
+			}
+		}
+
+		//科技
+		{
+			newCondition := condition + ` AND category_id_two IN(45)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				ssgsdyjyList = append(ssgsdyjyList, article)
+			}
+		}
+
+		//智造
+		{
+			newCondition := condition + ` AND category_id_two IN(86)`
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				ssgsdyjyList = append(ssgsdyjyList, article)
+			}
+		}
+
+		var logItems []*data_manage.CygxMinutesSummaryLog
+		for _, article := range ssgsdyjyList {
+			head := "<div class=\"title-content\">\n<strong> 【" + article.Title + "】</strong>\n    "
+			sliceSubjects := strings.Split(article.Stock, "/")
+			var company string
+			if sliceSubjects[0] != "" {
+				for _, vSubject := range sliceSubjects {
+					sliceKuohao := strings.Split(vSubject, "(")           //过滤括号
+					sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
+					subject := sliceXiahuaxian[0]
+					company += "#" + subject
+				}
+				company = "    <span style=\"color: #ff1720\">" + company + "</span>"
+			}
+			annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
+			annotation = strings.ReplaceAll(annotation, "</strong>", "")
+			re, _ := regexp.Compile("<strong.*?>")
+			annotation = re.ReplaceAllString(annotation, "")
+			logItem := data_manage.CygxMinutesSummaryLog{
+				ArticleId:         int(articleId),
+				Type:              "SSGS",
+				ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
+				CreateTime:        time.Now(),
+				Body:              head + company + annotation,
+				ReportLink:        "https://vmp.hzinsights.com/v2/articles/" + strconv.Itoa(article.ArticleId),
+				LinkArticleId:     article.LinkArticleId,
+			}
+			logItems = append(logItems, &logItem)
+		}
+		if len(logItems) > 0 {
+			_, e := data_manage.AddCygxMinutesSummaryLogOrm(logItems)
+			if e != nil {
+				err = e
+				return
+			}
+		}
+	}
+
+	//买方研选
+	{
+		var condition string
+		var pars []interface{}
+		condition += ` AND publish_date < ?  AND publish_date >= ? `
+		pars = append(pars, tuesday, lastTuesday)
+		mfyxList := make([]*data_manage.CygxArticle, 0)
+
+		//纪要
+		{
+			newCondition := condition + ` AND article_type_id = 1 `
+			list, e := data_manage.GetReportArticleList(newCondition, pars)
+			if e != nil {
+				err = e
+				fmt.Println("GetReportArticleList err:", e)
+				return
+			}
+			for _, article := range list {
+				mfyxList = append(mfyxList, article)
+			}
+		}
+		////观点
+		//{
+		//	newCondition := condition + ` AND article_type_id = 2 `
+		//	list ,e := data_manage.GetReportArticleList(newCondition, pars)
+		//	if e != nil {
+		//		err = e
+		//		fmt.Println("GetReportArticleList err:", e)
+		//		return
+		//	}
+		//	for _, article := range list {
+		//		mfyxList = append(mfyxList, article)
+		//	}
+		//}
+		////沙龙
+		//{
+		//	newCondition := condition + ` AND article_type_id = 13 `
+		//	list ,e := data_manage.GetReportArticleList(newCondition, pars)
+		//	if e != nil {
+		//		err = e
+		//		fmt.Println("GetReportArticleList err:", e)
+		//		return
+		//	}
+		//	for _, article := range list {
+		//		mfyxList = append(mfyxList, article)
+		//	}
+		//}
+		fmt.Println("mfyxList:", len(mfyxList))
+		var logItems []*data_manage.CygxMinutesSummaryLog
+		for _, article := range mfyxList {
+			head := "<div class=\"title-content\">\n<strong> 【" + article.Title + "】</strong>\n    "
+			body := strings.ReplaceAll(article.Body, "<strong>", "")
+			body = strings.ReplaceAll(body, "</strong>", "")
+			re, _ := regexp.Compile("<strong.*?>")
+			body = re.ReplaceAllString(body, "")
+			sliceSubjects := strings.Split(article.Stock, "/")
+			var company string
+			if sliceSubjects[0] != "" {
+				for _, vSubject := range sliceSubjects {
+					sliceKuohao := strings.Split(vSubject, "(")           //过滤括号
+					sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
+					subject := sliceXiahuaxian[0]
+					company += "#" + subject
+				}
+				company = "    <span style=\"color: #ff1720\">" + company + "</span>"
+			}
+			var plus int
+			coreIndex := strings.Index(body, "核心观点:")
+			plus = 15
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心观点:")
+				plus = 13
+			}
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心观点")
+				plus = 12
+			}
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心结论:")
+				plus = 15
+			}
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心结论:")
+				plus = 13
+			}
+			if coreIndex == -1 {
+				coreIndex = strings.Index(body, "核心结论")
+				plus = 12
+			}
+			endIndex := strings.Index(body, "<hr")
+			if coreIndex != -1 && endIndex != -1 {
+				body = body[coreIndex+plus:endIndex]
+				logItem := data_manage.CygxMinutesSummaryLog{
+					ArticleId:         int(articleId),
+					Type:              "YANX",
+					ChartPermissionId: articleTypeChartPermissionIdMap[article.ArticleTypeId],
+					CreateTime:        time.Now(),
+					Body:              head + company + body,
+					ReportLink:        "https://details.hzinsights.com/cygx/report?id=" + article.ArticleIdMd5,
+					LinkArticleId:     article.LinkArticleId,
+				}
+				logItems = append(logItems, &logItem)
+			}
+		}
+		if len(logItems) > 0 {
+			_, e := data_manage.AddCygxMinutesSummaryLogOrm(logItems)
+			if e != nil {
+				err = e
+				return
+			}
+		}
+
+	}
+
+	return
+}

+ 8 - 0
services/task.go

@@ -116,6 +116,14 @@ func Task() {
 	publishVoiceBroadcast := task.NewTask("publishVoiceBroadcast", "0 */1 * * * *", PublishVoiceBroadcast)
 	task.AddTask("定时发布研报语音播报", publishVoiceBroadcast)
 
+	// 定时生成本周研究汇总
+	cygxResearchSummary := task.NewTask("cygxResearchSummary", "0 0 9 * * 4", CygxResearchSummary)
+	task.AddTask("定时生成本周研究汇总", cygxResearchSummary)
+	// 定时生成上周纪要汇总
+	CygxLastWeekSummary := task.NewTask("CygxLastWeekSummary", "0 0 8 * * 4", CygxLastWeekSummary)
+	task.AddTask("定时生成上周纪要汇总", CygxLastWeekSummary)
+	//CygxResearchSummary()
+	//CygxLastWeekSummary()
 	task.StartTask()
 
 	fmt.Println("task end")

+ 83 - 0
utils/common.go

@@ -539,6 +539,83 @@ func GetNowWeekMonday() time.Time {
 	return mondayTime
 }
 
+// GetLastWeekMonday 获取上周周一的时间
+func GetLastWeekMonday() time.Time {
+	offset := int(time.Monday - time.Now().Weekday())
+	if offset == 1 { //正好是周日,但是按照中国人的理解,周日是一周最后一天,而不是一周开始的第一天
+		offset = -6
+	}
+	mondayTime := time.Now().AddDate(0, 0, offset-7)
+	mondayTime = time.Date(mondayTime.Year(), mondayTime.Month(), mondayTime.Day(), 0, 0, 0, 0, mondayTime.Location())
+	return mondayTime
+}
+
+// GetNowWeekTuesday 获取本周周二的时间
+func GetNowWeekTuesday() time.Time {
+	offset := int(time.Tuesday - time.Now().Weekday())
+	if offset == 1 { //正好是周日,但是按照中国人的理解,周日是一周最后一天,而不是一周开始的第一天
+		offset = -6
+	}
+	mondayTime := time.Now().AddDate(0, 0, offset)
+	mondayTime = time.Date(mondayTime.Year(), mondayTime.Month(), mondayTime.Day(), 0, 0, 0, 0, mondayTime.Location())
+	return mondayTime
+}
+
+// GetLastWeekTuesday 获取上周周二的时间
+func GetLastWeekTuesday() time.Time {
+	offset := int(time.Tuesday - time.Now().Weekday())
+	if offset == 1 { //正好是周日,但是按照中国人的理解,周日是一周最后一天,而不是一周开始的第一天
+		offset = -6
+	}
+	mondayTime := time.Now().AddDate(0, 0, offset-7)
+	mondayTime = time.Date(mondayTime.Year(), mondayTime.Month(), mondayTime.Day(), 0, 0, 0, 0, mondayTime.Location())
+	return mondayTime
+}
+
+// GetNowWeekFriday 获取本周周四的时间
+func GetNowWeekThursday() time.Time {
+	offset := int(time.Thursday - time.Now().Weekday())
+	if offset == 1 { //正好是周日,但是按照中国人的理解,周日是一周最后一天,而不是一周开始的第一天
+		offset = -6
+	}
+	fridayTime := time.Now().AddDate(0, 0, offset)
+	fridayTime = time.Date(fridayTime.Year(), fridayTime.Month(), fridayTime.Day(), 0, 0, 0, 0, fridayTime.Location())
+	return fridayTime
+}
+
+// GetLastWeekFriday 获取上周周四的时间
+func GetLastWeekThursday() time.Time {
+	offset := int(time.Thursday - time.Now().Weekday())
+	if offset == 1 { //正好是周日,但是按照中国人的理解,周日是一周最后一天,而不是一周开始的第一天
+		offset = -6
+	}
+	fridayTime := time.Now().AddDate(0, 0, offset-7)
+	fridayTime = time.Date(fridayTime.Year(), fridayTime.Month(), fridayTime.Day(), 0, 0, 0, 0, fridayTime.Location())
+	return fridayTime
+}
+
+// GetNowWeekFriday 获取本周周五的时间
+func GetNowWeekFriday() time.Time {
+	offset := int(time.Friday - time.Now().Weekday())
+	if offset == 1 { //正好是周日,但是按照中国人的理解,周日是一周最后一天,而不是一周开始的第一天
+		offset = -6
+	}
+	fridayTime := time.Now().AddDate(0, 0, offset)
+	fridayTime = time.Date(fridayTime.Year(), fridayTime.Month(), fridayTime.Day(), 0, 0, 0, 0, fridayTime.Location())
+	return fridayTime
+}
+
+// GetLastWeekFriday 获取上周周五的时间
+func GetLastWeekFriday() time.Time {
+	offset := int(time.Friday - time.Now().Weekday())
+	if offset == 1 { //正好是周日,但是按照中国人的理解,周日是一周最后一天,而不是一周开始的第一天
+		offset = -6
+	}
+	fridayTime := time.Now().AddDate(0, 0, offset-7)
+	fridayTime = time.Date(fridayTime.Year(), fridayTime.Month(), fridayTime.Day(), 0, 0, 0, 0, fridayTime.Location())
+	return fridayTime
+}
+
 // GetNowWeekLastDay 获取本周最后一天的时间
 func GetNowWeekLastDay() time.Time {
 	offset := int(time.Monday - time.Now().Weekday())
@@ -788,3 +865,9 @@ func GetLocalIP() (ip string, err error) {
 	}
 	return
 }
+
+//富文本字段过滤处理
+func GetRichText(content string) (contentSub string) {
+	contentSub = strings.Replace(content, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
+	return
+}