浏览代码

api任务自动同步文章

xingzai 3 年之前
父节点
当前提交
701bccfbc0

+ 446 - 0
controllers/article.go

@@ -8,6 +8,7 @@ import (
 
 
 	"bufio"
 	"bufio"
 	"io"
 	"io"
+	"io/ioutil"
 
 
 	//"bufio"
 	//"bufio"
 	"encoding/json"
 	"encoding/json"
@@ -897,3 +898,448 @@ type PublishPdfResult struct {
 	FileOldPath string `json:"file_old_path"`
 	FileOldPath string `json:"file_old_path"`
 	Pdfpath     string `json:"pdfpath"`
 	Pdfpath     string `json:"pdfpath"`
 }
 }
+
+// @Title 同步策略报告内容
+// @Description 同步策略报告内容接口
+// @Param   ArticleIdMd5   query   int  true       "报告ID"
+// @Success 200 {object} models.ArticleDetailResp
+// @router /look/listApi [get]
+func (this *ArticleCommonController) ListApi() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	url := "https://vmp.hzinsights.com/v2api/articles/mp?take=20&skip=0&publish_status=1"
+	method := "GET"
+	client := &nhttp.Client{}
+	req, err := nhttp.NewRequest(method, url, nil)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
+	res, err := client.Do(req)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	defer res.Body.Close()
+	body, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	var pdfResult models.ArticleResultApi
+	err = json.Unmarshal(body, &pdfResult)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "Unmarshal,Err:" + err.Error()
+		return
+	}
+	exitMap := make(map[int]int)
+	listMap, err := models.GetArticleApiMap()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取映射关系失败,Err:" + err.Error()
+		return
+	}
+	//新旧分类 反向隐射
+	for _, v := range listMap {
+		exitMap[v.Id] = v.OldId
+	}
+	listData := pdfResult.Data
+	var list []*models.Tactics2
+	var listAuthor []*models.CygxArticleAuthor
+	for _, v := range listData {
+		if exitMap[v.SeriesId] > 0 {
+			item := new(models.Tactics2)
+			itemAuthor := new(models.CygxArticleAuthor)
+			item.ArticleId = v.ArticleId
+			item.Title = v.Title
+			item.TitleEn = v.TitleEn
+			if v.Frequency == "日度" {
+				item.UpdateFrequency = "daily"
+			} else if v.Frequency == "周度" {
+				item.UpdateFrequency = "weekly"
+			} else if v.Frequency == "月度" {
+				item.UpdateFrequency = "monthly"
+			} else if v.Frequency == "季度" {
+				item.UpdateFrequency = "quarterly"
+			} else if v.Frequency == "年度" {
+				item.UpdateFrequency = "yearly"
+			} else {
+				item.UpdateFrequency = "unknow"
+			}
+			item.CreateDate = v.CreateDate
+			item.PublishDate = v.PublishDate
+			item.PublishStatus = v.PublishStatus
+			item.Body = v.Content.Body
+			item.Abstract = v.Content.Abstract
+			item.CategoryName = v.Industry.Name
+			item.CategoryId = exitMap[v.SeriesId]
+			item.SubCategoryName = v.Series.Name
+			list = append(list, item)
+			itemAuthor.ArticleId = v.ArticleId
+			itemAuthor.Name = v.Author.Name
+			itemAuthor.Mobile = v.Author.PhoneNumber
+			listAuthor = append(listAuthor, itemAuthor)
+		}
+	}
+
+	//同步作者
+	for _, v := range listAuthor {
+		count, err := models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
+		if err != nil {
+			fmt.Println("GetCount Err:", err.Error())
+			return
+		}
+		if count == 0 {
+			_, err := models.AddCygxActivityAuthor(v)
+			if err != nil {
+				fmt.Println("AddCygxActivityAuthor Err:", err.Error())
+				return
+			}
+		}
+	}
+	fmt.Println("同步文章条数:", len(list))
+	listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
+	if err != nil {
+		fmt.Println("GetTacticsList Err:", err.Error())
+		return
+	}
+	listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
+	if errMatch != nil {
+		fmt.Println("GetTacticsList Err:", errMatch.Error())
+		return
+	}
+
+	fmt.Println("list len:", len(list))
+	summaryCategoryIds := "28,32,45,50,57,62,72,74,79,84,86,88,90,93,95,96" //纪要库的文章类型categoty_id
+	listSummary := strings.Split(summaryCategoryIds, ",")
+	noSummaryArticleIds := "3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470" //非纪要库类型的文章ID
+	listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
+	listPermission, errper := models.GetPermissionMappingCategoryID()
+	if errper != nil {
+		fmt.Println("GetTacticsList Err:", errper.Error())
+		return
+	}
+	summaryMap := make(map[int]int)
+	for _, vSum := range listSummary {
+		vSumInt, _ := strconv.Atoi(vSum)
+		summaryMap[vSumInt] = 1
+	}
+	for k, v := range list {
+		//同步匹配类型
+		matchTypeName := ""
+		for _, vMatch := range listGetMatchTypeName {
+			if v.CategoryId == vMatch.CategoryId {
+				matchTypeName = vMatch.MatchTypeName
+			}
+		}
+		//是否属于纪要库的数据
+		if _, has := summaryMap[v.CategoryId]; has {
+			v.IsSummary = 1
+		}
+		//排除不属于纪要库类型的文章
+		for _, vArt := range listNoSummaryArticleIds {
+			vArtInt, _ := strconv.Atoi(vArt)
+			if v.ArticleId == vArtInt {
+				v.IsSummary = 0
+			}
+		}
+		for _, vPer := range listPermission {
+			if v.CategoryId == vPer.CategoryId {
+				v.IsReport = 1
+			}
+		}
+		if v.IsReport > 0 {
+			//是否属于策略 策略自动归类
+			//是否属于行业报告 行业报告自动归类
+			if v.CategoryId == 7 || v.CategoryId == 9 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 52 || v.CategoryId == 64 || v.CategoryId == 80 || v.CategoryId == 87 {
+				v.IsClass = 1
+				v.ReportType = 1 //是否属于行业报告
+			} else {
+				v.ReportType = 2 //是否属于产业报告
+			}
+		}
+		v.Department = "弘则权益研究"
+		fmt.Println(k, v.ArticleId)
+		hh, _ := time.ParseDuration("8h")
+		//pDate := publishDate.Add(hh)
+		v.PublishDate = v.PublishDate.Add(hh)
+		//判断是否已经存在
+		if v.ArticleId < 0 {
+			fmt.Println("AddCygxArticle Err:")
+			return
+		}
+		count, err := models.GetArticleCountById(v.ArticleId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			fmt.Println("AddCygxArticle Err:", err.Error())
+			return
+		}
+		v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
+		expertNumStr, expertContentStr, interviewDateStr, fileLink, bodyReturn := services.BodyAnalysis2(v.Body)
+		if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
+			v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
+			v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
+			v.Body = strings.Replace(v.Body, "):", "", -1)
+		}
+		var titleNew string
+		titleNew = v.Title
+		// 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
+		if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
+			if v.UpdateFrequency == "daily" {
+				var daystr string
+				daystr = strconv.Itoa(v.PublishDate.Day())
+				if len(daystr) == 1 {
+					daystr = "0" + daystr
+				}
+				titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
+			} else if v.UpdateFrequency == "weekly" {
+				titleNew = v.Title + utils.WeekByDate(v.PublishDate)
+			}
+		}
+		if v.CategoryId == 80 {
+			titleNew = v.Title + utils.WeekByDate(v.PublishDate)
+		}
+		if count > 0 {
+			fmt.Println(k, v.ArticleId, "edit")
+			var isCustom bool
+			bodyText, _ := services.GetReportContentTextSub(v.Body)
+			updateParams := make(map[string]interface{})
+			//updateParams["Title"] = v.Title
+			updateParams["Title"] = titleNew
+			updateParams["TitleEn"] = v.TitleEn
+			updateParams["UpdateFrequency"] = v.UpdateFrequency
+			updateParams["CreateDate"] = v.CreateDate
+			updateParams["PublishDate"] = v.PublishDate
+			//updateParams["Body"] = html.EscapeString(v.Body)
+			updateParams["Body"] = html.EscapeString(bodyReturn)
+			updateParams["BodyText"] = bodyText
+			updateParams["Abstract"] = html.EscapeString(v.Abstract)
+			updateParams["CategoryName"] = v.CategoryName
+
+			for _, vCustom := range listCustomArticle {
+				if v.ArticleId == vCustom.ArticleId {
+					fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
+					isCustom = true
+				}
+			}
+			if isCustom == false {
+				updateParams["CategoryId"] = v.CategoryId
+				updateParams["MatchTypeName"] = matchTypeName
+				updateParams["IsSummary"] = v.IsSummary
+				updateParams["IsReport"] = v.IsReport
+				updateParams["ReportType"] = v.ReportType
+				updateParams["SubCategoryName"] = v.SubCategoryName
+			}
+			//updateParams["CategoryId"] = v.CategoryId
+			updateParams["PublishStatus"] = v.PublishStatus
+			updateParams["ExpertBackground"] = expertContentStr
+			updateParams["ExpertNumber"] = expertNumStr
+			updateParams["InterviewDate"] = interviewDateStr
+			//updateParams["IsClass"] = v.IsClass
+
+			if v.Department != "弘则权益研究" {
+				v.Department = "弘则权益研究"
+			}
+			updateParams["Department"] = v.Department
+			updateParams["FileLink"] = fileLink
+			whereParam := map[string]interface{}{"article_id": v.ArticleId}
+			err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
+			if err != nil {
+				fmt.Println("UpdateByExpr Err:" + err.Error())
+			}
+		} else {
+			fmt.Println(k, v.ArticleId, "add")
+			item := new(models.CygxArticle)
+			articleIdInt := v.ArticleId
+			item.ArticleId = articleIdInt
+			//item.Title = v.Title
+			item.Title = titleNew
+			item.TitleEn = v.TitleEn
+			item.UpdateFrequency = v.UpdateFrequency
+			item.CreateDate = v.CreateDate
+			item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
+			//item.Body = html.EscapeString(v.Body)
+			item.Body = html.EscapeString(bodyReturn)
+			item.Abstract = html.EscapeString(v.Abstract)
+			item.CategoryName = v.CategoryName
+			item.SubCategoryName = v.SubCategoryName
+			item.CategoryId = v.CategoryId
+			item.PublishStatus = v.PublishStatus
+			item.ExpertBackground = expertContentStr
+			item.ExpertNumber = expertNumStr
+			item.InterviewDate = interviewDateStr
+			item.Department = v.Department
+			item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
+			item.IsClass = v.IsClass
+			item.IsSummary = v.IsSummary
+			item.IsReport = v.IsReport
+			item.ReportType = v.ReportType
+			item.FileLink = fileLink
+			item.MatchTypeName = matchTypeName
+			_, err = models.AddCygxArticles(item)
+			if err != nil {
+				fmt.Println("AddCygxArticle Err:", err.Error())
+				return
+			}
+		}
+
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = string(body)
+}
+
+// @Title 同步参会记录
+// @Description 获取报告详情接口
+// @Param   ArticleIdMd5   query   int  true       "报告ID"
+// @Success 200 {object} models.ArticleDetailResp
+// @router /look/detaisl [get]
+func (this *ArticleCommonController) Detaisl() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	var condition string
+	fmt.Println(condition)
+
+	//list, err := models.GetOfflineMeetingDetailList()
+	//if err != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取失败,Err:" + err.Error()
+	//	return
+	//}
+	//
+	//for _, v := range list {
+	//	item := new(models.CygxActivityMeetDetailLog)
+	//	item.ActivityId = v.ActivityId
+	//	item.RealName = v.RealName
+	//	item.Mobile = v.Mobile
+	//	item.CompanyName = v.CompanyName
+	//	item.CompanyId = v.CompanyId
+	//	item.CreateTime = v.CreateTime
+	//	newId, err := models.AddCygxActivityMeetDetailLog(item)
+	//	if err != nil {
+	//		br.Msg = "同步失败"
+	//		br.ErrMsg = "新增优化建议失败,Err:" + err.Error()
+	//		return
+	//	}
+	//	fmt.Println(newId)
+	//}
+
+	//list, err := models.GetActivityMeetDetailLog()
+	//if err != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取失败,Err:" + err.Error()
+	//	return
+	//}
+	//for _, v := range list {
+	//	condition = ` AND company_name = '` + v.CompanyName + `' `
+	//	total, err := models.GetActivityMeetDetailLogCount(condition)
+	//	if err != nil {
+	//		br.Msg = "获取失败"
+	//		br.ErrMsg = "获取失败,Err:" + err.Error()
+	//		return
+	//	}
+	//	fmt.Println(v.CompanyName, total)
+	//	err = models.UpdateActivityMeetDetailLog(v.CompanyName, total)
+	//	if err != nil {
+	//		br.Msg = "获取失败"
+	//		br.ErrMsg = "获取失败,Err:" + err.Error()
+	//		return
+	//	}
+	//}
+
+	//list, err := models.GetActivityMeetDetailLogByMobile()
+	//if err != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取失败,Err:" + err.Error()
+	//	return
+	//}
+	//for _, v := range list {
+	//	condition = ` AND mobile = '` + v.Mobile + `' `
+	//	total, err := models.GetActivityMeetDetailLogCount(condition)
+	//	if err != nil {
+	//		br.Msg = "获取失败"
+	//		br.ErrMsg = "获取失败,Err:" + err.Error()
+	//		return
+	//	}
+	//	fmt.Println(v.Mobile, total)
+	//	err = models.UpdateActivityMeetDetailLogByUser(v.Mobile, total)
+	//	if err != nil {
+	//		br.Msg = "获取失败"
+	//		br.ErrMsg = "获取失败,Err:" + err.Error()
+	//		return
+	//	}
+	//}
+
+	resp := new(models.ArticleDetailResp)
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 同步策略报告分类
+// @Description 同步策略报告内容接口
+// @Param   ArticleIdMd5   query   int  true       "报告ID"
+// @Success 200 {object} models.ArticleDetailResp
+// @router /look/industry [get]
+func (this *ArticleCommonController) Industry() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	url := "https://vmp.hzinsights.com/v2api/articles/industry"
+	method := "GET"
+	client := &nhttp.Client{}
+	req, err := nhttp.NewRequest(method, url, nil)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
+	res, err := client.Do(req)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	defer res.Body.Close()
+	body, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	var pdfResult models.ArticleIndustryApi
+	err = json.Unmarshal(body, &pdfResult)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "Unmarshal,Err:" + err.Error()
+		return
+	}
+	listData := pdfResult.Data
+	//var list []*models.Tactics2
+	for _, v := range listData {
+		item := new(models.Tactics2)
+		for _, v2 := range v.Series {
+			fmt.Println(v2.Name)
+			item.Body = v2.Name
+			//fmt.Println(v.Name, "+", v2.Name, "+", v2.Id)
+			//fmt.Println(v.Name, "+", v2.Name, "+", v2.Id)
+			//fmt.Println(v.Name, "+", v2.Name, "+", v2.Id)
+		}
+		//list = append(list, item)
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = string(body)
+}

