package controllers import ( "encoding/json" "eta/eta_mini_crm_ht/models" "eta/eta_mini_crm_ht/models/request" "eta/eta_mini_crm_ht/models/response" "eta/eta_mini_crm_ht/services" "net/http" ) type ETAController struct { BaseAuthController } // GetDataList // @Title 数据列表 // @Description 数据列表 // @Success 200 {object} models.LoginResp // @router /business_data/data/list [get] func (this *ETAController) GetDataList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() etaRequest := new(request.IndexDataListReq) // 绑定查询参数到结构体 if err := this.ParseForm(etaRequest); err != nil { this.Ctx.Output.SetStatus(http.StatusBadRequest) this.Data["json"] = map[string]string{"error": "Invalid request parameters"} this.ServeJSON() return } dataList, err := services.GetDataList(etaRequest.ToEtaDataRequest()) if err != nil { br.Msg = "分类列表获取失败" br.ErrMsg = "分类列表获取失败,系统错误,Err:" + err.Error() return } //var data = new(response.BaseFromBusinessIndexResponse) br.Data = dataList br.Ret = 200 br.Msg = "指标信息获取成功" br.Success = true } // GetList // @Title 数据列表 // @Description 数据列表 // @Success 200 {object} models.LoginResp // @router /business_data/list [get] func (this *ETAController) GetList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() etaRequest := new(request.IndexListReq) // 绑定查询参数到结构体 if err := this.ParseForm(etaRequest); err != nil { this.Ctx.Output.SetStatus(http.StatusBadRequest) this.Data["json"] = map[string]string{"error": "Invalid request parameters"} this.ServeJSON() return } if etaRequest.SortColumn == "" { etaRequest.SortColumn = "create_time" } if etaRequest.SortOrder == "" { etaRequest.SortOrder = "desc" } indexList, err := services.GetList(etaRequest.ToEtaRequest()) if err != nil { br.Msg = "分类列表获取失败" br.ErrMsg = "分类列表获取失败,系统错误,Err:" + err.Error() return } var data = new(response.BaseFromBusinessIndexResponse) br.Data = data.ToCrmRequest(indexList) br.Ret = 200 br.Msg = "指标信息获取成功" br.Success = true } // GetSourceList // @Title 渠道列表 // @Description 获取一期指标信息 // @Success 200 {object} models.LoginResp // @router /business_data/source/list [get] func (this *ETAController) GetSourceList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sourceList, err := services.GetSourceList() if err != nil { br.Msg = "分类列表获取失败" br.ErrMsg = "分类列表获取失败,系统错误,Err:" + err.Error() return } //过滤包含一期的来源 br.Data = sourceList br.Ret = 200 br.Msg = "指标信息获取成功" br.Success = true } // DeleteIndex // @Title 删除自有数据指标 // @Description 删除自有数据指标 // @Success 200 {object} models.LoginResp // @router /business_data/del [post] func (this *ETAController) DeleteIndex() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req request.IndexesDeleteReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.DeleteAll { req.DeleteList = []string{} undeleteMap := make(map[string]int, len(req.UnDeleteList)) if len(req.UnDeleteList) > 0 { for _, v := range req.UnDeleteList { undeleteMap[v] = 1 } } list, fetchErr := services.GetIndexList() if fetchErr != nil { br.Msg = "指标列表获取失败" br.ErrMsg = "指标列表获取失败:" + fetchErr.Error() return } for _, v := range list { if _, ok := undeleteMap[v]; !ok { req.DeleteList = append(req.DeleteList, v) } } } else { if len(req.DeleteList) == 0 { br.Msg = "指标编码不能为空" br.ErrMsg = "指标编码不能为空" return } } err = services.DeleteSyncTask(req.DeleteList) if err != nil { br.Msg = "删除指标失败" br.ErrMsg = "删除指标失败,系统错误,Err:" + err.Error() return } respList, err := services.DeleteIndexes(req.DeleteList) if err != nil { br.Msg = "分类列表获取失败" br.ErrMsg = "分类列表获取失败,系统错误,Err:" + err.Error() return } br.Data = respList br.Ret = 200 br.Msg = "删除指标成功" br.Success = true }