Browse Source

Merge branch 'feature/eta1.0.0' of eta_server/eta_api into master

xyxie 1 year ago
parent
commit
9f1d9009ec

+ 103 - 6
controllers/english_report/report.go

@@ -2,8 +2,6 @@ package english_report
 
 import (
 	"encoding/json"
-	"fmt"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"eta/eta_api/controllers"
 	"eta/eta_api/models"
 	"eta/eta_api/models/company"
@@ -11,6 +9,8 @@ import (
 	"eta/eta_api/services"
 	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/utils"
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"html"
 	"strconv"
 	"strings"
@@ -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")
@@ -335,14 +338,24 @@ func (this *EnglishReportController) ListReport() {
 	var pars []interface{}
 
 	if keyWord != "" {
-		condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
+		condition += ` AND (title LIKE '%` + keyWord + `%' OR admin_real_name 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,83 @@ 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
+	}
+	if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
+		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"

+ 99 - 3
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,18 +80,27 @@ 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{}
 
 	if keyWord != "" {
-		condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
+		condition += ` AND (title LIKE '%` + keyWord + `%' OR admin_real_name 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 != "" {
@@ -3154,3 +3165,88 @@ 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
+	}
+	if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
+		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 = "定时发布成功"
+}

+ 82 - 0
controllers/semantic_analysis/sa_compare.go

@@ -420,6 +420,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 {
@@ -649,3 +653,81 @@ func (this *SaCompareController) Move() {
 	br.Success = true
 	br.Msg = "操作成功"
 }
+
+// Search
+// @Title 文档对比搜索(从es获取)
+// @Description  图表模糊搜索(从es获取)
+// @Param   Keyword   query   string  true       "文档对比标题"
+// @Success 200 {object} saModel.CompareListByEsResp
+// @router /compare/search [get]
+func (this *SaCompareController) Search() {
+	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
+
+	var list []*saModel.SaCompare
+	saCompare := new(saModel.SaCompare)
+	existCond := fmt.Sprintf(` AND result_img != ""`)
+	existPars := make([]interface{}, 0)
+	if keyword != "" {
+		existCond += ` AND  ( title LIKE ? )`
+		existPars = append(existPars, `%`+keyword+`%`)
+	}
+	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)
+	}
+
+	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

+ 19 - 4
models/report.go

@@ -57,6 +57,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:"内容"`
@@ -137,14 +138,14 @@ func PublishReport(reportIds []int) (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, 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
@@ -264,6 +265,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"`
@@ -648,7 +655,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
 }
@@ -1013,3 +1020,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
+}

+ 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

@@ -3760,6 +3760,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["eta/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["eta/eta_api/controllers/english_report:EnglishReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/english_report:EnglishReportController"],
         beego.ControllerComments{
             Method: "PublishReport",
@@ -4237,6 +4246,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/semantic_analysis:SaCompareController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/semantic_analysis:SaCompareController"],
+        beego.ControllerComments{
+            Method: "Search",
+            Router: `/compare/search`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/semantic_analysis:SaCompareController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/semantic_analysis:SaCompareController"],
         beego.ControllerComments{
             Method: "SelectDocs",
@@ -5551,6 +5569,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"],
+        beego.ControllerComments{
+            Method: "PrePublishReport",
+            Router: `/pre_publish`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:ReportController"],
         beego.ControllerComments{
             Method: "PublishReport",