|
@@ -1,14 +1,7 @@
|
|
|
package controllers
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
"eta/eta_hub/models"
|
|
|
- "eta/eta_hub/services"
|
|
|
- "eta/eta_hub/utils"
|
|
|
- "fmt"
|
|
|
- "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
)
|
|
|
|
|
|
// SmartReportController 智能研报
|
|
@@ -37,86 +30,86 @@ func (this *SmartReportController) List() {
|
|
|
br.ErrMsg = "智能研报已合并到中文研报,请使用中文研报的接口"
|
|
|
return
|
|
|
|
|
|
- type SmartReportListReq struct {
|
|
|
- PageSize int `form:"PageSize"`
|
|
|
- CurrentIndex int `form:"CurrentIndex"`
|
|
|
- }
|
|
|
- params := new(SmartReportListReq)
|
|
|
- if e := this.ParseForm(params); e != nil {
|
|
|
- br.Msg = "获取失败"
|
|
|
- br.ErrMsg = "入参解析失败, Err: " + e.Error()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- var condition string
|
|
|
- var pars []interface{}
|
|
|
- keyword := this.GetString("Keyword")
|
|
|
- keyword = strings.TrimSpace(keyword)
|
|
|
- if keyword != "" {
|
|
|
- kw := fmt.Sprint("%", keyword, "%")
|
|
|
- condition += ` AND (title LIKE ? OR author LIKE ? OR admin_real_name LIKE ?) `
|
|
|
- pars = append(pars, kw, kw, kw)
|
|
|
- }
|
|
|
- state, _ := this.GetInt("State")
|
|
|
- if state > 0 {
|
|
|
- condition += ` AND state = ? `
|
|
|
- pars = append(pars, state)
|
|
|
- }
|
|
|
- admindId, _ := this.GetInt("AdminId")
|
|
|
- if admindId > 0 {
|
|
|
- condition += ` AND admin_id = ? `
|
|
|
- pars = append(pars, admindId)
|
|
|
- }
|
|
|
- classifyId, _ := this.GetInt("ClassifyId")
|
|
|
- if classifyId > 0 {
|
|
|
- condition += ` AND (classify_id_first = ? OR classify_id_second = ?) `
|
|
|
- pars = append(pars, classifyId, classifyId)
|
|
|
- }
|
|
|
-
|
|
|
- resp := new(models.SmartReportListResp)
|
|
|
- reportOB := new(models.SmartReport)
|
|
|
- total, e := reportOB.GetCountByCondition(condition, pars)
|
|
|
- if e != nil {
|
|
|
- br.Msg = "获取失败"
|
|
|
- br.ErrMsg = "获取报告总数失败, Err:" + e.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- if total <= 0 {
|
|
|
- page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
|
|
|
- resp.Paging = page
|
|
|
- br.Ret = 200
|
|
|
- br.Msg = "获取成功"
|
|
|
- br.Data = resp
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 分页列表
|
|
|
- var startSize int
|
|
|
- if params.PageSize <= 0 {
|
|
|
- params.PageSize = utils.PageSize20
|
|
|
- }
|
|
|
- if params.CurrentIndex <= 0 {
|
|
|
- params.CurrentIndex = 1
|
|
|
- }
|
|
|
- startSize = utils.StartIndex(params.CurrentIndex, 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 = 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
|
|
|
- br.Ret = 200
|
|
|
- br.Msg = "获取成功"
|
|
|
- br.Data = resp
|
|
|
+ //type SmartReportListReq struct {
|
|
|
+ // PageSize int `form:"PageSize"`
|
|
|
+ // CurrentIndex int `form:"CurrentIndex"`
|
|
|
+ //}
|
|
|
+ //params := new(SmartReportListReq)
|
|
|
+ //if e := this.ParseForm(params); e != nil {
|
|
|
+ // br.Msg = "获取失败"
|
|
|
+ // br.ErrMsg = "入参解析失败, Err: " + e.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //var condition string
|
|
|
+ //var pars []interface{}
|
|
|
+ //keyword := this.GetString("Keyword")
|
|
|
+ //keyword = strings.TrimSpace(keyword)
|
|
|
+ //if keyword != "" {
|
|
|
+ // kw := fmt.Sprint("%", keyword, "%")
|
|
|
+ // condition += ` AND (title LIKE ? OR author LIKE ? OR admin_real_name LIKE ?) `
|
|
|
+ // pars = append(pars, kw, kw, kw)
|
|
|
+ //}
|
|
|
+ //state, _ := this.GetInt("State")
|
|
|
+ //if state > 0 {
|
|
|
+ // condition += ` AND state = ? `
|
|
|
+ // pars = append(pars, state)
|
|
|
+ //}
|
|
|
+ //admindId, _ := this.GetInt("AdminId")
|
|
|
+ //if admindId > 0 {
|
|
|
+ // condition += ` AND admin_id = ? `
|
|
|
+ // pars = append(pars, admindId)
|
|
|
+ //}
|
|
|
+ //classifyId, _ := this.GetInt("ClassifyId")
|
|
|
+ //if classifyId > 0 {
|
|
|
+ // condition += ` AND (classify_id_first = ? OR classify_id_second = ?) `
|
|
|
+ // pars = append(pars, classifyId, classifyId)
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //resp := new(models.SmartReportListResp)
|
|
|
+ //reportOB := new(models.SmartReport)
|
|
|
+ //total, e := reportOB.GetCountByCondition(condition, pars)
|
|
|
+ //if e != nil {
|
|
|
+ // br.Msg = "获取失败"
|
|
|
+ // br.ErrMsg = "获取报告总数失败, Err:" + e.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //if total <= 0 {
|
|
|
+ // page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
|
|
|
+ // resp.Paging = page
|
|
|
+ // br.Ret = 200
|
|
|
+ // br.Msg = "获取成功"
|
|
|
+ // br.Data = resp
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //// 分页列表
|
|
|
+ //var startSize int
|
|
|
+ //if params.PageSize <= 0 {
|
|
|
+ // params.PageSize = utils.PageSize20
|
|
|
+ //}
|
|
|
+ //if params.CurrentIndex <= 0 {
|
|
|
+ // params.CurrentIndex = 1
|
|
|
+ //}
|
|
|
+ //startSize = utils.StartIndex(params.CurrentIndex, 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 = 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
|
|
|
+ //br.Ret = 200
|
|
|
+ //br.Msg = "获取成功"
|
|
|
+ //br.Data = resp
|
|
|
}
|
|
|
|
|
|
// Detail
|
|
@@ -136,29 +129,29 @@ func (this *SmartReportController) Detail() {
|
|
|
br.ErrMsg = "智能研报已合并到中文研报,请使用中文研报的接口"
|
|
|
return
|
|
|
|
|
|
- reportId, _ := this.GetInt("SmartReportId")
|
|
|
- if reportId <= 0 {
|
|
|
- br.Msg = "参数有误"
|
|
|
- br.ErrMsg = "报告ID有误"
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- ob := new(models.SmartReport)
|
|
|
- item, e := ob.GetItemById(reportId)
|
|
|
- if e != nil {
|
|
|
- if e.Error() == utils.ErrNoRow() {
|
|
|
- br.Msg = "报告已被删除"
|
|
|
- return
|
|
|
- }
|
|
|
- br.Msg = "操作失败"
|
|
|
- br.ErrMsg = "获取研报失败, Err: " + e.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- resp := models.FormatSmartReport2Item(item)
|
|
|
-
|
|
|
- br.Ret = 200
|
|
|
- br.Msg = "获取成功"
|
|
|
- br.Data = resp
|
|
|
+ //reportId, _ := this.GetInt("SmartReportId")
|
|
|
+ //if reportId <= 0 {
|
|
|
+ // br.Msg = "参数有误"
|
|
|
+ // br.ErrMsg = "报告ID有误"
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //ob := new(models.SmartReport)
|
|
|
+ //item, e := ob.GetItemById(reportId)
|
|
|
+ //if e != nil {
|
|
|
+ // if e.Error() == utils.ErrNoRow() {
|
|
|
+ // br.Msg = "报告已被删除"
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // br.Msg = "操作失败"
|
|
|
+ // br.ErrMsg = "获取研报失败, Err: " + e.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //resp := models.FormatSmartReport2Item(item)
|
|
|
+ //
|
|
|
+ //br.Ret = 200
|
|
|
+ //br.Msg = "获取成功"
|
|
|
+ //br.Data = resp
|
|
|
}
|
|
|
|
|
|
// Approve
|
|
@@ -178,107 +171,107 @@ func (this *SmartReportController) Approve() {
|
|
|
br.ErrMsg = "智能研报已合并到中文研报,请使用中文研报的接口"
|
|
|
return
|
|
|
|
|
|
- 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.ReportId <= 0 {
|
|
|
- br.Msg = "参数错误"
|
|
|
- br.ErrMsg = fmt.Sprintf("参数有误, SmartReportId: %d", req.ReportId)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- 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
|
|
|
- }
|
|
|
-
|
|
|
- // 校验审批配置
|
|
|
- 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
|
|
|
- }
|
|
|
-
|
|
|
- // 写入队列
|
|
|
- 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, models.ReportStatePublished)
|
|
|
- }()
|
|
|
- }
|
|
|
-
|
|
|
- // 记录报告变更状态
|
|
|
- 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 = "审批成功"
|
|
|
+ //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.ReportId <= 0 {
|
|
|
+ // br.Msg = "参数错误"
|
|
|
+ // br.ErrMsg = fmt.Sprintf("参数有误, SmartReportId: %d", req.ReportId)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //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
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //// 校验审批配置
|
|
|
+ //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
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 写入队列
|
|
|
+ // 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, models.ReportStatePublished)
|
|
|
+ // }()
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //// 记录报告变更状态
|
|
|
+ //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 = "审批成功"
|
|
|
}
|