private HDayAADTViewModel GetFirst(HDayAADTViewModel model)
 {
     HDayAADTViewModel HdayInfo = new HDayAADTViewModel();
     HdayInfo.LineType = 0;
     HdayInfo.ExNat = model.ExNat;
     HdayInfo.EnNat = model.EnNat;
     HdayInfo.NatSum = model.NatSum;
     HdayInfo.ExEqu = model.ExEqu;
     HdayInfo.EnEqu = model.EnEqu;
     HdayInfo.EquSum = model.EquSum;
     HdayInfo.CrowDeg = model.CrowDeg;
     HdayInfo.SmaEx = model.SmaEx;
     HdayInfo.SmaEn = model.SmaEn;
     HdayInfo.SmaSum = model.SmaSum;
     HdayInfo.MedEn = model.MedEn;
     HdayInfo.MedEx = model.MedEx;
     HdayInfo.MedSum = model.MedSum;
     HdayInfo.LarEx = model.LarEx;
     HdayInfo.LarEn = model.LarEn;
     HdayInfo.LarSum = model.LarSum;
     HdayInfo.HeaEn = model.HeaEn;
     HdayInfo.HeaEx = model.HeaEx;
     HdayInfo.HeaSum = model.HeaSum;
     HdayInfo.SupEn = model.SupEn;
     HdayInfo.SupEx = model.SupEx;
     HdayInfo.SupSum = model.SupSum;
     HdayInfo.EnExTrukNum = model.EnExTrukNum;
     HdayInfo.CarTrukPer = model.CarTrukPer;
     HdayInfo.SupTruNum = model.SupTruNum;
     HdayInfo.SupTruPer = model.SupTruPer;
     return HdayInfo;
 }
 /// <summary>
 /// 查询
 /// </summary>
 /// <param name="para"></param>
 /// <returns></returns>
 public IReportViewModel GetListByPra(QueryParameters para)
 {
     QueryHDayAADTViewModel pReturnData = new QueryHDayAADTViewModel();
     try
     {
         using (DataSubmittedEntities db = new DataSubmittedEntities())
         {
             InsertNull(para.StartTime.Value);
             //获取报表18查询集合
             List<HDayAADTViewModel> pHdayAADT = db.RP_HDayAADTSta.Where(s => s.CalcuTime == para.StartTime).Select(s => new HDayAADTViewModel()
             {
                 LineType = s.LineType,
                 ExNat = s.ExNat,
                 EnNat = s.EnNat,
                 NatSum = s.ExNat + s.EnNat,
                 ExEqu = s.ExEqu,
                 EnEqu = s.EnEqu,
                 EquSum = s.ExEqu + s.EnEqu,
                 CrowDeg = s.CrowDeg,
                 SmaEx = s.SmaEx,
                 SmaEn = s.SmaEn,
                 SmaSum = s.SmaEx + s.SmaEn,
                 MedEn = s.MedEn,
                 MedEx = s.MedEx,
                 MedSum = s.MedEx + s.MedEn,
                 LarEx = s.LarEx,
                 LarEn = s.LarEn,
                 LarSum = s.LarEn + s.LarEx,
                 HeaEn = s.HeaEn,
                 HeaEx = s.HeaEx,
                 HeaSum = s.HeaEx + s.HeaEn,
                 SupEn = s.SupEn,
                 SupEx = s.SupEx,
                 SupSum = s.SupEn + s.SupEx,
                 EnExTrukNum = s.EnExTrukNum,
                 CarTrukPer = s.CarTrukPer,
                 SupTruNum = s.SupTruNum,
                 SupTruPer = s.SupTruPer
             }).ToList();
             if (pHdayAADT.Count > 0)
             {
                 pReturnData.IsEdit = 1;
                 pReturnData.ReportData = pHdayAADT;
             }
             else
             {
                 pReturnData.IsEdit = 0;
                 for (int i = 1; i < 7; i++)//添加6条空数据
                 {
                     HDayAADTViewModel pHdayInfo = new HDayAADTViewModel();
                     pHdayInfo.LineType = i;
                     pHdayAADT.Add(pHdayInfo);
                 }
             }
             //添加第一条(G2)
             HDayAADTViewModel pHdayInfofirst = pHdayAADT.Where(s => s.LineType == 3).SingleOrDefault();
             pHdayAADT.Add(GetFirst(pHdayInfofirst));
             //升序排序
             pReturnData.ReportData = pHdayAADT.OrderBy(s => s.Sorting).ToList();
             //判断当前统计站类型,数据是否完整
             if (GetNoDataList(para).Count() > 0)
                 pReturnData.IsFull = 0;//不完整
             else
                 pReturnData.IsFull = 1;//完整 
             return pReturnData;
         }
     }
     catch (Exception ex)
     {
         SystemLog.GetInstance().Info(ex.Message);
         return pReturnData;
     }
 }
        /// <summary>
        /// 修改功能
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public CustomResult Update(UHDayRoadStaViewModel args)
        {
            using (DataSubmittedEntities db = new DataSubmittedEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    CustomResult pReturnValue = new CustomResult();
                    List<UpdateHDayRoadStaViewModel> list = args.DataInfo.Where(a => a.LineType != 0).ToList();
                    try
                    {
                        foreach (UpdateHDayRoadStaViewModel model in list)
                        {
                            var listHDayRoadSta = db.RP_HDayAADTSta.Where(a => a.CalcuTime == args.DataDate && a.LineType == model.LineType).ToList();
                            foreach (RP_HDayAADTSta hd in listHDayRoadSta)
                            {
                                //  hd.LineType = model.LineType;
                                hd.ExNat = model.ExNat;
                                hd.EnNat = model.EnNat;
                                hd.ExEqu = model.ExEqu;
                                hd.EnEqu = model.EnEqu;

                                //拥挤度-“拥挤度”=交通量(当量交通量)合计/设计交通量,保留四位小数;
                                if (hd.ExEqu != null && hd.EnEqu != null)
                                {
                                    HDayAADTViewModel model1 = new HDayAADTViewModel();
                                    model1.LineType = model.LineType;
                                    Nullable<double> crowDeg = double.Parse(string.Format("{0:0.0000}", (hd.ExEqu + hd.EnEqu) / model1.DeTra));
                                    hd.CrowDeg = crowDeg;
                                }
                                hd.SmaEx = model.SmaEx;
                                hd.SmaEn = model.SmaEn;
                                hd.MedEx = model.MedEx;
                                hd.MedEn = model.MedEn;
                                hd.LarEx = model.LarEx;
                                hd.LarEn = model.LarEn;
                                hd.HeaEx = model.HeaEx;
                                hd.HeaEn = model.HeaEn;
                                hd.SupEx = model.SupEx;
                                hd.SupEn = model.SupEn;
                                hd.EnExTrukNum = model.EnExTrukNum;

                                //客车货车比例-客车货车比例=(交通量(自然交通量)合计-进出京货车数量)/进出京货车数量*100%,保留四位小数;
                                if (hd.ExNat != null && hd.EnNat != null && hd.EnExTrukNum != null && hd.EnExTrukNum != null)
                                {
                                    if (hd.EnExTrukNum != 0)
                                    {
                                        Nullable<double> carTrukPer = double.Parse(string.Format("{0:0.0000}", (hd.ExNat.Value + hd.EnNat.Value - hd.EnExTrukNum.Value) / hd.EnExTrukNum.Value));
                                        hd.CarTrukPer = carTrukPer;
                                    }
                                    else
                                    {
                                        hd.CarTrukPer = 0;
                                    }
                                }

                                //进出京大货车以上车型数量-进出京大货车以上车型数量”=大型车(合计)+重型车(合计)+超大型车(合计)。
                                if (hd.LarEx != null && hd.LarEn != null && hd.HeaEx != null && hd.HeaEn != null && hd.SupEx != null && hd.SupEn != null)
                                {
                                    Nullable<double> supTruNum = hd.LarEx.Value + hd.LarEn.Value + hd.HeaEx.Value + hd.HeaEn.Value + hd.SupEx.Value + hd.SupEn.Value;
                                    hd.SupTruNum = supTruNum;
                                }
                                //大货车以上占货车交通量比例-大货车以上占货车交通量比例(%)=进出京大货车以上车型的数量/进出京货车数量*100%,保留四位小数。
                                if (hd.SupTruNum != null && hd.EnExTrukNum != null)
                                {
                                    if (hd.EnExTrukNum.Value != 0)
                                    {
                                        Nullable<double> supTruPer = double.Parse(string.Format("{0:0.0000}", hd.SupTruNum.Value / hd.EnExTrukNum.Value));
                                        hd.SupTruPer = supTruPer;
                                    }
                                    else
                                    {
                                        hd.SupTruPer = 0;
                                    }
                                }
                                hd.UpdDate = DateTime.Now;
                                hd.State = "1";
                                if (SessionManage.GetLoginUser() != null)
                                {
                                    hd.UpdBy = SessionManage.GetLoginUser().UserName;
                                }
                            }
                            db.SaveChanges();
                        }

                        transaction.Complete();
                        pReturnValue.ResultKey = (byte)EResult.Succeed;
                        pReturnValue.ResultValue = TipInfo.UpdateSuccess;
                        return pReturnValue;
                    }
                    catch (Exception ex)
                    {
                        Common.SystemLog.GetInstance().Log.Info(TipInfo.UpdateDataRepeat, ex);
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.UpdateDataRepeat;
                        return pReturnValue;
                    }
                }
            }
        }
        /// <summary>
        /// 校正
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        public CustomResult CalibrationData(QueryParameters para)
        {
            CustomResult pReturnValue = new CustomResult();
            double pFloating = 1 + para.FloatingRange * 0.01;

            List<RP_HDayAADTSta> pNaturalTraList = new List<RP_HDayAADTSta>();
            try
            {
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    //判断报表浮动百分比配置是否正确
                    OT_HDayConfig pds = HolidayConfig.GetInstance().GetById(para.ReportType);
                    if (pds == null)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileNoConfig;
                        return pReturnValue;
                    }
                    if (Math.Abs(para.FloatingRange) > (double)pds.CheckFloat.Value)
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.ErrorInfo + "范围应在负" + pds.CheckFloat.Value + "%-正" + pds.CheckFloat.Value + "%之间";
                        return pReturnValue;
                    }
                    //判断校正数据日期是否合理
                    if (para.LastYearStart < para.StartTime && para.StartTime < DateTime.Now.AddDays(1))
                    {
                        //获取参考日期符合校正时间段的数据,因为只校正一天的数据,所以只查询开始数据的日期就可以
                        List<RP_HDayAADTSta> pRefNaturalList = db.RP_HDayAADTSta.Where(s => s.CalcuTime == para.LastYearStart).ToList();
                        //如果参考日期数据为0 则返回失败
                        if (pRefNaturalList.Count == 0)
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;
                            pReturnValue.ResultValue = TipInfo.CalibrationFaileRefNoData;
                            return pReturnValue;
                        }
                        //需要校正的数据
                        var pCheckNaturalList = db.RP_HDayAADTSta.Where(s => s.CalcuTime == para.StartTime).ToList();
                        //如果需要校正的数据为空则返回失败
                        if (pCheckNaturalList.Count == 0)
                        {
                            pReturnValue.ResultKey = (byte)EResult.Fail;
                            pReturnValue.ResultValue = TipInfo.CalibrationFaileNoData;
                            return pReturnValue;
                        }
                        using (TransactionScope tran = new TransactionScope())
                        {

                            ////校正数据
                            //RP_HDayAADTSta pCheckInfo = pCheckNaturalList.First();
                            ////参考数据
                            //RP_HDayAADTSta pRefInfo = pRefNaturalList.First();

                            foreach (RP_HDayAADTSta pCheckInfo in pCheckNaturalList)//校正数据
                            {
                                foreach (RP_HDayAADTSta pRefInfo in pRefNaturalList)//参考数据
                                {
                                    if (pRefInfo.LineType != 0 && pCheckInfo.LineType == pRefInfo.LineType)
                                    {
                                        //出京自然交通辆
                                        if (pRefInfo.ExNat != null)
                                            pCheckInfo.ExNat = Math.Round(pRefInfo.ExNat.Value * pFloating);
                                        //进京自然交通辆
                                        if (pRefInfo.EnNat != null)
                                            pCheckInfo.EnNat = Math.Round(pRefInfo.EnNat.Value * pFloating);
                                        //出京当量交通辆
                                        if (pRefInfo.ExEqu != null)
                                            pCheckInfo.ExEqu = Math.Round(pRefInfo.ExEqu.Value * pFloating);
                                        //进京当量交通辆
                                        if (pRefInfo.EnEqu != null)
                                            pCheckInfo.EnEqu = Math.Round(pRefInfo.EnEqu.Value * pFloating);
                                        //拥挤度-“拥挤度”=交通量(当量交通量)合计/设计交通量,保留四位小数;
                                        if (pCheckInfo.ExEqu != null && pCheckInfo.EnEqu != null)
                                        {
                                            HDayAADTViewModel model = new HDayAADTViewModel();
                                            model.LineType = pRefInfo.LineType;
                                            pCheckInfo.CrowDeg = double.Parse(string.Format("{0:0.0000}", (pCheckInfo.ExEqu + pCheckInfo.EnEqu) / model.DeTra));
                                        }
                                        //小型车出京
                                        if (pRefInfo.SmaEx != null)
                                            pCheckInfo.SmaEx = Math.Round(pRefInfo.SmaEx.Value * pFloating);
                                        //小型车进京
                                        if (pRefInfo.SmaEn != null)
                                            pCheckInfo.SmaEn = Math.Round(pRefInfo.SmaEn.Value * pFloating);
                                        //中型车出京
                                        if (pRefInfo.MedEx != null)
                                            pCheckInfo.MedEx = Math.Round(pRefInfo.MedEx.Value * pFloating);
                                        //中型车进京
                                        if (pRefInfo.MedEn != null)
                                            pCheckInfo.MedEn = Math.Round(pRefInfo.MedEn.Value * pFloating);
                                        //大型车出京
                                        if (pRefInfo.LarEx != null)
                                            pCheckInfo.LarEx = Math.Round(pRefInfo.LarEx.Value * pFloating);
                                        //大型车进京
                                        if (pRefInfo.LarEn != null)
                                            pCheckInfo.LarEn = Math.Round(pRefInfo.LarEn.Value * pFloating);
                                        //重型车出京
                                        if (pRefInfo.HeaEx != null)
                                            pCheckInfo.HeaEx = Math.Round(pRefInfo.HeaEx.Value * pFloating);
                                        //重型车进京
                                        if (pRefInfo.HeaEn != null)
                                            pCheckInfo.HeaEn = Math.Round(pRefInfo.HeaEn.Value * pFloating);
                                        //超大型车出京
                                        if (pRefInfo.SupEx != null)
                                            pCheckInfo.SupEx = Math.Round(pRefInfo.SupEx.Value * pFloating);
                                        //超大型车进京
                                        if (pRefInfo.SupEn != null)
                                            pCheckInfo.SupEn = Math.Round(pRefInfo.SupEn.Value * pFloating);
                                        //进出京大货车以上车型数量-进出京大货车以上车型数量”=大型车(合计)+重型车(合计)+超大型车(合计)。
                                        if (pCheckInfo.LarEx != null && pCheckInfo.LarEn != null && pCheckInfo.HeaEx != null && pCheckInfo.HeaEn != null && pCheckInfo.SupEx != null && pCheckInfo.SupEn != null)
                                            pCheckInfo.SupTruNum = pCheckInfo.LarEx + pCheckInfo.LarEn + pCheckInfo.HeaEx + pCheckInfo.HeaEn + pCheckInfo.SupEx + pCheckInfo.SupEn;
                                        //进出京货车数量
                                        if (pRefInfo.EnExTrukNum != null)
                                            pCheckInfo.EnExTrukNum = Math.Round(pRefInfo.EnExTrukNum.Value * pFloating);
                                        //客车货车比例-客车货车比例=(交通量(自然交通量)合计-进出京货车数量)/进出京货车数量*100%,保留四位小数;
                                        if (pCheckInfo.ExNat != null && pCheckInfo.EnNat != null && pCheckInfo.EnExTrukNum != null && pCheckInfo.EnExTrukNum != null && pCheckInfo.EnExTrukNum != 0)
                                        {
                                            pCheckInfo.CarTrukPer = double.Parse(string.Format("{0:0.0000}", (pCheckInfo.ExNat + pCheckInfo.EnNat - pCheckInfo.EnExTrukNum) / pCheckInfo.EnExTrukNum));
                                        }
                                        //大货车以上占货车交通量比例-大货车以上占货车交通量比例(%)=进出京大货车以上车型的数量/进出京货车数量*100%,保留四位小数。
                                        if (pCheckInfo.SupTruNum != null && pCheckInfo.EnExTrukNum != null && pCheckInfo.EnExTrukNum != 0)
                                        {
                                            pCheckInfo.SupTruPer = double.Parse(string.Format("{0:0.0000}", pCheckInfo.SupTruNum / pCheckInfo.EnExTrukNum));
                                        }
                                        if (SessionManage.GetLoginUser() != null)
                                        {
                                            pCheckInfo.UpdBy = SessionManage.GetLoginUser().UserName;
                                        }
                                        pCheckInfo.UpdDate = DateTime.Now;
                                        pCheckInfo.State = "1";
                                        break;
                                    }
                                }
                            }
                            db.SaveChanges();
                            tran.Complete();
                            pReturnValue.ResultKey = (byte)EResult.Succeed;
                            pReturnValue.ResultValue = TipInfo.CalibrationSuccess;
                        }
                    }
                    else
                    {
                        pReturnValue.ResultKey = (byte)EResult.Fail;
                        pReturnValue.ResultValue = TipInfo.CalibrationFaileDate;
                    }
                }
                return pReturnValue;
            }
            catch (Exception e)
            {
                pReturnValue.ResultKey = (byte)EResult.Fail;
                pReturnValue.ResultValue = TipInfo.CalibrationFaile + e.Message.ToString();
                SystemLog.GetInstance().Error(TipInfo.CalibrationFaile, e);
                return pReturnValue;
            }
        }