123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- 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"
- "github.com/beego/beego/v2/core/logs"
- "strconv"
- "time"
- )
- // FenweiController 汾渭煤炭
- type FenweiController struct {
- BaseAuthController
- }
- // Add
- // @Title 新增汾渭煤炭指标接口
- // @Description 新增汾渭煤炭指标接口
- // @Success 200 {object} models.AddEdbInfoReq
- // @router /add [post]
- func (this *FenweiController) Add() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- 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
- }
- ob := new(models.BaseFromFenwei)
- cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(ob.GetSource()) + "_" + req.EdbCode
- if utils.Rc.IsExist(cacheKey) {
- br.Ret = 501
- br.Success = true
- br.Msg = "系统处理中,请稍后重试"
- return
- }
- utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
- defer func() {
- _ = utils.Rc.Delete(cacheKey)
- }()
- if err = ob.Add(req.EdbCode); err != nil {
- br.Msg = "获取指标信息失败!"
- br.ErrMsg = "获取指标信息失败 AddEdbDataFromFenwei,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Refresh
- // @Title 刷新汾渭煤炭指标接口
- // @Description 刷新汾渭煤炭指标接口
- // @Success 200 {object} models.RefreshEdbInfoReq
- // @router /refresh [post]
- func (this *FenweiController) Refresh() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- 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
- }
- ob := new(models.BaseFromFenwei)
- source := ob.GetSource()
- // 获取指标详情
- 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
- }
- utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
- defer func() {
- _ = utils.Rc.Delete(cacheKey)
- }()
- if req.EdbInfoId <= 0 {
- req.EdbInfoId = edbInfo.EdbInfoId
- }
- err = ob.Refresh(req.EdbInfoId, req.EdbCode, req.StartDate)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "刷新指标信息失败!"
- br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromFenwei,Err:" + err.Error()
- return
- }
- // 更新指标最大最小值
- err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- // 更新ES
- go logic.UpdateEs(edbInfo.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // HandleExcelData
- // @Title 处理汾渭煤炭指标的接口
- // @Description 处理汾渭煤炭指标的接口
- // @Success 200 string "操作成功"
- // @router /handle/excel_data [post]
- func (this *FenweiController) HandleExcelData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.HandleFenweiExcelDataReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- // 处理excel表数据
- if err = services.HandleFenweiIndex(&req); err != nil {
- br.Msg = "处理失败"
- br.ErrMsg = "处理失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // ClassifyTree
- // @Title 汾渭数据分类
- // @Description 汾渭数据分类接口
- // @Success 200 {object} models.BaseFromFenweiClassifyItem
- // @router /classify_tree [post]
- func (this *FenweiController) ClassifyTree() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyOb := new(models.BaseFromFenweiClassify)
- classifies, e := classifyOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "parent_id ASC, sort ASC")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取汾渭数据分类失败, Err: " + e.Error()
- return
- }
- resp := make([]*models.BaseFromFenweiClassifyItem, 0)
- parentMap := make(map[int][]*models.BaseFromFenweiClassifyItem)
- for _, v := range classifies {
- t := classifyOb.Format2Item(v)
- if v.ParentId == 0 {
- resp = append(resp, t)
- }
- if v.ParentId > 0 {
- if parentMap[v.ParentId] == nil {
- parentMap[v.ParentId] = make([]*models.BaseFromFenweiClassifyItem, 0)
- }
- parentMap[v.ParentId] = append(parentMap[v.ParentId], t)
- }
- }
- for _, v := range resp {
- v.Child = parentMap[v.ClassifyId]
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // BaseIndexList
- // @Title 汾渭指标基础信息列表
- // @Description 汾渭指标基础信息列表接口
- // @Success 200 {object} models.BaseFromFenweiIndex
- // @router /base_index_list [post]
- func (this *FenweiController) BaseIndexList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- ob := new(models.BaseFromFenweiIndex)
- list, e := ob.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取汾渭指标列表失败, Err: " + e.Error()
- return
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // NetDataHandle
- // @Title 汾渭网页数据落库
- // @Description 汾渭网页数据落库
- // @Success 200 string "操作成功"
- // @router /net/data/handle [post]
- func (this *FenweiController) NetDataHandle() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.HandleFenWeiNetDataReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- logs.Info("汾渭网页数据落库请求参数 List size:", len(req.List))
- err = services.NetDataHandle(req)
- if err != nil {
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|