/// <summary> /// 获取类别数据 /// </summary> /// <param name="id">类别code的字符串,逗号连接</param> /// <returns></returns> public IHttpActionResult GetData(string id) { var list = categoryService.GetCategoryByCode(id); var result = list.Select(p => new StockCategory { code = p.code, price = p.price, yestclose = p.yestclose, group_code = p.group_code, name = p.name }).ToList(); return(Ok(result)); }
/// <summary> /// 获取类别数据 /// </summary> /// <param name="id">类别code的字符串,逗号连接</param> /// <returns></returns> public IHttpActionResult PostData(string[][] id) { var p1 = id;// Newtonsoft.Json.JsonConvert.DeserializeObject<string[][]>(ids); List <string> objectList = new List <string>(); List <string> categoryList = new List <string>(); List <string> ecoList = new List <string>(); foreach (string[] item in p1) { //行业 if (item[0] == "2") { categoryList.Add(item[1]); } else if (item[0] == "3") { objectList.Add(item[1]); } else if (item[0] == "4") { ecoList.Add(item[1]); } } List <CustomObject> result = new List <CustomObject>(); //自定义对象 var cache_objs = CacheHelper.Get <PriceInfo>(objectList.Select(p => "3_" + p).ToArray()); if (cache_objs != null && cache_objs.Length > 0) { var t1 = cache_objs.Select(p => new CustomObject { code = p.code, type = "3", price = p.price, yestclose = p.yestclose }).ToList(); result.AddRange(t1); } else { var list1 = objectService.GetDataByCode(string.Join(",", objectList)); var result1 = list1.Select(p => new CustomObject { code = p.code, type = "3", price = p.price, yestclose = p.yestclose, name = p.name }).ToList(); result.AddRange(result1); } //行业 var cache_cate = CacheHelper.Get <PriceInfo>(categoryList.Select(p => "2_" + p).ToArray()); if (cache_cate != null && cache_cate.Length > 0) { var t2 = cache_cate.Select(p => new CustomObject { code = p.code, type = "2", price = p.price, yestclose = p.yestclose }).ToList(); result.AddRange(t2); } else { string cateStr = string.Join(",", categoryList); var list2 = categoryService.GetCategoryByCode(cateStr); var result2 = list2.Select(p => new CustomObject { code = p.code, type = "2", price = p.price, yestclose = p.yestclose, name = p.name }).ToList(); result.AddRange(result2); } //经济指数 string ecoStr = string.Join(",", ecoList); var list3 = relateService.GetDataByCode(ecoStr); var result3 = list3.Select(p => new CustomObject { code = p.code, type = "4", price = p.price, yestclose = p.yestclose, name = p.name }).ToList(); result.AddRange(result3); return(Ok(result)); }