|
@@ -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 = "审批成功"
|
|
|
}
|