Exemple #1
0
        /// <summary>
        /// 默认根据最近7天的销售情况,用标准差公式计算消化率稳定产品.
        /// </summary>
        /// <returns>.</returns>
        private static List <ProductExpendRateStandardDeviationModel> GetStableExpendRate()
        {
            try
            {
                List <ProductExpendRateStandardDeviationModel> list = new List <ProductExpendRateStandardDeviationModel>();
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    DateTime start_time = DateTime.Now; DateTime end_time = start_time.AddDays(7);
                    var      query = (from a in db.Product
                                      join b in db.Sell_Record on a.product_id equals b.product_id
                                      where b.create_time >= start_time && b.create_time <= end_time
                                      select new
                                      { a.product_id, a.product_name, a.stock_count, b.sell_count, b.create_time, a.product_category }).ToList();
                    if (query.Any())
                    {
                        var product = query.GroupBy(a => new { a.product_id, a.product_name });
                        if (product.Any())
                        {
                            foreach (var item in product)
                            {
                                List <double> expend_rate = new List <double>();
                                foreach (var info in item)
                                {
                                    double rate = ((double)info.sell_count / (double)info.stock_count) * 100;
                                    expend_rate.Add(rate);
                                }

                                ProductExpendRateStandardDeviationModel model = new ProductExpendRateStandardDeviationModel();
                                model.product_id     = item.Key.product_id;
                                model.product_name   = item.Key.product_name;
                                model.expend_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                list.Add(model);
                            }
                        }
                    }

                    if (list.Any())
                    {
                        list = list.OrderBy(a => a.expend_rate_sd).Take(5).ToList();
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
Exemple #2
0
        public IHttpActionResult GetLowExpendRateProduct()
        {
            try
            {
                List <ProductExpendRateStandardDeviationModel> list = new List <ProductExpendRateStandardDeviationModel>();
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var query = (from a in db.Product join b in db.Sell_Record on a.product_id equals b.product_id select new { a.product_id, a.product_name, a.stock_count, b.sell_count, a.product_category }).ToList();
                    if (query.Any())
                    {
                        var ri_pei    = query.Where(a => a.product_category == (int)Product_Category_Enum.RiPei).GroupBy(a => new { a.product_id, a.product_name });
                        var no_ri_pei = query.Where(a => a.product_category == (int)Product_Category_Enum.NoRiPei).GroupBy(a => new { a.product_id, a.product_name });

                        if (ri_pei.Any())
                        {
                            foreach (var item in ri_pei)
                            {
                                List <double> expend_rate = new List <double>();
                                foreach (var info in item)
                                {
                                    double rate = ((double)info.sell_count / (double)info.stock_count) * 100;
                                    expend_rate.Add(rate);
                                }

                                double expent_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                if (expent_rate_sd < 50) //日配商品消化率低于50%
                                {
                                    ProductExpendRateStandardDeviationModel model = new ProductExpendRateStandardDeviationModel();
                                    model.product_id     = item.Key.product_id;
                                    model.product_name   = item.Key.product_name;
                                    model.expend_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                    list.Add(model);
                                }
                            }
                        }

                        if (no_ri_pei.Any())
                        {
                            foreach (var item in ri_pei)
                            {
                                List <double> expend_rate = new List <double>();
                                foreach (var info in item)
                                {
                                    double rate = ((double)info.sell_count / (double)info.stock_count) * 100;
                                    expend_rate.Add(rate);
                                }

                                double expent_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                if (expent_rate_sd < 10) //非日配商品消化率低于10%
                                {
                                    ProductExpendRateStandardDeviationModel model = new ProductExpendRateStandardDeviationModel();
                                    model.product_id     = item.Key.product_id;
                                    model.product_name   = item.Key.product_name;
                                    model.expend_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                    list.Add(model);
                                }
                            }
                        }
                    }

                    return(Json(new { result = list }));
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }