package controllers import ( "eta/eta_hub/models" ) // SmartReportController 智能研报 type SmartReportController struct { BaseAuthController } // List // @Title 报告列表 // @Description 报告列表 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码" // @Param Keyword query string false "搜索关键词" // @Param State query int false "状态" // @Success 200 {object} models.SmartReportListResp // @router /list [get] func (this *SmartReportController) List() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() br.Ret = 301 br.Msg = "智能研报已合并到中文研报,请使用中文研报的接口" 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 } // Detail // @Title 详情 // @Description 详情 // @Param SmartReportId query int true "智能研报ID" // @Success 200 {object} models.SmartReportItem // @router /detail [get] func (this *SmartReportController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() br.Ret = 301 br.Msg = "智能研报已合并到中文研报,请使用中文研报的接口" 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 } // Approve // @Title 审批 // @Description 审批报告 // @Param request body models.SmartReportApproveReq true "type json string" // @Success 200 string "操作成功" // @router /approve [post] func (this *SmartReportController) Approve() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() br.Ret = 301 br.Msg = "智能研报已合并到中文研报,请使用中文研报的接口" 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 = "审批成功" }