/// <summary>
        /// 更新实体信息
        /// </summary>
        /// <param name="sourcelist">数据源列表</param>
        /// <param name="info">实体信息</param>
        /// <param name="statype">统计类型</param>
        /// <param name="dt">数据日期</param>
        /// <param name="ishas">记录是否已存在</param>
        private void UpdateInfo(IEnumerable <DS_DataSource> sourcelist, RP_EnEx info, int statype, DateTime dt, bool ishas)
        {
            //北京段只包含出口收费站
            List <int> outBJStation = StationConfiguration.GetOutBJStaion();

            if (ishas)//已存在,则更新
            {
                info.UpdDate = DateTime.Now;
                info.State   = "1";
            }
            else//不存在,添加
            {
                info.Id      = Guid.NewGuid();
                info.CrtDate = DateTime.Now;
                info.State   = "0";
            }
            //给实体字段赋值
            //0:小型客车,1:其他客车,2:货车,3:绿通
            info.EnSmaCar = sourcelist.Where(s => s.CalcuType == 0).Sum(s => s.OutNum.Value);
            info.EnOthCar = sourcelist.Where(s => s.CalcuType == 1).Sum(s => s.OutNum.Value);
            info.EnTruk   = sourcelist.Where(s => s.CalcuType == 2).Sum(s => s.OutNum.Value);
            //泗村店,入境“绿色通道”数据项填写“0”
            info.EnGre     = 0;
            info.StaType   = statype;
            info.CalcuTime = dt;
            //泗村店不统计出镜,,北京段出境绿通为0,不包含马驹桥东入口
            if (statype == (int)StationConfiguration.StationType.BeiJingDuan)
            {
                info.ExSmaCar = sourcelist.Where(s => outBJStation.Contains(s.StaID.Value) && s.CalcuType == 0).Sum(s => s.InNum.Value);
                info.ExOthCar = sourcelist.Where(s => outBJStation.Contains(s.StaID.Value) && s.CalcuType == 1).Sum(s => s.InNum.Value);
                info.ExTruk   = sourcelist.Where(s => outBJStation.Contains(s.StaID.Value) && s.CalcuType == 2).Sum(s => s.InNum.Value);
                info.ExGre    = 0;
                info.EnGre    = sourcelist.Where(s => s.CalcuType == 3).Sum(s => s.OutNum.Value);
            }
        }
        /// <summary>
        ///更新每日报送数据15.16.17
        /// </summary>
        public void Update(DateTime dt, int HourPer)
        {
            string startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            SystemLog.GetInstance().Log.Info(string.Format("{0}:开始获取15,16,17报表数据", startTime));
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                DateTime pdt = DateTime.Parse(dt.ToShortDateString());
                //北京段相同数据是否存在
                List <RP_NatSta> pBJlist = db.RP_NatSta.Where(p =>
                                                              p.CalcuTime == pdt &&
                                                              p.HourPer == (byte?)HourPer &&
                                                              p.StaType == (int)StationConfiguration.StationType.BeiJingDuan).ToList();
                bool BJHasTime = pBJlist.Count > 0;
                //大羊坊相同数据是否存在
                List <RP_NatSta> pDYFlist = db.RP_NatSta.Where(p =>
                                                               p.CalcuTime == pdt &&
                                                               p.HourPer == (byte?)HourPer &&
                                                               p.StaType == (int)StationConfiguration.StationID.DYF).ToList();
                bool DYFHasTime = pDYFlist.Count > 0;
                IList <RP_NatSta> pNaturalEntities = new List <RP_NatSta>();

                List <int> BJStation    = StationConfiguration.GetBJStaion();
                List <int> outBJStation = StationConfiguration.GetOutBJStaion();
                //p.VehType != 0 表示不包括合计数据,
                IEnumerable <DS_DataSource> pStagingCollection = db.DS_DataSource.Where(p =>
                                                                                        p.CalcuTime == dt &&
                                                                                        p.VehType != 0 &&
                                                                                        p.HourPer == HourPer &&
                                                                                        BJStation.Contains(p.StaID.Value));


                RP_NatSta pNaturalTrafficBJ = null; //北京段
                RP_NatSta pNaturalTraffic   = null; //大羊坊
                //北京段
                //如果相同日期,相同时间段,相同统计站类型数据已存在则进行更新
                if (!BJHasTime)
                {
                    pNaturalTrafficBJ    = new RP_NatSta();//北京段
                    pNaturalTrafficBJ.Id = Guid.NewGuid();
                }
                else
                {
                    pNaturalTrafficBJ = pBJlist[0];
                }
                pNaturalTrafficBJ.EnNum     = pStagingCollection.Sum(s => s.OutNum);
                pNaturalTrafficBJ.ExNum     = pStagingCollection.Where(s => outBJStation.Contains(s.StaID.Value)).Sum(s => s.InNum);
                pNaturalTrafficBJ.Sum       = pNaturalTrafficBJ.EnNum + pNaturalTrafficBJ.ExNum;
                pNaturalTrafficBJ.StaType   = (int)StationConfiguration.StationType.BeiJingDuan;
                pNaturalTrafficBJ.CalcuTime = DateTime.Parse(dt.ToShortDateString());
                pNaturalTrafficBJ.HourPer   = (byte)HourPer;
                pNaturalTrafficBJ.CrtDate   = DateTime.Now;
                pNaturalTrafficBJ.RunStae   = SystemConst.RunningStatus;
                pNaturalTrafficBJ.State     = "0";
                //大羊坊
                //如果相同日期,相同时间段,相同统计站类型数据已存在则进行更新
                if (!DYFHasTime)
                {
                    pNaturalTraffic    = new RP_NatSta();//大羊坊
                    pNaturalTraffic.Id = Guid.NewGuid();
                }
                else
                {
                    pNaturalTraffic = pDYFlist[0];
                }
                pNaturalTraffic.EnNum     = pStagingCollection.Where(s => s.StaID == (int)StationConfiguration.StationID.DYF).Sum(s => s.OutNum);
                pNaturalTraffic.ExNum     = pStagingCollection.Where(s => s.StaID == (int)StationConfiguration.StationID.DYF).Sum(s => s.InNum);
                pNaturalTraffic.Sum       = pNaturalTraffic.EnNum + pNaturalTraffic.ExNum;
                pNaturalTraffic.StaType   = (int)StationConfiguration.StationID.DYF;
                pNaturalTraffic.CrtDate   = DateTime.Now;
                pNaturalTraffic.HourPer   = (byte)HourPer;
                pNaturalTraffic.CalcuTime = DateTime.Parse(dt.ToShortDateString());
                pNaturalTraffic.RunStae   = SystemConst.RunningStatus;
                pNaturalTraffic.State     = "0";

                pNaturalEntities.Add(pNaturalTrafficBJ);
                pNaturalEntities.Add(pNaturalTraffic);
                using (TransactionScope transaction = new TransactionScope())
                {
                    //如果都不存在,则添加
                    if (!DYFHasTime && !BJHasTime)
                    {
                        db.RP_NatSta.AddRange(pNaturalEntities);
                    }
                    else if (!DYFHasTime && BJHasTime)
                    {
                        db.RP_NatSta.Add(pNaturalTraffic);
                    }
                    else if (DYFHasTime && !BJHasTime)
                    {
                        db.RP_NatSta.Add(pNaturalTrafficBJ);
                    }

                    db.SaveChanges();
                    //提交事务
                    transaction.Complete();
                }
                string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:结束获取15.16.17报表数据", endTime));
                SystemLog.GetInstance().Log.Info(string.Format("统计15,16,17报表数据耗时{0}秒", (DateTime.Parse(endTime) - DateTime.Parse(startTime)).TotalSeconds));
                //显示执行该方法的线程ID
                //SystemLog.GetInstance().Log.Info(string.Format("调用15,16,17Update的线程ID为:{0}", Thread.CurrentThread.ManagedThreadId));
                Thread.Sleep(1000);
            }
        }
