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));
        }
Пример #2
0
        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 void Execute(IJobExecutionContext context)
        {
            using (StockManDBEntities entity = new StockManDBEntities())
            {
                var msgList = entity.user_message.Where(p => p.notice_state == 0).ToList();

                foreach (var u in msgList)
                {
                    string email  = "";
                    var    config = entity.sys_userconfig.Where(p => p.code == u.user_id).FirstOrDefault();
                    if (config != null && !string.IsNullOrEmpty(config.config))
                    {
                        var configDetail = JsonConvert.DeserializeObject <UserConfigItem>(config.config);
                        email = configDetail.email;
                    }

                    if (string.IsNullOrEmpty(email))
                    {
                        if (u.user_id.IndexOf("@") > 0)
                        {
                            email = u.user_id;
                        }
                    }

                    if (!string.IsNullOrEmpty(email))
                    {
                        sendmail("慢牛提醒", u.content, "*****@*****.**", email, "*****@*****.**", "18669040658");

                        u.notice_state = 1;
                    }
                }
                entity.SaveChanges();
            }
        }
Пример #4
0
 public virtual void Delete(T data)
 {
     using (StockManDBEntities db = new StockManDBEntities())
     {
         Type           type    = data.GetType();
         PropertyInfo[] members = type.GetProperties();
         List <string>  ids     = new List <string>();
         foreach (PropertyInfo m in members)
         {
             var temp = m.GetCustomAttribute <KeyAttribute>();
             if (temp != null)
             {
                 object obj = m.GetValue(data);
                 ids.Add(obj.ToString());
                 continue;
             }
         }
         T entity = db.Set <T>().Find(ids.ToArray());
         if (entity != default(T))
         {
             db.Set <T>().Remove(entity);
             db.SaveChanges();
         }
     }
 }