+ 1 - 1
controllers/report.go

@@ -1422,7 +1422,7 @@ func (this *ReportController) ResearchDetail() {
 		//`description:"类型'SDBG深度报告片篇,’CYDYJY:产业调研纪要’,’SJDP事件点评,’BZCHJH:本周晨会精华’"`
 		//`description:"类型'SDBG深度报告片篇,’CYDYJY:产业调研纪要’,’SJDP事件点评,’BZCHJH:本周晨会精华’"`
 		if v.Type == "SDBG" {
 		if v.Type == "SDBG" {
 			listFirst[k].ListName = "深度报告"
 			listFirst[k].ListName = "深度报告"
-			listFirst[k].IcoLink = ""
+			listFirst[k].IcoLink = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202110/20211027/le8AcRjDz0MhA72bVDiaf3d5ALSe.png"
 		} else if v.Type == "BZCHJH" {
 		} else if v.Type == "BZCHJH" {
 			listFirst[k].ListName = "本周晨会精华"
 			listFirst[k].ListName = "本周晨会精华"
 			listFirst[k].IcoLink = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202110/20211020/DCfekcxaIKGePBsNVu1ULfmNcJBY.png"
 			listFirst[k].IcoLink = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202110/20211020/DCfekcxaIKGePBsNVu1ULfmNcJBY.png"

+ 72 - 0
models/activity_meet_detail_log.go

@@ -0,0 +1,72 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+//报名
+type CygxActivityMeetDetailLog struct {
+	AttendanceId int       `orm:"column(attendance_id);pk;"description:"主键ID"`
+	ActivityId   int       `description:"活动ID"`
+	RealName     string    `description:"姓名"`
+	Mobile       string    `description:"手机号"`
+	CompanyName  string    `description:"公司名称"`
+	CompanyId    int       `description:"公司id 不在数据库的用户为0"`
+	CreateTime   time.Time `description:"创建时间"`
+}
+
+func GetOfflineMeetingDetailList() (item []*CygxActivityMeetDetailLog, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_activity_offline_meeting_detail WHERE is_meeting = 1`
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}
+
+//添加优化建议
+func AddCygxActivityMeetDetailLog(item *CygxActivityMeetDetailLog) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+func GetActivityMeetDetailLog() (item []*CygxActivityMeetDetailLog, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM  cygx_activity_meet_detail_log WHERE company_name !='' GROUP BY company_name `
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}
+
+func GetActivityMeetDetailLogByMobile() (item []*CygxActivityMeetDetailLog, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM  cygx_activity_meet_detail_log WHERE mobile !='' GROUP BY mobile `
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}
+
+//获取数量
+func GetActivityMeetDetailLogCount(condition string) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_activity_meet_detail_log WHERE 1=1 `
+	if condition != "" {
+		sqlCount += condition
+	}
+	err = o.Raw(sqlCount).QueryRow(&count)
+	return
+}
+
+//修改公司参会数量
+func UpdateActivityMeetDetailLog(companyName string, num int) (err error) {
+	sql := ` UPDATE cygx_activity_meet_detail_log SET  company_meet_num= ?  WHERE company_name = ?`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, num, companyName).Exec()
+	return
+}
+
+//修改个人参会数量
+func UpdateActivityMeetDetailLogByUser(mobile string, num int) (err error) {
+	sql := ` UPDATE cygx_activity_meet_detail_log SET  user_meet_num= ?  WHERE mobile = ?`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, num, mobile).Exec()
+	return
+}

+ 88 - 5
models/article.go

@@ -2,6 +2,7 @@ package models
 
 
 import (
 import (
 	"rdluck_tools/orm"
 	"rdluck_tools/orm"
+	"time"
 )
 )
 
 
 type CygxArticle struct {
 type CygxArticle struct {
@@ -151,13 +152,20 @@ func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
 
 
 func GetSellerList(articleId int) (items []*SellerRep, err error) {
 func GetSellerList(articleId int) (items []*SellerRep, err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
-	o.Using("tactics")
+	//o.Using("tactics")
+	//sql := `SELECT
+	//	ac.phone_number as  seller_mobile,
+	//	ac.name as  seller_name
+	//	FROM
+	//	article_author AS au
+	//	INNER JOIN account_client as ac ON au.author_id = ac.phone_number
+	//	WHERE article_id = ?`
+
 	sql := `SELECT
 	sql := `SELECT
-		ac.phone_number as  seller_mobile,
-		ac.name as  seller_name
+		au.mobile as  seller_mobile,
+		au.name as  seller_name
 		FROM
 		FROM
-		article_author AS au 
-		INNER JOIN account_client as ac ON au.author_id = ac.phone_number
+		cygx_article_author AS au
 		WHERE article_id = ?`
 		WHERE article_id = ?`
 	_, err = o.Raw(sql, articleId).QueryRows(&items)
 	_, err = o.Raw(sql, articleId).QueryRows(&items)
 	return
 	return
@@ -472,3 +480,78 @@ func GetMaxArticleIdInfo() (item *ArticleDetail, err error) {
 	err = o.Raw(sql).QueryRow(&item)
 	err = o.Raw(sql).QueryRow(&item)
 	return
 	return
 }
 }
+
+type ArticleResultApi struct {
+	Data []ArticleResultApidate `json:"data"`
+	Code int                    `json:"code"`
+	Msg  string                 `json:"msg"`
+}
+
+type ArticleResultApidate struct {
+	ArticleId     int                      `json:"id"`
+	Title         string                   `json:"title"`
+	TitleEn       string                   `json:"title_en"`
+	Frequency     string                   `json:"frequency"`
+	CreateDate    string                   `json:"create_date"`
+	UpdateDate    string                   `json:"update_date"`
+	PublishDate   time.Time                `json:"publish_date"`
+	PublishStatus int                      `json:"publish_status"`
+	IndustrId     int                      `json:"industry_id"`
+	SeriesId      int                      `json:"series_id"`
+	Series        ArticleSeries            `json:"series"`
+	Content       ArticleResultApiContent  `json:"content"`
+	Author        ArticleResultApiAuthor   `json:"author"`
+	Industry      ArticleResultApiIndustry `json:"industry"`
+	Type          ArticleResultApiType     `json:"type"`
+}
+
+type ArticleSeries struct {
+	Name string `json:"name"`
+}
+type ArticleResultApiContent struct {
+	ArticleId int    `json:"id"`
+	Body      string `json:"body"`
+	Abstract  string `json:"abstract"`
+}
+
+type ArticleResultApiAuthor struct {
+	PhoneNumber string `json:"phone_number"`
+	Name        string `json:"name"`
+}
+
+type ArticleResultApiIndustry struct {
+	Name string `json:"name"`
+}
+
+type ArticleResultApiType struct {
+	Name string `json:"name"`
+}
+
+type ArticleIndustryApi struct {
+	Data []ArticleResultApiIndustrdate `json:"data"`
+	Code int                           `json:"code"`
+	Msg  string                        `json:"msg"`
+}
+
+type ArticleResultApiIndustrdate struct {
+	Id     int                          `json:"id"`
+	Name   string                       `json:"name"`
+	Series []ArticleResultApiSeriesdate `json:"series"`
+}
+
+type ArticleResultApiSeriesdate struct {
+	Id   int    `json:"id"`
+	Name string `json:"name"`
+}
+
+type ArticleApiMap struct {
+	Id    int `description:"新ID"`
+	OldId int `description:"旧Id"`
+}
+
+func GetArticleApiMap() (item []*ArticleApiMap, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT *  FROM	cygx_article_api_map WHERE	old_id > 0 ORDER BY old_id ASC  `
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}

+ 27 - 0
models/article_author.go

@@ -0,0 +1,27 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+)
+
+type CygxArticleAuthor struct {
+	Id        int    `orm:"column(id);pk;"description:"主键ID"`
+	ArticleId int    `description:"文章ID"`
+	Mobile    string `description:"手机号"`
+	Name      string `description:"姓名"`
+}
+
+//获取数量
+func GetActivityAuthorCount(articcleId int, mobile string) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_article_author WHERE article_id=? AND mobile = ? `
+	err = o.Raw(sqlCount, articcleId, mobile).QueryRow(&count)
+	return
+}
+
+//添加优化建议
+func AddCygxActivityAuthor(item *CygxArticleAuthor) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 2 - 0
models/db.go

@@ -62,5 +62,7 @@ func init() {
 		new(CygxArticleAsk),
 		new(CygxArticleAsk),
 		new(CygxPageHistoryRecord),
 		new(CygxPageHistoryRecord),
 		new(CygxReportHistoryRecord),
 		new(CygxReportHistoryRecord),
+		new(CygxActivityMeetDetailLog),
+		new(CygxArticleAuthor),
 	)
 	)
 }
 }

+ 1 - 1
models/minutesSummary.go

@@ -24,7 +24,7 @@ type MinutesSummaryLetailResp struct {
 type MinutesSummaryChartPermission struct {
 type MinutesSummaryChartPermission struct {
 	PermissionName    string `description:"行业名称"`
 	PermissionName    string `description:"行业名称"`
 	ChartPermissionId int    `description:"行业ID"`
 	ChartPermissionId int    `description:"行业ID"`
-	MinutesSummary    string `orm:"column(image_url)"description:"图标链接"`
+	IcoLink           string `orm:"column(image_url)"description:"图标链接"`
 	List              []*CygxMinutesSummaryLogDetail
 	List              []*CygxMinutesSummaryLogDetail
 }
 }
 
 

+ 288 - 0
services/article.go

@@ -1,11 +1,18 @@
 package services
 package services
 
 
 import (
 import (
+	"context"
+	"encoding/json"
 	"fmt"
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
 	"github.com/PuerkitoBio/goquery"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
 	"html"
 	"html"
+	"io/ioutil"
+	nhttp "net/http"
+	"strconv"
 	"strings"
 	"strings"
+	"time"
 )
 )
 
 
 func GetReportContentSub(content string) (contentSub string, err error) {
 func GetReportContentSub(content string) (contentSub string, err error) {
@@ -265,3 +272,284 @@ func FixArticleContent(articleId int) {
 		return
 		return
 	}
 	}
 }
 }
+
+func GetArticleListByApi(cont context.Context) (err error) {
+	url := "https://vmp.hzinsights.com/v2api/articles/mp?take=20&skip=0&publish_status=1"
+	method := "GET"
+	client := &nhttp.Client{}
+	req, err := nhttp.NewRequest(method, url, nil)
+	if err != nil {
+		fmt.Println("GetListApi Err:", err.Error())
+		return
+	}
+	req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
+	res, err := client.Do(req)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	defer res.Body.Close()
+	body, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		fmt.Println("Getres.Body Err:", err.Error())
+		return
+	}
+	var pdfResult models.ArticleResultApi
+	err = json.Unmarshal(body, &pdfResult)
+	if err != nil {
+		fmt.Println("Getres.pdfResult Err:", err.Error())
+		return
+	}
+	exitMap := make(map[int]int)
+	listMap, err := models.GetArticleApiMap()
+	if err != nil {
+		fmt.Println("GetlistMap Err:", err.Error())
+		return
+	}
+	//新旧分类 反向隐射
+	for _, v := range listMap {
+		exitMap[v.Id] = v.OldId
+	}
+	listData := pdfResult.Data
+	var list []*models.Tactics2
+	var listAuthor []*models.CygxArticleAuthor
+	for _, v := range listData {
+		if exitMap[v.SeriesId] > 0 {
+			item := new(models.Tactics2)
+			itemAuthor := new(models.CygxArticleAuthor)
+			item.ArticleId = v.ArticleId
+			item.Title = v.Title
+			item.TitleEn = v.TitleEn
+			if v.Frequency == "日度" {
+				item.UpdateFrequency = "daily"
+			} else if v.Frequency == "周度" {
+				item.UpdateFrequency = "weekly"
+			} else if v.Frequency == "月度" {
+				item.UpdateFrequency = "monthly"
+			} else if v.Frequency == "季度" {
+				item.UpdateFrequency = "quarterly"
+			} else if v.Frequency == "年度" {
+				item.UpdateFrequency = "yearly"
+			} else {
+				item.UpdateFrequency = "unknow"
+			}
+			item.CreateDate = v.CreateDate
+			item.PublishDate = v.PublishDate
+			item.PublishStatus = v.PublishStatus
+			item.Body = v.Content.Body
+			item.Abstract = v.Content.Abstract
+			item.CategoryName = v.Industry.Name
+			item.CategoryId = exitMap[v.SeriesId]
+			item.SubCategoryName = v.Series.Name
+			list = append(list, item)
+			itemAuthor.ArticleId = v.ArticleId
+			itemAuthor.Name = v.Author.Name
+			itemAuthor.Mobile = v.Author.PhoneNumber
+			listAuthor = append(listAuthor, itemAuthor)
+		}
+	}
+
+	//同步作者
+	for _, v := range listAuthor {
+		var count int
+		count, err = models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
+		if err != nil {
+			fmt.Println("GetCount Err:", err.Error())
+			return
+		}
+		if count == 0 {
+			_, err = models.AddCygxActivityAuthor(v)
+			if err != nil {
+				fmt.Println("AddCygxActivityAuthor Err:", err.Error())
+				return
+			}
+		}
+	}
+	fmt.Println("同步文章条数:", len(list))
+	listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
+	if err != nil {
+		fmt.Println("GetTacticsList Err:", err.Error())
+		return
+	}
+	listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
+	if errMatch != nil {
+		fmt.Println("GetTacticsList Err:", errMatch.Error())
+		return
+	}
+
+	fmt.Println("list len:", len(list))
+	summaryCategoryIds := "28,32,45,50,57,62,72,74,79,84,86,88,90,93,95,96" //纪要库的文章类型categoty_id
+	listSummary := strings.Split(summaryCategoryIds, ",")
+	noSummaryArticleIds := "3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470" //非纪要库类型的文章ID
+	listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
+	listPermission, errper := models.GetPermissionMappingCategoryID()
+	if errper != nil {
+		fmt.Println("GetTacticsList Err:", errper.Error())
+		return
+	}
+	summaryMap := make(map[int]int)
+	for _, vSum := range listSummary {
+		vSumInt, _ := strconv.Atoi(vSum)
+		summaryMap[vSumInt] = 1
+	}
+	for k, v := range list {
+		//同步匹配类型
+		matchTypeName := ""
+		for _, vMatch := range listGetMatchTypeName {
+			if v.CategoryId == vMatch.CategoryId {
+				matchTypeName = vMatch.MatchTypeName
+			}
+		}
+		//是否属于纪要库的数据
+		if _, has := summaryMap[v.CategoryId]; has {
+			v.IsSummary = 1
+		}
+		//排除不属于纪要库类型的文章
+		for _, vArt := range listNoSummaryArticleIds {
+			vArtInt, _ := strconv.Atoi(vArt)
+			if v.ArticleId == vArtInt {
+				v.IsSummary = 0
+			}
+		}
+		for _, vPer := range listPermission {
+			if v.CategoryId == vPer.CategoryId {
+				v.IsReport = 1
+			}
+		}
+		if v.IsReport > 0 {
+			//是否属于策略 策略自动归类
+			//是否属于行业报告 行业报告自动归类
+			if v.CategoryId == 7 || v.CategoryId == 9 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 52 || v.CategoryId == 64 || v.CategoryId == 80 || v.CategoryId == 87 {
+				v.IsClass = 1
+				v.ReportType = 1 //是否属于行业报告
+			} else {
+				v.ReportType = 2 //是否属于产业报告
+			}
+		}
+		v.Department = "弘则权益研究"
+		fmt.Println(k, v.ArticleId)
+		hh, _ := time.ParseDuration("8h")
+		//pDate := publishDate.Add(hh)
+		v.PublishDate = v.PublishDate.Add(hh)
+		//判断是否已经存在
+		if v.ArticleId < 0 {
+			fmt.Println("AddCygxArticle Err:")
+			return
+		}
+		var count int
+		count, err = models.GetArticleCountById(v.ArticleId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			fmt.Println("AddCygxArticle Err:", err.Error())
+			return
+		}
+		v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
+		expertNumStr, expertContentStr, interviewDateStr, fileLink, bodyReturn := BodyAnalysis2(v.Body)
+		if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
+			v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
+			v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
+			v.Body = strings.Replace(v.Body, "):", "", -1)
+		}
+		var titleNew string
+		titleNew = v.Title
+		// 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
+		if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
+			if v.UpdateFrequency == "daily" {
+				var daystr string
+				daystr = strconv.Itoa(v.PublishDate.Day())
+				if len(daystr) == 1 {
+					daystr = "0" + daystr
+				}
+				titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
+			} else if v.UpdateFrequency == "weekly" {
+				titleNew = v.Title + utils.WeekByDate(v.PublishDate)
+			}
+		}
+		if v.CategoryId == 80 {
+			titleNew = v.Title + utils.WeekByDate(v.PublishDate)
+		}
+		if count > 0 {
+			fmt.Println(k, v.ArticleId, "edit")
+			var isCustom bool
+			bodyText, _ := GetReportContentTextSub(v.Body)
+			updateParams := make(map[string]interface{})
+			//updateParams["Title"] = v.Title
+			updateParams["Title"] = titleNew
+			updateParams["TitleEn"] = v.TitleEn
+			updateParams["UpdateFrequency"] = v.UpdateFrequency
+			updateParams["CreateDate"] = v.CreateDate
+			updateParams["PublishDate"] = v.PublishDate
+			//updateParams["Body"] = html.EscapeString(v.Body)
+			updateParams["Body"] = html.EscapeString(bodyReturn)
+			updateParams["BodyText"] = bodyText
+			updateParams["Abstract"] = html.EscapeString(v.Abstract)
+			updateParams["CategoryName"] = v.CategoryName
+
+			for _, vCustom := range listCustomArticle {
+				if v.ArticleId == vCustom.ArticleId {
+					fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
+					isCustom = true
+				}
+			}
+			if isCustom == false {
+				updateParams["CategoryId"] = v.CategoryId
+				updateParams["MatchTypeName"] = matchTypeName
+				updateParams["IsSummary"] = v.IsSummary
+				updateParams["IsReport"] = v.IsReport
+				updateParams["ReportType"] = v.ReportType
+				updateParams["SubCategoryName"] = v.SubCategoryName
+			}
+			//updateParams["CategoryId"] = v.CategoryId
+			updateParams["PublishStatus"] = v.PublishStatus
+			updateParams["ExpertBackground"] = expertContentStr
+			updateParams["ExpertNumber"] = expertNumStr
+			updateParams["InterviewDate"] = interviewDateStr
+			//updateParams["IsClass"] = v.IsClass
+
+			if v.Department != "弘则权益研究" {
+				v.Department = "弘则权益研究"
+			}
+			updateParams["Department"] = v.Department
+			updateParams["FileLink"] = fileLink
+			whereParam := map[string]interface{}{"article_id": v.ArticleId}
+			err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
+			if err != nil {
+				fmt.Println("UpdateByExpr Err:" + err.Error())
+			}
+		} else {
+			fmt.Println(k, v.ArticleId, "add")
+			item := new(models.CygxArticle)
+			articleIdInt := v.ArticleId
+			item.ArticleId = articleIdInt
+			//item.Title = v.Title
+			item.Title = titleNew
+			item.TitleEn = v.TitleEn
+			item.UpdateFrequency = v.UpdateFrequency
+			item.CreateDate = v.CreateDate
+			item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
+			//item.Body = html.EscapeString(v.Body)
+			item.Body = html.EscapeString(bodyReturn)
+			item.Abstract = html.EscapeString(v.Abstract)
+			item.CategoryName = v.CategoryName
+			item.SubCategoryName = v.SubCategoryName
+			item.CategoryId = v.CategoryId
+			item.PublishStatus = v.PublishStatus
+			item.ExpertBackground = expertContentStr
+			item.ExpertNumber = expertNumStr
+			item.InterviewDate = interviewDateStr
+			item.Department = v.Department
+			item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
+			item.IsClass = v.IsClass
+			item.IsSummary = v.IsSummary
+			item.IsReport = v.IsReport
+			item.ReportType = v.ReportType
+			item.FileLink = fileLink
+			item.MatchTypeName = matchTypeName
+			_, err = models.AddCygxArticles(item)
+			if err != nil {
+				fmt.Println("AddCygxArticle Err:", err.Error())
+				return
+			}
+		}
+	}
+	return
+}

