|
@@ -4,6 +4,7 @@ import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"eta/eta_task/models"
|
|
|
+ "eta/eta_task/models/data_manage"
|
|
|
"eta/eta_task/utils"
|
|
|
"fmt"
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
@@ -18,9 +19,31 @@ import (
|
|
|
// 使用deepseek api 处理报告
|
|
|
func AutoCreateReportAssess(cont context.Context) (err error) {
|
|
|
//获取品种
|
|
|
- startTime := time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) + " 00:00:00"
|
|
|
- endTime := time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) + " 23:59:59"
|
|
|
- createDate := time.Now().AddDate(0, 0, -1).Format("2006.01.02")
|
|
|
+ startTime := "2025-03-03 00:00:00" //time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) + " 00:00:00"
|
|
|
+ weekStartTime, err := time.Parse(utils.FormatDateTime, startTime)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("weekStartTime time.Parse Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ weekEndTime := weekStartTime.AddDate(0, 0, 6)
|
|
|
+ for {
|
|
|
+ startTime = weekStartTime.Format(utils.FormatDateTime)
|
|
|
+ endTime := weekEndTime.Format(utils.FormatDateTime)
|
|
|
+ startDate := weekStartTime.Format(utils.FormatDate)
|
|
|
+ endDate := weekEndTime.Format(utils.FormatDate)
|
|
|
+ AutoCreateReportAssessByWeek(startTime, endTime, startDate, endDate)
|
|
|
+ fmt.Println(startTime, endTime)
|
|
|
+ if weekEndTime.After(time.Now()) {
|
|
|
+ fmt.Println("before:", weekEndTime, time.Now())
|
|
|
+ break
|
|
|
+ }
|
|
|
+ weekStartTime = weekEndTime.AddDate(0, 0, 1)
|
|
|
+ weekEndTime = weekStartTime.AddDate(0, 0, 6)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func AutoCreateReportAssessByWeek(startTime, endTime, startDate, endDate string) (err error) {
|
|
|
|
|
|
tagList, err := models.GetWechatArticleTags(startTime, endTime)
|
|
|
if err != nil {
|
|
@@ -47,10 +70,9 @@ func AutoCreateReportAssess(cont context.Context) (err error) {
|
|
|
msgList := make([]*DkCompletionsMessagesReq, 0)
|
|
|
msg := new(DkCompletionsMessagesReq)
|
|
|
//msg.Content = "请阅读如下文章。首先根据文章内容,对#品种名称 进行打分,打分规则为10分最看多,0分最看空。其次,对#品种名称 提炼主要逻辑和观点,得出总结,品种和品种之间用横线拆分,输出格式限定为:1. 使用语义化的HTML5标签,2. 采用现代响应式设计(无固定宽度),3. 包含丰富的文本格式元素,4. 通过内联样式确保自适应渲染"
|
|
|
- msg.Content = "请阅读如下文章。首先根据文章内容,对#品种名称 进行打分,打分规则为10分最看多,0分最看空。其次,对#品种名称 提炼主要逻辑和观点,得出总结,品种和品种之间用横线拆分,输出格式限定为:1. 使用语义化的HTML5标签代码段,不包含html,body,head,2. 采用现代响应式设计(无固定宽度),3. 包含丰富的文本格式元素,4. 通过内联样式确保自适应渲染"
|
|
|
+ msg.Content = "请阅读如下文章。首先根据文章内容,对#品种名称 进行打分,打分规则为10分最看多,0分最看空。其次,对#品种名称 提炼主要逻辑和观点,主要逻辑和观点尽可能的详细,得出总结,品种和品种之间用横线拆分,输出格式限定为:1. 使用语义化的HTML5标签代码段,不包含html,body,head,2. 采用现代响应式设计(无固定宽度),3. 包含丰富的文本格式元素,4. 通过内联样式确保自适应渲染"
|
|
|
msg.Role = "system"
|
|
|
msgList = append(msgList, msg)
|
|
|
-
|
|
|
for k, v := range tagList {
|
|
|
msgItem := new(DkCompletionsMessagesReq)
|
|
|
msgItem.Role = "user"
|
|
@@ -59,7 +81,7 @@ func AutoCreateReportAssess(cont context.Context) (err error) {
|
|
|
articleList, err := models.GetWechatArticle(v.ArticleId, startTime, endTime)
|
|
|
if err != nil {
|
|
|
fmt.Println("GetWechatArticle Err:" + err.Error())
|
|
|
- return
|
|
|
+ return err
|
|
|
}
|
|
|
var context string
|
|
|
context += `品种 ` + v.TagName + ":"
|
|
@@ -92,7 +114,7 @@ func AutoCreateReportAssess(cont context.Context) (err error) {
|
|
|
}
|
|
|
|
|
|
isSummary := 0
|
|
|
- isSuccess := dkCompletions(string(reqBody), startTime, endTime, createDate)
|
|
|
+ isSuccess := dkCompletions(string(reqBody), startTime, endTime, startDate, endDate)
|
|
|
if isSuccess {
|
|
|
isSummary = 1
|
|
|
for _, v := range tagList {
|
|
@@ -105,7 +127,7 @@ func AutoCreateReportAssess(cont context.Context) (err error) {
|
|
|
// 使用deepseek api 处理报告
|
|
|
func AutoCreateReportAssessV1() {
|
|
|
//获取品种
|
|
|
- startTime := `2025-05-12 00:00:00`
|
|
|
+ startTime := `2025-03-31 00:00:00`
|
|
|
endTime := `2025-05-18 00:00:00`
|
|
|
tagList, err := models.GetWechatArticleTags(startTime, endTime)
|
|
|
if err != nil {
|
|
@@ -133,7 +155,7 @@ func AutoCreateReportAssessV1() {
|
|
|
//dkCompletions(context)
|
|
|
}
|
|
|
|
|
|
-func dkCompletions(payloadBody, startTime, endTime, createDate string) (success bool) {
|
|
|
+func dkCompletions(payloadBody, startTime, endTime, startDate, endDate string) (success bool) {
|
|
|
|
|
|
utils.FileLog.Info(payloadBody)
|
|
|
|
|
@@ -184,7 +206,7 @@ func dkCompletions(payloadBody, startTime, endTime, createDate string) (success
|
|
|
resultContent = strings.ReplaceAll(resultContent, `\n`, "<br/>")
|
|
|
resultContent = strings.ReplaceAll(resultContent, "```html", "")
|
|
|
resultContent = strings.ReplaceAll(resultContent, "```", "")
|
|
|
-
|
|
|
+ scoreContent := resultContent
|
|
|
utils.FileLog.Info(resultContent)
|
|
|
|
|
|
//判断报告是否存在
|
|
@@ -198,19 +220,22 @@ func dkCompletions(payloadBody, startTime, endTime, createDate string) (success
|
|
|
fmt.Println("reportClassify is nil")
|
|
|
return
|
|
|
}
|
|
|
+ //classifyIdSecond := 245
|
|
|
var isAdd bool
|
|
|
- reportItem, err := models.GetReport(reportClassify.Id, startTime, endTime)
|
|
|
- if err != nil {
|
|
|
- if err.Error() == utils.ErrNoRow() {
|
|
|
- isAdd = true
|
|
|
- } else {
|
|
|
- fmt.Println("GetReport Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- if reportItem == nil {
|
|
|
- isAdd = true
|
|
|
- }
|
|
|
+ //reportItem, err := models.GetReport(reportClassify.Id, classifyIdSecond, startTime, endTime)
|
|
|
+ //if err != nil {
|
|
|
+ // if err.Error() == utils.ErrNoRow() {
|
|
|
+ // isAdd = true
|
|
|
+ // } else {
|
|
|
+ // fmt.Println("GetReport Err:" + err.Error())
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //if reportItem == nil {
|
|
|
+ // isAdd = true
|
|
|
+ //}
|
|
|
+ isAdd = true
|
|
|
+ fmt.Println("isAdd:", isAdd)
|
|
|
if isAdd {
|
|
|
//获取最大期数
|
|
|
//GetReportStage
|
|
@@ -222,20 +247,21 @@ func dkCompletions(payloadBody, startTime, endTime, createDate string) (success
|
|
|
|
|
|
fmt.Println(resultContent)
|
|
|
|
|
|
+ resultContent = "<p>" + startDate + "~" + endDate + "</p>" + resultContent
|
|
|
context := html.EscapeString(resultContent)
|
|
|
item := new(models.Report)
|
|
|
item.AddType = 1
|
|
|
item.ClassifyIdFirst = reportClassify.Id
|
|
|
item.ClassifyNameFirst = reportClassify.ClassifyName
|
|
|
- item.ClassifyIdSecond = 244
|
|
|
- item.ClassifyNameSecond = "AI智汇日报"
|
|
|
- item.Title = "大宗商品AI智汇日报" + createDate
|
|
|
- item.Frequency = "日度"
|
|
|
+ item.ClassifyIdSecond = 245
|
|
|
+ item.ClassifyNameSecond = "AI智慧周报"
|
|
|
+ item.Title = "智汇周报" + endDate
|
|
|
+ item.Frequency = "周度"
|
|
|
item.State = 2
|
|
|
item.Content = context
|
|
|
item.Stage = maxStage + 1
|
|
|
- item.CreateTime = startTime
|
|
|
- item.ModifyTime = startTime
|
|
|
+ item.CreateTime = endTime
|
|
|
+ item.ModifyTime = endTime
|
|
|
item.CollaborateType = 1
|
|
|
item.IsPublicPublish = 1
|
|
|
item.ReportLayout = 1
|
|
@@ -252,16 +278,127 @@ func dkCompletions(payloadBody, startTime, endTime, createDate string) (success
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
- reportContent := html.UnescapeString(reportItem.Content)
|
|
|
- resultContent = reportContent + resultContent
|
|
|
- resultContent = html.EscapeString(resultContent)
|
|
|
- err = models.ModifyReportContent(reportItem.Id, resultContent)
|
|
|
+ //reportContent := html.UnescapeString(reportItem.Content)
|
|
|
+ //resultContent = reportContent + resultContent
|
|
|
+ //resultContent = html.EscapeString(resultContent)
|
|
|
+ //err = models.ModifyReportContent(reportItem.Id, resultContent)
|
|
|
+ //if err != nil {
|
|
|
+ // fmt.Println("ModifyReportContent Err:" + err.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ success = true
|
|
|
+
|
|
|
+ //指标数据处理
|
|
|
+ {
|
|
|
+ fmt.Println("指标数据处理")
|
|
|
+ doc, err := goquery.NewDocumentFromReader(strings.NewReader(scoreContent))
|
|
|
if err != nil {
|
|
|
- fmt.Println("ModifyReportContent Err:" + err.Error())
|
|
|
+ fmt.Println("NewDocumentFromReader Err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
+ fmt.Println("new doc", doc)
|
|
|
+ doc.Find("h2").Each(func(i int, hs *goquery.Selection) {
|
|
|
+ h2Text := hs.Text()
|
|
|
+ fmt.Println("find h2:" + h2Text)
|
|
|
+ var score string
|
|
|
+ if strings.Contains(h2Text, "原油") {
|
|
|
+ fmt.Println(h2Text)
|
|
|
+ fmt.Println(hs.Next().Text())
|
|
|
+ pfText := hs.Next().Text()
|
|
|
+ pfArr := strings.Split(pfText, "/")
|
|
|
+ if len(pfArr) > 0 {
|
|
|
+ scoreStr := pfArr[0]
|
|
|
+ if scoreStr != "" {
|
|
|
+ scoreArr := strings.Split(scoreStr, ":")
|
|
|
+ if len(scoreArr) > 1 {
|
|
|
+ score = scoreArr[1]
|
|
|
+ fmt.Println("score:", strings.Trim(score, " "))
|
|
|
+ } else {
|
|
|
+ fmt.Println("scoreArr len is", len(scoreArr))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fmt.Println("scoreStr is empty")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fmt.Println("pfArr len is 0")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fmt.Println("not find h2")
|
|
|
+ }
|
|
|
+ fmt.Println("score,", score)
|
|
|
+ if score != "" {
|
|
|
+ score = strings.TrimLeft(score, " ")
|
|
|
+ scoreInt, err := strconv.Atoi(score)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(" strconv.Atoi(score) Err:" + err.Error())
|
|
|
+ }
|
|
|
+ if scoreInt > 0 {
|
|
|
+ params := make([]interface{}, 0)
|
|
|
+ params = append(params, "W9535748")
|
|
|
+ params = append(params, endDate)
|
|
|
+ params = append(params, scoreInt)
|
|
|
+ sql := `INSERT INTO edbdata(TRADE_CODE, DT, CLOSE, modify_time, create_time) VALUES (?, ?, ?, NOW(),NOW());`
|
|
|
+ err = data_manage.AddEdbDataManualBySql(sql, params)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("AddEdbDataManualBySql Err:" + err.Error())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ doc.Find("h3").Each(func(i int, hs *goquery.Selection) {
|
|
|
+ h2Text := hs.Text()
|
|
|
+ fmt.Println("find h2:" + h2Text)
|
|
|
+ var score string
|
|
|
+ if strings.Contains(h2Text, "原油") {
|
|
|
+ fmt.Println(h2Text)
|
|
|
+ fmt.Println(hs.Next().Text())
|
|
|
+ pfText := hs.Next().Text()
|
|
|
+ pfArr := strings.Split(pfText, "/")
|
|
|
+ if len(pfArr) > 0 {
|
|
|
+ scoreStr := pfArr[0]
|
|
|
+ if scoreStr != "" {
|
|
|
+ scoreArr := strings.Split(scoreStr, ":")
|
|
|
+ if len(scoreArr) > 1 {
|
|
|
+ score = scoreArr[1]
|
|
|
+ fmt.Println("score:", strings.Trim(score, " "))
|
|
|
+ } else {
|
|
|
+ fmt.Println("scoreArr len is", len(scoreArr))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fmt.Println("scoreStr is empty")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fmt.Println("pfArr len is 0")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fmt.Println("not find h2")
|
|
|
+ }
|
|
|
+ fmt.Println("score,", score)
|
|
|
+ if score != "" {
|
|
|
+ score = strings.TrimLeft(score, " ")
|
|
|
+ scoreInt, err := strconv.Atoi(score)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(" strconv.Atoi(score) Err:" + err.Error())
|
|
|
+ }
|
|
|
+ if scoreInt > 0 {
|
|
|
+ params := make([]interface{}, 0)
|
|
|
+ params = append(params, "W9535748")
|
|
|
+ params = append(params, endDate)
|
|
|
+ params = append(params, scoreInt)
|
|
|
+ sql := `INSERT INTO edbdata(TRADE_CODE, DT, CLOSE, modify_time, create_time) VALUES (?, ?, ?, NOW(),NOW());`
|
|
|
+ err = data_manage.AddEdbDataManualBySql(sql, params)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("AddEdbDataManualBySql Err:" + err.Error())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
- success = true
|
|
|
+
|
|
|
}
|
|
|
return success
|
|
|
}
|