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 = "删除成功" }