123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- package fe_calendar
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/fe_calendar"
- "eta/eta_api/services"
- "eta/eta_api/utils"
- "fmt"
- "time"
- )
- // FeCalendarAiArticleController 外汇日历-AI数据点评数据点评
- type FeCalendarAiArticleController struct {
- controllers.BaseAuthController
- }
- // Detail
- // @Title AI数据点评详情
- // @Description AI数据点评详情
- // @Param FeCalendarAiArticleId query int true "数据点评ID"
- // @Success 200 {object} fe_calendar.FeCalendarAiArticle
- // @router /ai_article/detail [get]
- func (this *FeCalendarAiArticleController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- articleId, err := this.GetInt("FeCalendarAiArticleId")
- if err != nil || articleId <= 0 {
- br.Msg = "请提供有效的数据点评ID"
- return
- }
- articleOb := new(fe_calendar.FeCalendarAiArticle)
- if err := articleOb.GetByID(uint(articleId)); err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "数据点评不存在"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取AI数据点评详情失败, ArticleId: %d, Err: %s", articleId, err.Error())
- return
- }
- // 查询指标
- edbInfo, err := data_manage.GetEdbInfoById(articleOb.EdbInfoId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取指标失败, Err: " + err.Error()
- return
- }
- data := &fe_calendar.FeCalendarAiArticleDetailResp{
- FeCalendarAiArticleId: articleOb.FeCalendarAiArticleId,
- EdbName: edbInfo.EdbName,
- EdbInfoId: articleOb.EdbInfoId,
- EdbCode: edbInfo.EdbCode,
- Content: articleOb.Content,
- ModifyTime: articleOb.ModifyTime.Format(utils.FormatDateTime),
- }
- br.Data = data
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Create
- // @Title 创建AI数据点评
- // @Description 创建AI数据点评
- // @Param request body fe_calendar.FeCalendarAiArticle true "type json string"
- // @Success 200 string "操作成功"
- // @router /ai_article/generate [post]
- func (this *FeCalendarAiArticleController) Generate() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req *fe_calendar.FeCalendarAiArticleGenerateReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + err.Error()
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "请选择指标"
- return
- }
- // 查询指标
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取指标失败, Err: " + err.Error()
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "请选择指标"
- return
- }
- if req.MatterDate == "" {
- br.Msg = "请选择日期"
- return
- }
- // 获取当月的最后一天
- matterDateTime, e := time.Parse(utils.FormatDate, req.MatterDate)
- if e != nil {
- br.Msg = "请选择正确的日期"
- return
- }
-
- data, err := services.GetFeCalendarAiArticle(req, matterDateTime, edbInfo, sysUser)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "保存AI数据点评失败, Err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = data
- }
- // Save
- // @Title 保存AI数据点评
- // @Description 保存AI数据点评
- // @Param request body fe_calendar.FeCalendarAiArticle true "type json string"
- // @Success 200 string "操作成功"
- // @router /ai_article/save [post]
- func (this *FeCalendarAiArticleController) Save() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req *fe_calendar.FeCalendarAiArticleSaveReq
- if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + err.Error()
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "请选择指标"
- return
- }
- // 查询指标
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "指标不存在"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取指标失败, Err: " + err.Error()
- return
- }
-
- // 参数校验
- if req.ChartPermissionId <= 0 {
- br.Msg = "请选择品种"
- return
- }
- if req.MatterDate == "" {
- br.Msg = "请选择日期"
- return
- }
- if req.Content == "" {
- br.Msg = "请输入内容"
- return
- }
- feCalendarAiArticleId := req.FeCalendarAiArticleId
- // 获取当月的最后一天
- matterDateTime, e := time.Parse(utils.FormatDate, req.MatterDate)
- if e != nil {
- br.Msg = "请选择正确的日期"
- return
- }
-
- // 获取品种信息
- permissionItem, err := models.GetChartPermissionById(req.ChartPermissionId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取品种信息失败, Err: " + err.Error()
- return
- }
- matterOb := new(fe_calendar.FeCalendarMatter)
- if req.FeCalendarMatterId > 0 {
- matterItem, err := matterOb.GetItemById(req.FeCalendarMatterId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取事项失败, Err: " + err.Error()
- return
- }
- if matterItem.MatterType != fe_calendar.MatterTypePredict {
- br.Msg = "事项类型不匹配"
- return
- }
- }
- if req.FeCalendarAiArticleId <= 0 { // 创建数据点评
- article := new(fe_calendar.FeCalendarAiArticle)
- article.Title = edbInfo.EdbName
- article.Content = req.Content
- article.Prompt = ""
- article.ChartPermissionId = req.ChartPermissionId
- article.ChartPermissionName = permissionItem.PermissionName
- article.EdbCode = edbInfo.EdbCode
- article.EdbInfoId = edbInfo.EdbInfoId
- article.MatterDate = req.MatterDate
- article.MatterMonth = matterDateTime.Format("2006-01")
- article.SysUserId = sysUser.AdminId
- article.SysUserName = sysUser.RealName
- err = article.Create()
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "保存AI数据点评失败, Err: " + err.Error()
- return
- }
- feCalendarAiArticleId = article.FeCalendarAiArticleId
- }else{ // 更新数据点评
- articleOb := new(fe_calendar.FeCalendarAiArticle)
- if err := articleOb.GetByID(uint(req.FeCalendarAiArticleId)); err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "数据点评不存在"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取AI数据点评失败, Err: " + err.Error()
- return
- }
- if articleOb.EdbInfoId != edbInfo.EdbInfoId {
- br.Msg = "指标不匹配"
- return
- }
- if articleOb.MatterDate != req.MatterDate {
- br.Msg = "日期不匹配"
- return
- }
- articleOb.Content = req.Content
- articleOb.ModifyTime = time.Now()
- err = articleOb.Update([]string{"content", "modify_time"})
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新AI数据点评失败, Err: " + err.Error()
- return
- }
- }
- // 更新事项
- if req.FeCalendarMatterId > 0 && matterOb != nil && matterOb.FeCalendarMatterId > 0 && matterOb.FeCalendarAiArticleId != feCalendarAiArticleId {
- matterOb.FeCalendarAiArticleId = feCalendarAiArticleId
- matterOb.ModifyTime = time.Now()
- err = matterOb.Update([]string{"fe_calendar_ai_article_id", "modify_time"})
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新事项失败, Err: " + err.Error()
- return
- }
- }
- data := &fe_calendar.FeCalendarAiArticleSaveResp{
- FeCalendarAiArticleId: feCalendarAiArticleId,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = data
- }
|