Пример #5
0
        private void SaveTechContext(string context, IndexDefinitionInfo define)
        {
            string objCode = (int)this.ObjectType + "";
            string code    = objCode + "_" + this.ObjectCode + "_" + define.code + "_" + this.Cycle;

            using (var entity = new StockManDBEntities())
            {
                var item = entity.tech_context.FirstOrDefault(p => p.code == code);
                if (item == null)
                {
                    entity.tech_context.Add(new tech_context()
                    {
                        code          = code,
                        category_code = objCode,
                        object_code   = this.ObjectCode,
                        index_code    = define.code,
                        context       = context,
                        createtime    = DateTime.Now
                    });
                }
                else
                {
                    item.context    = context;
                    item.createtime = DateTime.Now;
                }
                try
                {
                    entity.SaveChanges();
                }
                catch (Exception ex)
                {
                    this.Log().Error(ex.Message);
                }
            }
        }
        public IHttpActionResult ReplySuggest(dm.sys_goodidea sys_GoodIdea)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (StockManDBEntities db = new StockManDBEntities())
            {
                var item = db.sys_goodidea.FirstOrDefault(p => p.code == sys_GoodIdea.code);
                if (item == null)
                {
                    db.sys_goodidea.Add(sys_GoodIdea);
                }
                else
                {
                    item.description = sys_GoodIdea.description;
                }


                try
                {
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(Ok());
        }
Пример #7
0
        public virtual void DeleteRange(IList <T> datas)
        {
            using (StockManDBEntities db = new StockManDBEntities())
            {
                IList <T> list = new List <T>();
                foreach (T data in datas)
                {
                    Type           type    = data.GetType();
                    PropertyInfo[] members = type.GetProperties();
                    List <string>  ids     = new List <string>();
                    foreach (PropertyInfo m in members)
                    {
                        var temp = m.GetCustomAttribute <KeyAttribute>();
                        if (temp != null)
                        {
                            object obj = m.GetValue(data);
                            ids.Add(obj.ToString());
                            continue;
                        }
                    }
                    T entity = db.Set <T>().Find(ids.ToArray());
                    list.Add(entity);
                }

                if (list.Count > 0)
                {
                    foreach (var l in list)
                    {
                        db.Set <T>().Remove(l);
                    }

                    db.SaveChanges();
                }
            }
        }
        public void SetStrategy(string user_id, IList <string> strategry)
        {
            using (StockManDBEntities entity = new StockManDBEntities())
            {
                if (strategry == null)
                {
                    strategry = new List <string>();
                }

                var us = entity.user_strategy.FirstOrDefault(p => p.user_id == user_id);
                if (us == null)
                {
                    entity.user_strategy.Add(new user_strategy
                    {
                        user_id  = user_id,
                        strategy = JsonConvert.SerializeObject(strategry)
                    });
                }
                else
                {
                    us.strategy = JsonConvert.SerializeObject(strategry);
                }
                entity.SaveChanges();
            }
        }
Пример #9
0
        private void SaveTechState(IndexDefinitionInfo define, IndexState result)
        {
            using (StockManDBEntities entity = new StockManDBEntities())
            {
                var cate        = (int)this.ObjectType + "";
                var code        = cate + "_" + this.ObjectCode + "_" + define.code;
                var objectState = entity.objectstate.FirstOrDefault(p => p.code == code);
                if (objectState == null)
                {
                    var temp = new objectstate()
                    {
                        code          = code,
                        category_code = cate,
                        object_code   = this.ObjectCode,
                        index_code    = define.code,
                        date          = DateTime.Now
                    };

                    switch (this.Cycle)
                    {
                    case TechCycle.day:
                        temp.day = (int)result;
                        break;

                    case TechCycle.week:
                        temp.week = (int)result;
                        break;

                    default:
                        temp.month = (int)result;
                        break;
                    }
                    entity.objectstate.Add(temp);
                }
                else
                {
                    switch (this.Cycle)
                    {
                    case TechCycle.day:
                        objectState.last_day = objectState.day;
                        objectState.day      = (int)result;
                        break;

                    case TechCycle.week:
                        objectState.last_week = objectState.week;
                        objectState.week      = (int)result;
                        break;

                    default:
                        objectState.last_month = objectState.month;
                        objectState.month      = (int)result;
                        break;
                    }
                    objectState.date = DateTime.Now;
                }

                entity.SaveChanges();
            }
        }
Пример #10
0
 public virtual void Update(T data)
 {
     using (StockManDBEntities db = new StockManDBEntities())
     {
         db.Entry <T>(data).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Пример #11
0
        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();
                    }
                }
            }
        }
        public void AddPriceInfo(string categoryCode, PriceInfo info, TechCycle cycle)
        {
            using (var entity = new StockManDBEntities())
            {
                switch (cycle)
                {
                case TechCycle.day:
                    entity.data_category_day_latest.Add(new data_category_day_latest()
                    {
                        object_code = categoryCode,
                        code        = categoryCode + "_" + info.date.ToString("yyyyMMdd"),
                        date        = info.date,
                        high        = info.high,
                        low         = info.low,
                        open        = info.open,
                        price       = info.price,
                        yestclose   = info.yestclose,
                        volume      = info.volume
                    });
                    break;

                case TechCycle.week:
                    entity.data_category_week_latest.Add(new data_category_week_latest()
                    {
                        object_code = categoryCode,
                        code        = categoryCode + "_" + info.date.ToString("yyyyMMdd"),
                        date        = info.date,
                        high        = info.high,
                        low         = info.low,
                        open        = info.open,
                        price       = info.price,
                        yestclose   = info.yestclose,
                        volume      = info.volume
                    });
                    break;

                case TechCycle.month:
                    entity.data_category_month_latest.Add(new data_category_month_latest()
                    {
                        object_code = categoryCode,
                        code        = categoryCode + "_" + info.date.ToString("yyyyMMdd"),
                        date        = info.date,
                        high        = info.high,
                        low         = info.low,
                        open        = info.open,
                        price       = info.price,
                        yestclose   = info.yestclose,
                        volume      = info.volume
                    });
                    break;
                }
                entity.SaveChanges();
            }
        }
