123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889 |
- 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"
- )
- // MySteelChemicalController 钢联化工
- type MySteelChemicalController struct {
- BaseAuthController
- }
- // Add
- // @Title 新增钢联化工指标接口
- // @Description 新增钢联化工指标接口
- // @Success 200 {object} models.AddEdbInfoReq
- // @router /add [post]
- func (this *MySteelChemicalController) 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_MYSTEEL_CHEMICAL
- 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.AddEdbDataFromMysteelChemical(req.EdbCode)
- if err != nil {
- br.Msg = "获取指标信息失败!"
- br.ErrMsg = "获取指标信息失败 AddEdbDataFromMysteelChemical,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 *MySteelChemicalController) Refresh() {
- br := new(models.BaseResponse).Init()
- var cacheKey string
- defer func() {
- utils.Rc.Delete(cacheKey)
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source := utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- 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
- }
- 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)
- // 将数据刷新到BaseFromMysteelChemicalData
- err = services.RefreshDataFromMysteelChemical(req.EdbCode, utils.GetEdbRefreshStartDate(req.StartDate), utils.BASE_END_DATE)
- if err != nil {
- br.Msg = "获取指标信息失败!"
- br.ErrMsg = "获取指标信息失败 RefreshDataFromMysteelChemical,Err:" + err.Error()
- return
- }
- err = models.RefreshEdbDataFromMysteelChemical(req.EdbInfoId, req.EdbCode, req.StartDate)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "刷新指标信息失败!"
- br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromMysteel,Err:" + err.Error()
- return
- }
- if req.EdbInfoId != 0 {
- // 获取指标详情
- edbInfo, err := models.GetEdbInfoByEdbCode(source, req.EdbCode)
- if err != nil {
- br.Msg = "指标不存在!"
- br.ErrMsg = "指标不存在"
- return
- }
- // 更新指标最大最小值
- erDataUpdateDate, err, errMsg := models.UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo, dataUpdateTime)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- // 添加指标刷新成功日志
- isSourceRefresh := 0
- if utils.MysteelChemicalApiToken != "" {
- isSourceRefresh = 1
- }
- if erDataUpdateDate != "" {
- _ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 1, "", isSourceRefresh, 0)
- } else {
- _ = services.AddEdbInfoUpdateLog(edbInfo.EdbInfoId, 1, "", 2, "未刷新到数据", isSourceRefresh, 0)
- }
- // 更新ES
- go logic.UpdateEs(edbInfo.EdbInfoId)
- }
- if utils.MysteelChemicalApiToken != "" {
- // 钢联走api接口,那就更新数据源明细表
- _ = services.SetMysteelChemicalEdbInfoUpdateStat(false)
- _ = services.SetEdbSourceStat(false)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 查询刷新钢联指标的接口
- // @Description 查询刷新钢联指标的接口
- // @Success 200 {object} models.CheckDeleteClassifyResp
- // @router /query/refresh [post]
- func (this *MySteelChemicalController) QueryRefresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- mysteelIndex := new(models.BaseFromMysteelChemicalIndex)
- list, err := mysteelIndex.GetIndexRefreshAllByMergeFile()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败!"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if list == nil {
- list = make([]*models.BaseFromMysteelChemicalIndex, 0)
- }
- br.Ret = 200
- br.Data = list
- br.Success = true
- br.Msg = "获取成功"
- }
- // @Title 检查钢联化工的api是否可用
- // @Description 检查钢联化工的api是否可用
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /handle/mysteel/api/check [post]
- func (this *MySteelChemicalController) ApiHealthCheck() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- ok, err := services.ApiCheck()
- if err != nil {
- br.Msg = "处理失败"
- br.ErrMsg = "处理失败,Err:" + err.Error()
- utils.FileLog.Info("钢联化工api接口不可用,Err:", err.Error())
- return
- }
- resp := new(models.MysteelChemicalAPiCheck)
- resp.IsEnable = ok
- if !ok {
- resp.ErrMsg = "token已过期或已欠费"
- }
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // @Title 处理钢联指标的接口
- // @Description 处理钢联指标的接口
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /handle/mysteel/index [post]
- func (this *MySteelChemicalController) HandleMysteelIndex() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- body := this.Ctx.Input.RequestBody
- var req models.HandleMysteelIndexResp
- err := json.Unmarshal(body, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- err = services.HandleMysteelIndex(&req)
- if err != nil {
- fmt.Println("HandleMysteelIndex Err:" + err.Error())
- br.Msg = "处理失败"
- br.ErrMsg = "处理失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // @Title 处理钢联指标的接口
- // @Description 处理钢联指标的接口
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /handle/api/mysteel/index [post]
- func (this *MySteelChemicalController) HandleApiMysteelIndex() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- body := this.Ctx.Input.RequestBody
- var req models.HandleMysteelIndexResp
- err := json.Unmarshal(body, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- errMsg, err := services.HandleApiMysteelIndex(&req)
- if err != nil {
- fmt.Println("HandleMysteelIndex Err:" + err.Error())
- if errMsg == "" {
- br.Msg = "数据获取失败"
- } else {
- br.Msg = errMsg
- }
- br.ErrMsg = "处理失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // GetMaxFileIndex
- // @Title 获取最大的文件编号下标
- // @Description 获取最大的文件编号下标
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /getMaxFileIndex [post]
- func (this *MySteelChemicalController) GetMaxFileIndex() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetMaxFileIndexReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- // 获取最大的文件编号下标
- item, err := indexObj.GetMaxFileIndex(req.Frequency)
- if err != nil {
- return
- }
- br.Data = item
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // GetNoMergeIndexByFrequencyCount
- // @Title 获取未合并的指标总数量
- // @Description 获取未合并的指标总数量
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /getNoMergeIndexByFrequencyCount [post]
- func (this *MySteelChemicalController) GetNoMergeIndexByFrequencyCount() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetMaxFileIndexReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- // 获取未合并的指标总数量
- indexTotal, err := indexObj.GetNoMergeIndexByFrequencyCount(req.Frequency)
- if err != nil {
- return
- }
- br.Data = indexTotal
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // GetNoMergeIndexByFrequencyPage
- // @Title 获取未合并的指标列表
- // @Description 获取未合并的指标列表
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /getNoMergeIndexByFrequencyPage [post]
- func (this *MySteelChemicalController) GetNoMergeIndexByFrequencyPage() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetNoMergeIndexByFrequencyPageReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- // 获取未合并的指标总数量
- indexTotal, err := indexObj.GetNoMergeIndexByFrequencyPage(req.Frequency, req.Limit)
- if err != nil {
- return
- }
- br.Data = indexTotal
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // GetIndexCountByMergeFilePath
- // @Title 获取该文件下标已经存在多少的指标
- // @Description 获取该文件下标已经存在多少的指标
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /getIndexCountByMergeFilePath [post]
- func (this *MySteelChemicalController) GetIndexCountByMergeFilePath() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetIndexCountByMergeFilePathReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.MergeFilePath == "" {
- br.Msg = "参数有误"
- br.ErrMsg = "参数有误, 文件路径有误"
- return
- }
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- indexTotal, err := indexObj.GetIndexCountByMergeFilePath(req.MergeFilePath)
- if err != nil {
- return
- }
- br.Data = indexTotal
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // GetIndexCreate
- // @Title 获取两分钟前新增的指标
- // @Description 获取两分钟前新增的指标
- // @Success 200 {object} models.BaseFromMysteelChemicalIndex
- // @router /getIndexCreate [post]
- func (this *MySteelChemicalController) GetIndexCreate() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- // 终端编码
- terminalCode := this.GetString("TerminalCode")
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- items, err := indexObj.GetIndexCreate(terminalCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标失败, Err: " + err.Error()
- return
- }
- if items == nil {
- items = make([]*models.BaseFromMysteelChemicalIndex, 0)
- }
- br.Data = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // GetIndexRefreshMethanolByMergeFile
- // @Title 获取需要刷新的甲醇文件
- // @Description 获取需要刷新的甲醇文件
- // @Success 200 {object} models.BaseFromMysteelChemicalIndex
- // @router /getIndexRefreshMethanolByMergeFile [post]
- func (this *MySteelChemicalController) GetIndexRefreshMethanolByMergeFile() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- items, err := indexObj.GetIndexRefreshMethanolByMergeFile()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标失败, Err: " + err.Error()
- return
- }
- if items == nil {
- items = make([]*models.BaseFromMysteelChemicalIndex, 0)
- }
- br.Data = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // GetIndexRefreshMethanolByTimely
- // @Title 获取需要及时刷新的文件
- // @Description 获取需要及时刷新的文件
- // @Success 200 {object} models.BaseFromMysteelChemicalIndex
- // @router /getIndexRefreshMethanolByTimely [post]
- func (this *MySteelChemicalController) GetIndexRefreshMethanolByTimely() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- items, err := indexObj.GetIndexRefreshMethanolByTimely()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标失败, Err: " + err.Error()
- return
- }
- if items == nil {
- items = make([]*models.BaseFromMysteelChemicalIndex, 0)
- }
- br.Data = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // GetIndexByFrequency
- // @Title 根据频率获取指标
- // @Description 根据频率获取指标
- // @Success 200 {object} models.BaseFromMysteelChemicalIndex
- // @router /getIndexByFrequency [post]
- func (this *MySteelChemicalController) GetIndexByFrequency() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetIndexByFrequencyReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Frequency == "" {
- br.Msg = "参数有误"
- br.ErrMsg = "参数有误"
- return
- }
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- items, err := indexObj.GetIndexByFrequency(req.Frequency)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标失败, Err: " + err.Error()
- return
- }
- if items == nil {
- items = make([]*models.BaseFromMysteelChemicalIndex, 0)
- }
- br.Data = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // GetIndexRefreshWeek
- // @Title 根据周获取指标
- // @Description 根据周获取指标
- // @Success 200 {object} models.BaseFromMysteelChemicalIndex
- // @router /getIndexRefreshWeek [post]
- func (this *MySteelChemicalController) GetIndexRefreshWeek() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetIndexRefreshWeekReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.NowWeekZn == "" || req.StartTime == "" || req.EndTime == "" {
- br.Msg = "参数有误"
- br.ErrMsg = "参数有误"
- return
- }
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- items, err := indexObj.GetIndexRefreshWeek(req.NowWeekZn, req.StartTime, req.EndTime)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标失败, Err: " + err.Error()
- return
- }
- if items == nil {
- items = make([]*models.BaseFromMysteelChemicalIndex, 0)
- }
- br.Data = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // UpdateIndex
- // @Title 更新指标
- // @Description 更新指标
- // @Success 200 string "操作成功"
- // @router /updateIndex [post]
- //func (this *MySteelChemicalController) UpdateIndex() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- // var req models.UpdateIndexReq
- // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- // if req.Item == nil {
- // br.Msg = "参数有误"
- // br.ErrMsg = "参数有误, 指标信息有误"
- // return
- // }
- // if len(req.UpdateCols) == 0 {
- // br.Msg = "参数有误"
- // br.ErrMsg = "参数有误, 无更新字段"
- // return
- // }
- //
- // // 更新指标
- // indexObj := new(models.BaseFromMysteelChemicalIndex)
- // err = indexObj.UpdateIndex(req.Item, req.UpdateCols)
- // if err != nil {
- // br.Msg = "操作失败"
- // br.ErrMsg = "批量更新指标失败, MultiUpdateIndexByIndexCode err: " + err.Error()
- // return
- // }
- //
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "操作成功"
- //}
- // MultiUpdateIndex
- // @Title 批量更新指标
- // @Description 批量更新指标
- // @Success 200 string "操作成功"
- // @router /multiUpdateIndex [post]
- func (this *MySteelChemicalController) MultiUpdateIndex() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req []models.UpdateIndexReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if len(req) == 0 {
- br.Msg = "参数有误"
- br.ErrMsg = "参数有误, 无指标需要更新"
- return
- }
- // 批量更新指标
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- err = indexObj.MultiUpdateIndex(req)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "批量更新指标失败, MultiUpdateIndex err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // AddMysteelIndex
- // @Title 处理钢联指标的接口
- // @Description 处理钢联指标的接口
- // @Success 200 {object} models.AddMysteelIndexResp
- // @router /add/mysteel/index [post]
- func (this *MySteelChemicalController) AddMysteelIndex() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.AddMysteelIndexResp
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- mysteelIndexObj := new(models.BaseFromMysteelChemicalIndex)
- indexItem, err := mysteelIndexObj.GetIndexItem(req.EdbCode)
- var isAdd bool
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- isAdd = true
- } else {
- br.Msg = "判断指标是否存在失败"
- br.ErrMsg = "判断指标是否存在失败,Err:" + err.Error()
- return
- }
- }
- if indexItem == nil {
- isAdd = true
- }
- if isAdd {
- mysteelIndexObj.IndexCode = req.EdbCode
- mysteelIndexObj.TerminalCode = req.TerminalCode
- mysteelIndexObj.BaseFromMysteelChemicalClassifyId = req.BaseFromMysteelChemicalClassifyId
- mysteelIndexObj.SysUserId = req.SysUserId
- mysteelIndexObj.SysUserRealName = req.SysUserRealName
- mysteelIndexObj.CreateTime = time.Now()
- mysteelIndexObj.ModifyTime = time.Now()
- err = mysteelIndexObj.Add()
- if err != nil {
- br.Msg = "新增指标失败"
- br.ErrMsg = "新增指标失败,Err:" + err.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // GetIndexDetailByCode
- // @Title 获取指标详情
- // @Description 获取指标详情
- // @Success 200 {object} models.GetIndexDetailReq
- // @router /index_detail [post]
- func (this *MySteelChemicalController) GetIndexDetailByCode() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetIndexDetailReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.IndexCode == "" {
- br.Msg = "参数有误"
- br.ErrMsg = "参数有误"
- return
- }
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- item, err := indexObj.GetIndexItem(req.IndexCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标失败, Err: " + err.Error()
- return
- }
- br.Data = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // GetIndexCountByFrequency
- // @Title 根据频度获取指标总数量
- // @Description 根据频度获取指标总数量
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /getIndexCountByFrequency [post]
- func (this *MySteelChemicalController) GetIndexCountByFrequency() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetMaxFileIndexReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- var condition string
- var pars []interface{}
- if req.Frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, req.Frequency)
- }
- if req.EndDate != "" {
- condition += ` AND end_date < ? `
- pars = append(pars, req.EndDate)
- }
- // 终端编码
- condition += ` AND terminal_code = ? `
- pars = append(pars, req.TerminalCode)
- condition += ` AND is_stop = 0 `
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- // 获取未合并的指标总数量
- indexTotal, err := indexObj.GetIndexCountByFrequency(condition, pars)
- if err != nil {
- return
- }
- br.Data = indexTotal
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // GetIndexLimitByFrequency
- // @Title 获取未合并的指标列表
- // @Description 获取未合并的指标列表
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /getIndexLimitByFrequency [post]
- func (this *MySteelChemicalController) GetIndexLimitByFrequency() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetNoMergeIndexByFrequencyPageReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- // 获取未合并的指标总数量
- indexTotal, err := indexObj.GetIndexLimitByFrequency(req.Frequency, req.Limit)
- if err != nil {
- return
- }
- br.Data = indexTotal
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
- // GetIndexPageByFrequency
- // @Title 获取钢联指标分页数据
- // @Description 获取钢联指标分页数据
- // @Success 200 {object} models.HandleMysteelIndexResp
- // @router /getIndexPageByFrequency [post]
- func (this *MySteelChemicalController) GetIndexPageByFrequency() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.GetIndexPageByFrequencyPageReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- var condition string
- var pars []interface{}
- if req.Frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, req.Frequency)
- }
- if req.EndDate != "" {
- condition += ` AND end_date < ? `
- pars = append(pars, req.EndDate)
- }
- // 终端编码
- condition += ` AND terminal_code = ? `
- pars = append(pars, req.TerminalCode)
- condition += ` AND is_stop = 0 `
- indexObj := new(models.BaseFromMysteelChemicalIndex)
- // 获取未合并的指标总数量
- indexTotal, err := indexObj.GetIndexPageByFrequency(condition, pars, req.StartSize, req.PageSize)
- if err != nil {
- return
- }
- br.Data = indexTotal
- br.Ret = 200
- br.Success = true
- br.Msg = "处理成功"
- }
|