Browse Source

移动eta 增加文档对比搜索

xyxie 1 year ago
parent
commit
80b2b4a60e

+ 95 - 3
controllers/english_report/report.go

@@ -313,10 +313,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       "频度"
@@ -345,6 +347,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")
@@ -371,12 +374,21 @@ 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 != "" {
@@ -746,7 +758,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
@@ -761,6 +780,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"

+ 94 - 2
controllers/report.go

@@ -31,6 +31,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       "频度"
@@ -51,6 +52,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")
@@ -70,6 +72,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{}
 
@@ -77,11 +88,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 != "" {
@@ -2395,3 +2406,84 @@ 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
+	}
+	if req.PreMsgSend != 0 && req.PreMsgSend != 1 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "是否发送模版消息标识错误"
+		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, req.PreMsgSend); 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

@@ -0,0 +1,103 @@
+package semantic_analysis
+
+import (
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hongze_ETA_mobile_api/controllers"
+	"hongze/hongze_ETA_mobile_api/models"
+	"hongze/hongze_ETA_mobile_api/models/data_manage"
+	saModel "hongze/hongze_ETA_mobile_api/models/semantic_analysis"
+	"hongze/hongze_ETA_mobile_api/services"
+	"hongze/hongze_ETA_mobile_api/utils"
+	"time"
+)
+
+// SaCompareController 语义分析-文档比对
+type SaCompareController struct {
+	controllers.BaseAuthController
+}
+
+// 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 - 0
models/db.go

@@ -5,6 +5,7 @@ import (
 	"hongze/hongze_ETA_mobile_api/models/data_manage"
 	"hongze/hongze_ETA_mobile_api/models/ppt_english"
 	"hongze/hongze_ETA_mobile_api/models/sandbox"
+	saModel "hongze/hongze_ETA_mobile_api/models/semantic_analysis"
 	"hongze/hongze_ETA_mobile_api/models/system"
 	"hongze/hongze_ETA_mobile_api/utils"
 	"time"
@@ -42,6 +43,13 @@ func init() {
 	data_db, _ := orm.GetDB("data")
 	data_db.SetConnMaxLifetime(10 * time.Minute)
 
+	_ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_EDB)
+	orm.SetMaxIdleConns("eta", 50)
+	orm.SetMaxOpenConns("eta", 100)
+
+	etaDb, _ := orm.GetDB("eta")
+	etaDb.SetConnMaxLifetime(10 * time.Minute)
+
 	orm.Debug = true
 	orm.DebugLog = orm.NewLog(utils.Binlog)
 
@@ -176,3 +184,9 @@ func initSandbox() {
 		new(sandbox.Sandbox), //沙盘主表
 	)
 }
+
+func initSaCompare() {
+	orm.RegisterModel(
+		new(saModel.SaCompare), //文档对比
+	)
+}

+ 14 - 4
models/english_report.go

@@ -24,6 +24,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"`
@@ -240,6 +241,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"`
@@ -315,21 +317,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 - 3
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:"内容"`
@@ -138,9 +139,9 @@ 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, pre_msg_send=0 WHERE id =?`
 	} else {
-		sql = ` UPDATE report SET state=1 WHERE id =?`
+		sql = ` UPDATE report SET state=1, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
 	}
 	_, err = o.Raw(sql, reportIds).Exec()
 	return
@@ -257,6 +258,12 @@ type AddReq struct {
 	ReportVersion      int    `description:"1:旧版,2:新版"`
 }
 
+type PrePublishReq struct {
+	ReportId       int    `description:"报告id"`
+	PrePublishTime string `description:"预发布时间"`
+	PreMsgSend     int    `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
+}
+
 type AddResp struct {
 	ReportId   int64  `description:"报告id"`
 	ReportCode string `description:"报告code"`
@@ -641,7 +648,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, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
 	_, err = o.Raw(sql, publishTime, reportId).Exec()
 	return
 }
@@ -1006,3 +1013,11 @@ func ModifyReportMsgIsSendV2(reportId int) (err error) {
 	_, err = o.Raw(sql, reportId).Exec()
 	return
 }