+ 2 - 0
services/tactics.go

@@ -662,6 +662,8 @@ func BodyAnalysis2(body string) (expertNumStr, expertContentStr, interviewDateSt
 		if expertNumStr != "" {
 		if expertNumStr != "" {
 			expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
 			expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
 			expertNumStr = strings.Replace(expertNumStr, "# ", "", -1)
 			expertNumStr = strings.Replace(expertNumStr, "# ", "", -1)
+			expertNumStr = strings.Replace(expertNumStr, " ", "", -1)
+			expertNumStr = strings.Replace(expertNumStr, "\n", "", -1)
 			expertNumStr = strings.Trim(expertNumStr, "")
 			expertNumStr = strings.Trim(expertNumStr, "")
 		}
 		}
 	}
 	}

+ 4 - 1
services/task.go

@@ -57,6 +57,9 @@ func Task() {
 	chageIndustrialArticleNum := task.NewTask("chageIndustrialArticleNum", "0 01 00 * * *", ChageIndustrialArticleNum) //更改对应产业的文章阅读数量
 	chageIndustrialArticleNum := task.NewTask("chageIndustrialArticleNum", "0 01 00 * * *", ChageIndustrialArticleNum) //更改对应产业的文章阅读数量
 	task.AddTask("chageIndustrialArticleNum", chageIndustrialArticleNum)
 	task.AddTask("chageIndustrialArticleNum", chageIndustrialArticleNum)
 
 
+	getArticleListByApi := task.NewTask("getArticleListByApi", "0 */5 * * * *", GetArticleListByApi) //更改对应产业的文章阅读数量
+	task.AddTask("getArticleListByApi", getArticleListByApi)
+
 	//editOutboundMobile := task.NewTask("editOutboundMobile", "0 */1 8-22 * * *", EditOutboundMobile) //同步外呼号码与手机号
 	//editOutboundMobile := task.NewTask("editOutboundMobile", "0 */1 8-22 * * *", EditOutboundMobile) //同步外呼号码与手机号
 	//task.AddTask("sendEmailFileToExpert", editOutboundMobile)
 	//task.AddTask("sendEmailFileToExpert", editOutboundMobile)
 	//editUserOutboundMobile := task.NewTask("editUserOutboundMobile", "0 27 14 * * *   ", EditUserOutboundMobile) //同步外呼号码与手机号
 	//editUserOutboundMobile := task.NewTask("editUserOutboundMobile", "0 27 14 * * *   ", EditUserOutboundMobile) //同步外呼号码与手机号
@@ -378,7 +381,7 @@ func GetAddpArticle() {
 		item.SellerAndMobile = v.Author
 		item.SellerAndMobile = v.Author
 		item.PublishDate = v.PublishTime
 		item.PublishDate = v.PublishTime
 		item.Abstract = v.Abstract
 		item.Abstract = v.Abstract
-		item.Body = v.Content
+		item.Body = html.UnescapeString(v.Content)
 		item.BodyText, _ = GetReportContentTextSub(v.Content)
 		item.BodyText, _ = GetReportContentTextSub(v.Content)
 		item.IsReport = 1
 		item.IsReport = 1
 		item.Source = 1
 		item.Source = 1