123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_hub/models"
- "eta/eta_hub/models/data_manage"
- "eta/eta_hub/services/data"
- "eta/eta_hub/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strings"
- )
- // Push
- // @Title 指标数据
- // @Description 指标数据
- // @Success 200 {object} data.BaseFromBusinessIndexResp
- // @router /push [post]
- func (c *EdbController) Push() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- body := c.Ctx.Input.RequestBody
- var req data_manage.PushBusinessIndexReq
- err := json.Unmarshal(body, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- //if req.IndexCode == `` {
- // br.Msg = "指标编码不能为空"
- // return
- //}
- if req.IndexName == `` {
- br.Msg = "指标名称不能为空"
- return
- }
- if req.Unit == `` {
- br.Msg = "指标单位不能为空"
- return
- }
- if req.Frequency == `` {
- br.Msg = "指标频度不能为空"
- return
- }
- if req.SourceName == `` {
- br.Msg = "数据来源名称不能为空"
- return
- }
- // 兼容频度缺少度的字段
- if !strings.Contains(req.Frequency, "度") {
- req.Frequency = req.Frequency + "度"
- }
- if !utils.VerifyFrequency(req.Frequency) {
- br.Msg = "指标频度不合法:" + req.Frequency
- return
- }
- reqJson, err := json.Marshal(req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- respItem, err := data.PushEdb(string(reqJson))
- if err != nil {
- br.Msg = "处理失败"
- br.ErrMsg = "处理失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg
- return
- }
- br.Data = respItem.Data
- br.Ret = 200
- br.Msg = "处理成功"
- }
- // BusinessEdbList
- // @Title 获取自有数据列表
- // @Description 获取自有数据列表
- // @Success 200 {object} data_manage.BaseFromBusinessIndexResp
- // @router /business/edb/list [get]
- func (c *EdbController) BusinessEdbList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- pageSize, _ := c.GetInt("PageSize")
- currentIndex, _ := c.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //通过指标ID、指标名称、渠道、单位、频度查询匹配自有数据中已有的指标;
- indexCode := c.GetString("IndexCode")
- indexName := c.GetString("IndexName")
- //if indexName == `` && indexCode == `` {
- // br.Msg = "IndexCode与IndexName不能同时为空"
- // br.ErrMsg = "IndexCode与IndexName不能同时为空"
- // return
- //}
- cond := ``
- pars := make([]interface{}, 0)
- if indexCode != `` {
- cond += ` AND index_code = ?`
- pars = append(pars, indexCode)
- }
- if indexName != `` {
- cond += ` AND index_name like ?`
- pars = utils.GetLikeKeywordPars(pars, indexName, 1)
- }
- sourceName := c.GetString("SourceName")
- if sourceName != `` {
- cond += ` AND source_name = ?`
- pars = append(pars, sourceName)
- }
- unit := c.GetString("Unit")
- if unit != `` {
- cond += ` AND unit = ?`
- pars = append(pars, unit)
- }
- frequency := c.GetString("Frequency")
- if frequency != `` {
- cond += ` AND frequency = ?`
- pars = append(pars, frequency)
- }
- edbOb := new(data_manage.BaseFromBusinessIndex)
- total, edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{"index_code", "index_name", "frequency", "unit", "source_name"}, "base_from_business_index_id DESC", startSize, pageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "EdbList GetItemsByCondition err: " + e.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := data_manage.BaseFromBusinessIndexResp{
- Paging: page,
- List: edbList,
- }
- br.Data = resp
- br.Ret = 200
- br.Msg = "获取成功"
- }
- // BusinessEdbDel
- // @Title 删除指标数据
- // @Description 删除指标数据
- // @Success 200 {object} data_manage.EdbInfoItem
- // @router /business/edb/del [post]
- func (c *EdbController) BusinessEdbDel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- body := c.Ctx.Input.RequestBody
- var req data_manage.DelBusinessIndexReq
- err := json.Unmarshal(body, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if len(req.IndexCodeList) < 0 {
- br.Msg = "指标编码不允许为空"
- return
- }
- reqJson, err := json.Marshal(req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- respItem, err := data.DelBusinessIndex(string(reqJson))
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg
- return
- }
- br.Data = respItem.Data
- br.Ret = 200
- br.Msg = "删除成功"
- }
- // BusinessEdbDataDel
- // @Title 删除指标数据
- // @Description 删除指标数据
- // @Success 200 {object} data_manage.EdbInfoItem
- // @router /business/data/del [post]
- func (c *EdbController) BusinessEdbDataDel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- body := c.Ctx.Input.RequestBody
- var req data_manage.DelBusinessDataReq
- err := json.Unmarshal(body, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.IndexCode == `` {
- br.Msg = "指标编码不能为空"
- return
- }
- if req.StartDate == `` && req.EndDate == `` {
- br.Msg = "开始日期和结束日期不允许同时为空"
- return
- }
- reqJson, err := json.Marshal(req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- respItem, err := data.DelBusinessIndexData(string(reqJson))
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg
- return
- }
- br.Data = respItem.Data
- br.Ret = 200
- br.Msg = "删除成功"
- }
|