+
+// SetPrePublishReportById 设置定时发布
+func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
+	_, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
+	return
+}

+ 160 - 0
models/semantic_analysis/sa_compare.go

@@ -0,0 +1,160 @@
+package semantic_analysis
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"strings"
+	"time"
+)
+
+type SaCompare struct {
+	SaCompareId  int       `orm:"column(sa_compare_id);pk" description:"比对ID"`
+	ClassifyId   int       `description:"比对分类ID"`
+	ClassifyName string    `description:"比对分类名称"`
+	Title        string    `description:"标题"`
+	ResultImg    string    `description:"比对结果图片"`
+	SysAdminId   int       `description:"创建人ID"`
+	SysAdminName string    `description:"创建人姓名"`
+	Sort         int       `description:"排序"`
+	CreateTime   time.Time `description:"创建时间"`
+	ModifyTime   time.Time `description:"修改时间"`
+}
+
+var SaCompareColumns = struct {
+	SaCompareId  string
+	ClassifyId   string
+	ClassifyName string
+	Title        string
+	ResultImg    string
+	SysAdminId   string
+	SysAdminName string
+	Sort         string
+	CreateTime   string
+	ModifyTime   string
+}{
+	SaCompareId:  "sa_compare_id",
+	ClassifyId:   "classify_id",
+	ClassifyName: "classify_name",
+	Title:        "title",
+	ResultImg:    "result_img",
+	SysAdminId:   "sys_admin_id",
+	SysAdminName: "sys_admin_name",
+	Sort:         "sort",
+	CreateTime:   "create_time",
+	ModifyTime:   "modify_time",
+}
+
+func (m *SaCompare) TableName() string {
+	return "sa_compare"
+}
+
+func (m *SaCompare) Create() (err error) {
+	o := orm.NewOrmUsingDB("eta")
+	id, err := o.Insert(m)
+	if err != nil {
+		return
+	}
+	m.SaCompareId = int(id)
+	return
+}
+
+func (m *SaCompare) Update(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("eta")
+	_, err = o.Update(m, cols...)
+	return
+}
+
+func (m *SaCompare) Del() (err error) {
+	o := orm.NewOrmUsingDB("eta")
+	sql := `DELETE FROM sa_compare WHERE sa_compare_id = ? LIMIT 1`
+	_, err = o.Raw(sql, m.SaCompareId).Exec()
+	return
+}
+
+func (m *SaCompare) GetItemById(id int) (err error) {
+	o := orm.NewOrmUsingDB("eta")
+	sql := `SELECT * FROM sa_compare WHERE sa_compare_id = ? LIMIT 1`
+	err = o.Raw(sql, id).QueryRow(&m)
+	return
+}
+
+func (m *SaCompare) GetItemByCondition(condition string, pars []interface{}) (err error) {
+	o := orm.NewOrmUsingDB("eta")
+	sql := `SELECT * FROM sa_compare WHERE 1=1 `
+	sql += condition
+	sql += ` LIMIT 1`
+	err = o.Raw(sql, pars).QueryRow(&m)
+	return
+}
+
+func (m *SaCompare) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("eta")
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *SaCompare) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SaCompare, err error) {
+	o := orm.NewOrmUsingDB("eta")
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+func (m *SaCompare) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*SaCompare, err error) {
+	o := orm.NewOrmUsingDB("eta")
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
+	totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
+	if err = o.Raw(totalSql, pars).QueryRow(&total); err != nil {
+		return
+	}
+	sql += ` LIMIT ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+type SaCompareItem 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:"创建时间"`
+}
+
+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:"修改时间"`
+}
+
+// CompareListByEsResp 文档对比Es搜索返回
+type CompareListByEsResp struct {
+	Paging *paging.PagingItem
+	List   []*SaCompareElastic
+}

+ 27 - 0
routers/commentsRouter.go

@@ -664,6 +664,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_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/hongze_ETA_mobile_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_api/controllers/english_report:EnglishReportController"],
         beego.ControllerComments{
             Method: "PublishReport",
@@ -736,6 +745,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_api/controllers/semantic_analysis:SaCompareController"] = append(beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_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/hongze_ETA_mobile_api/controllers:ClassifyController"] = append(beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_api/controllers:ClassifyController"],
         beego.ControllerComments{
             Method: "ListClassify",
@@ -1537,6 +1555,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_api/controllers:ReportController"],
+        beego.ControllerComments{
+            Method: "PrePublishReport",
+            Router: `/pre_publish`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_ETA_mobile_api/controllers:ReportController"],
         beego.ControllerComments{
             Method: "PublishReport",

+ 6 - 0
routers/router.go

@@ -16,6 +16,7 @@ import (
 	"hongze/hongze_ETA_mobile_api/controllers/data_manage/line_feature"
 	"hongze/hongze_ETA_mobile_api/controllers/english_report"
 	"hongze/hongze_ETA_mobile_api/controllers/sandbox"
+	"hongze/hongze_ETA_mobile_api/controllers/semantic_analysis"
 
 	"github.com/beego/beego/v2/server/web"
 	"github.com/beego/beego/v2/server/web/filter/cors"
@@ -146,6 +147,11 @@ func init() {
 				&english_report.EnPermissionController{},
 			),
 		),
+		web.NSNamespace("/semantic_analysis",
+			web.NSInclude(
+				&semantic_analysis.SaCompareController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 165 - 0
services/elastic.go

@@ -2,8 +2,10 @@ package services
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 	"hongze/hongze_ETA_mobile_api/models"
+	saModel "hongze/hongze_ETA_mobile_api/models/semantic_analysis"
 	"hongze/hongze_ETA_mobile_api/services/alarm_msg"
 	"hongze/hongze_ETA_mobile_api/utils"
 	"strings"
@@ -134,3 +136,166 @@ 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
+}
+
+// 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
+}

+ 40 - 0
services/semantic_analysis.go

@@ -0,0 +1,40 @@
+package services
+
+import (
+	"fmt"
+	saModel "hongze/hongze_ETA_mobile_api/models/semantic_analysis"
+	"hongze/hongze_ETA_mobile_api/utils"
+)
+
+// 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
+}

+ 9 - 5
utils/config.go

@@ -17,6 +17,7 @@ var (
 	MYSQL_URL_GL          string
 	MYSQL_LOG_URL         string
 	MYSQL_URL_COMEIN_DATA string // 路演记录数据库
+	MYSQL_URL_ETA         string
 
 	REDIS_CACHE string       //缓存地址
 	Rc          *cache.Cache //redis缓存
@@ -83,11 +84,12 @@ var (
 
 // ES索引配置
 var (
-	DATA_INDEX_NAME          string //数据指标库索引
-	CHART_INDEX_NAME         string //研究图库索引
-	EsReportIndexName        string //研报ES索引
-	EsEnglishReportIndexName string //英文研报ES索引
-	MY_CHART_INDEX_NAME      string //研究图库(MY ETA)索引
+	DATA_INDEX_NAME                    string //数据指标库索引
+	CHART_INDEX_NAME                   string //研究图库索引
+	EsReportIndexName                  string //研报ES索引
+	EsEnglishReportIndexName           string //英文研报ES索引
+	MY_CHART_INDEX_NAME                string //研究图库(MY ETA)索引
+	EsSemanticAnalysisCompareIndexName string //ES语义分析文档对比索引名
 )
 
 // 阿里云配置
@@ -181,6 +183,7 @@ func init() {
 	MYSQL_URL_GL = config["mysql_url_gl"]
 	MYSQL_LOG_URL = config["mysql_url_log"]
 	MYSQL_URL_COMEIN_DATA = config["mysql_url_comein_data"]
+	MYSQL_URL_ETA = config["mysql_url_eta"]
 
 	REDIS_CACHE = config["beego_cache"]
 	if len(REDIS_CACHE) <= 0 {
@@ -263,6 +266,7 @@ func init() {
 		MY_CHART_INDEX_NAME = config["my_chart_index_name"]
 		EsReportIndexName = config["es_report_index_name"]
 		EsEnglishReportIndexName = config["es_english_report_index_name"]
+		EsSemanticAnalysisCompareIndexName = config["es_semantic_analysis_compare_doc_index_name"]
 	}
 
 	// 微信相关