package data_manage import ( "eta/eta_api/models" "eta/eta_api/models/data_manage" "eta/eta_api/utils" "fmt" "github.com/rdlucklib/rdluck_tools/paging" "strings" ) // RefreshSourceList // @Title 获取指标刷新配置的来源接口 // @Description 获取指标刷新配置的来源接口 // @Success Ret=200 获取成功 // @router /edb_info/refresh/source_list [get] func (c *EdbInfoController) RefreshSourceList() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() item := data_manage.EdbRefreshSource{} tmpList, err := item.GetAllList() if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取刷新数据源失败, Err: " + err.Error() return } list := make([]data_manage.EdbRefreshSourceList, 0) tmpMap := make(map[int]data_manage.EdbRefreshSourceList, 0) for _, v := range tmpList { tmp, ok := tmpMap[v.Source] if ok { continue } tmp = data_manage.EdbRefreshSourceList{ Source: v.Source, SourceName: v.SourceName, //SubSource: v.SubSource, //SubSourceName: v.SubSourceName, Child: make([]data_manage.EdbRefreshSourceList, 0), HasChild: v.HasChild, } if v.HasChild == 1 { for _, v2 := range tmpList { if v2.Source == v.Source { tmp.Child = append(tmp.Child, data_manage.EdbRefreshSourceList{ Source: v.Source, SourceName: v.SourceName, SubSource: v.SubSource, SubSourceName: v.SubSourceName, HasChild: 0, }) } } } tmpMap[v.Source] = tmp list = append(list, tmp) } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = list } // RefreshClassifyList // @Title 获取指标分类列表接口 // @Description 获取指标分类列表接口 // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博" // @Success Ret=200 获取成功 // @router /edb_info/refresh/classify_list [get] func (c *EdbInfoController) RefreshClassifyList() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() source, _ := c.GetInt("Source", utils.DATA_SOURCE_MYSTEEL_CHEMICAL) list := make([]*data_manage.BaseClassifyItems, 0) switch source { case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联 rootList, err := data_manage.GetBaseFromMysteelChemicalClassifyByParentId(0) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := data_manage.GetAllBaseFromMysteelChemicalClassify() if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } rootChildMap := make(map[int][]*data_manage.BaseClassifyItems) for _, v := range classifyAll { //tmpList, ok := rootChildMap[v.ParentId] //if !ok { // tmpList = make([]data_manage.BaseClassifyItems, 0) //} //tmpList = append(tmpList, data_manage.BaseClassifyItems{ // ClassifyId: v.BaseFromMysteelChemicalClassifyId, // ClassifyName: v.ClassifyName, // ParentId: v.ParentId, // UniqueCode: fmt.Sprint(v.BaseFromMysteelChemicalClassifyId), // Children: nil, //}) //rootChildMap[v.ParentId] = tmpList rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], &data_manage.BaseClassifyItems{ ClassifyId: v.BaseFromMysteelChemicalClassifyId, ClassifyName: v.ClassifyName, ParentId: v.ParentId, UniqueCode: fmt.Sprint(v.BaseFromMysteelChemicalClassifyId), Children: nil, }) } for _, v := range rootList { tmp := &data_manage.BaseClassifyItems{ ClassifyId: v.BaseFromMysteelChemicalClassifyId, ClassifyName: v.ClassifyName, ParentId: v.ParentId, UniqueCode: fmt.Sprint(v.BaseFromMysteelChemicalClassifyId), Children: nil, } if existItems, ok := rootChildMap[v.BaseFromMysteelChemicalClassifyId]; ok { tmp.Children = existItems } else { items := make([]*data_manage.BaseClassifyItems, 0) tmp.Children = items } list = append(list, tmp) } case utils.DATA_SOURCE_YS: // 有色 list = append(list, &data_manage.BaseClassifyItems{ ClassifyId: 0, ClassifyName: "未分类", ParentId: 0, UniqueCode: fmt.Sprint(0), Children: nil, }) rootList, err := data_manage.GetBaseFromSmmClassifyByParentId(0) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } classifyAll, err := data_manage.GetAllBaseFromSmmClassify() if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } rootChildMap := make(map[int][]*data_manage.BaseClassifyItems) for _, v := range classifyAll { rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], &data_manage.BaseClassifyItems{ ClassifyId: v.ClassifyId, ClassifyName: v.ClassifyName, ParentId: v.ParentId, UniqueCode: fmt.Sprint(v.ClassifyId), Children: nil, }) } for _, v := range rootList { tmp := &data_manage.BaseClassifyItems{ ClassifyId: v.ClassifyId, ClassifyName: v.ClassifyName, ParentId: v.ParentId, UniqueCode: fmt.Sprint(v.ClassifyId), Children: nil, } if existItems, ok := rootChildMap[v.ClassifyId]; ok { tmp.Children = existItems } else { items := make([]*data_manage.BaseClassifyItems, 0) tmp.Children = items } list = append(list, tmp) } default: tmpList, err := data_manage.GetAllEdbClassify() if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } for _, v := range tmpList { list = append(list, &data_manage.BaseClassifyItems{ ClassifyId: v.ClassifyId, ClassifyName: v.ClassifyName, ParentId: v.ParentId, UniqueCode: fmt.Sprint(v.ClassifyId), Children: nil, }) } list = buildTree(list, 0) //fmt.Println(result) } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = list } // 生成多层级列表的递归函数 func buildTree(items []*data_manage.BaseClassifyItems, parentId int) []*data_manage.BaseClassifyItems { var result []*data_manage.BaseClassifyItems // 遍历所有分类项 for i := range items { // 找到当前节点的子节点 if items[i].ParentId == parentId { // 递归构建子节点的子节点 items[i].Children = buildTree(items, items[i].ClassifyId) // 将当前节点添加到结果中 result = append(result, items[i]) } } return result } // RefreshEdbList // @Title 获取待配置的指标列表接口 // @Description 获取待配置的指标列表接口 // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博" // @Param SubSource query int true "来源:0:经济数据库,1:日期序列" // @Param ClassifyId query int false "分类ID" // @Param TerminalCode query string false "终端编码" // @Param SysUserId query string false "创建人" // @Param Frequency query string false "频度" // @Param Keyword query string false "关键词" // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp // @router /edb_info/refresh/edb_list [get] func (c *EdbInfoController) RefreshEdbList() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() source, _ := c.GetInt("Source") subSource, _ := c.GetInt("SubSource") classifyId, _ := c.GetInt("ClassifyId") terminalCode := c.GetString("TerminalCode") sysUserId := c.GetString("SysUserId") frequency := c.GetString("Frequency") keyword := c.GetString("Keyword") pageSize, _ := c.GetInt("PageSize") currentIndex, _ := c.GetInt("CurrentIndex") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) var pars []interface{} var condition string var total int list := make([]*data_manage.BaseEdbInfo, 0) var err error switch source { case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联 if classifyId > 0 { condition += " AND base_from_mysteel_chemical_classify_id = ? " pars = append(pars, classifyId) } if terminalCode != `` { condition += " AND terminal_code = ? " pars = append(pars, terminalCode) } if sysUserId != `` { sysUserIdSlice := strings.Split(sysUserId, ",") condition += ` AND sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)` pars = append(pars, sysUserIdSlice) } if frequency != `` { condition += " AND frequency = ? " pars = append(pars, frequency) } if keyword != `` { keywordSlice := strings.Split(keyword, ",") if len(keywordSlice) > 0 { tmpConditionSlice := make([]string, 0) tmpConditionSlice = append(tmpConditionSlice, ` index_name like ? or index_code like ? `) pars = utils.GetLikeKeywordPars(pars, keyword, 2) for _, v := range keywordSlice { tmpConditionSlice = append(tmpConditionSlice, ` index_name like ? or index_code like ? `) pars = utils.GetLikeKeywordPars(pars, v, 2) } condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)` } else { condition += ` index_name like ? or index_code like ? ` pars = utils.GetLikeKeywordPars(pars, keyword, 2) } } total, list, err = data_manage.GetMysteelChemicalBaseInfo(condition, pars, startSize, pageSize) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } case utils.DATA_SOURCE_YS: // 有色 if classifyId > 0 { condition += " AND classify_id = ? " pars = append(pars, classifyId) } if terminalCode != `` { condition += " AND terminal_code = ? " pars = append(pars, terminalCode) } if frequency != `` { condition += " AND frequency = ? " pars = append(pars, frequency) } if keyword != `` { keywordSlice := strings.Split(keyword, ",") if len(keywordSlice) > 0 { tmpConditionSlice := make([]string, 0) tmpConditionSlice = append(tmpConditionSlice, ` index_name like ? or index_code like ? `) pars = utils.GetLikeKeywordPars(pars, keyword, 2) for _, v := range keywordSlice { tmpConditionSlice = append(tmpConditionSlice, ` index_name like ? or index_code like ? `) pars = utils.GetLikeKeywordPars(pars, v, 2) } condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)` } else { condition += ` index_name like ? or index_code like ? ` pars = utils.GetLikeKeywordPars(pars, keyword, 2) } } total, list, err = data_manage.GetSmmBaseInfo(condition, pars, startSize, pageSize) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } default: condition += ` AND source = ? AND sub_source = ? ` pars = append(pars, source, subSource) if classifyId > 0 { condition += " AND classify_id = ? " pars = append(pars, classifyId) } if terminalCode != `` { condition += " AND terminal_code = ? " pars = append(pars, terminalCode) } if sysUserId != `` { sysUserIdSlice := strings.Split(sysUserId, ",") condition += ` AND sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)` pars = append(pars, sysUserIdSlice) } if frequency != `` { condition += " AND frequency = ? " pars = append(pars, frequency) } if keyword != `` { keywordSlice := strings.Split(keyword, ",") if len(keywordSlice) > 0 { tmpConditionSlice := make([]string, 0) tmpConditionSlice = append(tmpConditionSlice, ` edb_name like ? or edb_code like ? `) pars = utils.GetLikeKeywordPars(pars, keyword, 2) for _, v := range keywordSlice { tmpConditionSlice = append(tmpConditionSlice, ` edb_name like ? or edb_code like ? `) pars = utils.GetLikeKeywordPars(pars, v, 2) } condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)` } else { condition += ` edb_name like ? or edb_code like ? ` pars = utils.GetLikeKeywordPars(pars, keyword, 2) } } total, list, err = data_manage.GetEdbBaseInfo(condition, pars, startSize, pageSize) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } } page := paging.GetPaging(currentIndex, pageSize, total) resp := data_manage.RefreshBaseEdbInfoResp{ Paging: page, List: list, } // todo 数据源中的最新值 // todo 刷新时间 br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // GetEdbRefreshDefaultConfig // @Title 获取待配置的指标列表接口 // @Description 获取待配置的指标列表接口 // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博" // @Param SubSource query int true "来源:0:经济数据库,1:日期序列" // @Param Frequency query string false "频度" // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp // @router /edb_info/refresh/default_config [get] func (c *EdbInfoController) GetEdbRefreshDefaultConfig() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() source, _ := c.GetInt("Source") subSource, _ := c.GetInt("SubSource") frequency := c.GetString("Frequency") if source <= 0 { br.Msg = "来源不能为空" br.IsSendEmail = false return } if frequency == `` { br.Msg = "频度不能为空" br.IsSendEmail = false return } list, err := data_manage.GetListBySourceAndFrequency(source, subSource, frequency) if err != nil { br.Msg = "获取失败" br.ErrMsg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = list } // SaveEdbRefreshDefaultConfig // @Title 设置待配置的指标列表接口 // @Description 设置待配置的指标列表接口 // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博" // @Param SubSource query int true "来源:0:经济数据库,1:日期序列" // @Param Frequency query string false "频度" // @Success 200 {object} data_manage.RefreshBaseEdbInfoResp // @router /edb_info/refresh/default_config/save [post] func (c *EdbInfoController) SaveEdbRefreshDefaultConfig() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() source, _ := c.GetInt("Source") subSource, _ := c.GetInt("SubSource") frequency := c.GetString("Frequency") if source <= 0 { br.Msg = "来源不能为空" br.IsSendEmail = false return } if frequency == `` { br.Msg = "频度不能为空" br.IsSendEmail = false return } list, err := data_manage.GetListBySourceAndFrequency(source, subSource, frequency) if err != nil { br.Msg = "获取失败" br.ErrMsg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = list }