Просмотр исходного кода

Merge branch 'feature/eta_1.3.8' into debug

hsun 1 год назад
Родитель
Сommit
6c644c8454

+ 8 - 8
controllers/base_auth.go

@@ -25,7 +25,7 @@ func (this *BaseAuthController) Prepare() {
 		nonce := this.Ctx.Input.Header("nonce")
 		timestamp := this.Ctx.Input.Header("timestamp")
 		appid := this.Ctx.Input.Header("appid")
-		signature := this.Ctx.Input.Header("signature")
+		//signature := this.Ctx.Input.Header("signature")
 
 		if nonce == "" {
 			errMsg := "随机字符串不能为空"
@@ -48,13 +48,13 @@ func (this *BaseAuthController) Prepare() {
 			return
 		}
 
-		checkSign := utils.GetSign(nonce, timestamp)
-		if signature != checkSign {
-			errMsg := "签名错误"
-			this.JSON(models.BaseResponse{Ret: 401, Msg: "", ErrMsg: errMsg}, false, false)
-			this.StopRun()
-			return
-		}
+		//checkSign := utils.GetSign(nonce, timestamp)
+		//if signature != checkSign {
+		//	errMsg := "签名错误"
+		//	this.JSON(models.BaseResponse{Ret: 401, Msg: "", ErrMsg: errMsg}, false, false)
+		//	this.StopRun()
+		//	return
+		//}
 		if method != "GET" && method != "POST" {
 			errMsg := "无效的请求方式"
 			this.JSON(models.BaseResponse{Ret: 501, Msg: "", ErrMsg: errMsg}, false, false)

+ 227 - 0
controllers/english_report_approval.go

@@ -0,0 +1,227 @@
+package controllers
+
+import (
+	"encoding/json"
+	"eta/eta_hub/models"
+	"eta/eta_hub/services"
+	"eta/eta_hub/utils"
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"time"
+)
+
+// EnglishReportController 英文研报
+type EnglishReportController struct {
+	BaseAuthController
+}
+
+// List
+// @Title 报告列表
+// @Description 报告列表
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} models.EnglishReportListResp
+// @router /list [get]
+func (this *EnglishReportController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	var condition string
+	var pars []interface{}
+
+	reportOb := new(models.EnglishReport)
+	total, e := reportOb.GetCountByCondition(condition, pars)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取英文报告列表总数失败, Err: " + e.Error()
+		return
+	}
+
+	respList := make([]*models.EnglishReportItem, 0)
+	list, e := reportOb.GetPageItemsByCondition(condition, pars, []string{}, "", startSize, pageSize)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取英文报告列表失败, Err: " + e.Error()
+		return
+	}
+	for _, v := range list {
+		t := models.FormatEnglishReport2Item(v)
+		respList = append(respList, t)
+	}
+
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(models.EnglishReportListResp)
+	resp.Paging = page
+	resp.List = respList
+	br.Ret = 200
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// Detail
+// @Title 报告详情
+// @Description 报告详情
+// @Param	ReportId  query  int  true  "报告ID"
+// @Success 200 {object} models.EnglishReportItem
+// @router /detail [get]
+func (this *EnglishReportController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	reportId, err := this.GetInt("ReportId")
+	if err != nil {
+		br.Msg = "获取参数失败!"
+		br.ErrMsg = "获取参数失败,Err:" + err.Error()
+		return
+	}
+	if reportId <= 0 {
+		br.Msg = "参数错误"
+		return
+	}
+
+	reportOb := new(models.EnglishReport)
+	item, e := reportOb.GetItemById(reportId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			br.Msg = "报告已被删除"
+			return
+		}
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + e.Error()
+		return
+	}
+	detail := models.FormatEnglishReport2Item(item)
+
+	br.Data = detail
+	br.Ret = 200
+	br.Msg = "获取成功"
+}
+
+// Approve
+// @Title 审批
+// @Description 审批报告
+// @Param	request	body models.EnglishReportApproveReq true "type json string"
+// @Success 200 string "操作成功"
+// @router /approve [post]
+func (this *EnglishReportController) Approve() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	var req models.EnglishReportApproveReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ReportId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = fmt.Sprintf("参数有误, EnglishReportId: %d", req.ReportId)
+		return
+	}
+
+	ob := new(models.EnglishReport)
+	item, e := ob.GetItemById(req.ReportId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			br.Msg = "报告已被删除"
+			return
+		}
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取英文研报失败, Err: " + e.Error()
+		return
+	}
+	if item.State != models.ReportStateWaitApprove {
+		br.Msg = "报告状态有误"
+		br.ErrMsg = fmt.Sprintf("报告状态有误, State: %d", item.State)
+		return
+	}
+	if item.Content == "" {
+		br.Msg = "报告内容为空,请检查内容"
+		return
+	}
+
+	// 校验审批配置
+	confMap, e := models.GetBusinessConf()
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取审批配置失败, Err: " + e.Error()
+		return
+	}
+	if confMap[models.BusinessConfIsReportApprove] != "true" {
+		br.Msg = "未开启审批, 请开启后重新操作"
+		return
+	}
+	if confMap[models.BusinessConfReportApproveType] != models.BusinessConfReportApproveTypeOther {
+		br.Msg = "未开启第三方审批, 请开启后重新操作"
+		return
+	}
+
+	stateMap := map[bool]int{false: models.ReportStateRefused, true: models.ReportStatePass}
+	// 驳回
+	now := time.Now().Local()
+	if !req.Pass {
+		cols := []string{"State", "ModifyTime", "ApproveTime"}
+		item.State = stateMap[req.Pass]
+		item.ModifyTime = now
+		item.ApproveTime = now
+		if e = item.Update(cols); e != nil {
+			br.Msg = "审批失败"
+			br.ErrMsg = "报告审批驳回失败, Err: " + e.Error()
+			return
+		}
+	}
+
+	// 通过审批
+	if req.Pass {
+		cols := []string{"State", "ModifyTime", "ApproveTime", "PublishTime"}
+		item.State = stateMap[req.Pass]
+		item.ModifyTime = now
+		item.ApproveTime = now
+		item.PublishTime = now
+		if e = item.Update(cols); e != nil {
+			br.Msg = "审批失败"
+			br.ErrMsg = "报告审批通过失败, Err: " + e.Error()
+			return
+		}
+
+		// 更新报告ES
+		go func() {
+			_ = services.UpdateEnglishReportEs(item.Id, models.ReportStatePublished)
+		}()
+	}
+
+	// 记录报告变更状态
+	go func() {
+		recordItem := &models.ReportStateRecord{
+			ReportId:   req.ReportId,
+			ReportType: models.ReportTypeEnglish,
+			State:      item.State,
+			CreateTime: time.Now(),
+		}
+		_, _ = models.AddReportStateRecord(recordItem)
+	}()
+
+	br.Ret = 200
+	br.Msg = "审批成功"
+}

+ 118 - 173
controllers/report_approval.go

@@ -5,10 +5,8 @@ import (
 	"eta/eta_hub/models"
 	"eta/eta_hub/services"
 	"eta/eta_hub/utils"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
-	"html"
-	"strconv"
-	"strings"
 	"time"
 )
 
@@ -17,24 +15,14 @@ type ReportController struct {
 	BaseAuthController
 }
 
-// ListReport
+// List
 // @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       "频度"
