123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765 |
- // @Author gmy 2024/8/13 16:01:00
- package controllers
- import (
- "encoding/json"
- "eta/eta_index_lib/logic"
- "eta/eta_index_lib/models"
- "eta/eta_index_lib/services"
- "eta/eta_index_lib/utils"
- "fmt"
- "strconv"
- "time"
- )
- type BaseFromLyController struct {
- BaseAuthController
- }
- // Add
- // @Title 新增粮油商务网指标
- // @Description 新增粮油商务网指标
- // @router /add [post]
- func (this *BaseFromLyController) Add() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source := utils.DATA_SOURCE_LY
- var req models.AddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EdbCode == "" {
- br.Msg = "请输入指标编码!"
- br.ErrMsg = "请输入指标编码,指标编码为空"
- return
- }
- cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(source) + "_" + req.EdbCode
- if !utils.Rc.IsExist(cacheKey) {
- utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
- err = models.AddEdbDataFromLy(req.EdbCode)
- if err != nil {
- br.Msg = "获取指标信息失败!"
- br.ErrMsg = "获取指标信息失败 AddEdbDataFromSci99,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- } else {
- br.Ret = 501
- br.Success = true
- br.Msg = "系统处理中,请稍后重试"
- }
- }
- // Refresh
- // @Title 刷新粮油商务网指标接口
- // @Description 刷新粮油商务网指标接口
- // @Success 200 {object} models.RefreshEdbInfoReq
- // @router /refresh [post]
- func (this *BaseFromLyController) Refresh() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source := utils.DATA_SOURCE_LY
- var req models.RefreshEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EdbCode == "" {
- br.Msg = "请输入指标编码!"
- br.ErrMsg = "请输入指标编码,指标编码为空"
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "请输入指标ID!"
- br.ErrMsg = "请输入指标ID"
- return
- }
- // 获取指标详情
- edbInfo, err := models.GetEdbInfoByEdbCode(source, req.EdbCode)
- if err != nil {
- br.Msg = "指标不存在!"
- br.ErrMsg = "指标不存在"
- return
- }
- cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(source) + "_" + req.EdbCode
- if utils.Rc.IsExist(cacheKey) {
- br.Ret = 501
- br.Success = true
- br.Msg = "系统处理中,请稍后重试"
- return
- }
- dataUpdateTime := time.Now().Format(utils.FormatDateTime)
- utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
- err = models.RefreshEdbDataFromBloomberg(req.EdbInfoId, req.EdbCode, req.StartDate)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "刷新指标信息失败!"
- br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromBloomberg,Err:" + err.Error()
- return
- }
- // 更新指标最大最小值
- erDataUpdateDate, err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo, dataUpdateTime)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- // 添加指标刷新成功日志
- if erDataUpdateDate != "" {
- _ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 1, "", 0, 0)
- } else {
- _ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 2, "未刷新到数据", 0, 0)
- }
- // 更新ES
- go logic.UpdateEs(edbInfo.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // GetLyClassifyByName
- // @Title 获取分类
- // @Description 获取分类
- // @Success 200 {object} models.BaseFromLyClassify
- // @router /get/ly/classify/by/name [post]
- func (this *BaseFromLyController) GetLyClassifyByName() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- CategoryName string `json:"CategoryName"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- categoryName := reqData.CategoryName
- if categoryName == "" {
- br.Msg = "请输入分类!"
- br.ErrMsg = "请输入分类"
- return
- }
- lyClassify, err := models.GetLyClassifyByName(categoryName)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = lyClassify
- br.Msg = "获取成功"
- }
- // GetLyIndexRecordByUrl
- // @Title 根据url获取指标已读取记录
- // @Description 根据url获取指标已读取记录
- // @Success 200 {object} models.BaseFromLyIndexRecord
- // @router /get/ly/index/record/by/url [post]
- func (this *BaseFromLyController) GetLyIndexRecordByUrl() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- Url string `json:"Url"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- url := reqData.Url
- if url == "" {
- br.Msg = "请输入地址链接!"
- br.ErrMsg = "请输入地址链接"
- return
- }
- lyIndexRecord, err := models.GetLyIndexRecordByUrl(url)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = lyIndexRecord
- br.Msg = "获取成功"
- }
- // AddLyIndexRecord
- // @Title 维护指标数据读取进度到数据库
- // @Description 维护指标数据读取进度到数据库
- // @Success 200 string "处理成功"
- // @router /add/ly/index/record [post]
- func (this *BaseFromLyController) AddLyIndexRecord() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.BaseFromLyIndexRecord
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- id, err := models.AddLyIndexRecord(&req)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = id
- br.Msg = "处理成功"
- }
- // AddLyDataList
- // @Title 新增指标数据
- // @Description 新增指标数据列表
- // @Success 200 string "处理成功"
- // @router /add/ly/data/list [post]
- func (this *BaseFromLyController) AddLyDataList() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req []models.BaseFromLyData
- fmt.Println(string(this.Ctx.Input.RequestBody))
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- err = models.AddLyDataList(req)
- if err != nil {
- br.Msg = "新增指标数据失败!"
- br.ErrMsg = "新增指标数据失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // AddLyIndex
- // @Title 新增指标
- // @Description 新增指标
- // @Success 200 string "处理成功"
- // @router /add/ly/index [post]
- func (this *BaseFromLyController) AddLyIndex() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.BaseFromLyIndex
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- indexId, err := models.AddLyIndex(&req)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = indexId
- br.Msg = "处理成功"
- }
- // GetLyDataByIndexIdAndDataTime
- // @Title 根据指标id和时间获取指标数据
- // @Description 根据指标id和时间获取指标数据
- // @Success 200 {object} models.BaseFromLyData
- // @router /get/ly/data/by/index/id/and/data/time [post]
- func (this *BaseFromLyController) GetLyDataByIndexIdAndDataTime() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- IndexId int `json:"IndexId"`
- DataTime string `json:"DataTime"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- indexId := reqData.IndexId
- if indexId == 0 {
- br.Msg = "请输入指标id!"
- br.ErrMsg = "请输入指标id"
- return
- }
- dataTime := reqData.DataTime
- if dataTime == "" {
- br.Msg = "请输入时间!"
- br.ErrMsg = "请输入时间"
- return
- }
- lyData, err := models.GetLyDataByIndexIdAndDataTime(indexId, dataTime)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = lyData
- br.Msg = "获取成功"
- }
- // GetLyDataByIndexIdAndDataTimeYM
- // @Title 根据指标id和年月时间获取指标数据
- // @Description 根据指标id和年月时间获取指标数据
- // @Success 200 {object} models.BaseFromLyData
- // @router /get/ly/data/by/index/id/and/data/time/ym [post]
- func (this *BaseFromLyController) GetLyDataByIndexIdAndDataTimeYM() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- IndexId int `json:"IndexId"`
- YearMonth string `json:"YearMonth"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- indexId := reqData.IndexId
- if indexId == 0 {
- br.Msg = "请输入指标id!"
- br.ErrMsg = "请输入指标id"
- return
- }
- yearMonth := reqData.YearMonth
- if yearMonth == "" {
- br.Msg = "请输入时间!"
- br.ErrMsg = "请输入时间"
- return
- }
- lyData, err := models.GetLyDataByIndexIdAndDataTimeYM(indexId, yearMonth)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = lyData
- br.Msg = "获取成功"
- }
- // UpdateLyDataById
- // @Title 更新数据源指标数据
- // @Description 更新数据源指标数据
- // @Success 200 string "处理成功"
- // @router /update/ly/data/by/id [post]
- func (this *BaseFromLyController) UpdateLyDataById() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- Id int `json:"Id"`
- Value float64 `json:"Value"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- id := reqData.Id
- if id == 0 {
- br.Msg = "请输入id!"
- br.ErrMsg = "请输入id"
- return
- }
- value := reqData.Value
- if value == 0 {
- br.Msg = "请输入值!"
- br.ErrMsg = "请输入值"
- return
- }
- err = models.UpdateLyDataById(id, value)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // GetLyEdbDataByIndexCodeAndDataTime
- // @Title 根据指标编码和模糊日期获取指标库数据
- // @Description 根据指标编码和模糊日期获取指标库数据
- // @Success 200 {object} []models.EdbDataLy
- // @router /get/ly/edb/data/by/index/code/and/data/time [post]
- func (this *BaseFromLyController) GetLyEdbDataByIndexCodeAndDataTime() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- IndexCode string `json:"IndexCode"`
- DataTime string `json:"DataTime"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- indexCode := reqData.IndexCode
- if indexCode == "" {
- br.Msg = "请输入指标id!"
- br.ErrMsg = "请输入指标id"
- return
- }
- dataTime := reqData.DataTime
- if dataTime == "" {
- br.Msg = "请输入时间!"
- br.ErrMsg = "请输入时间"
- return
- }
- lyEdbData, err := models.GetLyEdbDataByIndexCodeAndDataTime(indexCode, dataTime)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = lyEdbData
- br.Msg = "获取成功"
- }
- // GetLyEdbDataByIndexCodeAndExactDataTime
- // @Title 根据指标编码和精确日期获取指标库数据
- // @Description 根据指标编码和精确日期获取指标库数据
- // @Success 200 {object} []models.EdbDataLy
- // @router /get/ly/edb/data/by/index/code/and/exact/data/time [post]
- func (this *BaseFromLyController) GetLyEdbDataByIndexCodeAndExactDataTime() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- IndexCode string `json:"IndexCode"`
- DataTime string `json:"DataTime"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- indexCode := reqData.IndexCode
- if indexCode == "" {
- br.Msg = "请输入指标id!"
- br.ErrMsg = "请输入指标id"
- return
- }
- dataTime := reqData.DataTime
- if dataTime == "" {
- br.Msg = "请输入时间!"
- br.ErrMsg = "请输入时间"
- return
- }
- lyEdbData, err := models.GetLyEdbDataByIndexCodeAndExactDataTime(indexCode, dataTime)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = lyEdbData
- br.Msg = "获取成功"
- }
- // UpdateLyEdbDataById
- // @Title 更新指标库数据 须根据指标编码和日期更新 仅适合月度数据
- // @Description 更新指标库数据 须根据指标编码和日期更新 仅适合月度数据
- // @Success 200 string "处理成功"
- // @router /update/ly/edb/data/by/id [post]
- func (this *BaseFromLyController) UpdateLyEdbDataById() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- Id int `json:"Id"`
- Value float64 `json:"Value"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- id := reqData.Id
- if id == 0 {
- br.Msg = "请输入id!"
- br.ErrMsg = "请输入id"
- return
- }
- value := reqData.Value
- if value == 0 {
- br.Msg = "请输入值!"
- br.ErrMsg = "请输入值"
- return
- }
- err = models.UpdateLyEdbDataById(id, value)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // GetLyIndexByCode
- // @Title 查询指标编码是否存在
- // @Description 查询指标编码是否存在
- // @Success 200 {object} models.BaseFromLyIndex
- // @router /get/ly/index/by/code [post]
- func (this *BaseFromLyController) GetLyIndexByCode() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- IndexCode string `json:"IndexCode"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- indexCode := reqData.IndexCode
- if indexCode == "" {
- br.Msg = "请输入指标id!"
- br.ErrMsg = "请输入指标id"
- return
- }
- lyIndex, err := models.GetLyIndexByCode(indexCode)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = lyIndex
- br.Msg = "获取成功"
- }
- // GetEdbInfoByIndexCode
- // @Title 根据指标code获取指标信息
- // @Description 根据指标code获取指标信息
- // @Success 200 {object} models.EdbInfo
- // @router /get/edb/info/by/index/code [post]
- func (this *BaseFromLyController) GetEdbInfoByIndexCode() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var reqData struct {
- IndexCode string `json:"IndexCode"`
- Source int `json:"Source"`
- }
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &reqData)
- if err != nil {
- br.ErrMsg = "无法解析请求体"
- return
- }
- indexCode := reqData.IndexCode
- if indexCode == "" {
- br.Msg = "请输入指标id!"
- br.ErrMsg = "请输入指标id"
- return
- }
- source := reqData.Source
- if source == 0 {
- br.Msg = "请输入来源!"
- br.ErrMsg = "请输入来源"
- return
- }
- lyEdbData, err := models.GetEdbInfoByEdbCode(source, indexCode)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Data = lyEdbData
- br.Msg = "获取成功"
- }
- // AddBatchLyEdbData
- // @Title 批量增加粮油指标库数据
- // @Description 批量增加粮油指标库数据
- // @Success 200 string "处理成功"
- // @router /add/batch/ly/edb/data [post]
- func (this *BaseFromLyController) AddBatchLyEdbData() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- _ = utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req []models.EdbDataLy
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- err = models.AddLyEdbDataList(req)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
|