Пример #13
0
 public void DeleteGroup(string code)
 {
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         var obj = entity.indexdefinegroup.FirstOrDefault(p => p.code == code);
         if (obj != null)
         {
             entity.indexdefinegroup.Remove(obj);
             entity.SaveChanges();
         }
     }
 }
Пример #14
0
 public void Release(string code)
 {
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         var index = entity.indexdefinition.First(p => p.code == code);
         if (index != null)
         {
             index.state = (int)IndexEnableState.Running;
             entity.SaveChanges();
         }
     }
 }
Пример #15
0
        /// <summary>
        /// 同步自选股
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="indexCodeList"></param>
        /// <returns></returns>
        public bool SyncMyIndex(string userId, IList <index_user_map> indexCodeList)
        {
            int count = indexCodeList.Count(p => string.IsNullOrEmpty(p.user_id) || string.IsNullOrEmpty(p.index_code));

            if (count > 0)
            {
                throw new Exception("缺失属性user_id和index_code");
            }
            //新增
            IList <string> newCodeList = indexCodeList.Select(p => p.index_code).ToList();

            using (StockManDBEntities entity = new StockManDBEntities())
            {
                var oldMapList = (from t in entity.index_user_map
                                  where t.user_id == userId
                                  select t).ToList();

                var oldCodeList = (from t in oldMapList
                                   select t.index_code).ToList();
                var addCodeList    = newCodeList.Except(oldCodeList).ToList();
                var deleteCodeList = oldCodeList.Except(newCodeList).ToList();
                var updateCodeLIst = newCodeList.Intersect(oldCodeList).ToList();

                List <index_user_map> addMapList = indexCodeList.Where(p => addCodeList.Contains(p.index_code)).ToList();

                foreach (var add in addMapList)
                {
                    entity.index_user_map.Add(add);
                }


                List <index_user_map> updateMapList = indexCodeList.Where(p => updateCodeLIst.Contains(p.index_code)).ToList();
                index_user_map        oldMap        = null;
                foreach (var map in updateMapList)
                {
                    oldMap      = oldMapList.First(p => p.index_code == map.index_code);
                    oldMap.sort = map.sort;
                }

                List <index_user_map> removeMapList = oldMapList.Where(p => deleteCodeList.Contains(p.index_code)).ToList();

                foreach (var r in removeMapList)
                {
                    entity.index_user_map.Remove(r);
                }


                entity.SaveChanges();

                return(true);
            }
        }
Пример #16
0
 private void SaveUserMessage(IList <data.user_message> messageList)
 {
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         foreach (var msg in messageList)
         {
             if (!entity.user_message.Any(p => p.code == msg.code))
             {
                 entity.user_message.Add(msg);
             }
         }
         entity.SaveChanges();
     }
 }
 public void AddMyCategory(stockcategory_user_map data)
 {
     if (data == null ||
         string.IsNullOrEmpty(data.cate_code) ||
         string.IsNullOrEmpty(data.user_id))
     {
         throw new Exception("参数不合规");
     }
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         entity.stockcategory_user_map.Add(data);
         entity.SaveChanges();
     }
 }
Пример #18
0
        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 UpdateMyCateVersion(string user_id, decimal version)
 {
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         var list = entity.userdataversion
                    .Where(p => p.user_id == user_id && p.code == "my_category")
                    .FirstOrDefault();
         if (list != null)
         {
             list.version = version;
             entity.SaveChanges();
         }
     }
 }
 public void AddAmount(string user_id, decimal amount)
 {
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         var um = entity
                  .user_amount
                  .FirstOrDefault(p => p.id == user_id);
         if (um != null)
         {
             um.amount = um.amount + amount;
             entity.SaveChanges();
         }
     }
 }
Пример #21
0
        public indexdefinegroup AddGroup(indexdefinegroup group)
        {
            if (string.IsNullOrEmpty(group.code) || string.IsNullOrEmpty(group.group_name))
            {
                return(null);
            }

            using (StockManDBEntities entity = new StockManDBEntities())
            {
                entity.indexdefinegroup.Add(group);
                entity.SaveChanges();
                return(group);
            }
        }