-// @Param   ClassifyNameFirst   query   string  true       "一级分类名称"
-// @Param   ClassifyNameSecond   query   string  true       "二级分类名称"
-// @Param   State   query   int  true       "状态"
-// @Param   KeyWord   query   string  true       "搜索关键词"
-// @Param   PublishSort   query   string  true       "desc:降序,asc 升序(预留)"
-// @Param   CompanyType   query   string  false       "产品类型,枚举值:'ficc','权益';不传默认返回全部"
 // @Success 200 {object} models.ReportListResp
 // @router /list [get]
-func (this *ReportController) ListReport() {
+func (this *ReportController) List() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
@@ -43,16 +31,6 @@ 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")
-	//classifyNameFirst := this.GetString("ClassifyNameFirst")
-	//classifyNameSecond := this.GetString("ClassifyNameSecond")
-	//state, _ := this.GetInt("State")
-	//keyWord := this.GetString("KeyWord")
-	//companyType := this.GetString("CompanyType")
-
 	var startSize int
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
@@ -62,216 +40,183 @@ 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 ? OR admin_real_name LIKE ? ) `
-	//	pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
-	//}
-	//if startDate != "" {
-	//	condition += ` AND ` + timeType + ` >= ? `
-	//	pars = append(pars, startDate)
-	//}
-	//if endDate != "" {
-	//	condition += ` AND ` + timeType + ` <= ? `
-	//	pars = append(pars, endDate)
-	//}
-	//if frequency != "" {
-	//	condition += ` AND frequency = ? `
-	//	pars = append(pars, frequency)
-	//}
-	//if classifyNameFirst != "" {
-	//	condition += ` AND classify_name_first = ? `
-	//	pars = append(pars, classifyNameFirst)
-	//}
-	//
-	//if classifyNameSecond != "" {
-	//	condition += ` AND classify_name_second = ? `
-	//	pars = append(pars, classifyNameSecond)
-	//}
-	//if state > 0 {
-	//	condition += ` AND state = ? `
-	//	pars = append(pars, state)
-	//}
-	condition += ` AND state <> 1 `
-
 	total, err := models.GetReportListCount(condition, pars, "")
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
-	list, err := models.GetReportList(condition, pars, "", startSize, pageSize)
+	list, err := models.GetReportList(condition, pars, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
 
-	listLen := len(list)
-	if listLen > 0 {
-		for i := 0; i < listLen; i++ {
-			list[i].Content = html.UnescapeString(list[i].Content)
-			list[i].ContentSub = html.UnescapeString(list[i].ContentSub)
-		}
+	results := make([]*models.ReportItem, 0)
+	for _, v := range list {
+		t := models.FormatReport2Item(v)
+		results = append(results, t)
 	}
 
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp := new(models.ReportListResp)
 	resp.Paging = page
-	resp.List = list
+	resp.List = results
 	br.Ret = 200
-	
 	br.Msg = "获取成功"
 	br.Data = resp
 }
 
-// PublishReport
-// @Title 审核报告接口
-// @Description 发布报告
-// @Param	request	body models.PublishReq true "type json string"
-// @Success 200 Ret=200 发布成功
-// @router /publish [post]
-func (this *ReportController) PublishReport() {
+// Detail
+// @Title 获取报告详情接口
+// @Description 获取报告详情
+// @Param   ReportId  query  int  true  "报告ID"
+// @Success 200 {object} models.ReportItem
+// @router /detail [get]
+func (this *ReportController) Detail() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	var req models.PublishReq
-	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+
+	reportId, err := this.GetInt("ReportId")
 	if err != nil {
-		br.Msg = "参数解析异常!"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		br.Msg = "获取参数失败!"
+		br.ErrMsg = "获取参数失败,Err:" + err.Error()
 		return
 	}
-	reportIds := req.ReportIds
-	if reportIds == "" {
+	if reportId <= 0 {
 		br.Msg = "参数错误"
-		br.ErrMsg = "参数错误,报告id不可为空"
 		return
 	}
-	if req.State != 3 && req.State != 4 {
-		br.Msg = "参数有误"
-		return
-	}
-
-	reportArr := strings.Split(reportIds, ",")
-	for _, v := range reportArr {
-		vint, err := strconv.Atoi(v)
-		if err != nil {
-			br.Msg = "参数错误"
-			br.ErrMsg = "参数错误,Err:" + err.Error()
-			return
-		}
-		report, err := models.GetReportById(vint)
-		if err != nil {
-			br.Msg = "获取报告信息失败"
-			br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
-			return
-		}
-		if report == nil {
-			br.Msg = "报告不存在"
-			return
-		}
-		if report.State != 2 {
-			br.Msg = "报告状态错误"
-			br.ErrMsg = "报告状态非待审核状态,Err:" + err.Error()
-			return
-		}
-		publishTime := time.Now()
-		var tmpErr error
-		if report.Content == "" {
-			br.Msg = "报告内容为空"
-			br.ErrMsg = "报告内容为空,report_id:" + strconv.Itoa(report.Id)
-			return
-		}
-		if tmpErr = models.PublishReportById(report.Id, req.State, publishTime); tmpErr != nil {
-			br.Msg = "报告审核失败"
-			br.ErrMsg = "报告审核失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
+	item, err := models.GetReportById(reportId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "报告已被删除"
 			return
 		}
-		recordItem := &models.ReportStateRecord{
-			ReportId:   vint,
-			ReportType: 1,
-			State:      req.State,
-			CreateTime: time.Now(),
-		}
-		go func() {
-			_, _ = models.AddReportStateRecord(recordItem)
-		}()
-
-		go func() {
-			// 更新报告Es
-			_ = services.UpdateReportEs(report.Id, req.State)
-		}()
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
 	}
+	resp := models.FormatReport2Item(item)
 
-	if req.State == 3 {
-		br.Msg = "驳回成功"
-	} else {
-		br.Msg = "审批通过"
-	}
+	br.Data = resp
 	br.Ret = 200
-	
-	br.Msg = "审批成功"
+	br.Msg = "获取成功"
 }
 
-// Detail
-// @Title 获取报告详情接口
-// @Description 获取报告详情
-// @Param	request	body models.ReportDetailReq true "type json string"
-// @Success 200 {object} models.Report
-// @router /detail [get]
-func (this *ReportController) Detail() {
+// Approve
+// @Title 审批
+// @Description 报告审批
+// @Param	request	body models.PublishReq true "type json string"
+// @Success 200 Ret=200 发布成功
+// @router /approve [post]
+func (this *ReportController) Approve() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-
-	reportId, err := this.GetInt("ReportId")
+	var req models.ReportApproveReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
-		br.Msg = "获取参数失败!"
-		br.ErrMsg = "获取参数失败,Err:" + err.Error()
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
-	if reportId <= 0 {
+	if req.ReportId <= 0 {
 		br.Msg = "参数错误"
+		br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
 		return
 	}
-	item, err := models.GetReportById(reportId)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
+
+	item, e := models.GetReportById(req.ReportId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
 			br.Msg = "报告已被删除"
 			return
 		}
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,Err:" + err.Error()
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取报告信息失败, Err:" + e.Error()
+		return
+	}
+	if item.State != models.ReportStateWaitApprove {
+		br.Msg = "报告状态有误"
+		br.ErrMsg = fmt.Sprintf("报告状态有误, State: %d", item.State)
+		return
+	}
+	if item.Content == "" {
+		br.Msg = "报告内容为空,请检查内容"
 		return
 	}
 
-	// 报告状态 2待审核 3已驳回 4已审批
-	if  !utils.InArrayByInt([]int{2,3,4}, item.State) {
-		br.Msg = "报告状态错误"
-		br.ErrMsg = "报告状态错误"
+	// 校验审批配置
+	confMap, e := models.GetBusinessConf()
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取审批配置失败, Err: " + e.Error()
+		return
+	}
+	if confMap[models.BusinessConfIsReportApprove] != "true" {
+		br.Msg = "未开启审批, 请开启后重新操作"
+		return
+	}
+	if confMap[models.BusinessConfReportApproveType] != models.BusinessConfReportApproveTypeOther {
+		br.Msg = "未开启第三方审批, 请开启后重新操作"
 		return
 	}
-	item.Content = html.UnescapeString(item.Content)
-	item.ContentSub = html.UnescapeString(item.ContentSub)
+
+	stateMap := map[bool]int{false: models.ReportStateRefused, true: models.ReportStatePass}
+	// 驳回
+	now := time.Now().Local()
+	if !req.Pass {
+		cols := []string{"State", "ModifyTime", "ApproveTime"}
+		item.State = stateMap[req.Pass]
+		item.ModifyTime = now
+		item.ApproveTime = now
+		if e = item.UpdateReport(cols); e != nil {
+			br.Msg = "审批失败"
+			br.ErrMsg = "报告审批驳回失败, Err: " + e.Error()
+			return
+		}
+	}
+
+	// 通过审批
+	if req.Pass {
+		cols := []string{"State", "ModifyTime", "ApproveTime", "PublishTime"}
+		item.State = stateMap[req.Pass]
+		item.ModifyTime = now
+		item.ApproveTime = now
+		item.PublishTime = now
+		if e = item.UpdateReport(cols); e != nil {
+			br.Msg = "审批失败"
+			br.ErrMsg = "报告审批通过失败, Err: " + e.Error()
+			return
+		}
+
+		// 更新报告Es
+		go func() {
+			_ = services.UpdateReportEs(req.ReportId, models.ReportStatePublished) // 注:状态用已发布的, 兼容以前的代码
+		}()
+	}
+
+	// 记录报告变更状态
+	go func() {
+		recordItem := &models.ReportStateRecord{
+			ReportId:   req.ReportId,
+			ReportType: models.ReportTypeChinese,
+			State:      item.State,
+			CreateTime: time.Now(),
+		}
+		_, _ = models.AddReportStateRecord(recordItem)
+	}()
 
 	br.Ret = 200
-	
-	br.Msg = "获取成功"
-	br.Data = item
+	br.Msg = "审批成功"
 }

+ 96 - 130
controllers/smart_report_approval.go

@@ -5,9 +5,8 @@ import (
 	"eta/eta_hub/models"
 	"eta/eta_hub/services"
 	"eta/eta_hub/utils"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
-	"strconv"
-	"strings"
 	"time"
 )
 
@@ -21,14 +20,6 @@ type SmartReportController struct {
 // @Description 报告列表
 // @Param   PageSize			query	int		true	"每页数据条数"
 // @Param   CurrentIndex		query	int		true	"当前页页码"
-// @Param   TimeType			query	string	false	"筛选的时间类别: publish_time-发布时间, modify_time-更新时间"
-// @Param   StartDate			query   string  false	"开始时间"
-// @Param   EndDate				query   string  false	"结束时间"
-// @Param   Frequency			query   string  false	"频度"
-// @Param   ClassifyIdFirst		query	int		false	"一级分类ID"
-// @Param   ClassifyIdSecond	query	int		false	"二级分类ID"
-// @Param   State				query	int		false	"发布状态: 1-待发布; 2-已发布"
-// @Param   Keyword				query	string	false	"搜索关键词"
 // @Success 200 {object} models.SmartReportListResp
 // @router /list [get]
 func (this *SmartReportController) List() {
@@ -39,16 +30,8 @@ func (this *SmartReportController) List() {
 	}()
 
 	type SmartReportListReq struct {
-		PageSize         int    `form:"PageSize"`
-		CurrentIndex     int    `form:"CurrentIndex"`
-		TimeType         string `form:"TimeType"`
-		StartDate        string `form:"StartDate"`
-		EndDate          string `form:"EndDate"`
-		Frequency        string `form:"Frequency"`
-		ClassifyIdFirst  int    `form:"ClassifyIdFirst"`
-		ClassifyIdSecond int    `form:"ClassifyIdSecond"`
-		State            int    `form:"State"`
-		Keyword          string `form:"Keyword"`
+		PageSize     int `form:"PageSize"`
+		CurrentIndex int `form:"CurrentIndex"`
 	}
 	params := new(SmartReportListReq)
 	if e := this.ParseForm(params); e != nil {
@@ -56,52 +39,10 @@ func (this *SmartReportController) List() {
 		br.ErrMsg = "入参解析失败, Err: " + e.Error()
 		return
 	}
-	if params.TimeType == "" {
-		params.TimeType = "publish_time"
-	}
-	if params.TimeType != "publish_time" && params.TimeType != "modify_time" {
-		br.Msg = "请选择正确的时间类型"
-		return
-	}
-	// 更新时间指的是内容更新时间
-	if params.TimeType == "modify_time" {
-		params.TimeType = "content_modify_time"
-	}
 
 	var condition string
 	var pars []interface{}
-	// 筛选项
-	{
-		//keyword := strings.TrimSpace(params.Keyword)
-		//if keyword != "" {
-		//	kw := fmt.Sprint("%", keyword, "%")
-		//	condition += fmt.Sprintf(` AND (title LIKE ? OR admin_real_name LIKE ? OR last_modify_admin_name LIKE ?)`)
-		//	pars = append(pars, kw, kw, kw)
-		//}
-		//if params.StartDate != "" && params.EndDate != "" {
-		//	st := fmt.Sprintf("%s 00:00:00", params.StartDate)
-		//	ed := fmt.Sprintf("%s 23:59:59", params.EndDate)
-		//	condition += fmt.Sprintf(` AND %s >= ? AND %s <= ?`, params.TimeType, params.TimeType)
-		//	pars = append(pars, st, ed)
-		//}
-		//if params.Frequency != "" {
-		//	condition += ` AND frequency = ?`
-		//	pars = append(pars, params.Frequency)
-		//}
-		//if params.ClassifyIdFirst > 0 {
-		//	condition += ` AND classify_id_first = ?`
-		//	pars = append(pars, params.ClassifyIdFirst)
-		//}
-		//if params.ClassifyIdSecond > 0 {
-		//	condition += ` AND classify_id_second = ?`
-		//	pars = append(pars, params.ClassifyIdSecond)
-		//}
-		//if params.State > 0 {
-		//	condition += ` AND state = ?`
-		//	pars = append(pars, params.State)
-		//}
-	}
-	condition += ` AND state <> 1 `
+
 	resp := new(models.SmartReportListResp)
 	reportOB := new(models.SmartReport)
 	total, e := reportOB.GetCountByCondition(condition, pars)
@@ -129,20 +70,17 @@ func (this *SmartReportController) List() {
 	}
 	startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
 
-	// 列表查询过滤掉富文本内容
-	fields := []string{
-		"smart_report_id", "report_code", "classify_id_first", "classify_name_first", "classify_id_second", "classify_name_second", "add_type",
-		"title", "abstract", "author", "frequency", "stage", "video_url", "video_name", "video_play_seconds", "video_size", "detail_img_url", "detail_pdf_url",
-		"admin_id", "admin_real_name", "state", "publish_time", "pre_publish_time", "pre_msg_send", "msg_is_send", "msg_send_time", "create_time", "modify_time",
-		"last_modify_admin_id", "last_modify_admin_name", "content_modify_time", "pv", "uv",
-	}
-	list, e := reportOB.GetPageItemsByCondition(condition, pars, fields, "", startSize, params.PageSize)
+	list, e := reportOB.GetPageItemsByCondition(condition, pars, []string{}, "", startSize, params.PageSize)
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取报告分页列表失败, Err:" + e.Error()
 		return
 	}
-	resp.List = list
+	resp.List = make([]*models.SmartReportItem, 0)
+	for _, v := range list {
+		t := models.FormatSmartReport2Item(v)
+		resp.List = append(resp.List, t)
+	}
 
 	page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
 	resp.Paging = page
@@ -175,19 +113,13 @@ func (this *SmartReportController) Detail() {
 	item, e := ob.GetItemById(reportId)
 	if e != nil {
 		if e.Error() == utils.ErrNoRow() {
-			br.Msg = "报告不存在, 请刷新页面"
+			br.Msg = "报告已被删除"
 			return
 		}
 		br.Msg = "操作失败"
 		br.ErrMsg = "获取研报失败, Err: " + e.Error()
 		return
 	}
-	// 报告状态 2待审核 3已驳回 4已审批
-	if !utils.InArrayByInt([]int{models.SmartReportStatePublished, models.SmartReportStateRejected, models.SmartReportStateApprovaled}, item.State) {
-		br.Msg = "报告状态错误"
-		br.ErrMsg = "报告状态错误"
-		return
-	}
 	resp := models.FormatSmartReport2Item(item)
 
 	br.Ret = 200
@@ -195,86 +127,120 @@ func (this *SmartReportController) Detail() {
 	br.Data = resp
 }
 
-// Publish
-// @Title 发布/取消发布
-// @Description 发布/取消发布
-// @Param	request	body models.SmartReportPublishReq true "type json string"
+// Approve
+// @Title 审批
+// @Description 审批报告
+// @Param	request	body models.SmartReportApproveReq true "type json string"
 // @Success 200 string "操作成功"
-// @router /publish [post]
-func (this *SmartReportController) Publish() {
+// @router /approve [post]
+func (this *SmartReportController) Approve() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
 
-	var req models.SmartReportPublishReq
+	var req models.SmartReportApproveReq
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
 		br.Msg = "参数解析异常!"
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
-	if req.SmartReportIds == "" {
-		br.Msg = "参数有误"
-		br.ErrMsg = "报告ID为空"
-		return
-	}
-	if req.PublishState != models.SmartReportStateRejected && req.PublishState != models.SmartReportStateApprovaled {
-		br.Msg = "参数有误"
+	if req.ReportId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = fmt.Sprintf("参数有误, SmartReportId: %d", req.ReportId)
 		return
 	}
 
-	reportArr := strings.Split(req.SmartReportIds, ",")
-	for _, v := range reportArr {
-		vint, err := strconv.Atoi(v)
-		if err != nil {
-			br.Msg = "参数错误"
-			br.ErrMsg = "参数错误,Err:" + err.Error()
-			return
-		}
-		ob := new(models.SmartReport)
-		item, e := ob.GetItemById(vint)
-		if e != nil {
-			if e.Error() == utils.ErrNoRow() {
-				br.Msg = "报告不存在, 请刷新页面"
-				return
-			}
-			br.Msg = "操作失败"
-			br.ErrMsg = "获取研报失败, Err: " + e.Error()
+	ob := new(models.SmartReport)
+	item, e := ob.GetItemById(req.ReportId)
+	if e != nil {
+		if e.Error() == utils.ErrNoRow() {
+			br.Msg = "报告已被删除"
 			return
 		}
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取智能研报失败, Err: " + e.Error()
+		return
+	}
+	if item.State != models.ReportStateWaitApprove {
+		br.Msg = "报告状态有误"
+		br.ErrMsg = fmt.Sprintf("报告状态有误, State: %d", item.State)
+		return
+	}
+	if item.Content == "" {
+		br.Msg = "报告内容为空,请检查内容"
+		return
+	}
 
-		cols := []string{"State", "ModifyTime"}
-		item.State = req.PublishState
-		item.ModifyTime = time.Now().Local()
+	// 校验审批配置
+	confMap, e := models.GetBusinessConf()
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取审批配置失败, Err: " + e.Error()
+		return
+	}
+	if confMap[models.BusinessConfIsReportApprove] != "true" {
+		br.Msg = "未开启审批, 请开启后重新操作"
+		return
+	}
+	if confMap[models.BusinessConfReportApproveType] != models.BusinessConfReportApproveTypeOther {
+		br.Msg = "未开启第三方审批, 请开启后重新操作"
+		return
+	}
 
+	stateMap := map[bool]int{false: models.ReportStateRefused, true: models.ReportStatePass}
+	// 驳回
+	now := time.Now().Local()
+	if !req.Pass {
+		cols := []string{"State", "ModifyTime", "ApproveTime"}
+		item.State = stateMap[req.Pass]
+		item.ModifyTime = now
+		item.ApproveTime = now
 		if e = item.Update(cols); e != nil {
-			br.Msg = "操作失败"
-			br.ErrMsg = "更新研报失败, Err: " + e.Error()
+			br.Msg = "审批失败"
+			br.ErrMsg = "报告审批驳回失败, Err: " + e.Error()
 			return
 		}
+	}
 
-		recordItem := &models.ReportStateRecord{
-			ReportId:   vint,
-			ReportType: 2,
-			State:      req.PublishState,
-			CreateTime: time.Now(),
+	// 通过审批
+	if req.Pass {
+		cols := []string{"State", "ModifyTime", "ApproveTime", "PublishTime"}
+		item.State = stateMap[req.Pass]
+		item.ModifyTime = now
+		item.ApproveTime = now
+		item.PublishTime = now
+		if e = item.Update(cols); e != nil {
+			br.Msg = "审批失败"
+			br.ErrMsg = "报告审批通过失败, Err: " + e.Error()
+			return
 		}
-		go func() {
-			_, _ = models.AddReportStateRecord(recordItem)
-		}()
 
-		// ES更新报告
+		// 写入队列
+		var queue models.Report2ImgQueueReq
+		queue.ReportType = 2
+		queue.ReportCode = item.ReportCode
+		_ = utils.Rc.LPush(utils.CACHE_CREATE_REPORT_IMGPDF_QUEUE, queue)
+
+		// 更新报告ES
 		go func() {
-			_ = services.SmartReportElasticUpsert(item.SmartReportId, req.PublishState)
+			_ = services.SmartReportElasticUpsert(item.SmartReportId, models.ReportStatePublished)
 		}()
 	}
 
-	if req.PublishState == models.SmartReportStateRejected {
-		br.Msg = "驳回成功"
-	} else {
-		br.Msg = "审批通过"
-	}
+	// 记录报告变更状态
+	go func() {
+		recordItem := &models.ReportStateRecord{
+			ReportId:   req.ReportId,
+			ReportType: models.ReportTypeSmart,
+			State:      item.State,
+			CreateTime: time.Now(),
+		}
+		_, _ = models.AddReportStateRecord(recordItem)
+	}()
+
 	br.Ret = 200
+	br.Msg = "审批成功"
 }

+ 64 - 0
models/business_conf.go

@@ -0,0 +1,64 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"html"
+	"time"
+)
+
+const (
+	BusinessConfUseXf             = "UseXf"
+	BusinessConfXfAppid           = "XfAppid"
+	BusinessConfXfApiKey          = "XfApiKey"
+	BusinessConfXfApiSecret       = "XfApiSecret"
+	BusinessConfXfVcn             = "XfVcn"
+	BusinessConfEnPptCoverImgs    = "EnPptCoverImgs"
+	BusinessConfIsReportApprove   = "IsReportApprove"
+	BusinessConfReportApproveType = "ReportApproveType"
+)
+
+const (
+	BusinessConfReportApproveTypeEta   = "eta"
+	BusinessConfReportApproveTypeOther = "other"
+)
+
+// BusinessConf 商户配置表
+type BusinessConf struct {
+	Id         int    `orm:"column(id);pk"`
+	ConfKey    string `description:"配置Key"`
+	ConfVal    string `description:"配置值"`
+	ValType    int    `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
+	Necessary  int    `description:"是否必填:0-否;1-是"`
+	Remark     string `description:"备注"`
+	CreateTime time.Time
+}
+
+// GetBusinessConf 获取商家配置
+func GetBusinessConf() (list map[string]string, err error) {
+	list = make(map[string]string)
+
+	var items []*BusinessConf
+	o := orm.NewOrm()
+	sql := `SELECT * FROM business_conf`
+	_, err = o.Raw(sql).QueryRows(&items)
+	if err != nil {
+		return
+	}
+
+	for _, v := range items {
+		if v.ValType == 4 {
+			list[v.ConfKey] = html.UnescapeString(v.ConfVal)
+			continue
+		}
+		list[v.ConfKey] = v.ConfVal
+	}
+	return
+}
+
+func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
+	err = o.Raw(sql, key).QueryRow(&item)
+	return
+}