Пример #3
0
        /// <summary>
        /// 8.9.10数据源更新方法
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="HourPer"></param>
        public void Update(DateTime dt, int HourPer)
        {
            try
            {
                string startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:开始获取8,9,10报表数据", startTime));
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    DateTime             plasttime   = new DateTime();
                    List <OT_HDayConfig> pdayconfigs = db.OT_HDayConfig.Where(s => s.Id == 9).ToList();
                    OT_HDayConfig        pdayconfig  = new OT_HDayConfig();
                    if (pdayconfigs.Count > 0)
                    {
                        pdayconfig = pdayconfigs.First();
                        if (pdayconfig.HDayStart.HasValue && pdayconfig.HDayEnd.HasValue)
                        {
                            int ptemp = 0;
                            //判断当天是否在假期配置时间范围内
                            DateTime ptempdt = DateTime.Parse(dt.ToShortDateString());
                            if (ptempdt >= pdayconfig.HDayStart.Value && ptempdt <= pdayconfig.HDayEnd)
                            {
                                //间隔的天数
                                ptemp = (ptempdt - pdayconfig.HDayStart.Value).Days;
                            }
                            if (pdayconfig.CompStart.HasValue)
                            {
                                plasttime = pdayconfig.CompStart.Value.AddDays(ptemp);
                            }
                        }
                    }

                    List <RP_AADTSta> pOlds = db.RP_AADTSta.Where(s => s.CalculTime == plasttime).ToList();
                    //判断去年同期是否存在
                    RP_AADTSta oldinfo = new RP_AADTSta();
                    if (pOlds.Count > 0)
                    {
                        oldinfo = pOlds.First();
                    }
                    DateTime pdt = DateTime.Parse(dt.ToShortDateString());
                    //北京段包含出入口收费站
                    List <int> BJStation = StationConfiguration.GetBJStaion();
                    //北京段只包含出口收费站
                    List <int> outBJStation = StationConfiguration.GetOutBJStaion();
                    //获取北京段数据//p.VehType == 0 表示合计数据,
                    IEnumerable <DS_DataSource> pBJCollection = db.DS_DataSource.Where(p =>
                                                                                       DbFunctions.TruncateTime(p.CalcuTime) == DbFunctions.TruncateTime(dt) &&
                                                                                       p.VehType == 0 &&
                                                                                       BJStation.Contains(p.StaID.Value));
                    //判断数据是否已存在
                    RP_AADTSta        pAADTStaInfo = null;
                    List <RP_AADTSta> pList        = db.RP_AADTSta.Where(p => p.CalculTime == pdt).ToList();
                    if (pList.Count > 0)//已存在,则更新
                    {
                        pAADTStaInfo         = pList.FirstOrDefault();
                        pAADTStaInfo.UpdDate = DateTime.Now;
                        pAADTStaInfo.State   = "1";
                    }
                    else//不存在,添加
                    {
                        pAADTStaInfo         = new RP_AADTSta();
                        pAADTStaInfo.Id      = Guid.NewGuid();
                        pAADTStaInfo.CrtDate = DateTime.Now;
                        pAADTStaInfo.State   = "0";
                    }
                    //涉及到金额的单位全部转为万元,保留两位小数
                    //出京路线总交通量,不包括绿通
                    pAADTStaInfo.LineExSum = pBJCollection.Where(s => outBJStation.Contains(s.StaID.Value) && s.CalcuType != 3).Sum(s => s.InNum);
                    //入京路线总交通量,不包括绿通
                    pAADTStaInfo.LineEnSum = pBJCollection.Where(s => BJStation.Contains(s.StaID.Value) && s.CalcuType != 3).Sum(s => s.OutNum);
                    pAADTStaInfo.LineSum   = pAADTStaInfo.LineEnSum + pAADTStaInfo.LineExSum;
                    //总交通量同比增幅
                    if (oldinfo.LineSum.HasValue)
                    {
                        pAADTStaInfo.SumGrow = double.Parse(string.Format("{0:0.00}", (pAADTStaInfo.LineSum - oldinfo.LineSum) / oldinfo.LineSum));
                    }
                    //出进京比
                    pAADTStaInfo.ExEnPer = double.Parse(string.Format("{0:0.00}", (pAADTStaInfo.LineExSum / pAADTStaInfo.LineEnSum)));
                    //收费/免征总金额
                    pAADTStaInfo.FeeSum = Math.Round(pBJCollection.Sum(s => s.RecMoney.Value) / 10000, 2);
                    //出京小型客车免费通行交通量
                    pAADTStaInfo.ExSmaCarFee = pBJCollection.Where(s => s.CalcuType == 0 && outBJStation.Contains(s.StaID.Value)).Sum(s => s.InNum);
                    //进京小型客车免费通行交通量
                    pAADTStaInfo.EnSmaCarFee = pBJCollection.Where(s => s.CalcuType == 0).Sum(s => s.OutNum);
                    //小型客车免费通行交通量(合计)
                    pAADTStaInfo.SmaCarFeeNum = pAADTStaInfo.ExSmaCarFee + pAADTStaInfo.EnSmaCarFee;
                    //小型客车交通量同比增幅
                    if (oldinfo.SmaCarFeeNum.HasValue)
                    {
                        pAADTStaInfo.SmaCarCompGrow = double.Parse(string.Format("{0:0.00}", (pAADTStaInfo.SmaCarFeeNum - oldinfo.SmaCarFeeNum) / oldinfo.SmaCarFeeNum));
                    }//小型客车免费金额
                    pAADTStaInfo.SmaCarFee = Math.Round(pBJCollection.Where(s => s.CalcuType.Value == 0).Sum(s => s.RecMoney.Value) / 10000, 2);
                    //出京收费车辆
                    pAADTStaInfo.ExChagNum = pBJCollection.Where(s => outBJStation.Contains(s.StaID.Value) && (s.CalcuType == 1 || s.CalcuType == 2)).Sum(s => s.InNum);
                    //进京收费车辆
                    pAADTStaInfo.EnChagNum = pBJCollection.Where(s => s.CalcuType == 1 || s.CalcuType == 2).Sum(s => s.OutNum);
                    //收费车辆合计
                    pAADTStaInfo.ChagSumNum = pAADTStaInfo.ExChagNum + pAADTStaInfo.EnChagNum;
                    //收费额度
                    pAADTStaInfo.ChagAmount = Math.Round(pBJCollection.Where(s => s.CalcuType == 1 || s.CalcuType == 2).Sum(s => s.RecMoney.Value) / 10000, 2);
                    //绿色通道车辆数
                    pAADTStaInfo.GreNum = pBJCollection.Where(s => s.CalcuType == 3).Sum(s => s.OutNum);
                    //绿色通道免收费金额
                    pAADTStaInfo.GreFee = Math.Round(pBJCollection.Where(s => s.CalcuType == 3).Sum(s => s.RecMoney.Value) / 10000, 2);
                    //出京总交通量(站)
                    pAADTStaInfo.StaExSum = pBJCollection.Where(s => s.StaID == (int)StationConfiguration.StationID.DYF).Sum(s => s.InNum);
                    //进京总交通量(站)
                    pAADTStaInfo.StaEnSum   = pBJCollection.Where(s => s.StaID == (int)StationConfiguration.StationID.DYF).Sum(s => s.OutNum);
                    pAADTStaInfo.CalculTime = pdt;

                    using (TransactionScope trans = new TransactionScope())
                    {
                        if (pList.Count <= 0)
                        {
                            db.RP_AADTSta.Add(pAADTStaInfo);
                        }
                        db.SaveChanges();
                        trans.Complete();
                    }
                }
                string endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                SystemLog.GetInstance().Log.Info(string.Format("{0}:结束获取8,9,10报表数据", endTime));
                SystemLog.GetInstance().Log.Info(string.Format("统计8,9,10报表数据耗时{0}秒", (DateTime.Parse(endTime) - DateTime.Parse(startTime)).TotalSeconds));
                //显示执行该方法的线程ID
                //SystemLog.GetInstance().Log.Info(string.Format("调用8,9,10Update的线程ID为:{0}", Thread.CurrentThread.ManagedThreadId));
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }