package data_manage import ( "encoding/json" "eta_gn/eta_api/controllers" "eta_gn/eta_api/models" "eta_gn/eta_api/models/company" "eta_gn/eta_api/models/data_manage" "eta_gn/eta_api/models/data_manage/cross_variety" request2 "eta_gn/eta_api/models/data_manage/excel/request" "eta_gn/eta_api/models/data_manage/request" "eta_gn/eta_api/models/data_manage/response" "eta_gn/eta_api/models/system" "eta_gn/eta_api/services" "eta_gn/eta_api/services/alarm_msg" "eta_gn/eta_api/services/data" "eta_gn/eta_api/services/data/data_manage_permission" excel2 "eta_gn/eta_api/services/data/excel" "eta_gn/eta_api/services/elastic" "eta_gn/eta_api/utils" "fmt" "strconv" "strings" "sync" "time" "github.com/rdlucklib/rdluck_tools/paging" ) // EdbInfoController 数据管理 type EdbInfoController struct { controllers.BaseAuthController } // EdbInfoSearch // @Title 新增指标-查询指标信息接口 // @Description 新增指标-查询指标信息接口 // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博" // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列" // @Param EdbCode query string false "指标编码/指标代码" // @Param StockCode query string false "证券代码" // @Param Frequency query string false "频度" // @Success 200 {object} data_manage.EdbInfoSearchResp // @router /edb_info/search [get] func (this *EdbInfoController) EdbInfoSearch() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() source, _ := this.GetInt("Source") edbCode := this.GetString("EdbCode") edbCode = strings.Trim(edbCode, "\t") edbCode = strings.Trim(edbCode, " ") edbCode = strings.Replace(edbCode, "\t", "", -1) subSource, _ := this.GetInt("SubSource") stockCode := this.GetString("StockCode") frequency := this.GetString("Frequency") extraPars := this.GetString("ExtraPars") extraPars = strings.TrimSpace(extraPars) if source <= 0 { br.Msg = "无效的数据来源" return } if edbCode == "" { br.Msg = "请输入指标ID" return } //如果是彭博财务指标,那么需要传入客户code if source == utils.DATA_SOURCE_PB_FINANCE { companyCode := this.GetString("CompanyCode") companyCode = strings.Trim(companyCode, "\t") companyCode = strings.Trim(companyCode, " ") companyCode = strings.Replace(companyCode, "\t", "", -1) // 如果财务数据,那么需要拼接上客户code edbCode = companyCode + "&&" + edbCode } resp := new(data_manage.EdbInfoSearchResp) //判断指标是否存在 var item *data_manage.EdbInfo var err error item, err = data_manage.GetEdbInfoByEdbCode(source, edbCode) if err != nil { if !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } } var isAdd bool var isInEdb bool //是否在指标库中 if item != nil && item.EdbInfoId > 0 { isInEdb = true //在指标库中 resp.Status = 1 searchItem := new(data_manage.EdbInfoSearch) searchItem.EdbCode = item.EdbCode searchItem.StartDate = utils.TimeToFormatDate(item.StartDate) searchItem.EndDate = utils.TimeToFormatDate(item.EndDate) searchItem.EdbName = item.EdbName resp.SearchItem = searchItem //查询目录 resultList, _ := data_manage.GetClassifyAllByClassifyId(item.ClassifyId) resp.ClassifyList = resultList // 查询该指标是否有权限 obj := data_manage.EdbInfoNoPermissionAdmin{} conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, item.EdbInfoId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error() return } if conf != nil && conf.Id > 0 { resp.Status = 3 } } else { //dateNow := time.Now() //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDate) searchItem := new(data_manage.EdbInfoSearch) if source == utils.DATA_SOURCE_MANUAL { //手工数据指标 dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_MANUAL, subSource, utils.EDB_DATA_LIMIT) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error() return } fmt.Println("ths len:", len(dataItems)) if len(dataItems) > 0 { fmt.Println("ths data exist") searchItem.EdbCode = edbCode minDate, maxDate, err := data_manage.GetEdbDataManualMaxOrMinDate(edbCode) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error() return } searchItem.DataList = dataItems searchItem.StartDate = minDate searchItem.EndDate = maxDate } else { //searchItem, err = data_manage.GetEdbDataByManual(edbCode, startDate, endDate) //if err != nil { // br.Msg = "获取失败" // br.ErrMsg = "获取失败,Err:" + err.Error() // return //} respItem, err := data.AddEdbData(source, edbCode, frequency) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if respItem.Ret != 200 { br.Msg = "未搜索到该指标" br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode return } isAdd = true } //获取指标信息 manualInfo, err := models.GetEdbinfoByTradeCode(edbCode) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error() return } if manualInfo != nil { searchItem.Frequency = manualInfo.Frequency searchItem.Unit = manualInfo.Unit searchItem.EdbName = manualInfo.SecName } } else if source == utils.DATA_SOURCE_LT { fmt.Println("lt data exist") if strings.Contains(edbCode, "=") { br.Msg = "暂不支持编码中含有=的指标" br.ErrMsg = "暂不支持编码中含有=的指标" return } dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LT, subSource, utils.EDB_DATA_LIMIT) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取 lt 已存在信息失败,Err:" + err.Error() return } fmt.Println("lt dataItems:", len(dataItems)) if len(dataItems) > 0 { searchItem.EdbCode = edbCode edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取lt日期信息失败,Err:" + err.Error() return } searchItem.DataList = dataItems searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate } else { //endDate := dateNow.Format(utils.FormatDate) //searchItem, err = data.GetEdbDataByLt(edbCode, startDate, endDate) //if err != nil { // br.Msg = "获取失败" // br.ErrMsg = "lt 获取失败,Err:" + err.Error() // return //} respItem, err := data.AddEdbData(source, edbCode, frequency) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if respItem.Ret != 200 { br.Msg = respItem.Msg br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode return } isAdd = true } } else if source == utils.DATA_SOURCE_GOOGLE_TRAVEL { //谷歌出行数据 dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error() return } if len(dataItems) > 0 { searchItem.EdbCode = edbCode item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error() return } if item != nil { searchItem.DataList = dataItems searchItem.StartDate = item.MinDate searchItem.EndDate = item.MaxDate } } else { respItem, err := data.AddEdbData(source, edbCode, frequency) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } if respItem.Ret != 200 { br.Msg = "未搜索到该指标" br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode return } isAdd = true } } else if source == utils.DATA_SOURCE_BUSINESS { //自有数据 indexObj := data_manage.BaseFromBusinessIndex{} indexInfo, err := indexObj.GetDetailByEdbCode(edbCode) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取自有数据指标信息失败,Err:" + err.Error() return } _, tmpDataList, err := data.GetPageBaseBusinessIndexData(edbCode, 1, utils.EDB_DATA_LIMIT) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取自有数据已存在信息失败,Err:" + err.Error() return } dataItems := make([]*data_manage.EdbInfoSearchData, 0) for _, v := range tmpDataList { dataItems = append(dataItems, &data_manage.EdbInfoSearchData{ DataTime: v.DataTime, Value: v.Value, }) } searchItem.EdbCode = edbCode searchItem.DataList = dataItems searchItem.StartDate = indexInfo.StartDate.Format(utils.FormatDate) searchItem.EndDate = indexInfo.EndDate.Format(utils.FormatDate) searchItem.Frequency = indexInfo.Frequency searchItem.Unit = indexInfo.Unit searchItem.EdbName = indexInfo.IndexName } else { // 代码中没有的来源那么从edb_source中找是否有对应的 sourceItem := data_manage.GetEdbSourceBySourceId(source) if sourceItem == nil { br.Msg = "无效指标来源" return } // 获取指标数据 dataList, e := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT) if e != nil { br.Msg = "获取失败" br.ErrMsg = "获取指标数据失败, Err: " + e.Error() return } if len(dataList) > 0 { searchItem.EdbCode = edbCode searchItem.DataList = dataList // 获取最大最小值 edbInfoMaxAndMinInfo, e := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode) if e != nil && !utils.IsErrNoRow(e) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败, GetEdbInfoMaxAndMinInfo Err:" + e.Error() return } if edbInfoMaxAndMinInfo != nil { searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate } } else { // 新增指标数据 addRes, e := data.AddEdbData(source, edbCode, frequency) if e != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + e.Error() return } if addRes == nil { br.Msg = "获取失败" br.ErrMsg = "新增指标数据失败, addRes nil" return } if addRes.Ret != 200 { br.Msg = "未搜索到该指标, " + addRes.Msg //br.ErrMsg = addRes.ErrMsg + ";EdbCode:" + edbCode br.Success = true return } isAdd = true } // 查询基本信息 baseIndexInfo, tErr := data_manage.GetBaseIndexInfoByEdbCode(edbCode, source) if tErr == nil { searchItem.EdbName = baseIndexInfo.IndexName searchItem.Frequency = baseIndexInfo.Frequency searchItem.Unit = baseIndexInfo.Unit } } if isAdd { if subSource == utils.DATA_SUB_SOURCE_DATE { if source == utils.DATA_SOURCE_WIND { //wsdData := windWsdRespItem.Data //var buf bytes.Buffer //// 创建一个encoder并指定目标为buf //enc := gob.NewEncoder(&buf) // //// 将data编码到buf中 //err = enc.Encode(wsdData) //if err != nil { // br.Msg = "获取失败" // br.ErrMsg = "获取数据失败,wind wsd encoding GOB Err:" + err.Error() // return //} // //wsdDataMap := make(map[string]map[string]interface{}) //err = json.Unmarshal(buf.Bytes(), &wsdDataMap) //if err != nil { // br.Msg = "获取失败" // br.ErrMsg = "获取数据失败,wind wsd json.Unmarshal Err:" + err.Error() // return //} // //stockList := make([]*data_manage.StockInfo, 0) // //dataList := make([]*data_manage.EdbInfoSearchData, 0) //for wk, wv := range wsdDataMap { // for vk, vv := range wv { // wkInt, err := strconv.ParseInt(wk, 10, 64) // if err != nil { // br.Msg = "获取失败" // br.ErrMsg = "获取数据失败,转换日期类型失败 Err:" + err.Error() // return // } // // vk = strings.ToLower(vk) // wkInt = wkInt / 1000 // t := time.Unix(wkInt, 0) // dateTime := t.Format(utils.FormatDate) // //saveVal := utils.SubFloatToString(val, 20) // if vv == nil { // continue // } // var saveVal string // switch vt := vv.(type) { // case int: // saveVal = strconv.Itoa(vt) // case float64: // saveVal = utils.SubFloatToFloatStr(vt, 20) // case string: // saveVal = vt // } // // dataItem := new(data_manage.EdbInfoSearchData) // dataItem.Value = saveVal // dataItem.DataTime = dateTime // dataList = append(dataList, dataItem) // if len(dataList) >= 10 { // break // } // } //} //searchItem.StockList = stockList stockList := make([]*data_manage.StockInfo, 0) edbCodeArr := strings.Split(edbCode, ",") for _, v := range edbCodeArr { indexCode := utils.WindDbWsd + stockCode + v dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error() return } stockInfo := new(data_manage.StockInfo) stockInfo.StockCode = stockCode stockInfo.EdbCode = v stockInfo.DataList = dataList stockList = append(stockList, stockInfo) } searchItem.StockList = stockList } else if source == utils.DATA_SOURCE_THS { stockList := make([]*data_manage.StockInfo, 0) edbCodeArr := strings.Split(edbCode, ",") for _, v := range edbCodeArr { indexCode := utils.ThsDs + stockCode + v dataList, err := data_manage.GetEdbDataAllByEdbCodeAndSubSource(indexCode, source, utils.DATA_SUB_SOURCE_DATE, utils.EDB_DATA_LIMIT) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error() return } stockInfo := new(data_manage.StockInfo) stockInfo.StockCode = stockCode stockInfo.EdbCode = v stockInfo.DataList = dataList stockList = append(stockList, stockInfo) } searchItem.StockList = stockList } else { br.Msg = "来源错误" br.ErrMsg = "来源错误" return } } else { dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, subSource, utils.EDB_DATA_LIMIT) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error() return } searchItem.DataList = dataList edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error() return } searchItem.EdbCode = edbCode searchItem.DataList = dataList if edbInfoMaxAndMinInfo != nil { searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate } //edb指标信息 edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode) if edbInfoItem != nil { searchItem.EdbName = edbInfoItem.EdbName } } } resp.Status = 2 resp.SearchItem = searchItem } //如果不在指标库中,且不是新增 if !isInEdb && !isAdd { if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 { br.Msg = "目标指标无有效值,请重新搜索" br.Data = resp return } } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // EdbInfoList // @Title 指标列表接口 // @Description 指标列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param EdbInfoId query int true "指标id" // @Param KeyWord query string false "搜索关键词:指标ID/指标名称" // @Success 200 {object} data_manage.EdbInfoListResp // @router /edb_info/list [get] func (this *EdbInfoController) EdbInfoList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() edbInfoId, _ := this.GetInt("EdbInfoId") keyWord := this.GetString("KeyWord") pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") var total int page := paging.GetPaging(currentIndex, pageSize, total) var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) var condition string var pars []interface{} //if edbInfoId <= 0 && keyWord == "" { // br.Msg = "参数错误" // return //} // 指标类型,0:普通指标,1:预测指标 condition += " AND edb_info_type=? " pars = append(pars, 0) if edbInfoId > 0 { condition += " AND edb_info_id=? " pars = append(pars, edbInfoId) // 获取当前账号的不可见指标配置 obj := data_manage.EdbInfoNoPermissionAdmin{} conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error() return } if conf != nil && conf.Id > 0 { br.Msg = "无权限,请联系管理员" br.IsSendEmail = false return } } if keyWord != "" { condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )` //pars = append(pars, keyWord) //pars = append(pars, keyWord) } resp := new(data_manage.EdbInfoListResp) if condition == "" { item := new(data_manage.EdbInfoList) resp.Paging = page resp.Item = item br.Ret = 200 br.Success = true br.Msg = "获取成功" return } //获取指标信息 edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars) if err != nil && !utils.IsErrNoRow(err) { br.Success = true br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } if edbInfoItem == nil || (err != nil && utils.IsErrNoRow(err)) { item := new(data_manage.EdbInfoList) resp.Paging = page resp.Item = item br.Ret = 200 br.Success = true br.Msg = "获取成功" return } // 时间转格式 edbInfoItem.ConvertToResp() //获取英文频度 edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency) // 获取是否供应商停更 edbInfoItem.IsSupplierStop = data.GetIsSupplierStop(edbInfoItem.Source, edbInfoItem.EdbCode) //查询目录 classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId) if err != nil { br.Msg = err.Error() br.ErrMsg = errMsg return } // 权限校验 { var currClassify *data_manage.EdbClassifyIdItems for _, v := range classifyList { if edbInfoItem.ClassifyId == v.ClassifyId { currClassify = v break } } if currClassify != nil { edbInfoItem.HaveOperaAuth, err = data_manage_permission.CheckEdbPermission(edbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfoItem.EdbInfoId, edbInfoItem.ClassifyId) if err != nil { br.Msg = err.Error() br.ErrMsg = "校验指标权限失败,err:" + err.Error() return } } } // 按钮校验 button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType, edbInfoItem.HaveOperaAuth) button.AddButton = false edbInfoItem.Button = button edbInfoItem.DataList = make([]*data_manage.EdbData, 0) // 如果有数据权限,那么就去获取指标数据 if edbInfoItem.HaveOperaAuth { dataCount, dataList, err := data.GetPageData(edbInfoItem.EdbInfoId, edbInfoItem.Source, edbInfoItem.SubSource, "", startSize, pageSize) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error() return } page = paging.GetPaging(currentIndex, pageSize, dataCount) edbInfoItem.DataList = dataList } // 获取指标插入配置 { edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标数据失败,Err:" + err.Error() return } if edbDataInsertConfig != nil { edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate) edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate) edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value } } //是否展示英文标识 edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn) // 所属收藏分类id列表 { obj := data_manage.EdbCollect{} tmpCondition := ` AND sys_user_id = ? AND edb_info_id = ? ` tmpPars := []interface{}{this.SysUser.AdminId, edbInfoId} collectList, err := obj.GetItemsByCondition(tmpCondition, tmpPars, []string{"edb_collect_classify_id"}, "") if err != nil { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标数据失败,Err:" + err.Error() return } collectIdList := make([]int, 0) for _, v := range collectList { collectIdList = append(collectIdList, v.EdbCollectClassifyId) } edbInfoItem.CollectClassifyIdList = collectIdList } //CollectClassifyIdList resp.Paging = page resp.Item = edbInfoItem resp.ClassifyList = classifyList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // EdbInfoAdd // @Title 新增指标接口 // @Description 新增指标接口 // @Param request body data_manage.AddEdbInfoReq true "type json string" // @Success Ret=200 保存成功 // @router /edb_info/add [post] func (this *EdbInfoController) EdbInfoAdd() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } deleteCache := true cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId) defer func() { if deleteCache { utils.Rc.Delete(cacheKey) } }() if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) { deleteCache = false br.Msg = "系统处理中,请稍后重试!" br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody) return } var req data_manage.AddEdbInfoReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } source := req.Source if source <= 0 { br.Msg = "无效的数据来源" return } req.EdbName = strings.Trim(req.EdbName, " ") req.EdbCode = strings.Trim(req.EdbCode, " ") if req.EdbCode == "" { br.Msg = "指标ID不能为空" return } if req.EdbName == "" { br.Msg = "指标名称不能为空" return } if req.Frequency == "" { br.Msg = "频率不能为空" return } if req.Unit == "" { br.Msg = "单位不能为空" return } if req.ClassifyId <= 0 { br.Msg = "请选择分类" return } // 指标入库 edbInfo, err, errMsg, isSendEmail := data.EdbInfoAdd(source, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, req.StartDate, req.EndDate, sysUser.AdminId, sysUser.RealName, this.Lang) if err != nil { br.Msg = "保存失败" if errMsg != `` { br.Msg = errMsg } br.ErrMsg = err.Error() br.IsSendEmail = isSendEmail return } //新增操作日志 { edbLog := new(data_manage.EdbInfoLog) edbLog.EdbInfoId = edbInfo.EdbInfoId edbLog.SourceName = edbInfo.SourceName edbLog.Source = edbInfo.Source edbLog.EdbCode = edbInfo.EdbCode edbLog.EdbName = edbInfo.EdbName edbLog.ClassifyId = edbInfo.ClassifyId edbLog.SysUserId = sysUser.AdminId edbLog.SysUserRealName = sysUser.RealName edbLog.CreateTime = time.Now() edbLog.Content = string(this.Ctx.Input.RequestBody) edbLog.Status = "新增指标" edbLog.Method = this.Ctx.Input.URI() go data_manage.AddEdbInfoLog(edbLog) } // 更新es go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId) resp := new(data_manage.AddEdbInfoResp) resp.EdbInfoId = edbInfo.EdbInfoId resp.UniqueCode = edbInfo.UniqueCode br.Ret = 200 br.Success = true br.Msg = "保存成功" br.Data = resp br.IsAddLog = true } // EdbInfoEdit // @Title 编辑指标接口 // @Description 编辑指标接口 // @Success 200 {object} data_manage.EditEdbInfoReq // @router /edb_info/edit [post] func (this *EdbInfoController) EdbInfoEdit() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req data_manage.EditEdbInfoReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } req.EdbName = strings.Trim(req.EdbName, " ") if req.EdbInfoId <= 0 { br.Msg = "参数错误" br.ErrMsg = "指标id小于等于0" return } if req.EdbName == "" { br.Msg = "指标名称不能为空" return } if req.Frequency == "" { br.Msg = "频率不能为空" return } if req.Unit == "" { br.Msg = "单位不能为空" return } if req.ClassifyId <= 0 { br.Msg = "请选择分类" return } edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId) if err != nil { br.Msg = "修改失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } // 记录旧的指标基本信息 oldEdbName := edbInfo.EdbName oldFrequency := edbInfo.Frequency oldUnit := edbInfo.Unit var haveOperaAuth bool // 权限校验 { haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() br.ErrMsg = "校验指标权限失败,err:" + err.Error() return } } // 编辑权限校验 button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth) if !button.OpButton { br.Msg = "无权限操作" br.IsSendEmail = false return } //判断指标名称是否存在 var condition string var pars []interface{} condition += " AND edb_info_id<>? " pars = append(pars, req.EdbInfoId) //condition += " AND source=? " //pars = append(pars, edbInfo.Source) updateCols := make([]string, 0) switch this.Lang { case utils.EnLangVersion: condition += " AND edb_name_en = ? " edbInfo.EdbNameEn = req.EdbName edbInfo.Frequency = req.Frequency edbInfo.UnitEn = req.Unit edbInfo.ClassifyId = req.ClassifyId updateCols = append(updateCols, "EdbNameEn", "Frequency", "UnitEn", "ClassifyId") default: condition += " AND edb_name=? " edbInfo.EdbName = req.EdbName edbInfo.EdbNameSource = req.EdbName edbInfo.Frequency = req.Frequency edbInfo.Unit = req.Unit edbInfo.ClassifyId = req.ClassifyId updateCols = append(updateCols, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId") } pars = append(pars, req.EdbName) count, err := data_manage.GetEdbInfoCountByCondition(condition, pars) if err != nil { br.Msg = "判断指标名称是否存在失败" br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error() return } if count > 0 { br.Msg = "指标名称已存在,请重新填写" br.ErrMsg = "指标名称已存在,请重新填写" br.IsSendEmail = false return } if len(updateCols) > 0 { err = edbInfo.Update(updateCols) if err != nil { br.Msg = "保存失败" br.ErrMsg = "修改失败,Err:" + err.Error() return } } //处理同名指标 //{ // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName) // if err != nil { // br.Msg = "保存失败" // br.ErrMsg = "获取指标信息失败,Err:" + err.Error() // return // } // if len(edbNameList) >= 2 { // for _, v := range edbNameList { // edbName := v.EdbName + "(" + v.SourceName + ")" // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId) // if err != nil { // br.Msg = "保存失败" // br.ErrMsg = "修改指标名称失败,Err:" + err.Error() // return // } // } // } //} // 新增保存记录日志 oldEdbInfo := new(data_manage.EdbInfo) oldEdbInfo.EdbInfoId = edbInfo.EdbInfoId oldEdbInfo.EdbName = oldEdbName oldEdbInfo.Frequency = oldFrequency oldEdbInfo.Unit = oldUnit newEdbInfoRecord := new(data_manage.EdbInfoEditRecord) newEdbInfoRecord.EdbName = req.EdbName newEdbInfoRecord.Frequency = req.Frequency newEdbInfoRecord.Unit = req.Unit newEdbInfoRecord.OperateUserId = sysUser.AdminId newEdbInfoRecord.OperateUserRealName = sysUser.RealName go data.AddEditEdbInfoRcord(oldEdbInfo, newEdbInfoRecord) //新增操作日志 { edbLog := new(data_manage.EdbInfoLog) edbLog.EdbInfoId = edbInfo.EdbInfoId edbLog.SourceName = edbInfo.SourceName edbLog.Source = edbInfo.Source edbLog.EdbCode = edbInfo.EdbCode edbLog.EdbName = edbInfo.EdbName edbLog.ClassifyId = edbInfo.ClassifyId edbLog.SysUserId = sysUser.AdminId edbLog.SysUserRealName = sysUser.RealName edbLog.CreateTime = time.Now() edbLog.Content = string(this.Ctx.Input.RequestBody) edbLog.Status = "编辑指标" edbLog.Method = this.Ctx.Input.URI() go data_manage.AddEdbInfoLog(edbLog) } //添加es data.AddOrEditEdbInfoToEs(req.EdbInfoId) switch this.Lang { case utils.EnLangVersion: // 修改关联的预测指标基础信息 go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit) default: // 修改关联的预测指标基础信息 go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, req.Frequency, req.Unit) } br.Ret = 200 br.Success = true br.Msg = "保存成功" br.IsAddLog = true } // EdbEnInfoEdit // @Title 编辑指标英文信息接口 // @Description 编辑指标英文信息接口 // @Success 200 {object} data_manage.EditEdbEnInfoReq // @router /edb_info/en/edit [post] func (this *EdbInfoController) EdbEnInfoEdit() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req data_manage.EditEdbEnInfoReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } req.EdbNameEn = strings.Trim(req.EdbNameEn, " ") req.UnitEn = strings.Trim(req.UnitEn, " ") if req.EdbInfoId <= 0 { br.Msg = "参数错误" br.ErrMsg = "指标id小于等于0" return } edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId) if err != nil { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } if req.EdbNameEn != "" { //判断指标名称是否存在 var condition string var pars []interface{} condition += " AND edb_info_id<>? " pars = append(pars, req.EdbInfoId) /*condition += " AND source=? " pars = append(pars, edbInfo.Source)*/ condition += " AND edb_name_en=? " pars = append(pars, req.EdbNameEn) edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars) if err != nil { if !utils.IsErrNoRow(err) { br.Msg = "判断英文指标名称是否存在失败" br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error() return } } if err == nil && edbExist.EdbInfoId > 0 { br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在" br.ErrMsg = "英文指标名称已存在,请重新填写" br.IsSendEmail = false return } } err = data_manage.ModifyEdbEnInfo(&req) if err != nil { br.Msg = "保存失败" br.ErrMsg = "修改失败,Err:" + err.Error() return } //新增操作日志 { edbLog := new(data_manage.EdbInfoLog) edbLog.EdbInfoId = edbInfo.EdbInfoId edbLog.SourceName = edbInfo.SourceName edbLog.Source = edbInfo.Source edbLog.EdbCode = edbInfo.EdbCode edbLog.EdbName = edbInfo.EdbName edbLog.ClassifyId = edbInfo.ClassifyId edbLog.SysUserId = sysUser.AdminId edbLog.SysUserRealName = sysUser.RealName edbLog.CreateTime = time.Now() edbLog.Content = string(this.Ctx.Input.RequestBody) edbLog.Status = "编辑指标英文信息" edbLog.Method = this.Ctx.Input.URI() go data_manage.AddEdbInfoLog(edbLog) } //添加es data.AddOrEditEdbInfoToEs(req.EdbInfoId) // 修改关联的预测指标基础信息 if edbInfo.EdbInfoType == 0 { go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.UnitEn) } br.Ret = 200 br.Success = true br.Msg = "保存成功" br.IsAddLog = true } // EdbInfoBaseEdit // @Title 编辑指标基础信息接口 // @Description 编辑指标基础信息接口 // @Success 200 {object} data_manage.EditEdbBaseInfoReq // @router /edb_info/base/edit [post] func (this *EdbInfoController) EdbInfoBaseEdit() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req data_manage.EditEdbBaseInfoReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } req.EdbName = strings.Trim(req.EdbName, " ") req.Unit = strings.Trim(req.Unit, " ") if req.EdbInfoId <= 0 { br.Msg = "参数错误" br.ErrMsg = "指标id小于等于0" return } edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId) if err != nil { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } updateCols := make([]string, 0) if req.EdbName != "" { //判断指标名称是否存在 var condition string var pars []interface{} condition += " AND edb_info_id<>? " pars = append(pars, req.EdbInfoId) /*condition += " AND source=? " pars = append(pars, edbInfo.Source)*/ switch this.Lang { case utils.EnLangVersion: condition += " AND edb_name_en = ? " edbInfo.EdbNameEn = req.EdbName edbInfo.UnitEn = req.Unit edbInfo.ModifyTime = time.Now() updateCols = append(updateCols, "EdbNameEn", "UnitEn", "ModifyTime") default: condition += " AND edb_name = ? " edbInfo.EdbName = req.EdbName edbInfo.EdbNameSource = req.EdbName edbInfo.Unit = req.Unit edbInfo.ModifyTime = time.Now() updateCols = append(updateCols, "EdbName", "EdbNameSource", "Unit", "ModifyTime") } pars = append(pars, req.EdbName) edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars) if err != nil { if !utils.IsErrNoRow(err) { br.Msg = "判断英文指标名称是否存在失败" br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error() return } } if err == nil && edbExist.EdbInfoId > 0 { br.Msg = edbExist.EdbName + ":" + req.EdbName + "指标名称已存在" br.ErrMsg = "英文指标名称已存在,请重新填写" br.IsSendEmail = false return } } if len(updateCols) > 0 { err = edbInfo.Update(updateCols) if err != nil { br.Msg = "保存失败" br.ErrMsg = "修改失败,Err:" + err.Error() return } } //新增操作日志 { edbLog := new(data_manage.EdbInfoLog) edbLog.EdbInfoId = edbInfo.EdbInfoId edbLog.SourceName = edbInfo.SourceName edbLog.Source = edbInfo.Source edbLog.EdbCode = edbInfo.EdbCode edbLog.EdbName = edbInfo.EdbName edbLog.ClassifyId = edbInfo.ClassifyId edbLog.SysUserId = sysUser.AdminId edbLog.SysUserRealName = sysUser.RealName edbLog.CreateTime = time.Now() edbLog.Content = string(this.Ctx.Input.RequestBody) edbLog.Status = "编辑指标英文信息" edbLog.Method = this.Ctx.Input.URI() go data_manage.AddEdbInfoLog(edbLog) } //添加es data.AddOrEditEdbInfoToEs(req.EdbInfoId) // 修改关联的预测指标基础信息 if edbInfo.EdbInfoType == 0 { switch this.Lang { case utils.EnLangVersion: go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit) default: go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, edbInfo.Frequency, req.Unit) } } br.Ret = 200 br.Success = true br.Msg = "保存成功" br.IsAddLog = true } // EdbInfoNewest // @Title 获取最新指标接口 // @Description 获取最新指标接口 // @Success 200 {object} data_manage.EdbInfoList // @router /edb_info/newest [get] func (this *EdbInfoController) EdbInfoNewest() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() item, err := data_manage.GetEdbInfoByNewest() if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取最新指标失败" br.ErrMsg = "获取最新指标失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = item } // EdbInfoRefresh // @Title 指标刷新接口 // @Description 指标刷新接口 // @Param EdbInfoId query int true "指标id" // @Success Ret=200 刷新成功 // @router /edb_info/refresh [get] func (this *EdbInfoController) EdbInfoRefresh() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } edbInfoId, _ := this.GetInt("EdbInfoId") if edbInfoId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } _, err := data_manage.GetEdbInfoById(edbInfoId) if err != nil { if utils.IsErrNoRow(err) { br.Msg = "数据已被删除,请刷新页面" br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId) return } br.Msg = "刷新失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false, false) if err != nil { br.Msg = "刷新失败" br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error() return } br.Ret = 200 br.Msg = "刷新成功" if isAsync { br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据" } br.Success = true br.IsAddLog = true } // EdbInfoMove // @Title 移动指标接口 // @Description 移动指标接口 // @Success 200 {object} data_manage.MoveEdbInfoReq // @router /edb_info/move [post] func (this *EdbInfoController) EdbInfoMove() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req data_manage.MoveEdbInfoReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.EdbInfoId <= 0 { br.Msg = "参数错误" br.ErrMsg = "指标id小于等于0" return } if req.ClassifyId <= 0 { br.Msg = "请选择分类" return } //判断分类是否存在 count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId) if count <= 0 { br.Msg = "分类已被删除,不可移动,请刷新页面" return } edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } var haveOperaAuth bool // 权限校验 { haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.IsJoinPermission, edbInfo.EdbInfoId, edbInfo.ClassifyId, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() br.ErrMsg = "校验指标权限失败,err:" + err.Error() return } } // 移动权限校验 button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth) if !button.MoveButton { br.Msg = "无权限操作" br.IsSendEmail = false return } //如果改变了分类,那么移动该指标数据 if edbInfo.ClassifyId != req.ClassifyId { err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "移动指标失败,Err:" + err.Error() return } } updateCol := make([]string, 0) //如果有传入 上一个兄弟节点分类id if req.PrevEdbInfoId > 0 { prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error() return } //如果是移动在两个兄弟节点之间 if req.NextEdbInfoId > 0 { //下一个兄弟节点 nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId) if err != nil { br.Msg = "移动失败" br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error() return } //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1 if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort { //变更兄弟节点的排序 updateSortStr := `sort + 2` _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr) } else { //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了 if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 { //变更兄弟节点的排序 updateSortStr := `sort + 1` _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr) } } } edbInfo.Sort = prevEdbInfo.Sort + 1 edbInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } else { firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "移动失败" br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error() return } //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序 if firstClassify != nil && firstClassify.ClassifyId > 0 && firstClassify.Sort == 0 { updateSortStr := ` sort + 1 ` _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr) } edbInfo.Sort = 0 //那就是排在第一位 edbInfo.ModifyTime = time.Now() updateCol = append(updateCol, "Sort", "ModifyTime") } //更新 if len(updateCol) > 0 { err = edbInfo.Update(updateCol) if err != nil { br.Msg = "移动失败" br.ErrMsg = "修改失败,Err:" + err.Error() return } } if err != nil { br.Msg = "移动失败" br.ErrMsg = "修改失败,Err:" + err.Error() return } //新增操作日志 { edbLog := new(data_manage.EdbInfoLog) edbLog.EdbInfoId = edbInfo.EdbInfoId edbLog.SourceName = edbInfo.SourceName edbLog.Source = edbInfo.Source edbLog.EdbCode = edbInfo.EdbCode edbLog.EdbName = edbInfo.EdbName edbLog.ClassifyId = edbInfo.ClassifyId edbLog.SysUserId = sysUser.AdminId edbLog.SysUserRealName = sysUser.RealName edbLog.CreateTime = time.Now() edbLog.Content = string(this.Ctx.Input.RequestBody) edbLog.Status = "移动指标" edbLog.Method = this.Ctx.Input.URI() go data_manage.AddEdbInfoLog(edbLog) } br.Ret = 200 br.Success = true br.Msg = "移动成功" } // EdbInfoDetail // @Title 获取指标详情 // @Description 获取指标详情接口 // @Param EdbInfoId query int true "指标id" // @Success 200 {object} data_manage.EdbInfo // @router /edb_info/detail [get] func (this *EdbInfoController) EdbInfoDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } edbInfoId, _ := this.GetInt("EdbInfoId") if edbInfoId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } edbInfo, err := data_manage.GetEdbInfoById(edbInfoId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } var resp data_manage.EdbInfoFullClassify classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId) if err != nil { br.Msg = err.Error() br.ErrMsg = errMsg return } // 权限校验 { classifyMap := make(map[int]*data_manage.EdbClassifyIdItems) for _, v := range classifyList { classifyMap[v.ClassifyId] = v } if currClassify, ok := classifyMap[edbInfo.ClassifyId]; ok { haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassify.IsJoinPermission, this.SysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId) if err != nil { br.Msg = err.Error() br.ErrMsg = "校验指标权限失败,err:" + err.Error() return } resp.HaveOperaAuth = haveOperaAuth } } edbInfoResp, err := edbInfo.ConvertToResp() if err != nil { br.Msg = err.Error() br.ErrMsg = errMsg return } resp.EdbInfoResp = edbInfoResp resp.ClassifyList = classifyList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // EdbInfoFilter // @Title 指标筛选接口 // @Description 指标筛选接口 // @Param KeyWord query string false "搜索关键词:指标ID/指标名称" // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标" // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Success 200 {object} data_manage.EdbInfoList // @router /edb_info/filter [get] func (this *EdbInfoController) EdbInfoFilter() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() keyWord := this.GetString("KeyWord") filterSource, _ := this.GetInt("FilterSource") if filterSource <= 0 { filterSource = 1 } var pars []interface{} noPermissionEdbInfoIdList := make([]int, 0) //无权限指标 // 获取当前账号的不可见指标 { obj := data_manage.EdbInfoNoPermissionAdmin{} confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } for _, v := range confList { noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId) } } var keyWordArr []string keyWordArr = append(keyWordArr, keyWord) if keyWord != "" { newKeyWord := strings.Split(keyWord, " ") keyWordArr = append(keyWordArr, newKeyWord...) } //var err error edbInfoList := make([]*data_manage.EdbInfoList, 0) //if keyWord == "" { // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars) // if err != nil && !utils.IsErrNoRow(err) { // br.Success = true // br.Msg = "获取指标信息失败" // br.ErrMsg = "获取指标信息失败,Err:" + err.Error() // return // } //} else { // //获取指标信息 // indexName := utils.DATA_INDEX_NAME // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource) // if err != nil && !utils.IsErrNoRow(err) { // br.Success = true // br.Msg = "获取指标信息失败" // br.ErrMsg = "获取指标信息失败,Err:" + err.Error() // return // } //} var baseCondition string // 无权限指标id lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList) if lenNoPermissionEdbInfoIdList > 0 { baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) ` pars = append(pars, noPermissionEdbInfoIdList) } existMap := make(map[int]string) for _, v := range keyWordArr { v = strings.Replace(v, " ", "%", -1) var condition string if filterSource == 2 { condition += ` AND frequency='月度' ` } if filterSource == 3 { condition += ` AND frequency <> '日度' ` } if filterSource == 4 { condition += ` AND edb_type = 1 ` } conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )` condition += conditionWhere + baseCondition newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars) if err != nil && !utils.IsErrNoRow(err) { br.Success = true br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } for _, nv := range newEdbInfoList { nv.ConvertToResp() if _, ok := existMap[nv.EdbInfoId]; !ok { edbInfoList = append(edbInfoList, nv) } existMap[nv.EdbInfoId] = nv.EdbCode } } if edbInfoList == nil { edbInfoList = make([]*data_manage.EdbInfoList, 0) } edbInfoListLen := len(edbInfoList) for i := 0; i < edbInfoListLen; i++ { // 时间转格式 edbInfoList[i].ConvertToResp() edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName } for i := 0; i < edbInfoListLen; i++ { for j := 0; j < edbInfoListLen; j++ { if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) && (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) && !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) { edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")" } } } //新增搜索词记录 { searchKeyword := new(data_manage.SearchKeyword) searchKeyword.KeyWord = keyWord searchKeyword.CreateTime = time.Now() go data_manage.AddSearchKeyword(searchKeyword) } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = edbInfoList } // EdbInfoFilterByEs // @Title 指标筛选接口 // @Description 指标筛选接口 // @Param KeyWord query string false "搜索关键词:指标ID/指标名称" // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比" // @Param Frequency query string false "频度" // @Param IsAddPredictEdb query bool false "是否查询添加预测指标" // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param EdbType query int false "指标类型:0-基础和计算;1-基础指标;2-计算指标;3-衍生指标" // @Param EdbAuth query int false "指标权限:0-全部;1-我的;2-公共" // @Param EdbCollect query int false "指标收藏状态:0-全部;1-已收藏" // @Param ClassifyId query int false "父级分类id" // @Success 200 {object} data_manage.EdbInfoList // @router /edb_info/filter_by_es [get] func (this *EdbInfoController) EdbInfoFilterByEs() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") var total int64 var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) keyWord := this.GetString("KeyWord") if keyWord == `` { keyWord = this.GetString("Keyword") } keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格 filterSource, _ := this.GetInt("FilterSource") if filterSource <= 0 { filterSource = 1 } //指标来源 source, _ := this.GetInt("Source") frequency := this.GetString("Frequency") //频度 edbTypeStr := this.GetString("EdbType", "0") // 指标类型:0-基础和计算;1-基础指标;2-计算指标;3-预测指标 edbAuth, _ := this.GetInt("EdbAuth", 0) // 指标权限范围,0-全部;1-我的;2-公共 edbCollect, _ := this.GetInt("EdbCollect", 0) // 指标收藏状态:0-全部;1-已收藏 // 父级分类id classifyId, _ := this.GetInt("ClassifyId") var edbInfoList []*data_manage.EdbInfoList var err error // 获取es搜索参数 source, frequency, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, collectEdbInfoIdList, searchClassifyIdList, searchPublicClassifyIdList, edbTypeList, edbInfoType, edbAuth, searchUserId, err, errMsg := data.GetGeneralEdbEsSearchParams(edbTypeStr, this.SysUser.AdminId, edbAuth, edbCollect, classifyId) if err != nil { br.Msg = "获取失败" if errMsg != `` { br.Msg = errMsg } br.ErrMsg = "获取失败:" + err.Error() return } sortMap := make(map[string]string) // 如果没有搜索关键词,则默认根据指标编码倒序排序 if keyWord == `` { sortMap["EdbInfoId"] = `desc` } // 普通的搜索 total, edbInfoList, err = elastic.SearchEdbInfoData(keyWord, startSize, pageSize, filterSource, source, frequency, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, collectEdbInfoIdList, searchClassifyIdList, searchPublicClassifyIdList, edbTypeList, edbInfoType, edbAuth, searchUserId, sortMap) if err != nil { edbInfoList = make([]*data_manage.EdbInfoList, 0) } page := paging.GetPaging(currentIndex, pageSize, int(total)) edbInfoListLen := len(edbInfoList) classifyIdList := make([]int, 0) for _, v := range edbInfoList { v.ConvertToResp() v.EdbNameAlias = v.EdbName classifyIdList = append(classifyIdList, v.ClassifyId) } // 当前列表中的分类map classifyMap := make(map[int]*data_manage.EdbClassify) if len(classifyIdList) > 0 { classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取分类列表失败,Err:" + err.Error() return } for _, v := range classifyList { classifyMap[v.ClassifyId] = v } // 获取所有有权限的指标和分类 permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error() return } // 因为是ES查找的,所以需要重新查一下指标的信息,主要是为了把是否授权字段找出来 { edbInfoIdList := make([]int, 0) for _, tmpEdbInfo := range edbInfoList { edbInfoIdList = append(edbInfoIdList, tmpEdbInfo.EdbInfoId) if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok { tmpEdbInfo.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList) } } tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error() return } edbInfoMap := make(map[int]*data_manage.EdbInfo) for _, v := range tmpEdbList { edbInfoMap[v.EdbInfoId] = v } // 查询收藏 collectEdbMap := make(map[int][]int) collectNameEdbMap := make(map[int][]string) { obj := data_manage.EdbCollect{} collectList, err := obj.GetItemsByUserIdAndEdbInfoIdList(this.SysUser.AdminId, edbInfoIdList) if err != nil { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标数据失败,Err:" + err.Error() return } for _, v := range collectList { collectIdList, ok := collectEdbMap[v.EdbInfoId] if !ok { collectIdList = make([]int, 0) } collectEdbMap[v.EdbInfoId] = append(collectIdList, v.EdbCollectClassifyId) collectNameList, ok := collectNameEdbMap[v.EdbInfoId] if !ok { collectNameList = make([]string, 0) } collectNameEdbMap[v.EdbInfoId] = append(collectNameList, v.ClassifyName) } } for _, v := range edbInfoList { if collectIdList, ok := collectEdbMap[v.EdbInfoId]; ok { v.CollectClassifyIdList = collectIdList } else { v.CollectClassifyIdList = []int{} } if collectNameList, ok := collectNameEdbMap[v.EdbInfoId]; ok { v.CollectClassifyNameList = collectNameList } else { v.CollectClassifyNameList = []string{} } tmpEdbInfo, ok := edbInfoMap[v.EdbInfoId] if !ok { continue } v.IsJoinPermission = tmpEdbInfo.IsJoinPermission } } // 权限校验 for _, tmpEdbInfoItem := range edbInfoList { if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok { tmpEdbInfoItem.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList) } } } for i := 0; i < edbInfoListLen; i++ { for j := 0; j < edbInfoListLen; j++ { if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) && (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) && !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) { edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")" } } } // 不返回无权限的指标 respList := make([]*data_manage.EdbInfoList, 0) for _, v := range edbInfoList { if v.HaveOperaAuth { respList = append(respList, v) } } resp := data_manage.EdbInfoFilterDataResp{ Paging: page, List: respList, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } func (this *EdbInfoController) EdbInfoFilter2() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() keyWord := this.GetString("KeyWord") keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格 filterSource, _ := this.GetInt("FilterSource") if filterSource <= 0 { filterSource = 1 } var pars []interface{} //if keyWord != "" { // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )` //} var keyWordArr []string keyWordArr = append(keyWordArr, keyWord) if keyWord != "" { newKeyWord := strings.Split(keyWord, " ") keyWordArr = append(keyWordArr, newKeyWord...) } keywordLen := len(keyWordArr) ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen) searchWait := sync.WaitGroup{} searchWait.Add(keywordLen) for index, v := range keyWordArr { v = strings.Replace(v, " ", "%", -1) var condition string if filterSource == 2 { condition += ` AND frequency='月度' ` } if filterSource == 3 { condition += ` AND frequency <> '日度' ` } if filterSource == 4 { condition += ` AND edb_type = 1 ` } conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )` condition += conditionWhere go searchEdbInfoFilter(condition, pars, index, ch, &searchWait) } searchWait.Wait() newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList) i := 0 for tmpEdbInfoList := range ch { i++ for k, v := range tmpEdbInfoList { newEdbInfoListMap[k] = v } if i == keywordLen { break } } close(ch) edbInfoList := make([]*data_manage.EdbInfoList, 0) existMap := make(map[int]string) for i := 0; i < keywordLen; i++ { if newEdbInfoList, ok := newEdbInfoListMap[i]; ok { for _, nv := range newEdbInfoList { if _, ok := existMap[nv.EdbInfoId]; !ok { edbInfoList = append(edbInfoList, nv) } existMap[nv.EdbInfoId] = nv.EdbCode } } } if edbInfoList == nil { edbInfoList = make([]*data_manage.EdbInfoList, 0) } edbInfoListLen := len(edbInfoList) for i := 0; i < edbInfoListLen; i++ { edbInfoList[i].ConvertToResp() edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName } for i := 0; i < edbInfoListLen; i++ { for j := 0; j < edbInfoListLen; j++ { if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) && (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) && !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) { edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")" } } } //新增搜索词记录 { searchKeyword := new(data_manage.SearchKeyword) searchKeyword.KeyWord = keyWord searchKeyword.CreateTime = time.Now() go data_manage.AddSearchKeyword(searchKeyword) } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = edbInfoList } func searchEdbInfoFilter(condition string, pars []interface{}, i int, ch chan map[int][]*data_manage.EdbInfoList, searchWait *sync.WaitGroup) (newEdbInfoListMap map[int][]*data_manage.EdbInfoList, err error) { newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList) defer func() { if err != nil { go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3) //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers) } ch <- newEdbInfoListMap searchWait.Done() }() newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars) for _, v := range newEdbInfoList { v.ConvertToResp() } newEdbInfoListMap[i] = newEdbInfoList return } // EdbInfoAllRefresh // @Title 指标全部刷新接口 // @Description 指标全部刷新接口 // @Param EdbInfoId query int true "指标id" // @Success Ret=200 全部刷新成功 // @router /edb_info/refresh/all [get] func (this *EdbInfoController) EdbInfoAllRefresh() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } edbInfoId, _ := this.GetInt("EdbInfoId") if edbInfoId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } edbInfo, err := data_manage.GetEdbInfoById(edbInfoId) if err != nil { if utils.IsErrNoRow(err) { br.Msg = "数据已被删除,请刷新页面" br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId) return } br.Msg = "刷新失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } if edbInfo == nil { br.Msg = "数据已被删除,请刷新页面" br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId) return } err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true, false) if err != nil { br.Msg = "刷新失败" br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "刷新成功" if isAsync { br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据" } } // EdbInfoData // @Title 获取指标数据 // @Description 获取指标数据 // @Param EdbInfoId query int true "指标ID" // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部" // @Param StartDate query string true "自定义开始日期" // @Param EndDate query string true "自定义结束日期" // @Success 200 {object} data_manage.EdbInfoDataResp // @router /edb_info/data [get] func (this *ChartInfoController) EdbInfoData() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } fullEdb := new(data_manage.EdbInfoFullClassify) resp := new(data_manage.EdbInfoDataFullClassifyResp) dataList := make([]*data_manage.EdbDataList, 0) edbInfoId, _ := this.GetInt("EdbInfoId") if edbInfoId <= 0 { br.Msg = "参数错误" return } dateType, _ := this.GetInt("DateType") if dateType <= 0 { dateType = 3 } edbInfoType, _ := this.GetInt("EdbInfoType") if edbInfoType < 0 { edbInfoType = 1 } startDate := this.GetString("StartDate") endDate := this.GetString("EndDate") startYear, _ := this.GetInt("StartYear") edbInfo, err := data_manage.GetEdbInfoById(edbInfoId) if err != nil { if utils.IsErrNoRow(err) { br.Ret = 200 return } br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } // 分类 classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId) if err != nil { br.Msg = err.Error() br.ErrMsg = errMsg return } edbInfoResp, err := edbInfo.ConvertToResp() if err != nil { br.Msg = err.Error() br.ErrMsg = errMsg return } fullEdb.EdbInfoResp = edbInfoResp // 是否供应商停更 fullEdb.IsSupplierStop = data.GetIsSupplierStop(edbInfo.Source, edbInfo.EdbCode) fullEdb.ClassifyList = classifyList var currClassifyItem *data_manage.EdbClassifyIdItems for _, v := range classifyList { if v.ClassifyId == edbInfo.ClassifyId { currClassifyItem = v } } if currClassifyItem != nil { haveOperaAuth, err := data_manage_permission.CheckEdbPermission(edbInfo.IsJoinPermission, currClassifyItem.IsJoinPermission, sysUser.AdminId, edbInfo.EdbInfoId, edbInfo.ClassifyId) if err != nil { br.Msg = err.Error() br.ErrMsg = "校验指标权限失败,err:" + err.Error() return } fullEdb.HaveOperaAuth = haveOperaAuth } resp.EdbInfo = fullEdb resp.DataList = make([]*data_manage.EdbDataList, 0) // 数据获取 if fullEdb.HaveOperaAuth { // 有权限才获取数据 maxYear := 0 if edbInfo.LatestDate != "" { latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate) maxYear = latestDateT.Year() } startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear) dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } resp.DataList = dataList } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // EdbInfoReplaceCheck // @Title 指标一键刷新接口 // @Description 指标一键刷新接口 // @Success Ret=200 更新成功 // @router /edb_info/replace/check [post] func (this *EdbInfoController) EdbInfoReplaceCheck() { br := new(models.BaseResponse).Init() setNxKey := "EDB_INFO_REPLACE" defer func() { this.Data["json"] = br this.ServeJSON() }() status := 0 if utils.Rc.IsExist(setNxKey) { status = 1 } else { status = 2 } br.Ret = 200 br.Success = true br.Msg = "检测成功" br.Data = status } // EdbInfoReplace // @Title 替换指标 // @Description 替换指标 // @Param request body data_manage.EdbInfoReplaceReq true "type json string" // @Success 200 {object} data_manage.EdbInfoDataResp // @router /edb_info/replace [post] func (this *ChartInfoController) EdbInfoReplace() { br := new(models.BaseResponse).Init() setNxKey := "EDB_INFO_REPLACE" deleteCache := true defer func() { if deleteCache { utils.Rc.Delete(setNxKey) } this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) { deleteCache = false br.Msg = "当前正在替换中,请耐心等待!" br.IsSendEmail = false return } var req data_manage.EdbInfoReplaceReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 { br.Msg = "参数错误!" br.ErrMsg = "参数错误,指标id为0" return } oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId) if err != nil { br.Msg = "替换失败!" br.ErrMsg = "获取原指标失败,Err:" + err.Error() return } newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId) if err != nil { br.Msg = "替换失败!" br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error() return } //if oldEdbInfo.EdbType != 1 { // br.Msg = "原指标为计算指标,不可替换!" // br.ErrMsg = "原指标为计算指标,不可替换!" // return //} // //if newEdbInfo.EdbType != 1 { // br.Msg = "替换指标为计算指标,不可替换!" // br.ErrMsg = "替换指标为计算指标,不可替换!" // return //} if oldEdbInfo.Frequency != newEdbInfo.Frequency { br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!" br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!" return } sysAdminId := sysUser.AdminId //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName) _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName) //msgContent := `` if err != nil { br.Msg = "替换失败" br.ErrMsg = "替换失败 replace err:" + err.Error() return } br.Msg = "替换成功" br.ErrMsg = "替换成功" br.Ret = 200 br.IsAddLog = true return } // RelationChartList // @Title 获取ETA指标关联的图表列表接口 // @Description 获取ETA指标关联的图表列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param EdbInfoId query int true "指标id" // @Param IsShowMe query bool true "是否只看我的,true、false" // @Success 200 {object} data_manage.ChartListResp // @router /edb_info/relation/chart_list [get] func (this *EdbInfoController) RelationChartList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } edbInfoId, _ := this.GetInt("EdbInfoId") pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") resp := data_manage.ChartListResp{} var total int page := paging.GetPaging(currentIndex, pageSize, total) var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) var condition string var pars []interface{} if edbInfoId <= 0 { br.Msg = "请选择指标" br.ErrMsg = "请选择指标" br.IsSendEmail = false return } /*// 关联指标 condition += ` AND b.edb_info_id = ? ` pars = append(pars, edbInfoId)*/ //只看我的 isShowMe, _ := this.GetBool("IsShowMe") if isShowMe { condition += ` AND a.sys_user_id = ? ` pars = append(pars, sysUser.AdminId) } chartIds := make([]int, 0) chartIdMap := make(map[int]bool) // 查询指标绑定的图表 edbListTemp, err := data_manage.GetEdbMappingListByEdbInfoId(edbInfoId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取图表信息失败" br.ErrMsg = "获取图表信息失败,Err:" + err.Error() return } for _, v := range edbListTemp { if _, ok := chartIdMap[v.ChartInfoId]; !ok { chartIdMap[v.ChartInfoId] = true } } // 查询跨品种的图表 tagXList, err := cross_variety.GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取图表信息失败" br.ErrMsg = "获取图表信息失败,Err:" + err.Error() return } for _, v := range tagXList { if _, ok := chartIdMap[v.ChartInfoId]; !ok { chartIdMap[v.ChartInfoId] = true } } tagYList, err := cross_variety.GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取图表信息失败" br.ErrMsg = "获取图表信息失败,Err:" + err.Error() return } for _, v := range tagYList { if _, ok := chartIdMap[v.ChartInfoId]; !ok { chartIdMap[v.ChartInfoId] = true } } // 获取当前账号的不可见图表 { obj := data_manage.EdbInfoNoPermissionAdmin{} confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } for _, v := range confList { if _, ok := chartIdMap[v.ChartInfoId]; ok { delete(chartIdMap, v.ChartInfoId) } } } for k, _ := range chartIdMap { chartIds = append(chartIds, k) } // 关联指标 if len(chartIds) > 0 { condition += ` AND a.chart_info_id in (` + utils.GetOrmInReplace(len(chartIds)) + `)` pars = append(pars, chartIds) } else { items := make([]*data_manage.ChartInfoView, 0) resp.Paging = page resp.List = items br.Ret = 200 br.Success = true br.Msg = "获取成功" return } // 得到图表ID //获取关联图表列表 list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize) if err != nil && !utils.IsErrNoRow(err) { br.Success = true br.Msg = "获取图表信息失败" br.ErrMsg = "获取图表信息失败,Err:" + err.Error() return } if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) { items := make([]*data_manage.ChartInfoView, 0) resp.Paging = page resp.List = items br.Ret = 200 br.Success = true br.Msg = "获取成功" return } // 获取关联图表总数 dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error() return } // 获取MY ETA 图表,用来判断是否加入我的图库 myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取图表信息失败" br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error() return } myChartMap := make(map[int]*data_manage.MyChartView) for _, v := range myChartList { myChartMap[v.ChartInfoId] = v } listLen := len(list) if listLen > 0 { // 分类id classifyIdList := make([]int, 0) // 当前列表中的分类map classifyMap := make(map[int]*data_manage.ChartClassify) for _, v := range list { classifyIdList = append(classifyIdList, v.ChartClassifyId) } classifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取分类列表失败,Err:" + err.Error() return } for _, v := range classifyList { classifyMap[v.ChartClassifyId] = v } // 已授权分类id permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error() return } for _, v := range list { if existItem, ok := myChartMap[v.ChartInfoId]; ok { v.IsAdd = true v.MyChartId = existItem.MyChartId v.MyChartClassifyId = existItem.MyChartClassifyId } // 权限 if currClassify, ok := classifyMap[v.ChartClassifyId]; ok { v.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList) } } } page = paging.GetPaging(currentIndex, pageSize, dataCount) resp.Paging = page resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // RelationEdbList // @Title 获取ETA指标关联的指标列表接口 // @Description 获取ETA指标关联的指标列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param EdbInfoId query int true "指标id" // @Param IsShowMe query bool true "是否只看我的,true、false" // @Success 200 {object} data_manage.ChartListResp // @router /edb_info/relation/edbinfo_list [get] func (this *EdbInfoController) RelationEdbList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } edbInfoId, _ := this.GetInt("EdbInfoId") pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") resp := data_manage.RelationEdbInfoListResp{} var total int page := paging.GetPaging(currentIndex, pageSize, total) var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) var condition string var pars []interface{} if edbInfoId <= 0 { br.Msg = "请选择指标" br.ErrMsg = "请选择指标" br.IsSendEmail = false return } // 关联指标 condition += ` AND b.from_edb_info_id = ? ` pars = append(pars, edbInfoId) //只看我的 isShowMe, _ := this.GetBool("IsShowMe") if isShowMe { condition += ` AND a.sys_user_id = ? ` pars = append(pars, sysUser.AdminId) } // 获取当前账号的不可见图表 noPermissionEdbIdList := make([]int, 0) { obj := data_manage.EdbInfoNoPermissionAdmin{} confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } for _, v := range confList { noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId) } } noPermissionEdbIdNum := len(noPermissionEdbIdList) if noPermissionEdbIdNum > 0 { condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) ` pars = append(pars, noPermissionEdbIdList) } //获取关联图表列表 list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize) if err != nil && !utils.IsErrNoRow(err) { br.Success = true br.Msg = "获取图表信息失败" br.ErrMsg = "获取图表信息失败,Err:" + err.Error() return } if list == nil || len(list) <= 0 || (err != nil && utils.IsErrNoRow(err)) { items := make([]*data_manage.ChartEdbInfoMapping, 0) resp.Paging = page resp.List = items br.Ret = 200 br.Success = true br.Msg = "获取成功" return } // 获取关联图表总数 dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error() return } if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error() return } edbList := make([]*data_manage.ChartEdbInfoMapping, 0) if len(list) > 0 { // 当前的分类 classifyMap := make(map[int]*data_manage.EdbClassify) { classifyIdList := make([]int, 0) for _, v := range list { classifyIdList = append(classifyIdList, v.ClassifyId) } classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList) if err != nil { if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取分类列表失败,Err:" + err.Error() return } } for _, v := range classifyList { classifyMap[v.ClassifyId] = v } } // 获取所有有权限的指标和分类 permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error() return } for _, v := range list { item := new(data_manage.ChartEdbInfoMapping) item.EdbInfoId = v.EdbInfoId item.SourceName = v.SourceName item.Source = v.Source item.EdbCode = v.EdbCode item.EdbName = v.EdbName item.EdbNameEn = v.EdbNameEn item.Frequency = v.Frequency item.FrequencyEn = data.GetFrequencyEn(v.Frequency) if v.Unit != `无` { item.Unit = v.Unit } item.UnitEn = v.UnitEn item.StartDate = v.StartDate item.EndDate = v.EndDate item.ModifyTime = v.ModifyTime item.IsAxis = 1 item.LeadValue = 0 item.LeadUnit = "" item.ChartEdbMappingId = 0 item.ChartInfoId = 0 item.IsOrder = false item.EdbInfoType = v.EdbInfoType item.EdbInfoCategoryType = v.EdbInfoType item.ChartStyle = "" item.ChartColor = "" item.ChartWidth = 0 item.MaxData = v.MaxValue item.MinData = v.MinValue item.LatestValue = v.LatestValue item.LatestDate = v.LatestDate item.UniqueCode = v.UniqueCode item.ClassifyId = v.ClassifyId dataList := make([]*data_manage.EdbDataList, 0) // 指标权限 if currClassify, ok := classifyMap[v.ClassifyId]; ok { item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList) } // 有权限则获取数据 if item.HaveOperaAuth { if v.EdbInfoType == 0 { dataList, err = data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, "", "") } else { _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false) } if err != nil { br.Msg = "获取失败" br.Msg = "获取失败,Err:" + err.Error() return } } item.DataList = dataList item.ConvertToResp() edbList = append(edbList, item) } } page = paging.GetPaging(currentIndex, pageSize, dataCount) resp.Paging = page resp.List = edbList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // EdbInfoDataTb // @Title 获取指标数据同比值 // @Description 获取指标数据 // @Param EdbInfoId query int true "指标ID" // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部" // @Param StartDate query string true "自定义开始日期" // @Param EndDate query string true "自定义结束日期" // @Success 200 {object} data_manage.EdbInfoDataResp // @router /edb_info/data/tb [get] func (this *ChartInfoController) EdbInfoDataTb() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } edbInfoId, _ := this.GetInt("EdbInfoId") if edbInfoId <= 0 { br.Msg = "参数错误" return } dateType, _ := this.GetInt("DateType") if dateType <= 0 { dateType = 3 } edbInfoType, _ := this.GetInt("EdbInfoType") if edbInfoType < 0 { edbInfoType = 1 } startDate := this.GetString("StartDate") endDate := this.GetString("EndDate") startYear, _ := this.GetInt("StartYear") edbInfo, err := data_manage.GetEdbInfoById(edbInfoId) if err != nil { br.Msg = "获取失败" br.Msg = "获取失败,Err:" + err.Error() return } maxYear := 0 if edbInfo.LatestDate != "" { latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate) maxYear = latestDateT.Year() } startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear) var startDateTime time.Time if startDate != `` { startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local) if err != nil { br.Msg = "开始日期异常" br.Msg = "开始日期异常,Err:" + err.Error() return } //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天)) startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate) } tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDate, endDate) if err != nil { br.Msg = "获取失败" br.Msg = "获取失败,Err:" + err.Error() return } // 计算同比值 dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime) if err != nil { br.Msg = "获取失败" br.Msg = "计算同比值失败,Err:" + err.Error() return } edbInfo.MaxValue = maxValue edbInfo.MinValue = minValue resp := new(data_manage.EdbInfoDataResp) resp.EdbInfo = edbInfo resp.DataList = dataList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // EdbInfoDataSeasonal // @Title 获取指标数据(季节性) // @Description 获取指标数据 // @Param EdbInfoId query int true "指标ID" // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部" // @Param StartDate query string true "自定义开始日期" // @Param EndDate query string true "自定义结束日期" // @Param Calendar query string true "公历/农历" // @Success 200 {object} data_manage.EdbInfoDataResp // @router /edb_info/data/seasonal [get] func (this *ChartInfoController) EdbInfoDataSeasonal() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } dateType, _ := this.GetInt("DateType") startDate := this.GetString("StartDate") endDate := this.GetString("EndDate") startYear, _ := this.GetInt("StartYear") edbInfoIdStr := this.GetString("EdbInfoId") edbInfoId, err := strconv.Atoi(edbInfoIdStr) if err != nil { br.Msg = "指标id异常" br.Msg = "指标id转换异常,Err:" + err.Error() return } fmt.Println("startDate:", startDate) fmt.Println("endDate:", endDate) calendar := this.GetString("Calendar") if calendar == "" { calendar = "公历" } if dateType == 0 { if startDate == "" { dateType = utils.DateTypeNYears } else { dateType = 5 } } edbInfo, err := data_manage.GetEdbInfoById(edbInfoId) if err != nil { br.Msg = "获取失败" br.Msg = "获取失败,Err:" + err.Error() return } maxYear := 0 if edbInfo.LatestDate != "" { latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate) maxYear = latestDateT.Year() } startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear) dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error() return } resp := new(data_manage.EdbInfoDataSeasonalResp) resp.EdbInfo = edbInfo resp.DataList = dataList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // SetEdbDataInsertConfig 设置插入值 // @Title 设置插入值接口 // @Description 设置插入值接口 // @Success 200 {object} data_manage.EditEdbEnInfoReq // @router /edb_info/insert_config/set [post] func (this *EdbInfoController) SetEdbDataInsertConfig() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req data_manage.SetEdbDataInsertConfigReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } dateStr := req.Date if dateStr == `` { br.Msg = "请选择日期" br.IsSendEmail = false return } date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local) if err != nil { br.Msg = "日期异常" br.ErrMsg = "日期异常,err:" + err.Error() br.IsSendEmail = false return } edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId) if err != nil { br.Msg = "获取指标信息失败" br.ErrMsg = "获取指标信息失败,Err:" + err.Error() return } err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value) if err != nil { br.Msg = "设置失败" if errMsg != `` { br.Msg = errMsg } br.ErrMsg = "修改失败,Err:" + err.Error() br.IsSendEmail = isSendEmail return } //新增操作日志 { edbLog := new(data_manage.EdbInfoLog) edbLog.EdbInfoId = edbInfo.EdbInfoId edbLog.SourceName = edbInfo.SourceName edbLog.Source = edbInfo.Source edbLog.EdbCode = edbInfo.EdbCode edbLog.EdbName = edbInfo.EdbName edbLog.ClassifyId = edbInfo.ClassifyId edbLog.SysUserId = sysUser.AdminId edbLog.SysUserRealName = sysUser.RealName edbLog.CreateTime = time.Now() edbLog.Content = string(this.Ctx.Input.RequestBody) edbLog.Status = "设置插入值" edbLog.Method = this.Ctx.Input.URI() go data_manage.AddEdbInfoLog(edbLog) } br.Ret = 200 br.Success = true br.Msg = "保存成功" br.IsAddLog = true } // TraceEdbInfo // @Title 指标溯源接口 // @Description 指标溯源接口 // @Param UniqueCode query int true "指标唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc" // @Success 200 {object} data_manage.ChartListResp // @router /edb_info/trace [get] func (this *EdbInfoController) TraceEdbInfo() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } //edbInfoId, _ := this.GetInt("EdbInfoId") //if edbInfoId <= 0 { // br.Msg = "参数错误" // br.ErrMsg = "参数错误" // return //} uniqueCode := this.GetString("UniqueCode") if uniqueCode == `` { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } // 根据UniqueCode获取指标信息 edbInfo, err := data_manage.GetEdbInfoByUniqueCode(uniqueCode) if err != nil { br.Msg = "获取失败" br.Msg = "获取失败,Err:" + err.Error() if utils.IsErrNoRow(err) { br.Msg = "指标不存在" } return } resp, err := data.TraceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, this.SysUser.AdminId) if err != nil { br.Msg = "获取失败" br.Msg = "获取失败,Err:" + err.Error() return } br.Ret = 200 br.Data = resp br.Success = true br.Msg = "刷新成功" } // AllEdbInfoByEs // @Title 所有指标筛选接口 // @Description 所有指标筛选接口 // @Param KeyWord query string false "搜索关键词:指标ID/指标名称" // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比" // @Param Frequency query string false "频度" // @Param IsAddPredictEdb query bool false "是否查询添加预测指标" // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Success 200 {object} data_manage.EdbInfoList // @router /edb_info/filter_by_es/all [get] func (this *EdbInfoController) AllEdbInfoByEs() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") var total int64 var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) keyWord := this.GetString("KeyWord") keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格 filterSource, _ := this.GetInt("FilterSource") if filterSource <= 0 { filterSource = 1 } //指标来源 source, _ := this.GetInt("Source") frequency := this.GetString("Frequency") //频度 isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标 edbType, _ := this.GetInt("EdbType", 0) // 指标类型:0-基础和计算;1-基础指标;2-计算指标 var edbInfoList []*data_manage.EdbInfoList var err error // 无权限指标 和 无权限指标分类id noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.EDB_INFO_TYPE, edbType) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } // 是否走ES isEs := false if keyWord != "" { var keyWordArr []string keyWordArr = append(keyWordArr, keyWord) newKeyWord := strings.Split(keyWord, " ") keyWordArr = append(keyWordArr, newKeyWord...) // 普通的搜索 total, edbInfoList, err = elastic.SearchEdbInfoData(keyWord, startSize, pageSize, filterSource, source, frequency, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, []int{}, []int{}, []int{}, []int{1, 2}, -1, 0, this.SysUser.AdminId, map[string]string{}) isEs = true } else { var condition string var pars []interface{} // 普通指标 condition += ` AND edb_info_type = ? ` pars = append(pars, 0) // 无权限指标id lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList) if lenNoPermissionEdbInfoIdList > 0 { condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) ` pars = append(pars, noPermissionEdbInfoIdList) } // 无权限指标分类id lenNoPermissionEdbClassifyIdList := len(noPermissionEdbClassifyIdList) if lenNoPermissionEdbClassifyIdList > 0 { condition += ` AND classify_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbClassifyIdList) + `) ` pars = append(pars, noPermissionEdbClassifyIdList) } switch filterSource { case 2: condition += ` AND frequency='月度' ` case 3: condition += ` AND frequency <> '日度' ` case 4: condition += ` AND edb_type = 1 ` case 5: condition += ` AND source = 6 ` //来源(同比值) case 6: condition += ` AND frequency != ? ` pars = append(pars, "年度") } //频度 if frequency != "" { condition += ` AND frequency = ? ` pars = append(pars, frequency) } // 查询只允许添加预测指标的搜索 if isAddPredictEdb { condition += ` AND frequency in ("日度","周度","月度") ` } total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize) } if err != nil { edbInfoList = make([]*data_manage.EdbInfoList, 0) } page := paging.GetPaging(currentIndex, pageSize, int(total)) edbInfoListLen := len(edbInfoList) classifyIdList := make([]int, 0) for i := 0; i < edbInfoListLen; i++ { edbInfoList[i].ConvertToResp() edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId) } // 当前列表中的分类map classifyMap := make(map[int]*data_manage.EdbClassify) if edbInfoListLen > 0 { classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取分类列表失败,Err:" + err.Error() return } for _, v := range classifyList { classifyMap[v.ClassifyId] = v } // 获取所有有权限的指标和分类 permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error() return } // 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来 if isEs { edbInfoIdList := make([]int, 0) for i := 0; i < edbInfoListLen; i++ { edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId) tmpEdbInfo := edbInfoList[i] if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok { edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList) } } tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error() return } edbInfoMap := make(map[int]*data_manage.EdbInfo) for _, v := range tmpEdbList { edbInfoMap[v.EdbInfoId] = v } for i := 0; i < edbInfoListLen; i++ { tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId] if !ok { continue } edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission } } // 权限校验 for i := 0; i < edbInfoListLen; i++ { tmpEdbInfoItem := edbInfoList[i] if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok { edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList) } } } for i := 0; i < edbInfoListLen; i++ { for j := 0; j < edbInfoListLen; j++ { if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) && (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) && !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) { edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")" } } } //新增搜索词记录 { searchKeyword := new(data_manage.SearchKeyword) searchKeyword.KeyWord = keyWord searchKeyword.CreateTime = time.Now() go data_manage.AddSearchKeyword(searchKeyword) } resp := data_manage.EdbInfoFilterDataResp{ Paging: page, List: edbInfoList, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // GetEdbDateData // @Title 根据指标ID和具体日期获取对应日期的数据值 // @Description 根据指标ID和具体日期获取对应日期的数据值 // @Param EdbInfoId query int false "指标id" // @Param Date query string false "日期" // @Success 200 {object} data_manage.EdbInfoList // @router /edb_info/date_data [get] func (this *EdbInfoController) GetEdbDateData() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() edbInfoId, _ := this.GetInt("EdbInfoId") date := this.GetString("Date") if edbInfoId <= 0 { br.Msg = "请选择指标" br.IsSendEmail = false return } if date == `` { br.Msg = "请选择日期" br.IsSendEmail = false return } edbInfo, err := data_manage.GetEdbInfoById(edbInfoId) if err != nil { br.Msg = "获取失败" br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error()) return } startDate := date endDate := date dateType := "day" //如果填写的是月度日期 if strings.Count(date, "-") == 1 { startDate = date + "-01" endDate = `` dateType = "month" } dataItem, err := data.GetDateData(edbInfo, startDate, endDate) if err != nil { br.Msg = "获取失败" br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error()) return } val := `` if dataItem != nil { switch dateType { case "month": dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local) dateTimeStr := dateTime.Format(utils.FormatYearMonthDate) if dateTimeStr != date { val = `` } } val = fmt.Sprint(dataItem.Value) } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = val } // GetEdbBeforeAndAfterDateData // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期 // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期 // @Param EdbInfoId query int false "指标id" // @Param Date query string false "日期" // @Param Num query int false "前后几期数据" // @Success 200 {object} data_manage.EdbInfoList // @router /edb_info/date_data/before_after [post] func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() requestBody := string(this.Ctx.Input.RequestBody) var req request2.DateDataBeforeAfterReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } edbInfoId := req.EdbInfoId currDate := req.Date num := req.Num // 默认2期数据 if num <= 0 { num = 2 } if edbInfoId <= 0 { br.Msg = "请选择指标" br.IsSendEmail = false return } edbInfo, err := data_manage.GetEdbInfoById(edbInfoId) if err != nil { br.Msg = "获取失败" br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error()) return } dataList := make([]*data_manage.EdbDataList, 0) switch edbInfo.EdbInfoType { case 0: dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``) case 1: _, dataList, _, _, _, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false) default: br.Msg = "指标类型异常!" br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType) return } if currDate == `` { currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList) if err != nil { br.Msg = "日期前移失败" br.ErrMsg = "日期前移失败,Err:" + err.Error() return } } else { if strings.Count(currDate, "-") == 1 { currDate = currDate + "-01" // 查找这个月早的时间作为起始时间 for _, v := range dataList { if v.DataTime >= currDate { currDate = v.DataTime break } } } } currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody) if err != nil { br.Msg = "日期变换失败" br.ErrMsg = "日期变换失败,Err:" + err.Error() return } list := make([]*data_manage.EdbDataList, 5) list, err = data.GetEdbBeforeAndAfterDateData(currDate, dataList) if err != nil { br.Msg = "获取失败" br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error()) return } // 这个日期不存在的话直接返回空数组 resp := data_manage.BeforeAndAfterDateDataResp{ List: list, Date: currDate, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // EdbChartAdminList // @Title 获取创建人员分组 // @Description 获取创建人员分组 // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库" // @Success 200 {object} company.DepartmentGroupSellersResp // @router /edb_chart/adminList [get] func (this *EdbInfoController) EdbChartAdminList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } source, _ := this.GetInt("Source", 0) if source <= 0 || source > 5 { br.Msg = "错误的来源" br.IsSendEmail = false return } idList, err := data.GetEdbChartAdminList(source) if err != nil { //br.Success = true br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } fmt.Println("idlist:", idList) systemAdminMap := make(map[int]*system.Admin) departmentMap := make(map[string]string) departmentAdminMap := make(map[int]string) groupMap := make(map[string]string) systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList) if err != nil { br.Msg = "获取用户列表失败" br.ErrMsg = "获取用户列表失败,Err:" + err.Error() return } for _, v := range systemAdminList { systemAdminMap[v.AdminId] = v departmentMap[v.DepartmentName] = v.DepartmentName departmentAdminMap[v.AdminId] = v.DepartmentName groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName } depList := make([]company.DepartmentGroupAdmins, 0) i := 1 for _, v := range departmentMap { item := company.DepartmentGroupAdmins{ AdminId: "dep_" + strconv.Itoa(i), RealName: v, } i++ depList = append(depList, item) } for k := 0; k < len(depList); k++ { for k1, v1 := range groupMap { if v1 == depList[k].RealName && v1 != "" { item := &company.DepartmentGroupAdmins{ AdminId: "group_" + strconv.Itoa(k), RealName: strings.Replace(k1, v1, "", -1), } depList[k].ChildrenList = append(depList[k].ChildrenList, item) } } } for _, admin := range systemAdminList { for i, v := range depList { for k, group := range v.ChildrenList { if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName { item := &company.DepartmentGroupAdmins{ AdminId: strconv.Itoa(admin.AdminId), RealName: admin.RealName, RoleTypeCode: admin.RoleTypeCode, Authority: admin.Authority, } if group.RealName != "" { depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item) } else { depList[i].ChildrenList = append(depList[i].ChildrenList, item) } } } } } for i, groupList := range depList { for k, v := range groupList.ChildrenList { if v.RealName == "" { newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...) depList[i].ChildrenList = newChildrenList } } } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = depList } // EdbSourceList // @Title 指标来源列表 // @Description 指标来源列表 // @Param IsBase query int false "是否为基础指标: 1-基础指标,2:计算指标" // @Param EdbInfoType query int false "指标类型,0:指标库;1:预测指标,默认:0" // @Success 200 {object} data_manage.EdbInfoListResp // @router /edb_source/list [get] func (this *EdbInfoController) EdbSourceList() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() isBase, _ := this.GetInt("IsBase", 0) edbInfoType, _ := this.GetInt("EdbInfoType", 0) pars := make([]interface{}, 0) cond := ` AND edb_info_type = ? ` pars = append(pars, edbInfoType) // 计算类型 switch isBase { case 1: cond += ` AND is_base = ? ` pars = append(pars, 1) case 2: cond += ` AND is_base = ? ` pars = append(pars, 2) } list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "") if e != nil { br.Msg = "获取失败" br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error() return } br.Data = list br.Ret = 200 br.Success = true br.Msg = "获取成功" } // EdbSourceListByPython // @Title 指标来源列表 // @Description 指标来源列表 // @Param IsBase query int false "是否为基础指标: 1-是" // @Success 200 {object} data_manage.EdbInfoListResp // @router /edb_source/list/python [get] func (this *EdbInfoController) EdbSourceListByPython() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() isBase, _ := this.GetInt("IsBase", 0) cond := `` if isBase > 0 { cond = ` AND is_base = 1` } pars := make([]interface{}, 0) list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "") if e != nil { br.Msg = "获取失败" br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error() return } baseEdbList := make([]data_manage.EdbSourceChild, 0) calEdbList := make([]data_manage.EdbSourceChild, 0) for _, v := range list { switch v.IsBase { case 1: baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{ EdbSourceId: v.EdbSourceId, SourceName: v.SourceName, IsBase: v.IsBase, TableName: v.TableName, Child: []data_manage.EdbSourceChild{}, }) case 2: calEdbList = append(calEdbList, data_manage.EdbSourceChild{ EdbSourceId: v.EdbSourceId, SourceName: v.SourceName, IsBase: v.IsBase, TableName: v.TableName, Child: []data_manage.EdbSourceChild{}, }) } } resp := []data_manage.EdbSourceChild{ { EdbSourceId: 0, SourceName: "基础指标", IsBase: 1, Child: baseEdbList, }, { EdbSourceId: 0, SourceName: "计算指标", IsBase: 1, Child: calEdbList, }, } br.Data = resp br.Ret = 200 br.Success = true br.Msg = "获取成功" } // EdbChartList // @Title 指标缩略图列表接口 // @Description 指标缩略图列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param ClassifyId query int true "分类id" // @Param AdminId query int false "创建人id" // @Param IsOnlyMe query bool false "是否只看我的" // @Success 200 {object} response.EdbInfoChartListResp // @router /edb_info/chart/list [get] func (this *EdbInfoController) EdbChartList() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } // 分页 pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") var total int page := paging.GetPaging(currentIndex, pageSize, total) var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) // 基础指标 var condition string var pars []interface{} condition += ` AND edb_info_type = ? ` pars = append(pars, 0) // 指标类型 edbType, _ := this.GetInt("EdbType", 1) if edbType > 0 { condition += ` AND edb_type = ? ` pars = append(pars, edbType) } switch edbType { case utils.EdbTypeBase: condition += ` AND edb_type = ? ` pars = append(pars, edbType) case utils.EdbTypeCalculate: condition += ` AND edb_type = ? AND sys_user_id = ? ` pars = append(pars, edbType, sysUser.AdminId) } // 分类筛选 classifyId, _ := this.GetInt("ClassifyId") if classifyId > 0 { childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId) if e != nil && !utils.IsErrNoRow(e) { br.Msg = "获取失败" br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error() return } var classifyIds []int for _, v := range childClassify { classifyIds = append(classifyIds, v.ClassifyId) } condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds))) pars = append(pars, classifyIds) } // 创建人 adminId, _ := this.GetInt("AdminId") if adminId > 0 { condition += ` AND sys_user_id = ? ` pars = append(pars, adminId) } // 无权限指标 和 无权限指标分类id noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err := data_manage_permission.GetUserAllEdbAndClassifyNoPermissionList(this.SysUser.AdminId, utils.EDB_INFO_TYPE, edbType) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error() return } noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList) if noPermissionEdbInfoIdNum > 0 { condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) ` pars = append(pars, noPermissionEdbInfoIdList) } noPermissionClassifyInfoIdNum := len(noPermissionEdbClassifyIdList) if noPermissionClassifyInfoIdNum > 0 { condition += ` AND classify_id NOT IN (` + utils.GetOrmInReplace(noPermissionClassifyInfoIdNum) + `) ` pars = append(pars, noPermissionEdbClassifyIdList) } // 获取指标信息 dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize) if e != nil { br.Msg = "获取失败" br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error() return } respList := make([]*data_manage.EdbInfoList, 0) if len(list) > 0 { classifyIdList := make([]int, 0) for _, v := range list { v.ConvertToResp() classifyIdList = append(classifyIdList, v.ClassifyId) } // 指标权限 { // 当前的分类 classifyMap := make(map[int]*data_manage.EdbClassify) classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList) if err != nil { if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取分类列表失败,Err:" + err.Error() return } } for _, v := range classifyList { classifyMap[v.ClassifyId] = v } // 获取所有有权限的指标和分类 permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error() return } { tmpEdbCodeList := make([]string, 0) for _, v := range list { if v.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL { tmpEdbCodeList = append(tmpEdbCodeList, v.EdbCode) } } } for _, v := range list { if currClassify, ok := classifyMap[v.ClassifyId]; ok { v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList) // 不展示无权限的 if !v.HaveOperaAuth { continue } v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType, v.HaveOperaAuth) } respList = append(respList, v) } } page = paging.GetPaging(currentIndex, pageSize, int(dataCount)) } resp := response.EdbInfoChartListResp{ Paging: page, List: respList, } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // Modify // @Title 修改指标信息接口 // @Description 编辑指标接口 // @Success 200 string "操作成功" // @router /edb_info/modify [post] func (this *EdbInfoController) Modify() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req request.ModifyEdbInfoReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } edbInfoId := req.EdbInfoId if edbInfoId <= 0 { br.Msg = "请选择指标" br.IsSendEmail = false return } edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId) if e != nil { br.Msg = "操作失败" br.ErrMsg = "获取指标信息失败, Err:" + err.Error() return } var haveOperaAuth bool // 权限校验 { haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() br.ErrMsg = "校验指标权限失败,err:" + err.Error() return } } // 编辑权限校验 button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth) if !button.OpButton { br.Msg = "无权限操作" return } edbInfo.MaxValue = req.MaxValue edbInfo.MinValue = req.MinValue edbInfo.ManualSave = 1 edbInfo.ModifyTime = time.Now() err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"}) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } //修改es data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId) br.Ret = 200 br.Success = true br.Msg = "修改成功" br.IsAddLog = true } // ChartImageSet // @Title 设置指标的图表图片 // @Description 设置指标的图表图片接口 // @Param request body data_manage.SetChartInfoImageReq true "type json string" // @Success Ret=200 保存成功 // @router /edb_info/image/set [post] func (this *EdbInfoController) ChartImageSet() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req data_manage.SetEdbInfoImageReq if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + e.Error() return } if req.EdbInfoId <= 0 || req.ImageUrl == "" { br.Ret = 200 br.Success = true br.Msg = "保存成功" return } edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId) if e != nil { if utils.IsErrNoRow(e) { br.Msg = "找不到该指标" return } br.Msg = "保存失败" br.ErrMsg = "获取指标失败, Err:" + e.Error() return } edbInfo.ChartImage = req.ImageUrl if e = edbInfo.Update([]string{"ChartImage"}); e != nil { br.Msg = "保存失败" br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error() return } // 修改es数据 go data.AddOrEditEdbInfoToEs(req.EdbInfoId) br.Ret = 200 br.Success = true br.Msg = "保存成功" } // EdbInfoExistCheck // @Title 新增指标-检验指标是否存在接口 // @Description 新增指标-检验指标是否存在接口 // @Param Source query int true "来源:1:同花顺,2:wind" // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列" // @Param EdbCode query string false "指标编码/指标代码" // @Param StockCode query string false "证券代码" // @Success 200 {object} data_manage.EdbInfoExistCheckResp // @router /edb_info/exist/check [get] func (this *EdbInfoController) EdbInfoExistCheck() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() source, _ := this.GetInt("Source") edbCode := this.GetString("EdbCode") edbCode = strings.Trim(edbCode, "\t") edbCode = strings.Trim(edbCode, " ") edbCode = strings.Replace(edbCode, "\t", "", -1) subSource, _ := this.GetInt("SubSource") stockCode := this.GetString("StockCode") if source <= 0 { br.Msg = "无效的数据来源" return } if edbCode == "" { br.Msg = "请输入指标ID" return } if source != utils.DATA_SOURCE_WIND && source != utils.DATA_SOURCE_THS { br.Msg = "无效的数据来源" return } if subSource != utils.DATA_SUB_SOURCE_DATE { br.Msg = "无效的数据库来源" return } var indexCodeArr []string edbCodeArr := strings.Split(edbCode, ",") stockCodeArr := strings.Split(stockCode, ",") var prefix string if source == utils.DATA_SOURCE_WIND { prefix = utils.WindDbWsd } else if source == utils.DATA_SOURCE_THS { prefix = utils.ThsDs } else { br.Msg = "来源错误" br.ErrMsg = "来源错误" return } for _, sv := range stockCodeArr { for _, ev := range edbCodeArr { indexCode := prefix + sv + ev indexCodeArr = append(indexCodeArr, indexCode) } } indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr) if err != nil && !utils.IsErrNoRow(err) { br.Msg = "校验指标是否存在失败" br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error() return } var existStockCodeArr []string var existEdbCodeArr []string var existClassifyId []int var existIndexId []int for _, indexItem := range indexList { for _, sv := range stockCodeArr { for _, ev := range edbCodeArr { if strings.Contains(indexItem.EdbCode, sv) { existStockCodeArr = append(existStockCodeArr, sv) } if strings.Contains(indexItem.EdbCode, ev) { existEdbCodeArr = append(existEdbCodeArr, ev) existClassifyId = append(existClassifyId, indexItem.ClassifyId) existIndexId = append(existIndexId, indexItem.EdbInfoId) } } } } resp := new(data_manage.EdbInfoExistCheckResp) if len(indexList) > 0 { resp.IndexExist = true } resp.ExistEdbCodeArr = existEdbCodeArr resp.ExistStockCodeArr = existStockCodeArr resp.ExistClassifyId = existClassifyId resp.ExistIndexId = existIndexId resp.ExistEdbInfo = indexList br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // EdbInfoAdd // @Title 指标批量保存接口 // @Description 指标批量保存接口 // @Param request body data_manage.BatchAddEdbInfoReq true "type json string" // @Success Ret=200 保存成功 // @router /edb_info/batch/add [post] func (this *EdbInfoController) EdbInfoBatchAdd() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } deleteCache := true cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId) defer func() { if deleteCache { utils.Rc.Delete(cacheKey) } }() if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) { deleteCache = false br.Msg = "系统处理中,请稍后重试!" br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody) return } var req data_manage.BatchAddEdbInfoReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } resp := new(data_manage.AddEdbInfoResp) var edbNames string for _, v := range req.BatchList { edbNames += "'" + v.EdbName + "'," } edbNames = strings.Trim(edbNames, ",") infoList, err := data_manage.GetEdbInfoByNames(edbNames) if err != nil { br.Msg = "查询指标名称重复错误!" br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error() return } if len(infoList) > 0 { for _, v := range infoList { resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName) } br.Data = resp br.Msg = "指标名称重复!" br.ErrMsg = "指标名称重复" return } for k, v := range req.BatchList { v.EdbName = strings.Trim(v.EdbName, " ") v.EdbCode = strings.Trim(v.EdbCode, " ") v.StockCode = strings.Trim(v.StockCode, " ") if v.Source <= 0 { br.Msg = "无效的数据来源" return } if v.EdbCode == "" { br.Msg = "指标ID不能为空" return } if v.StockCode == "" { br.Msg = "证券代码不能为空" return } if v.EdbName == "" { br.Msg = "指标名称不能为空" return } if v.Frequency == "" { br.Msg = "频率不能为空" return } if v.ClassifyId <= 0 { br.Msg = "请选择分类" return } terminalCode, serverUrl, _, e := data.GetEdbTerminalCodeBySource(v.Source, v.EdbCode, v.StockCode) if e != nil { br.Msg = "获取可以使用的终端地址失败" br.ErrMsg = "获取可以使用的终端地址失败,Err:" + e.Error() return } edbInfoItem := new(data_manage.EdbInfo) edbInfoItem.Source = v.Source switch v.Source { case utils.DATA_SOURCE_WIND: edbInfoItem.SourceName = "wind" edbInfoItem.EdbCode = utils.WindDbWsd + v.StockCode + v.EdbCode case utils.DATA_SOURCE_THS: edbInfoItem.SourceName = "ths" edbInfoItem.EdbCode = utils.ThsDs + v.StockCode + v.EdbCode } edbInfoItem.SubSource = utils.DATA_SUB_SOURCE_DATE edbInfoItem.SubSourceName = "日期序列" edbInfoItem.EdbName = v.EdbName edbInfoItem.EdbNameSource = v.EdbName edbInfoItem.EdbNameEn = v.EdbName edbInfoItem.Frequency = v.Frequency edbInfoItem.Unit = v.Unit edbInfoItem.UnitEn = v.Unit edbInfoItem.ClassifyId = v.ClassifyId edbInfoItem.SysUserId = sysUser.AdminId edbInfoItem.SysUserRealName = sysUser.RealName edbInfoItem.IndicatorCode = v.EdbCode edbInfoItem.StockCode = v.StockCode edbInfoItem.TerminalCode = terminalCode edbInfoItem.ServerUrl = serverUrl var extra data_manage.EdbInfoExtra if v.ApiExtraPars != "" { extra.ApiExtraPars = v.ApiExtraPars b, e := json.Marshal(extra) if e != nil { br.Msg = "保存失败" br.ErrMsg = fmt.Sprintf("额外参数JSON格式化失败, %v", e) return } edbInfoItem.Extra = string(b) } // 指标入库 edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem) if err != nil { br.Msg = "保存失败" if errMsg != `` { br.Msg = errMsg } br.ErrMsg = err.Error() br.IsSendEmail = isSendEmail return } //新增操作日志 { edbLog := new(data_manage.EdbInfoLog) edbLog.EdbInfoId = edbInfo.EdbInfoId edbLog.SourceName = edbInfo.SourceName edbLog.Source = edbInfo.Source edbLog.EdbCode = edbInfo.EdbCode edbLog.EdbName = edbInfo.EdbName edbLog.ClassifyId = edbInfo.ClassifyId edbLog.SysUserId = sysUser.AdminId edbLog.SysUserRealName = sysUser.RealName edbLog.CreateTime = time.Now() edbLog.Content = string(this.Ctx.Input.RequestBody) edbLog.Status = "新增指标" edbLog.Method = this.Ctx.Input.URI() go data_manage.AddEdbInfoLog(edbLog) } if k <= 0 { resp.EdbInfoId = edbInfo.EdbInfoId resp.UniqueCode = edbInfo.UniqueCode } } br.Ret = 200 br.Success = true br.Msg = "保存成功" br.Data = resp br.IsAddLog = true } // SmmEdbInfoBatchAdd // @Title 指标批量保存接口-smm // @Description 指标批量保存接口-smm // @Param request body data_manage.BatchAddEdbInfoReq true "type json string" // @Success Ret=200 保存成功 // @router /edb_info/smm/batch/add [post] func (this *EdbInfoController) SmmEdbInfoBatchAdd() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } deleteCache := true cacheKey := "CACHE_EDB_INFO_BATCH_ADD_" + strconv.Itoa(sysUser.AdminId) defer func() { if deleteCache { utils.Rc.Delete(cacheKey) } }() if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) { deleteCache = false br.Msg = "系统处理中,请稍后重试!" br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody) return } var req data_manage.BatchAddEdbInfoReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } resp := new(data_manage.AddEdbInfoResp) var edbNames string for _, v := range req.BatchList { edbNames += "'" + v.EdbName + "'," } edbNames = strings.Trim(edbNames, ",") infoList, err := data_manage.GetEdbInfoByNames(edbNames) if err != nil { br.Msg = "查询指标名称重复错误!" br.ErrMsg = "GetEdbInfoByNames,Err:" + err.Error() return } if len(infoList) > 0 { for _, v := range infoList { resp.ExistEdbName = append(resp.ExistEdbName, v.EdbName) } br.Data = resp br.Msg = "指标名称重复!" br.ErrMsg = "指标名称重复" return } for k, v := range req.BatchList { v.EdbName = strings.Trim(v.EdbName, " ") v.EdbCode = strings.Trim(v.EdbCode, " ") if v.Source <= 0 { br.Msg = "无效的数据来源" return } if v.EdbCode == "" { br.Msg = "指标ID不能为空" return } if v.EdbName == "" { br.Msg = "指标名称不能为空" return } if v.Frequency == "" { br.Msg = "频率不能为空" return } if v.ClassifyId <= 0 { br.Msg = "请选择分类" return } edbInfoItem := new(data_manage.EdbInfo) edbInfoItem.Source = v.Source edbInfoItem.SourceName = "SMM" edbInfoItem.EdbCode = v.EdbCode edbInfoItem.SubSource = 0 edbInfoItem.SubSourceName = "" edbInfoItem.EdbName = v.EdbName edbInfoItem.EdbNameSource = v.EdbName edbInfoItem.EdbNameEn = v.EdbName edbInfoItem.Frequency = v.Frequency edbInfoItem.Unit = v.Unit edbInfoItem.UnitEn = v.Unit edbInfoItem.ClassifyId = v.ClassifyId edbInfoItem.SysUserId = sysUser.AdminId edbInfoItem.SysUserRealName = sysUser.RealName edbInfoItem.IndicatorCode = "" edbInfoItem.StockCode = "" // 指标入库 edbInfo, err, errMsg, isSendEmail := data.EdbInfoWsdAdd(edbInfoItem) if err != nil { br.Msg = "保存失败" if errMsg != `` { br.Msg = errMsg } br.ErrMsg = err.Error() br.IsSendEmail = isSendEmail return } //新增操作日志 { edbLog := new(data_manage.EdbInfoLog) edbLog.EdbInfoId = edbInfo.EdbInfoId edbLog.SourceName = edbInfo.SourceName edbLog.Source = edbInfo.Source edbLog.EdbCode = edbInfo.EdbCode edbLog.EdbName = edbInfo.EdbName edbLog.ClassifyId = edbInfo.ClassifyId edbLog.SysUserId = sysUser.AdminId edbLog.SysUserRealName = sysUser.RealName edbLog.CreateTime = time.Now() edbLog.Content = string(this.Ctx.Input.RequestBody) edbLog.Status = "新增指标" edbLog.Method = this.Ctx.Input.URI() go data_manage.AddEdbInfoLog(edbLog) } if k <= 0 { resp.EdbInfoId = edbInfo.EdbInfoId resp.UniqueCode = edbInfo.UniqueCode } } br.Ret = 200 br.Success = true br.Msg = "保存成功" br.Data = resp br.IsAddLog = true } // ChartImageSetBySvg // @Title 设置指标的图表图片 // @Description 设置指标的图表图片接口 // @Param request body data_manage.SetChartInfoImageReq true "type json string" // @Success Ret=200 保存成功 // @router /edb_info/image/set_by_svg [post] func (this *EdbInfoController) ChartImageSetBySvg() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } imgData := this.GetString("Img") if imgData == "" { br.Msg = "图片参数错误" br.ErrMsg = "图片参数错误,Img Is Empty" return } edbInfoId, _ := this.GetInt("EdbInfoId", 0) if edbInfoId <= 0 { br.Msg = "指标参数错误" br.ErrMsg = "指标参数错误,EdbInfoId Is Empty" return } // 通过svg图片生成图片资源地址 resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData) if err != nil { br.Msg = errMsg br.ErrMsg = err.Error() return } if edbInfoId <= 0 || resourceUrl == "" { br.Ret = 200 br.Success = true br.Msg = "保存成功" return } edbInfo, e := data_manage.GetEdbInfoById(edbInfoId) if e != nil { if utils.IsErrNoRow(e) { br.Msg = "找不到该指标" return } br.Msg = "保存失败" br.ErrMsg = "获取指标失败, Err:" + e.Error() return } edbInfo.ChartImage = resourceUrl if e = edbInfo.Update([]string{"ChartImage"}); e != nil { br.Msg = "保存失败" br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error() return } // 修改es数据 go data.AddOrEditEdbInfoToEs(edbInfoId) br.Ret = 200 br.Success = true br.Msg = "保存成功" } // BatchMoveEdb // @Title 指标批量移动接口 // @Description 指标批量移动接口 // @Param request body request.MoveEdbClassifyReq true "type json string" // @Success Ret=200 移动成功 // @router /edb_info/batch_move [post] func (this *EdbInfoController) BatchMoveEdb() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req request.MoveEdbClassifyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.NewClassifyId <= 0 { br.Msg = `请选择要转移的新分类` br.IsSendEmail = false return } classifyItem, err := data_manage.GetEdbClassifyById(req.NewClassifyId) if err != nil { br.Msg = "获取指标分类失败!" br.ErrMsg = "获取指标分类失败!" + err.Error() return } if classifyItem.SysUserId != this.SysUser.AdminId { br.Msg = `您没有权限移动指标到该分类!` br.IsSendEmail = false return } edbInfoIdList := make([]int, 0) if req.IsSelectAll { // 获取指标 edbInfoList, err := data.GetAllEdbInfoListBySearchPublicEdbReq(req.SearchPublicEdbReq, this.SysUser.AdminId) if err != nil { br.Msg = "获取指标列表失败!" br.ErrMsg = "获取指标列表失败,Err:" + err.Error() return } // 如果有过滤指标,那么就过滤吧 if len(req.NoEdbIdList) > 0 { noEdbIdMap := make(map[int]bool) for _, v := range req.NoEdbIdList { noEdbIdMap[v] = true } for _, edbInfo := range edbInfoList { if _, ok := noEdbIdMap[edbInfo.EdbInfoId]; !ok { if edbInfo.SysUserId != this.SysUser.AdminId { br.Msg = `您没有权限移动该指标!` br.IsSendEmail = false return } // 如果不在未选中的指标id列表中,那么就加入到选中的指标id列表 edbInfoIdList = append(edbInfoIdList, edbInfo.EdbInfoId) } } } else { for _, edbInfo := range edbInfoList { edbInfoIdList = append(edbInfoIdList, edbInfo.EdbInfoId) for _, v := range edbInfoList { if v.SysUserId != this.SysUser.AdminId { br.Msg = `您没有权限移动该指标!` br.IsSendEmail = false return } } } } } else { edbInfoList, err := data_manage.GetEdbInfoListByCond(` AND edb_info_id in (?) `, []interface{}{req.EdbIdList}) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error() return } for _, v := range edbInfoList { if v.SysUserId != this.SysUser.AdminId { br.Msg = `您没有权限移动该指标!` br.IsSendEmail = false return } } edbInfoIdList = req.EdbIdList } num := len(edbInfoIdList) if num <= 0 { br.Msg = `请选择要移动的指标!` br.IsSendEmail = false return } if num > 100 { br.Msg = `最多只能选择100条指标!` br.IsSendEmail = false return } // 开始批量修改指标分类 if len(edbInfoIdList) > 0 { err = data_manage.UpdateClassifyIdByEdbInfoIdList(edbInfoIdList, req.NewClassifyId) if err != nil { br.Msg = `指标移动失败!` br.ErrMsg = `指标移动失败,ERR:` + err.Error() return } // 还得修改ES呢 for _, v := range edbInfoIdList { data.AddOrEditEdbInfoToEs(v) } } br.Ret = 200 br.Success = true br.Msg = "获取成功" }