+ 1 - 0
models/db.go

@@ -38,6 +38,7 @@ func init() {
 	// 注册对象
 	orm.RegisterModel(
 		new(Report),
+		new(EnglishReport),
 		new(SmartReport),
 		new(ReportStateRecord),
 		new(data_manage.EdbSource),

+ 186 - 0
models/english_report.go

@@ -0,0 +1,186 @@
+package models
+
+import (
+	"eta/eta_hub/utils"
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"strings"
+	"time"
+)
+
+type EnglishReport struct {
+	Id                 int       `orm:"column(id)" description:"报告Id"`
+	AddType            int       `description:"新增方式:1:新增报告,2:继承报告"`
+	ClassifyIdFirst    int       `description:"一级分类id"`
+	ClassifyNameFirst  string    `description:"一级分类名称"`
+	ClassifyIdSecond   int       `description:"二级分类id"`
+	ClassifyNameSecond string    `description:"二级分类名称"`
+	Title              string    `description:"标题"`
+	Abstract           string    `description:"摘要"`
+	Author             string    `description:"作者"`
+	Frequency          string    `description:"频度"`
+	CreateTime         time.Time `description:"创建时间"`
+	ModifyTime         time.Time `description:"修改时间"`
+	State              int       `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
+	PublishTime        time.Time `description:"发布时间"`
+	PrePublishTime     time.Time `description:"预发布时间"`
+	Stage              int       `description:"期数"`
+	Content            string    `description:"内容"`
+	VideoUrl           string    `description:"音频文件URL"`
+	VideoName          string    `description:"音频文件名称"`
+	VideoPlaySeconds   string    `description:"音频播放时长"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
+	ContentSub         string    `description:"内容前两个章节"`
+	ReportCode         string    `description:"报告唯一编码"`
+	Pv                 int       `description:"Pv"`
+	PvEmail            int       `description:"邮箱PV"`
+	EmailState         int       `description:"群发邮件状态: 0-未发送; 1-已发送"`
+	Overview           string    `description:"英文概述部分"`
+	KeyTakeaways       string    `description:"关键点"`
+	FromReportId       int       `description:"继承的报告ID(英文策略报告ID)"`
+	AdminId            int       `description:"创建者账号"`
+	AdminRealName      string    `description:"创建者姓名"`
+	ApproveTime        time.Time `description:"审批时间"`
+	ApproveId          int       `description:"审批ID"`
+}
+
+func (m *EnglishReport) Update(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(m, cols...)
+	return
+}
+
+func (m *EnglishReport) GetItemById(id int) (item *EnglishReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
+	err = o.Raw(sql, id).QueryRow(&item)
+	return
+}
+
+func (m *EnglishReport) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM english_report WHERE 1=1 %s`, condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *EnglishReport) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EnglishReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	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 english_report WHERE 1=1 %s %s`, fields, condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+func (m *EnglishReport) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EnglishReport, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM english_report WHERE 1=1 %s %s LIMIT ?,?`, fields, condition, order)
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+type EnglishReportItem struct {
+	Id                 int    `description:"报告Id"`
+	ReportCode         string `description:"报告唯一编码"`
+	ClassifyIdFirst    int    `description:"一级分类id"`
+	ClassifyNameFirst  string `description:"一级分类名称"`
+	ClassifyIdSecond   int    `description:"二级分类id"`
+	ClassifyNameSecond string `description:"二级分类名称"`
+	Title              string `description:"标题"`
+	Abstract           string `description:"摘要"`
+	Author             string `description:"作者"`
+	Frequency          string `description:"频度"`
+	State              int    `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
+	Stage              int    `description:"期数"`
+	Content            string `description:"内容"`
+	VideoUrl           string `description:"音频文件URL"`
+	VideoName          string `description:"音频文件名称"`
+	VideoPlaySeconds   string `description:"音频播放时长"`
+	VideoSize          string `description:"音频文件大小,单位M"`
+	AdminId            int    `description:"创建者账号"`
+	AdminRealName      string `description:"创建者姓名"`
+	ApproveTime        string `description:"审批时间"`
+	PublishTime        string `description:"发布时间"`
+	CreateTime         string `description:"创建时间"`
+	ModifyTime         string `description:"修改时间"`
+}
+
+func FormatEnglishReport2Item(origin *EnglishReport) (item *EnglishReportItem) {
+	if origin == nil {
+		return
+	}
+	item = new(EnglishReportItem)
+	item.Id = origin.Id
+	item.ReportCode = origin.ReportCode
+	item.ClassifyIdFirst = origin.ClassifyIdFirst
+	item.ClassifyNameFirst = origin.ClassifyNameFirst
+	item.ClassifyIdSecond = origin.ClassifyIdSecond
+	item.ClassifyNameSecond = origin.ClassifyNameSecond
+	item.Title = origin.Title
+	item.Abstract = origin.Abstract
+	item.Author = origin.Author
+	item.Frequency = origin.Frequency
+	item.State = origin.State
+	item.Stage = origin.Stage
+	item.Content = origin.Content
+	item.VideoUrl = origin.VideoUrl
+	item.VideoName = origin.VideoName
+	item.VideoPlaySeconds = origin.VideoPlaySeconds
+	item.VideoSize = origin.VideoSize
+	item.AdminId = origin.AdminId
+	item.AdminRealName = origin.AdminRealName
+	item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
+	item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
+	item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
+	item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
+	return
+}
+
+type EnglishReportListResp struct {
+	List   []*EnglishReportItem
+	Paging *paging.PagingItem `description:"分页数据"`
+}
+
+// EnglishReportApproveReq 英文研报审批请求体
+type EnglishReportApproveReq struct {
+	ReportId int  `description:"报告ID"`
+	Pass     bool `description:"是否通过审批"`
+}
+
+type ElasticEnglishReportDetail struct {
+	Id                 string `description:"报告id或者线上路演Id"`
+	ReportId           int    `description:"报告id"`
+	VideoId            int    `description:"线上路演Id"`
+	ClassifyIdFirst    int    `description:"一级分类id"`
+	ClassifyNameFirst  string `description:"一级分类名称"`
+	ClassifyIdSecond   int    `description:"二级分类id"`
+	ClassifyNameSecond string `description:"二级分类名称"`
+	StageStr           string `description:"报告期数"`
+	Title              string `description:"标题"`
+	Abstract           string `description:"摘要"`
+	Author             string `description:"作者"`
+	Frequency          string `description:"频度"`
+	PublishState       int    `description:"状态:1:未发布,2:已发布"`
+	BodyContent        string `description:"内容"`
+	ContentSub         string `description:"前两段内容"`
+	CreateTime         string `description:"创建时间"`
+	PublishTime        string `description:"发布时间"`
+	ReportCode         string `description:"报告唯一编码"`
+	Overview           string `description:"英文概述部分"`
+}

+ 109 - 18
models/report.go

@@ -4,10 +4,38 @@ import (
 	"eta/eta_hub/utils"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"html"
 	"strings"
 	"time"
 )
 
+// 报告状态
+const (
+	ReportStateUnpublished = 1 // 未发布
+	ReportStatePublished   = 2 // 已发布
+	ReportStateWaitSubmit  = 3 // 待提交
+	ReportStateWaitApprove = 4 // 审批中
+	ReportStateRefused     = 5 // 已驳回
+	ReportStatePass        = 6 // 已通过
+)
+
+// 报告操作
+const (
+	ReportOperateAdd           = 1 // 新增报告
+	ReportOperateEdit          = 2 // 编辑报告
+	ReportOperatePublish       = 3 // 发布报告
+	ReportOperateCancelPublish = 4 // 取消发布报告
+	ReportOperateSubmitApprove = 5 // 提交审批
+	ReportOperateCancelApprove = 6 // 撤回审批
+)
+
+// 报告类型
+const (
+	ReportTypeChinese = 1 // 中文研报
+	ReportTypeEnglish = 2 // 英文研报
+	ReportTypeSmart   = 3 // 智能研报
+)
+
 type Report struct {
 	Id                 int       `orm:"column(id)" description:"报告Id"`
 	AddType            int       `json:"-" description:"新增方式:1:新增报告,2:继承报告"`
@@ -19,10 +47,7 @@ type Report struct {
 	Abstract           string    `description:"摘要"`
 	Author             string    `description:"作者"`
 	Frequency          string    `description:"频度"`
-	CreateTime         string    `description:"创建时间"`
-	ModifyTime         time.Time `description:"修改时间"`
 	State              int       `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
-	PublishTime        time.Time `description:"发布时间"`
 	Stage              int       `description:"期数"`
 	MsgIsSend          int       `json:"-" description:"消息是否已发送,0:否,1:是"`
 	ThsMsgIsSend       int       `json:"-" description:"客户群消息是否已发送,0:否,1:是"`
@@ -40,10 +65,14 @@ type Report struct {
 	MsgSendTime        time.Time `json:"-" description:"模版消息发送时间"`
 	AdminId            int       `description:"创建者账号"`
 	AdminRealName      string    `description:"创建者姓名"`
+	ApproveTime        time.Time `description:"审批时间"`
+	PublishTime        time.Time `description:"发布时间"`
+	CreateTime         time.Time `description:"创建时间"`
+	ModifyTime         time.Time `description:"修改时间"`
 }
 
 type ReportListResp struct {
-	List   []*Report
+	List   []*ReportItem
 	Paging *paging.PagingItem `description:"分页数据"`
 }
 
@@ -65,21 +94,13 @@ func GetReportListCount(condition string, pars []interface{}, companyType string
 	return
 }
 
-func GetReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*Report, err error) {
+func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*Report, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	//产品权限
-	companyTypeSqlStr := ``
-	if companyType == "ficc" {
-		companyTypeSqlStr = " AND classify_id_first != 40 "
-	} else if companyType == "权益" {
-		companyTypeSqlStr = " AND classify_id_first = 40 "
-	}
-
-	sql := `SELECT * FROM report WHERE 1=1  ` + companyTypeSqlStr
+	sql := `SELECT * FROM report WHERE 1=1 `
 	if condition != "" {
 		sql += condition
 	}
-	sql += `ORDER BY state ASC, modify_time DESC LIMIT ?,?`
+	sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
@@ -342,8 +363,8 @@ func GetReportByReportId(reportId int) (item *Report, err error) {
 // 发布报告
 func PublishReportById(reportId, state int, publishTime time.Time) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `UPDATE report SET state = ?, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
-	_, err = o.Raw(sql, state,publishTime, reportId).Exec()
+	sql := `UPDATE report SET state = ?, publish_time = ?, pre_publish_time = null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
+	_, err = o.Raw(sql, state, publishTime, reportId).Exec()
 	return
 }
 
@@ -411,4 +432,74 @@ type ElasticReportDetail struct {
 	ClassifyNameSecond string `description:"二级分类名称"`
 	Categories         string `description:"关联的品种名称(包括品种别名)"`
 	StageStr           string `description:"报告期数"`
-}
+}
+
+type ReportItem struct {
+	Id                 int    `description:"报告Id"`
+	ReportCode         string `description:"报告唯一编码"`
+	ClassifyIdFirst    int    `description:"一级分类id"`
+	ClassifyNameFirst  string `description:"一级分类名称"`
+	ClassifyIdSecond   int    `description:"二级分类id"`
+	ClassifyNameSecond string `description:"二级分类名称"`
+	Title              string `description:"标题"`
+	Abstract           string `description:"摘要"`
+	Author             string `description:"作者"`
+	Frequency          string `description:"频度"`
+	State              int    `description:"状态:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
+	Stage              int    `description:"期数"`
+	Content            string `description:"内容"`
+	VideoUrl           string `description:"音频文件URL"`
+	VideoName          string `description:"音频文件名称"`
+	VideoPlaySeconds   string `description:"音频播放时长"`
+	VideoSize          string `description:"音频文件大小,单位M"`
+	AdminId            int    `description:"创建者账号"`
+	AdminRealName      string `description:"创建者姓名"`
+	PublishTime        string `description:"发布时间"`
+	ApproveTime        string `description:"审批时间"`
+	CreateTime         string `description:"创建时间"`
+	ModifyTime         string `description:"修改时间"`
+}
+
+func FormatReport2Item(origin *Report) (item *ReportItem) {
+	if origin == nil {
+		return
+	}
+	item = new(ReportItem)
+	item.Id = origin.Id
+	item.ReportCode = origin.ReportCode
+	item.ClassifyIdFirst = origin.ClassifyIdFirst
+	item.ClassifyNameFirst = origin.ClassifyNameFirst
+	item.ClassifyIdSecond = origin.ClassifyIdSecond
+	item.ClassifyNameSecond = origin.ClassifyNameSecond
+	item.Title = origin.Title
+	item.Abstract = origin.Abstract
+	item.Author = origin.Author
+	item.Frequency = origin.Frequency
+	item.State = origin.State
+	item.Stage = origin.Stage
+	item.Content = html.UnescapeString(origin.Content)
+	item.VideoUrl = origin.VideoUrl
+	item.VideoName = origin.VideoName
+	item.VideoPlaySeconds = origin.VideoPlaySeconds
+	item.VideoSize = origin.VideoSize
+	item.AdminId = origin.AdminId
+	item.AdminRealName = origin.AdminRealName
+	item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
+	item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
+	item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
+	item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
+	return
+}
+
+// ReportApproveReq 报告审批请求体
+type ReportApproveReq struct {
+	ReportId int  `description:"报告ID"`
+	Pass     bool `description:"是否通过审批"`
+}
+
+// UpdateReport 更新报告
+func (m *Report) UpdateReport(cols []string) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Update(m, cols...)
+	return
+}

+ 13 - 29
models/smart_report.go

@@ -10,13 +10,6 @@ import (
 	"time"
 )
 
-const (
-	SmartReportStateWaitPublish = 1
-	SmartReportStatePublished   = 2
-	SmartReportStateRejected   = 3
-	SmartReportStateApprovaled   = 4
-)
-
 // SmartReport 智能研报
 type SmartReport struct {
 	SmartReportId       int       `orm:"column(smart_report_id);pk" description:"智能研报ID"`
@@ -53,6 +46,7 @@ type SmartReport struct {
 	MsgSendTime         time.Time `json:"-" description:"模版消息发送时间"`
 	DetailImgUrl        string    `json:"-" description:"报告详情长图地址"`
 	DetailPdfUrl        string    `json:"-" description:"报告详情PDF地址"`
+	ApproveTime         time.Time `description:"审批时间"`
 	CreateTime          time.Time `description:"创建时间"`
 	ModifyTime          time.Time `description:"修改时间"`
 }
@@ -138,7 +132,7 @@ func (m *SmartReport) GetItemsByCondition(condition string, pars []interface{},
 	if len(fieldArr) == 0 {
 		fields = `*`
 	}
-	order := `ORDER BY create_time DESC`
+	order := `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC`
 	if orderRule != "" {
 		order = ` ORDER BY ` + orderRule
 	}
@@ -153,7 +147,7 @@ func (m *SmartReport) GetPageItemsByCondition(condition string, pars []interface
 	if len(fieldArr) == 0 {
 		fields = `*`
 	}
-	order := `ORDER BY create_time DESC`
+	order := `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC`
 	if orderRule != "" {
 		order = ` ORDER BY ` + orderRule
 	}
@@ -177,15 +171,12 @@ type SmartReportItem struct {
 	ClassifyNameFirst   string  `description:"一级分类名称"`
 	ClassifyIdSecond    int     `description:"二级分类ID"`
 	ClassifyNameSecond  string  `description:"二级分类名称"`
-	AddType             int     `json:"-" description:"新增方式:1-新增报告;2-继承报告"`
 	Title               string  `description:"标题"`
 	Abstract            string  `description:"摘要"`
 	Author              string  `description:"作者"`
 	Frequency           string  `description:"频度"`
 	Stage               int     `description:"期数"`
 	Content             string  `description:"内容"`
-	ContentSub          string  `description:"内容前两个章节"`
-	ContentStruct       string  `description:"内容组件"`
 	VideoUrl            string  `description:"音频文件URL"`
 	VideoName           string  `description:"音频文件名称"`
 	VideoPlaySeconds    float64 `description:"音频播放时长"`
@@ -195,19 +186,13 @@ type SmartReportItem struct {
 	LastModifyAdminId   int     `description:"最后更新人ID"`
 	LastModifyAdminName string  `description:"最后更新人姓名"`
 	ContentModifyTime   string  `description:"内容更新时间"`
-	Pv                  int     `json:"-" description:"pv"`
-	Uv                  int     `json:"-" description:"uv"`
 	State               int     `description:"发布状态:1-待发布;2-已发布"`
 	PublishTime         string  `description:"发布时间"`
-	PrePublishTime      string  `description:"预发布时间"`
-	MsgIsSend           int     `json:"-" description:"消息是否已发送:0-否;1-是"`
-	MsgSendTime         string  `json:"-" description:"模版消息发送时间"`
 	DetailImgUrl        string  `description:"报告详情长图地址"`
 	DetailPdfUrl        string  `description:"报告详情PDF地址"`
+	ApproveTime         string  `description:"审批时间"`
 	CreateTime          string  `description:"创建时间"`
 	ModifyTime          string  `description:"修改时间"`
-	CanEdit             bool    `json:"-" description:"是否可编辑"`
-	Editor              string  `json:"-" description:"当前编辑人"`
 }
 
 // FormatSmartReport2Item 格式化智能研报数据格式
@@ -222,15 +207,12 @@ func FormatSmartReport2Item(origin *SmartReport) (item *SmartReportItem) {
 	item.ClassifyNameFirst = origin.ClassifyNameFirst
 	item.ClassifyIdSecond = origin.ClassifyIdSecond
 	item.ClassifyNameSecond = origin.ClassifyNameSecond
-	item.AddType = origin.AddType
 	item.Title = origin.Title
 	item.Abstract = origin.Abstract
 	item.Author = origin.Author
 	item.Frequency = origin.Frequency
 	item.Stage = origin.Stage
 	item.Content = html.UnescapeString(origin.Content)
-	item.ContentSub = html.UnescapeString(origin.ContentSub)
-	item.ContentStruct = html.UnescapeString(origin.ContentStruct)
 	item.VideoUrl = origin.VideoUrl
 	item.VideoName = origin.VideoName
 	item.VideoPlaySeconds = origin.VideoPlaySeconds
@@ -240,15 +222,11 @@ func FormatSmartReport2Item(origin *SmartReport) (item *SmartReportItem) {
 	item.LastModifyAdminId = origin.LastModifyAdminId
 	item.LastModifyAdminName = origin.LastModifyAdminName
 	item.ContentModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ContentModifyTime)
-	item.Pv = origin.Pv
-	item.Uv = origin.Uv
 	item.State = origin.State
 	item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
-	item.PrePublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PrePublishTime)
-	item.MsgIsSend = origin.MsgIsSend
-	item.MsgSendTime = utils.TimeTransferString(utils.FormatDateTime, origin.MsgSendTime)
 	item.DetailImgUrl = origin.DetailImgUrl
 	item.DetailPdfUrl = origin.DetailPdfUrl
+	item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
 	item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
 	item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
 	return
@@ -283,7 +261,7 @@ type SmartReportRemoveReq struct {
 // SmartReportPublishReq 审核智能研报请求体
 type SmartReportPublishReq struct {
 	SmartReportIds string `description:"智能研报ID,多个用英文逗号隔开"`
-	PublishState  int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
+	PublishState   int    `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
 }
 
 // SmartReportPrePublishReq 预发布智能研报请求体
@@ -319,7 +297,7 @@ type SmartReportMarkEditReq struct {
 
 // SmartReportListResp 智能研报
 type SmartReportListResp struct {
-	List   []*SmartReport
+	List   []*SmartReportItem
 	Paging *paging.PagingItem `description:"分页数据"`
 }
 
@@ -345,3 +323,9 @@ type Report2ImgQueueReq struct {
 	ReportType int    `description:"报告类型: 1-研报; 2-智能研报"`
 	ReportCode string `description:"报告唯一编码"`
 }
+
+// SmartReportApproveReq 智能研报审批请求体
+type SmartReportApproveReq struct {
+	ReportId int  `description:"报告ID"`
+	Pass     bool `description:"是否通过审批"`
+}

+ 36 - 9
routers/commentsRouter.go

@@ -133,7 +133,16 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"],
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:EnglishReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:EnglishReportController"],
+        beego.ControllerComments{
+            Method: "Approve",
+            Router: `/approve`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:EnglishReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:EnglishReportController"],
         beego.ControllerComments{
             Method: "Detail",
             Router: `/detail`,
@@ -142,9 +151,9 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"],
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:EnglishReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:EnglishReportController"],
         beego.ControllerComments{
-            Method: "ListReport",
+            Method: "List",
             Router: `/list`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),
@@ -153,14 +162,14 @@ func init() {
 
     beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"],
         beego.ControllerComments{
-            Method: "PublishReport",
-            Router: `/publish`,
+            Method: "Approve",
+            Router: `/approve`,
             AllowHTTPMethods: []string{"post"},
             MethodParams: param.Make(),
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"],
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"],
         beego.ControllerComments{
             Method: "Detail",
             Router: `/detail`,
@@ -169,7 +178,7 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"],
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:ReportController"],
         beego.ControllerComments{
             Method: "List",
             Router: `/list`,
@@ -180,13 +189,31 @@ func init() {
 
     beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"],
         beego.ControllerComments{
-            Method: "Publish",
-            Router: `/publish`,
+            Method: "Approve",
+            Router: `/approve`,
             AllowHTTPMethods: []string{"post"},
             MethodParams: param.Make(),
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:SmartReportController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_hub/controllers:StatisticAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_hub/controllers:StatisticAnalysisController"],
         beego.ControllerComments{
             Method: "ChartList",

+ 5 - 0
routers/router.go

@@ -19,6 +19,11 @@ func init() {
 				&controllers.ReportController{},
 			),
 		),
+		web.NSNamespace("/english_report",
+			web.NSInclude(
+				&controllers.EnglishReportController{},
+			),
+		),
 		web.NSNamespace("/smart_report",
 			web.NSInclude(
 				&controllers.SmartReportController{},

+ 73 - 2
services/elastic.go

@@ -3,6 +3,7 @@ package services
 import (
 	"context"
 	"eta/eta_hub/models"
+	"eta/eta_hub/services/alarm_msg"
 	"eta/eta_hub/utils"
 	"fmt"
 	"github.com/olivere/elastic/v7"
@@ -17,8 +18,6 @@ func NewClient() (client *elastic.Client, err error) {
 	return
 }
 
-
-
 // EsAddOrEditReport 新增编辑es报告
 func EsAddOrEditReport(indexName, docId string, item *models.ElasticReportDetail) (err error) {
 	defer func() {
@@ -79,6 +78,78 @@ func EsAddOrEditReport(indexName, docId string, item *models.ElasticReportDetail
 	return
 }
 
+// EsAddOrEditEnglishReport 新增编辑es英文报告
+func EsAddOrEditEnglishReport(indexName, docId string, item *models.ElasticEnglishReportDetail) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("EsAddOrEditEnglishReport Err:", err.Error())
+			go alarm_msg.SendAlarmMsg("新增编辑es英文报告 EsAddOrEditEnglishReport,Err:"+err.Error(), 3)
+		}
+	}()
+	client, err := NewClient()
+	if err != nil {
+		return
+	}
+	// 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{}{
+			"Id":                 item.Id,
+			"ReportId":           item.ReportId,
+			"VideoId":            item.VideoId,
+			"Title":              item.Title,
+			"Abstract":           item.Abstract,
+			"BodyContent":        item.BodyContent,
+			"PublishTime":        item.PublishTime,
+			"PublishState":       item.PublishState,
+			"Author":             item.Author,
+			"ClassifyIdFirst":    item.ClassifyIdFirst,
+			"ClassifyNameFirst":  item.ClassifyNameFirst,
+			"ClassifyIdSecond":   item.ClassifyIdSecond,
+			"ClassifyNameSecond": item.ClassifyNameSecond,
+			"CreateTime":         item.CreateTime,
+			"Overview":           item.Overview,
+			"ReportCode":         item.ReportCode,
+			"Frequency":          item.Frequency,
+			"StageStr":           item.StageStr,
+			"ContentSub":         item.ContentSub,
+		}).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
+}
+
 // EsAddOrEditSmartReport 新增编辑es智能研报
 func EsAddOrEditSmartReport(indexName, docId string, item *models.ElasticSmartReport) (err error) {
 	defer func() {

+ 47 - 0
services/english_report.go

@@ -0,0 +1,47 @@
+package services
+
+import (
+	"eta/eta_hub/models"
+	"eta/eta_hub/utils"
+	"fmt"
+	"html"
+	"strconv"
+)
+
+// UpdateEnglishReportEs 更新英文报告/章节Es
+func UpdateEnglishReportEs(reportId int, publishState int) (err error) {
+	if reportId <= 0 {
+		return
+	}
+	reportOb := new(models.EnglishReport)
+	reportInfo, err := reportOb.GetItemById(reportId)
+	if err != nil {
+		return
+	}
+	// 新增报告ES
+	esReport := &models.ElasticEnglishReportDetail{
+		Id:                 strconv.Itoa(reportInfo.Id),
+		ReportId:           reportInfo.Id,
+		Title:              reportInfo.Title,
+		Abstract:           reportInfo.Abstract,
+		BodyContent:        utils.TrimHtml(html.UnescapeString(reportInfo.Content)),
+		PublishTime:        utils.TimeTransferString(utils.FormatDateTime, reportInfo.PublishTime),
+		CreateTime:         utils.TimeTransferString(utils.FormatDateTime, reportInfo.CreateTime),
+		ReportCode:         reportInfo.ReportCode,
+		PublishState:       publishState,
+		Author:             reportInfo.Author,
+		Frequency:          reportInfo.Frequency,
+		ClassifyIdFirst:    reportInfo.ClassifyIdFirst,
+		ClassifyNameFirst:  reportInfo.ClassifyNameFirst,
+		ClassifyIdSecond:   reportInfo.ClassifyIdSecond,
+		ClassifyNameSecond: reportInfo.ClassifyNameSecond,
+		StageStr:           strconv.Itoa(reportInfo.Stage),
+		Overview:           utils.TrimHtml(html.UnescapeString(reportInfo.Overview)),
+		ContentSub:         utils.TrimHtml(html.UnescapeString(reportInfo.ContentSub)),
+	}
+	docId := fmt.Sprintf("%d", reportInfo.Id)
+	if err = EsAddOrEditEnglishReport(utils.EsEnglishReportIndexName, docId, esReport); err != nil {
+		return
+	}
+	return
+}

+ 4 - 2
utils/config.go

@@ -38,8 +38,9 @@ var (
 
 // ES索引配置
 var (
-	EsReportIndexName    string //研报ES索引
-	SmartReportIndexName string //智能研报ES索引
+	EsReportIndexName        string //研报ES索引
+	EsEnglishReportIndexName string //英文研报ES索引
+	SmartReportIndexName     string //智能研报ES索引
 )
 
 // ES配置
@@ -125,6 +126,7 @@ func init() {
 	// ES 索引
 	{
 		EsReportIndexName = config["es_report_index_name"]
+		EsEnglishReportIndexName = config["es_english_report_index_name"]
 		SmartReportIndexName = config["es_smart_report_index_name"]
 	}
 

+ 5 - 0
utils/constants.go

@@ -148,3 +148,8 @@ const (
 const (
 	ChartLibChartDetailFromUnicodeApi = "/v1/chart/detail" // 图表详情
 )
+
+// 缓存key
+const (
+	CACHE_CREATE_REPORT_IMGPDF_QUEUE = "eta_report:report_img_pdf_queue" // 生成报告长图PDF队列
+)