Пример #22
0
        // PUT: odata/Recommend(5)
        public IHttpActionResult Put([FromODataUri] string key, Delta <reco_stock_category_index> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            reco_stock_category_index reco_stock_category_index = db.reco_stock_category_index.Find(key);

            if (reco_stock_category_index == null)
            {
                return(NotFound());
            }

            patch.Put(reco_stock_category_index);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!reco_stock_category_indexExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(reco_stock_category_index));
        }
Пример #23
0
        // PUT: odata/GoodIdea(5)
        public IHttpActionResult Put([FromODataUri] string key, Delta <sys_goodidea> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            sys_goodidea sys_GoodIdea = db.sys_goodidea.Find(key);

            if (sys_GoodIdea == null)
            {
                return(NotFound());
            }

            patch.Put(sys_GoodIdea);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Sys_GoodIdeaExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(sys_GoodIdea));
        }
        // PUT: odata/UserMessage(5)
        public IHttpActionResult Put([FromODataUri] string key, Delta <user_message> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            user_message user_message = db.user_message.Find(key);

            if (user_message == null)
            {
                return(NotFound());
            }

            patch.Put(user_message);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!user_messageExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(user_message));
        }
        // PUT: odata/StockNew(5)
        public IHttpActionResult Put([FromODataUri] string key, Delta <stock_new> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            stock_new stock_New = db.stock_new.Find(key);

            if (stock_New == null)
            {
                return(NotFound());
            }

            patch.Put(stock_New);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Stock_NewExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(stock_New));
        }
Пример #26
0
 public virtual T Add(T data)
 {
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         entity.Set <T>().Add(data);
         try
         {
             entity.SaveChanges();
         }
         catch (System.Data.Entity.Validation.DbEntityValidationException ex)
         {
             throw ex;
         }
         return(data);
     }
 }
 public void SubPosition(string user_id, string stock_code, int position)
 {
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         var code = user_id + "_" + stock_code;
         var pos  = entity.user_position.FirstOrDefault(p => p.code == code);
         if (pos != null)
         {
             if (pos.position >= position)
             {
                 pos.position = pos.position - position;
                 entity.SaveChanges();
             }
         }
     }
 }
Пример #28
0
        private void ComputeCategoryCount(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();;
            }

            using (var entity = new StockManDBEntities())
            {
                cateList.Each(p =>
                {
                    indexList.Each(i =>
                    {
                        this.Log().Info("推荐行业:" + p.name + ",技术" + i.name);
                        var count = entity.reco_stock_category_index.Count(s => s.cate_code == p.code && s.index_code == i.code);
                        var code  = p.code + "_" + i.code;

                        var rcc = entity.reco_category_count.FirstOrDefault(s => s.code == code);
                        if (rcc == null)
                        {
                            entity.reco_category_count.Add(new data.reco_category_count
                            {
                                code       = code,
                                cate_code  = p.code,
                                cate_type  = group,
                                index_code = i.code,
                                count      = count
                            });
                        }
                        else
                        {
                            rcc.count = count;
                        }
                    });

                    entity.SaveChanges();
                });
            }
        }
 public void AddTrade(string user_id, string stock_code, decimal price, int count, TradeDirection tradeDirection)
 {
     using (StockManDBEntities entity = new StockManDBEntities())
     {
         var code = user_id + "_" + stock_code + "_" + (int)tradeDirection + "_" + DateTime.Now.ToString("yyyyMMddhhmmss");
         entity.user_trade.Add(new user_trade
         {
             code       = code,
             user_id    = user_id,
             stock_code = stock_code,
             count      = count,
             direact    = (int)tradeDirection,
             price      = price,
             date       = DateTime.Now
         });
         entity.SaveChanges();
     }
 }
Пример #30
0
        public virtual void AddRange(IList <T> datas)
        {
            using (StockManDBEntities entity = new StockManDBEntities())
            {
                foreach (var data in datas)
                {
                    entity.Set <T>().Add(data);
                }

                try
                {
                    entity.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }