public IHttpActionResult PutUser_InvestIntention(string id, user_investintention user_InvestIntention) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user_InvestIntention.code) { return(BadRequest()); } db.Entry(user_InvestIntention).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!User_InvestIntentionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Putrelated_object_define(string id, related_object_define related_object_define) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != related_object_define.code) { return(BadRequest()); } db.Entry(related_object_define).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!related_object_defineExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public virtual void Update(T data) { using (StockManDBEntities db = new StockManDBEntities()) { db.Entry <T>(data).State = EntityState.Modified; db.SaveChanges(); } }
private void RecoCategoryStock(string group) { IList <data.stockcategory> cateList = null; IList <data.indexdefinition> indexList = indexService.FindAll().Where(p => p.state == 1).ToList(); if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1") { cateList = cateService.GetCategoryList(group); } else { string[] cates = this.CategoryCode.Split(','); cateList = cateService.GetCategoryList(group).Where(p => cates.Contains(p.code)).ToList();; } //每个行业,每个技术,最多推荐5只股票。 foreach (var p in cateList) { foreach (var i in indexList) { this.Log().Info("推荐行业:" + p.name + ",技术" + i.name); //and (c.day=1 or ( c.last_day=-1 and c.day=0)) string sql = string.Format(@"select distinct CONCAT(b.cate_code,'_',c.index_code,'_',a.code) as code, a.code as object_code,a.name as object_name,a.price,a.yestclose,a.percent,a.pe, a.pb,a.mv,a.fv,b.cate_code as cate_code,d.name as cate_name,c.index_code as index_code,e.name as index_name, c.day,c.week,c.month,c.last_day,c.last_week,c.last_month from stock a inner join stock_category_map b on b.stock_code=a.code inner join stockcategory d on b.cate_code=d.code inner join objectstate c on a.code=c.object_code inner join indexdefinition e on c.index_code=e.code where b.cate_code ='{0}' and c.index_code ='{1}' and c.week=1 and c.month=1 and (c.day=1 or ( c.last_day=-1 and c.day=0)) LIMIT 5;", p.code, i.code); using (var entity = new StockManDBEntities()) { var recos = entity.Database.SqlQuery <data.reco_stock_category_index>(sql).ToList(); recos.Each(reco => { this.Log().Info("推荐股票:" + reco.object_code + "_" + reco.object_name); if (entity.reco_stock_category_index.Any(x => x.code == reco.code)) { entity.Entry(reco).State = EntityState.Modified; } else { entity.reco_stock_category_index.Add(reco); } }); entity.SaveChanges(); } } } }
private void RecoStateReverseStock(string group, string cycle) { IList <data.stockcategory> cateList = null; IList <data.indexdefinition> indexList = indexService.FindAll().Where(p => p.state == 1).ToList(); if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1") { cateList = cateService.GetCategoryList(group); } else { string[] cates = this.CategoryCode.Split(','); cateList = cateService.GetCategoryList(group).Where(p => cates.Contains(p.code)).ToList();; } //每个行业,每个技术,最多推荐5只股票。 cateList.Each(p => { this.Log().Info("推荐行业:" + p.name); string sql = string.Format(@"select distinct CONCAT(b.cate_code,'_',a.code,'_',c.index_code,'_','{1}') as code, a.code as object_code,a.name as object_name,a.price,a.yestclose,a.percent,a.pe, a.pb,a.mv,a.fv,b.cate_code as cate_code,d.name as cate_name,c.index_code,i.name as index_name,c.index_code as tag_code,i.name as tag_name, c.day,c.week,c.month,c.last_day,c.last_week,c.last_month,'{1}' as cycle from objectstate c left join stock a on a.code=c.object_code left join stock_category_map b on b.stock_code=a.code left join stockcategory d on b.cate_code=d.code inner join indexdefinition i on c.index_code=i.code where c.{1}='1' and c.last_{1}='-1' and c.month='1' and b.cate_code ='{0}' limit 5", p.code, cycle); using (var entity = new StockManDBEntities()) { var recos = entity.Database.SqlQuery <data.reco_stock_category_state>(sql).ToList(); recos.Each(reco => { this.Log().Info("推荐股票:" + reco.object_code + "_" + reco.object_name); if (entity.reco_stock_category_state.Any(x => x.code == reco.code)) { entity.Entry(reco).State = EntityState.Modified; } else { entity.reco_stock_category_state.Add(reco); } }); entity.SaveChanges(); } }); }
public void Excute(string message) { RecoCateStock msg = JsonConvert.DeserializeObject <RecoCateStock>(message); string cateCode = msg.CateCode; string cateName = msg.CateName; string indexCode = msg.IndexCode; string indexName = msg.IndexName; this.Log().Info("计算开始:推荐行业:" + cateName + ",技术" + indexName); //and (c.day=1 or ( c.last_day=-1 and c.day=0)) string sql = string.Format(@"select distinct CONCAT(b.cate_code,'_',c.index_code,'_',a.code) as code, a.code as object_code,a.name as object_name,a.price,a.yestclose,a.percent,a.pe, a.pb,a.mv,a.fv,b.cate_code as cate_code,d.name as cate_name,c.index_code as index_code,e.name as index_name, c.day,c.week,c.month,c.last_day,c.last_week,c.last_month from stock a inner join stock_category_map b on b.stock_code=a.code inner join stockcategory d on b.cate_code=d.code inner join objectstate c on a.code=c.object_code inner join indexdefinition e on c.index_code=e.code where b.cate_code ='{0}' and c.index_code ='{1}' and c.week=1 and c.month=1 and (c.day=1 or ( c.last_day=-1 and c.day=0)) LIMIT 5;", cateCode, indexCode); using (var entity = new StockManDBEntities()) { var recos = entity.Database.SqlQuery <data.reco_stock_category_index>(sql).ToList(); foreach (var reco in recos) { this.Log().Info("推荐股票:" + reco.object_code + "_" + reco.object_name); if (entity.reco_stock_category_index.Any(x => x.code == reco.code)) { entity.Entry(reco).State = EntityState.Modified; } else { entity.reco_stock_category_index.Add(reco); } } entity.SaveChanges(); } this.Log().Info("计算完成:推荐行业:" + cateName + ",技术" + indexName); }
public void AddPriceByDay <TM>(IList <PriceInfo> priceList, bool check = true) where TM : ObjectDataBase, new() { using (StockManDBEntities entity = new StockManDBEntities()) { string tableName = typeof(TM).Name; //IList<TM> list = new List<TM>(); foreach (PriceInfo p in priceList) { if (!p.open.HasValue || p.open.Value <= 0) { continue; } string code = p.code + "_" + p.date.ToString("yyyyMMdd"); if (check && entity.Set <TM>().Count(s => s.code == code) > 0) { entity.Entry(new TM() { code = code, date = p.date,//new DateTime(int.Parse(date.Substring(0, 4)), int.Parse(date.Substring(4, 2)), int.Parse(p.date.Substring(6))), price = p.price, yestclose = p.yestclose, high = p.high, low = p.low, open = p.open, percent = p.percent, object_code = p.code, updown = p.updown, volume = p.volume, turnover = p.turnover }).State = EntityState.Modified; } else { entity.Set <TM>().Add(new TM() { code = code, date = p.date,//new DateTime(int.Parse(date.Substring(0, 4)), int.Parse(date.Substring(4, 2)), int.Parse(p.date.Substring(6))), price = p.price, yestclose = p.yestclose, high = p.high, low = p.low, open = p.open, percent = p.percent, object_code = p.code, updown = p.updown, volume = p.volume, turnover = p.turnover }); } } //foreach (var l in list) //{ // entity.Set<TM>().Add(l); //} try { entity.SaveChanges(); } catch (Exception ex) { throw ex; } } }