浏览代码

Merge branch 'feature/eta1.0.0' into debug

xyxie 1 年之前
父节点
当前提交
a90e0165cf

+ 96 - 3
controllers/english_report/report.go

@@ -279,10 +279,12 @@ func (this *EnglishReportController) Detail() {
 	br.Data = item
 }
 
+// ListReport
 // @Title 获取报告列表接口
 // @Description 获取报告列表
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   TimeType     query string true  "筛选的时间类别:publish_time(发布时间),modify_time(更新时间)"
 // @Param   StartDate   query   string  true       "开始时间"
 // @Param   EndDate   query   string  true       "结束时间"
 // @Param   Frequency   query   string  true       "频度"
@@ -311,6 +313,7 @@ func (this *EnglishReportController) ListReport() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 
+	timeType := this.GetString("TimeType")
 	startDate := this.GetString("StartDate")
 	endDate := this.GetString("EndDate")
 	frequency := this.GetString("Frequency")
@@ -337,12 +340,22 @@ func (this *EnglishReportController) ListReport() {
 	if keyWord != "" {
 		condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
 	}
+
+	if timeType == "" {
+		timeType = "publish_time"
+	}
+	if timeType != "publish_time" && timeType != "modify_time" {
+		br.Msg = "请选择正确的时间"
+		br.ErrMsg = "请选择正确的时间"
+		return
+	}
+
 	if startDate != "" {
-		condition += ` AND create_time >= ? `
+		condition += ` AND ` + timeType + ` >= ? `
 		pars = append(pars, startDate)
 	}
 	if endDate != "" {
-		condition += ` AND create_time <= ? `
+		condition += ` AND ` + timeType + ` <= ? `
 		pars = append(pars, endDate)
 	}
 	if frequency != "" {
@@ -603,7 +616,14 @@ func (this *EnglishReportController) PublishReport() {
 			br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
 			return
 		}
-		if tmpErr = models.PublishEnglishReportById(report.Id); tmpErr != nil {
+		var publishTime string
+		if report.PublishTime != "" {
+			// 发布时间固定为首次发布时间
+			publishTime = report.PublishTime
+		} else {
+			publishTime = time.Now().Format(utils.FormatDateTime)
+		}
+		if tmpErr = models.PublishEnglishReportById(report.Id, publishTime); tmpErr != nil {
 			br.Msg = "报告发布失败"
 			br.ErrMsg = "报告发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
 			return
@@ -618,6 +638,79 @@ func (this *EnglishReportController) PublishReport() {
 	br.Msg = "发布成功"
 }
 
+// PrePublishReport
+// @Title 设置定时发布接口
+// @Description 设置定时发布接口
+// @Param	request	body models.PrePublishReq true "type json string"
+// @Success 200 Ret=200 发布成功
+// @router /pre_publish [post]
+func (this *EnglishReportController) PrePublishReport() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.PrePublishReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	reportId := req.ReportId
+	if reportId == 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,报告id不可为空"
+		return
+	}
+	if req.PrePublishTime == "" {
+		br.Msg = "发布时间不能为空"
+		return
+	}
+	prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
+	if err != nil {
+		br.Msg = "发布时间格式错误"
+		br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
+		return
+	}
+	if prePublishTime.Before(time.Now()) {
+		br.Msg = "发布时间不允许选择过去时间"
+		return
+	}
+	report, err := models.GetEnglishReportById(reportId)
+	if err != nil {
+		br.Msg = "获取报告信息失败"
+		br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
+		return
+	}
+	if report == nil {
+		br.Msg = "报告不存在"
+		return
+	}
+
+	if report.Content == "" {
+		br.Msg = "报告内容为空,不可发布"
+		br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
+		return
+	}
+
+	if report.State == 2 {
+		br.Msg = "报告已发布,不可设置定时发布"
+		return
+	}
+
+	var tmpErr error
+	if tmpErr = models.SetPrePublishEnglishReportById(report.Id, req.PrePublishTime); tmpErr != nil {
+		br.Msg = "设置定时发布失败"
+		br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "定时发布成功"
+}
+
 // @Title 取消发布报告接口
 // @Description 取消发布报告
 // @Param	request	body models.PublishCancelReq true "type json string"

+ 89 - 2
controllers/report.go

@@ -39,6 +39,7 @@ type ReportUploadCommonController struct {
 // @Description 获取报告列表
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   TimeType     query string true  "筛选的时间类别:publish_time(发布时间),modify_time(更新时间)"
 // @Param   StartDate   query   string  true       "开始时间"
 // @Param   EndDate   query   string  true       "结束时间"
 // @Param   Frequency   query   string  true       "频度"
@@ -59,6 +60,7 @@ func (this *ReportController) ListReport() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 
+	timeType := this.GetString("TimeType")
 	startDate := this.GetString("StartDate")
 	endDate := this.GetString("EndDate")
 	frequency := this.GetString("Frequency")
@@ -78,6 +80,15 @@ func (this *ReportController) ListReport() {
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
 
+	if timeType == "" {
+		timeType = "publish_time"
+	}
+	if timeType != "publish_time" && timeType != "modify_time" {
+		br.Msg = "请选择正确的时间"
+		br.ErrMsg = "请选择正确的时间"
+		return
+	}
+
 	var condition string
 	var pars []interface{}
 
@@ -85,11 +96,11 @@ func (this *ReportController) ListReport() {
 		condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
 	}
 	if startDate != "" {
-		condition += ` AND create_time >= ? `
+		condition += ` AND ` + timeType + ` >= ? `
 		pars = append(pars, startDate)
 	}
 	if endDate != "" {
-		condition += ` AND create_time <= ? `
+		condition += ` AND ` + timeType + ` <= ? `
 		pars = append(pars, endDate)
 	}
 	if frequency != "" {
@@ -3053,3 +3064,79 @@ func (this *ReportController) CheckDayWeekReportChapterVideo() {
 	br.Msg = "保存成功"
 	br.Data = typeNameArr
 }
+
+// PrePublishReport
+// @Title 设置定时发布接口
+// @Description 设置定时发布接口
+// @Param	request	body models.PrePublishReq true "type json string"
+// @Success 200 Ret=200 发布成功
+// @router /pre_publish [post]
+func (this *ReportController) PrePublishReport() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.PrePublishReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	reportId := req.ReportId
+	if reportId == 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,报告id不可为空"
+		return
+	}
+	if req.PrePublishTime == "" {
+		br.Msg = "发布时间不能为空"
+		return
+	}
+	prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
+	if err != nil {
+		br.Msg = "发布时间格式错误"
+		br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
+		return
+	}
+	if prePublishTime.Before(time.Now()) {
+		br.Msg = "发布时间不允许选择过去时间"
+		return
+	}
+	report, err := models.GetReportById(reportId)
+	if err != nil {
+		br.Msg = "获取报告信息失败"
+		br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
+		return
+	}
+	if report == nil {
+		br.Msg = "报告不存在"
+		return
+	}
+	if report.HasChapter == 1 && (report.ChapterType == utils.REPORT_TYPE_DAY || report.ChapterType == utils.REPORT_TYPE_WEEK) {
+		br.Msg = "晨报周报不支持定时发布"
+		return
+	}
+	if report.Content == "" {
+		br.Msg = "报告内容为空,不可发布"
+		br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
+		return
+	}
+
+	if report.State == 2 {
+		br.Msg = "报告已发布,不可设置定时发布"
+		return
+	}
+
+	var tmpErr error
+	if tmpErr = models.SetPrePublishReportById(report.Id, req.PrePublishTime); tmpErr != nil {
+		br.Msg = "设置定时发布失败"
+		br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "定时发布成功"
+}

+ 103 - 0
controllers/semantic_analysis/sa_compare.go

@@ -6,6 +6,7 @@ import (
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hz_eta_api/controllers"
 	"hongze/hz_eta_api/models"
+	"hongze/hz_eta_api/models/data_manage"
 	saModel "hongze/hz_eta_api/models/semantic_analysis"
 	"hongze/hz_eta_api/services"
 	"hongze/hz_eta_api/utils"
@@ -177,6 +178,11 @@ func (this *SaCompareController) Save() {
 		}
 	}
 
+	// 新增ES对比文档
+	go func() {
+		_ = services.HandleElasticSaCompare(compareItem.SaCompareId)
+	}()
+
 	// 获取表格数据
 	compLabCond := fmt.Sprintf(` AND a.%s = ?`, saModel.SaCompareLabelColumns.CompareId)
 	compLabPars := make([]interface{}, 0)
@@ -319,6 +325,11 @@ func (this *SaCompareController) UpdateResultImg() {
 		return
 	}
 
+	// 新增ES对比文档
+	go func() {
+		_ = services.HandleElasticSaCompare(compareItem.SaCompareId)
+	}()
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"
@@ -420,6 +431,10 @@ func (this *SaCompareController) SelectDocs() {
 		br.Msg = "请选择文档"
 		return
 	}
+	if len(docIdArr) > 10 {
+		br.Msg = "最多支持选择10个文档"
+		return
+	}
 	for i := range docIdArr {
 		d, e := strconv.Atoi(docIdArr[i])
 		if e != nil {
@@ -487,6 +502,9 @@ func (this *SaCompareController) Del() {
 		br.ErrMsg = "删除语义分析比对失败, Err: " + e.Error()
 		return
 	}
+	go func() {
+		_ = services.DeleteElasticSaCompare(item.SaCompareId)
+	}()
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"
@@ -649,3 +667,88 @@ func (this *SaCompareController) Move() {
 	br.Success = true
 	br.Msg = "操作成功"
 }
+
+// SearchByEs
+// @Title 文档对比搜索(从es获取)
+// @Description  图表模糊搜索(从es获取)
+// @Param   Keyword   query   string  true       "文档对比标题"
+// @Success 200 {object} saModel.CompareListByEsResp
+// @router /compare/search [get]
+func (this *SaCompareController) SearchByEs() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	keyword := this.GetString("Keyword")
+
+	var searchList []*saModel.SaCompareElastic
+	var total int
+	var err error
+
+	if keyword != "" {
+		total, searchList, err = services.EsSearchSaCompareData(keyword, startSize, pageSize)
+	} else {
+		var list []*saModel.SaCompare
+		saCompare := new(saModel.SaCompare)
+		existCond := fmt.Sprintf(` AND result_img != ""`)
+		existPars := make([]interface{}, 0)
+		total, list, err = saCompare.GetPageItemsByCondition(startSize, pageSize, existCond, existPars, []string{}, "")
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range list {
+			tmp := new(saModel.SaCompareElastic)
+			tmp.SaCompareId = v.SaCompareId
+			tmp.ResultImg = v.ResultImg
+			tmp.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
+			tmp.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
+			tmp.SysAdminId = v.SysAdminId
+			tmp.SysAdminName = v.SysAdminName
+			tmp.ClassifyId = v.ClassifyId
+			tmp.ClassifyName = v.ClassifyName
+			tmp.Title = v.Title
+			searchList = append(searchList, tmp)
+		}
+	}
+	//新增搜索词记录
+	{
+		searchKeyword := new(data_manage.SearchKeyword)
+		searchKeyword.KeyWord = keyword
+		searchKeyword.CreateTime = time.Now()
+		go data_manage.AddSearchKeyword(searchKeyword)
+	}
+
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := saModel.CompareListByEsResp{
+		Paging: page,
+		List:   searchList,
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 14 - 4
models/english_report.go

@@ -25,6 +25,7 @@ type EnglishReport struct {
 	ModifyTime         time.Time `description:"修改时间"`
 	State              int       `description:"1:未发布,2:已发布"`
 	PublishTime        time.Time `description:"发布时间"`
+	PrePublishTime     time.Time `description:"预发布时间"`
 	Stage              int       `description:"期数"`
 	Content            string    `description:"内容"`
 	VideoUrl           string    `description:"音频文件URL"`
@@ -238,6 +239,7 @@ type EnglishReportList struct {
 	ModifyTime         time.Time `description:"修改时间"`
 	State              int       `description:"1:未发布,2:已发布"`
 	PublishTime        string    `description:"发布时间"`
+	PrePublishTime     string    `description:"预发布时间"`
 	Stage              int       `description:"期数"`
 	Content            string    `description:"内容"`
 	VideoUrl           string    `description:"音频文件URL"`
@@ -317,21 +319,29 @@ func GetEnglishReportByCondition(condition string, pars []interface{}) (items []
 }
 
 // 发布报告
-func PublishEnglishReportById(reportId int) (err error) {
+func PublishEnglishReportById(reportId int, publishTime string) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `UPDATE english_report SET state=2,publish_time=now(),modify_time=NOW() WHERE id = ? `
-	_, err = o.Raw(sql, reportId).Exec()
+	sql := `UPDATE english_report SET state=2,publish_time=?,pre_publish_time=null,modify_time=NOW() WHERE id = ? `
+	_, err = o.Raw(sql, publishTime, reportId).Exec()
 	return
 }
 
 // 取消发布报告
 func PublishCancelEnglishReport(reportIds int) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := ` UPDATE english_report SET state=1,publish_time=null WHERE id =?  `
+	sql := ` UPDATE english_report SET state=1,pre_publish_time=null WHERE id =?  `
 	_, err = o.Raw(sql, reportIds).Exec()
 	return
 }
 
+// SetPrePublishEnglishReportById 设置定时发布
+func SetPrePublishEnglishReportById(reportId int, prePublishTime string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `UPDATE english_report SET pre_publish_time=? WHERE id = ? and state = 1 `
+	_, err = o.Raw(sql, prePublishTime, reportId).Exec()
+	return
+}
+
 // DeleteEnglishReportAndChapter 删除报告及章节
 func DeleteEnglishReportAndChapter(reportInfo *EnglishReportDetail) (err error) {
 	reportId := reportInfo.Id

+ 18 - 4
models/report.go

@@ -56,6 +56,7 @@ type ReportList struct {
 	ModifyTime         time.Time                 `description:"修改时间"`
 	State              int                       `description:"1:未发布,2:已发布"`
 	PublishTime        string                    `description:"发布时间"`
+	PrePublishTime     string                    `description:"预发布时间"`
 	Stage              int                       `description:"期数"`
 	MsgIsSend          int                       `description:"模板消息是否已发送,0:否,1:是"`
 	Content            string                    `description:"内容"`
@@ -133,14 +134,14 @@ func PublishReport(reportIds string) (err error) {
 	return
 }
 
-// 取消发布报告
+// PublishCancleReport 取消发布报告
 func PublishCancleReport(reportIds int, publishTimeNullFlag bool) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	var sql string
 	if publishTimeNullFlag {
-		sql = ` UPDATE report SET state=1, publish_time=null WHERE id =?`
+		sql = ` UPDATE report SET state=1, publish_time=null, pre_publish_time=null WHERE id =?`
 	} else {
-		sql = ` UPDATE report SET state=1 WHERE id =?`
+		sql = ` UPDATE report SET state=1, pre_publish_time=null WHERE id =?`
 	}
 	_, err = o.Raw(sql, reportIds).Exec()
 	return
@@ -257,6 +258,11 @@ type AddReq struct {
 	ReportVersion      int    `description:"1:旧版,2:新版"`
 }
 
+type PrePublishReq struct {
+	ReportId       int    `description:"报告id"`
+	PrePublishTime string `description:"预发布时间"`
+}
+
 type AddResp struct {
 	ReportId   int64  `description:"报告id"`
 	ReportCode string `description:"报告code"`
@@ -641,7 +647,7 @@ SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video
 // 发布报告
 func PublishReportById(reportId int, publishTime time.Time) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? `
+	sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, modify_time = NOW() WHERE id = ? `
 	_, err = o.Raw(sql, publishTime, reportId).Exec()
 	return
 }
@@ -1006,3 +1012,11 @@ func ModifyReportMsgIsSendV2(reportId int) (err error) {
 	_, err = o.Raw(sql, reportId).Exec()
 	return
 }
+
+// SetPrePublishReportById 设置定时发布
+func SetPrePublishReportById(reportId int, prePublishTime string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `UPDATE report SET pre_publish_time=? WHERE id = ? and state = 1 `
+	_, err = o.Raw(sql, prePublishTime, reportId).Exec()
+	return
+}

+ 18 - 0
models/semantic_analysis/sa_compare.go

@@ -193,6 +193,18 @@ type SaCompareItem struct {
 	CreateTime   string `description:"创建时间"`
 }
 
+type SaCompareElastic struct {
+	SaCompareId  int    `description:"比对ID"`
+	ClassifyId   int    `description:"比对分类ID"`
+	ClassifyName string `description:"比对分类名称"`
+	Title        string `description:"标题"`
+	ResultImg    string `description:"比对结果图片"`
+	SysAdminId   int    `description:"创建人ID"`
+	SysAdminName string `description:"创建人姓名"`
+	CreateTime   string `description:"创建时间"`
+	ModifyTime   string `description:"修改时间"`
+}
+
 // SaCompareUpdateResultImgReq 更新比对结果图片请求体
 type SaCompareUpdateResultImgReq struct {
 	SaCompareId int    `description:"比对ID"`
@@ -410,3 +422,9 @@ func GetFirstSortSaCompare(classifyId int) (item *SaCompare, err error) {
 	err = o.Raw(sql, classifyId).QueryRow(&item)
 	return
 }
+
+// CompareListByEsResp 文档对比Es搜索返回
+type CompareListByEsResp struct {
+	Paging *paging.PagingItem
+	List   []*SaCompareElastic
+}

+ 27 - 0
routers/commentsRouter.go

@@ -3778,6 +3778,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/english_report:EnglishReportController"],
+        beego.ControllerComments{
+            Method: "PrePublishReport",
+            Router: `/pre_publish`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/english_report:EnglishReportController"],
         beego.ControllerComments{
             Method: "PublishReport",
@@ -4219,6 +4228,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/semantic_analysis:SaCompareController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/semantic_analysis:SaCompareController"],
+        beego.ControllerComments{
+            Method: "SearchByEs",
+            Router: `/compare/search`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/semantic_analysis:SaCompareController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers/semantic_analysis:SaCompareController"],
         beego.ControllerComments{
             Method: "SelectDocs",
@@ -5497,6 +5515,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:ReportController"],
+        beego.ControllerComments{
+            Method: "PrePublishReport",
+            Router: `/pre_publish`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["hongze/hz_eta_api/controllers:ReportController"],
         beego.ControllerComments{
             Method: "PublishReport",

+ 164 - 0
services/elastic.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 	"github.com/olivere/elastic/v7"
 	"hongze/hz_eta_api/models"
@@ -207,6 +208,65 @@ func EsAddOrEditEnglishReport(indexName, docId string, item *models.ElasticEngli
 	return
 }
 
+// EsAddOrEditSaCompare 新增编辑es语义分析文档对比
+func EsAddOrEditSaCompare(indexName, docId string, item *saModel.SaCompareElastic) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("EsAddOrEditSaCompare Err:", err.Error())
+			go alarm_msg.SendAlarmMsg("新增编辑es语义分析文档对比 EsAddOrEditSaCompare,Err:"+err.Error(), 3)
+		}
+	}()
+	client := utils.EsClient
+	// docId为报告ID
+	searchById, err := client.Get().Index(indexName).Id(docId).Do(context.Background())
+	if err != nil {
+		if strings.Contains(err.Error(), "404") {
+			err = nil
+		} else {
+			fmt.Println("Get Err" + err.Error())
+			return
+		}
+	}
+	if searchById != nil && searchById.Found {
+		resp, e := client.Update().Index(indexName).Id(docId).Doc(map[string]interface{}{
+			"SaCompareId":  item.SaCompareId,
+			"ClassifyName": item.ClassifyName,
+			"ClassifyId":   item.ClassifyId,
+			"Title":        item.Title,
+			"ResultImg":    item.ResultImg,
+			"CreateTime":   item.CreateTime,
+			"ModifyTime":   item.ModifyTime,
+			"SysAdminId":   item.SysAdminId,
+			"SysAdminName": item.SysAdminName,
+		}).Do(context.Background())
+		if e != nil {
+			err = e
+			return
+		}
+		//fmt.Println(resp.Status, resp.Result)
+		if resp.Status == 0 {
+			fmt.Println("修改成功" + docId)
+			err = nil
+		} else {
+			fmt.Println("EditData", resp.Status, resp.Result)
+		}
+	} else {
+		resp, e := client.Index().Index(indexName).Id(docId).BodyJson(item).Do(context.Background())
+		if e != nil {
+			err = e
+			fmt.Println("新增失败:", err.Error())
+			return
+		}
+		if resp.Status == 0 && resp.Result == "created" {
+			fmt.Println("新增成功" + docId)
+			return
+		} else {
+			fmt.Println("AddData", resp.Status, resp.Result)
+		}
+	}
+	return
+}
+
 // EsAddOrEditSaDoc 新增编辑语义分析文档
 func EsAddOrEditSaDoc(indexName, docId string, item *saModel.ElasticSaDoc) (err error) {
 	defer func() {
@@ -267,3 +327,107 @@ func EsAddOrEditSaDoc(indexName, docId string, item *saModel.ElasticSaDoc) (err
 	fmt.Println("AddData", resp.Status, resp.Result)
 	return
 }
+
+// EsSearchSaCompareData 查询es中的文档对比信息
+func EsSearchSaCompareData(keywordStr string, from, size int) (total int, list []*saModel.SaCompareElastic, err error) {
+	list = make([]*saModel.SaCompareElastic, 0)
+	indexName := utils.EsSemanticAnalysisCompareIndexName
+	var tmpTotal int64
+	defer func() {
+		if err != nil {
+			fmt.Println("EsSearchSaCompareData Err:", err.Error())
+		}
+	}()
+	client := utils.EsClient
+
+	mustMap := make([]interface{}, 0)
+	mustNotMap := make([]interface{}, 0)
+
+	//关键字匹配
+	shouldMap := map[string]interface{}{
+		"should": []interface{}{
+			map[string]interface{}{
+				"match_phrase": map[string]interface{}{
+					"Title": keywordStr,
+					//"Frequency.keyword": "月度",
+				},
+			},
+		},
+	}
+	mustMap = append(mustMap, map[string]interface{}{
+		"bool": shouldMap,
+	})
+
+	queryMap := map[string]interface{}{
+		"query": map[string]interface{}{
+			"bool": map[string]interface{}{
+				"must":     mustMap,
+				"must_not": mustNotMap,
+				//"should":   shouldMap,
+			},
+		},
+	}
+
+	//根据条件数量统计
+	requestTotalHits := client.Count(indexName).BodyJson(queryMap)
+	tmpTotal, err = requestTotalHits.Do(context.Background())
+	if err != nil {
+		return
+	}
+	total = int(tmpTotal)
+	// 分页查询
+	queryMap["from"] = from
+	queryMap["size"] = size
+	queryMap["sort"] = []map[string]interface{}{
+		map[string]interface{}{
+			"CreateTime.keyword": map[string]interface{}{
+				"order": "desc",
+			},
+		},
+		map[string]interface{}{
+			"_score": map[string]interface{}{
+				"order": "desc",
+			},
+		},
+	}
+	jsonBytes, _ := json.Marshal(queryMap)
+	fmt.Println(string(jsonBytes))
+
+	request := client.Search(indexName).Source(queryMap) // sets the JSON request
+
+	searchMap := make(map[string]string)
+
+	searchResp, err := request.Do(context.Background())
+	if err != nil {
+		return
+	}
+	fmt.Println(searchResp)
+	fmt.Println(searchResp.Status)
+	if searchResp.Status != 0 {
+		return
+	}
+
+	if searchResp.Hits != nil {
+		for _, v := range searchResp.Hits.Hits {
+			if _, ok := searchMap[v.Id]; !ok {
+				itemJson, tmpErr := v.Source.MarshalJSON()
+				if tmpErr != nil {
+					err = tmpErr
+					fmt.Println("movieJson err:", err)
+					return
+				}
+				compareItem := new(saModel.SaCompareElastic)
+				tmpErr = json.Unmarshal(itemJson, &compareItem)
+				if err != nil {
+					fmt.Println("json.Unmarshal itemJson err:", err)
+					err = tmpErr
+					return
+				}
+
+				list = append(list, compareItem)
+				searchMap[v.Id] = v.Id
+			}
+		}
+	}
+	return
+}

+ 63 - 0
services/english_report.go

@@ -598,6 +598,69 @@ func CreateEnglishReportIndex() {
 	EsCreateIndex(indexName, mappingJson)
 }
 
+func CreateSaCompareES() {
+	indexName := utils.EsSemanticAnalysisCompareIndexName
+	mappingJson := `{
+  "mappings": {
+    "dynamic": true,
+    "properties": {
+        "ResultImg" : {
+          "type" : "text"
+        },
+        "ClassifyName" : {
+          "type" : "text",
+          "fields" : {
+            "keyword" : {
+              "type" : "keyword",
+              "ignore_above" : 256
+            }
+          }
+        },
+		"SysAdminName" : {
+          "type" : "text"
+        },
+		"SysAdminId" : {
+          "type" : "long"
+        },
+        "ClassifyId" : {
+          "type" : "long"
+        },
+        "ModifyTime" : {
+          "type" : "text",
+          "fields" : {
+            "keyword" : {
+              "type" : "keyword",
+              "ignore_above" : 256
+            }
+          }
+        },
+       "CreateTime" : {
+          "type" : "text",
+          "fields" : {
+            "keyword" : {
+              "type" : "keyword",
+              "ignore_above" : 256
+            }
+          }
+        },
+        "SaCompareId" : {
+          "type" : "long"
+        },
+        "Title" : {
+          "type" : "text",
+          "fields" : {
+            "keyword" : {
+              "type" : "keyword",
+              "ignore_above" : 256
+            }
+          }
+        }
+      }
+  }
+}`
+	EsCreateIndex(indexName, mappingJson)
+}
+
 // UpdateEnReportEditMark 更新英文研报当前更新状态
 // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
 func UpdateEnReportEditMark(reportId, nowUserId, status int, nowUserName string) (ret models.MarkReportResp, err error) {

+ 50 - 0
services/semantic_analysis.go

@@ -513,3 +513,53 @@ func FormatCompareLabels2TableData(compareLabels []*saModel.SaCompareLabelItem)
 	}
 	return
 }
+
+// HandleElasticSaCompare 更新语义分析文档Es
+func HandleElasticSaCompare(saCompareId int) (err error) {
+	if saCompareId <= 0 {
+		return
+	}
+	saCompare := new(saModel.SaCompare)
+	err = saCompare.GetItemById(saCompareId)
+	if err != nil {
+		return
+	}
+	// 没有预览图,则不加入es
+	if saCompare.ResultImg == "" {
+		return
+	}
+	// 新增报告ES
+	saItem := &saModel.SaCompareElastic{
+		SaCompareId:  saCompare.SaCompareId,
+		ClassifyId:   saCompare.ClassifyId,
+		ClassifyName: saCompare.ClassifyName,
+		Title:        saCompare.Title,
+		ResultImg:    saCompare.ResultImg,
+		CreateTime:   saCompare.CreateTime.Format(utils.FormatDateTime),
+		ModifyTime:   saCompare.ModifyTime.Format(utils.FormatDateTime),
+		SysAdminId:   saCompare.SysAdminId,
+		SysAdminName: saCompare.SysAdminName,
+	}
+	docId := fmt.Sprintf("%d", saCompare.SaCompareId)
+	if err = EsAddOrEditSaCompare(utils.EsSemanticAnalysisCompareIndexName, docId, saItem); err != nil {
+		return
+	}
+	return
+}
+
+// DeleteElasticSaCompare Elastic-删除语义分析文档对比图
+func DeleteElasticSaCompare(saCompareId int) (err error) {
+	defer func() {
+		if err != nil {
+			alarm_msg.SendAlarmMsg(fmt.Sprintf("Elastic-删除语义分析文档对比图, Err: %s", err.Error()), 2)
+		}
+	}()
+	indexName := utils.EsSemanticAnalysisCompareIndexName
+
+	docId := fmt.Sprintf("%d", saCompareId)
+	if e := EsDeleteData(indexName, docId); e != nil && !strings.Contains(e.Error(), "404") {
+		err = fmt.Errorf("删除ES语义分析文档对比失败, Err: %s", e.Error())
+		return
+	}
+	return
+}

+ 87 - 0
services/task.go

@@ -1,8 +1,11 @@
 package services
 
 import (
+	"context"
 	"fmt"
+	"github.com/beego/beego/v2/adapter/logs"
 	"hongze/hz_eta_api/models"
+	saModel "hongze/hz_eta_api/models/semantic_analysis"
 	"hongze/hz_eta_api/services/alarm_msg"
 	"hongze/hz_eta_api/services/data"
 	"hongze/hz_eta_api/utils"
@@ -471,3 +474,87 @@ func FixEnCompanyPermission() {
 	}
 	fmt.Println("修复完成")
 }
+
+func ElasticSaCompareInit() {
+	// 标题去重
+	CreateSaCompareES()
+	var err error
+	defer func() {
+		if err != nil {
+			logs.Info("批量新增文档对比es出错" + err.Error())
+		}
+	}()
+	existItem := new(saModel.SaCompare)
+	existCond := fmt.Sprintf(` AND result_img != ""`)
+	existPars := make([]interface{}, 0)
+	list, e := existItem.GetItemsByCondition(existCond, existPars, []string{}, "")
+	if e != nil {
+		err = e
+		return
+	}
+	client := utils.EsClient
+	for _, saCompare := range list {
+		// 新增报告ES
+		item := &saModel.SaCompareElastic{
+			SaCompareId:  saCompare.SaCompareId,
+			ClassifyId:   saCompare.ClassifyId,
+			ClassifyName: saCompare.ClassifyName,
+			Title:        saCompare.Title,
+			ResultImg:    saCompare.ResultImg,
+			CreateTime:   saCompare.CreateTime.Format(utils.FormatDateTime),
+			ModifyTime:   saCompare.ModifyTime.Format(utils.FormatDateTime),
+			SysAdminId:   saCompare.SysAdminId,
+			SysAdminName: saCompare.SysAdminName,
+		}
+		docId := fmt.Sprintf("%d", saCompare.SaCompareId)
+		indexName := utils.EsSemanticAnalysisCompareIndexName
+
+		// docId为报告ID
+		searchById, err := client.Get().Index(indexName).Id(docId).Do(context.Background())
+		if err != nil {
+			if strings.Contains(err.Error(), "404") {
+				err = nil
+			} else {
+				fmt.Println("Get Err" + err.Error())
+				return
+			}
+		}
+		if searchById != nil && searchById.Found {
+			resp, e := client.Update().Index(indexName).Id(docId).Doc(map[string]interface{}{
+				"SaCompareId":  item.SaCompareId,
+				"ClassifyName": item.ClassifyName,
+				"ClassifyId":   item.ClassifyId,
+				"Title":        item.Title,
+				"ResultImg":    item.ResultImg,
+				"CreateTime":   item.CreateTime,
+				"ModifyTime":   item.ModifyTime,
+				"SysAdminId":   item.SysAdminId,
+				"SysAdminName": item.SysAdminName,
+			}).Do(context.Background())
+			if e != nil {
+				err = e
+				return
+			}
+			//fmt.Println(resp.Status, resp.Result)
+			if resp.Status == 0 {
+				fmt.Println("修改成功" + docId)
+				err = nil
+			} else {
+				fmt.Println("EditData", resp.Status, resp.Result)
+			}
+		} else {
+			resp, e := client.Index().Index(indexName).Id(docId).BodyJson(item).Do(context.Background())
+			if e != nil {
+				err = e
+				fmt.Println("新增失败:", err.Error())
+				return
+			}
+			if resp.Status == 0 && resp.Result == "created" {
+				fmt.Println("新增成功" + docId)
+			} else {
+				fmt.Println("AddData", resp.Status, resp.Result)
+			}
+		}
+
+	}
+}

+ 8 - 6
utils/config.go

@@ -100,12 +100,13 @@ var (
 
 // ES索引配置
 var (
-	DATA_INDEX_NAME                string //数据指标库索引
-	CHART_INDEX_NAME               string //研究图库索引
-	EsReportIndexName              string //研报ES索引
-	EsEnglishReportIndexName       string //英文研报ES索引
-	MY_CHART_INDEX_NAME            string //研究图库(MY ETA)索引
-	EsSemanticAnalysisDocIndexName string //ES语义分析文档索引名
+	DATA_INDEX_NAME                    string //数据指标库索引
+	CHART_INDEX_NAME                   string //研究图库索引
+	EsReportIndexName                  string //研报ES索引
+	EsEnglishReportIndexName           string //英文研报ES索引
+	MY_CHART_INDEX_NAME                string //研究图库(MY ETA)索引
+	EsSemanticAnalysisDocIndexName     string //ES语义分析文档索引名
+	EsSemanticAnalysisCompareIndexName string //ES语义分析文档对比索引名
 )
 
 // 科大讯飞--语音合成
@@ -385,6 +386,7 @@ func init() {
 		EsReportIndexName = config["es_report_index_name"]
 		EsEnglishReportIndexName = config["es_english_report_index_name"]
 		EsSemanticAnalysisDocIndexName = config["es_semantic_analysis_doc_index_name"]
+		EsSemanticAnalysisCompareIndexName = config["es_semantic_analysis_compare_doc_index_name"]
 	}
 
 	CrmEtaServerUrl = config["crm_eta_server_url"]