public void Statistics_DailyGather(DateTime start, DateTime end) { try { IParking iparking = ParkingFactory.GetFactory(); string strerror = string.Empty; List <BaseParkinfo> parks = iparking.QueryParkingAll(); if (parks == null || parks.Count == 0) { return; } end = end.Date.AddHours(23).AddMinutes(59); //循环车场 foreach (BaseParkinfo p in parks) { //如果在线上统计,则本地就不统计 if (p.IsOnLineGathe == YesOrNo.Yes) { continue; } List <ParkGate> gatelist = ParkGateServices.QueryByParkingId(p.PKID); TimeSpan ts = end - start; //统计近8天的数据 for (int i = ts.Days; i >= 0; i--) { try { new DailyGatherServices().Statistics_DailyByHour(p, end, i); } catch (Exception ex) { Common.Services.TxtLogServices.WriteTxtLog("按时统计异常 异常信息:{0}", ex.Message); } //按通道统计时数据 try { new GateGatherServices().Statistics_DailyByGate(gatelist, p, end, i); } catch (Exception ex) { Common.Services.TxtLogServices.WriteTxtLog("按通道统计异常 异常信息:{0}", ex.Message); } } } } catch (Exception ex) { Common.Services.TxtLogServices.WriteTxtLog("按日统计异常 异常信息:{0}", ex.Message); } }
/// <summary> /// 当班统计 /// </summary> public void Statistics_OnDuty() { try { IParking iparking = ParkingFactory.GetFactory(); IParkIORecord iorecordfactory = ParkIORecordFactory.GetFactory(); IStatistics_Gather gatherfactory = Statistics_GatherFactory.GetFactory(); IParkChangeshiftrecord ichangeshift = ParkChangeshiftrecordFactory.GetFactory(); IParkOrder iorder = ParkOrderFactory.GetFactory(); IParkBox iparkbox = ParkBoxFactory.GetFactory(); IStatistics_ChangeShift istatisticschangeshift = Statistics_ChangeShiftFactory.GetFactory(); List <BaseParkinfo> parks = iparking.QueryParkingAll(); if (parks == null || parks.Count == 0) { return; } DateTime dtNow = DateTime.Now; foreach (BaseParkinfo parking in parks) { if (parking.IsOnLineGathe == YesOrNo.Yes) { continue; } List <ParkBox> boxlist = iparkbox.QueryByParkingID(parking.PKID); if (boxlist != null && boxlist.Count > 0) { foreach (ParkBox box in boxlist) { List <ParkChangeshiftrecord> ondutys = ichangeshift.GetChangeShiftRecord(box.BoxID); if (ondutys == null || ondutys.Count == 0) { continue; } foreach (ParkChangeshiftrecord onduty in ondutys) { Statistics_ChangeShift changeshift = new Statistics_ChangeShift { BoxID = onduty.BoxID, ParkingName = parking.PKName, StartWorkTime = onduty.StartWorkTime, EndWorkTime = onduty.EndWorkTime, ParkingID = parking.PKID, AdminID = onduty.UserID, ChangeShiftID = onduty.RecordID }; DateTime starttime = onduty.StartWorkTime; DateTime endtime = DateTime.Now; if (onduty.EndWorkTime > DateTime.MinValue) { endtime = onduty.EndWorkTime; } //统计相关信息 //查询进场数 changeshift.Entrance_Count = iorecordfactory.EntranceCountByBox(box.BoxID, starttime, endtime); //查询出场数 changeshift.Exit_Count = iorecordfactory.ExitCountByBox(box.BoxID, starttime, endtime); #region 进场卡片类型 List <KeyValue> _InCardType = iorecordfactory.GetInCardTypeByBoxID(box.BoxID, starttime, endtime); if (_InCardType != null && _InCardType.Count > 0) { foreach (var k in _InCardType) { switch (k.KeyName) { case "0": changeshift.VIPCard = k.Key_Value; break; case "1": changeshift.StordCard = k.Key_Value; break; case "2": changeshift.MonthCard = k.Key_Value; break; case "3": changeshift.TempCard = k.Key_Value; break; case "4": changeshift.JobCard = k.Key_Value; break; default: break; } } } #endregion #region 统计放行类型 List <KeyValue> _ReleaseType = iorecordfactory.GetReleaseTypeByBox(box.BoxID, starttime, endtime); if (_ReleaseType != null && _ReleaseType.Count > 0) { foreach (KeyValue k in _ReleaseType) { switch (k.KeyName) { case "0": changeshift.ReleaseType_Normal = k.Key_Value; break; case "1": changeshift.ReleaseType_Charge = k.Key_Value; break; case "2": changeshift.ReleaseType_Free = k.Key_Value; break; case "3": changeshift.ReleaseType_Catch = k.Key_Value; break; } } } #endregion #region 统计费用相关 List <ParkOrder> _orderfee = iorder.GetOrdersByBoxID(parking.PKID, onduty.BoxID, starttime, endtime); if (_orderfee != null && _orderfee.Count > 0) { foreach (ParkOrder o in _orderfee) { changeshift.Receivable_Amount += o.Amount; changeshift.Diff_Amount += o.UnPayAmount; changeshift.Real_Amount = (changeshift.Receivable_Amount - changeshift.Diff_Amount); //支付方式(1.现金、2.微信、3.支付宝、4.网银、5.电子钱包、6.优免卷7.余额 switch (o.PayWay) { case OrderPayWay.Cash: changeshift.Cash_Amount += o.PayAmount; changeshift.Cash_Count++; if (o.DiscountAmount > 0) { changeshift.CashDiscount_Amount += o.DiscountAmount; changeshift.CashDiscount_Count++; changeshift.Discount_Amount += o.DiscountAmount; changeshift.Discount_Count++; } break; case OrderPayWay.WeiXin: case OrderPayWay.Alipay: case OrderPayWay.OnlineBanking: case OrderPayWay.Wallet: changeshift.OnLine_Amount += o.PayAmount; changeshift.OnLine_Count++; if (o.DiscountAmount > 0) { changeshift.OnLineDiscount_Amount += o.DiscountAmount; changeshift.OnLineDiscount_Count++; changeshift.Discount_Amount += o.DiscountAmount; changeshift.Discount_Count++; } break; case OrderPayWay.PreferentialTicket: changeshift.Discount_Amount += o.DiscountAmount; changeshift.Discount_Count++; break; case OrderPayWay.ValueCard: changeshift.StordCard_Amount += o.PayAmount; changeshift.StordCard_Count++; break; } switch (o.OrderType) { //临时卡缴费 case OrderType.TempCardPayment: case OrderType.AreaTempCardPayment: switch (o.PayWay) { case OrderPayWay.WeiXin: case OrderPayWay.Alipay: case OrderPayWay.OnlineBanking: case OrderPayWay.Wallet: changeshift.OnLineTemp_Amount += o.PayAmount; changeshift.OnLineTemp_Count++; break; default: changeshift.Temp_Amount += o.PayAmount; changeshift.Temp_Count++; break; } break; //月卡续期 case OrderType.MonthCardPayment: switch (o.PayWay) { case OrderPayWay.WeiXin: case OrderPayWay.Alipay: case OrderPayWay.OnlineBanking: case OrderPayWay.Wallet: changeshift.OnLineMonthCardExtend_Amount += o.PayAmount; changeshift.OnLineMonthCardExtend_Count++; break; default: changeshift.MonthCardExtend_Amount += o.PayAmount; changeshift.MonthCardExtend_Count++; break; } break; //VIP卡续期 case OrderType.VIPCardRenewal: changeshift.VIPExtend_Count++; break; //储值卡充值 case OrderType.ValueCardRecharge: switch (o.PayWay) { case OrderPayWay.WeiXin: case OrderPayWay.Alipay: case OrderPayWay.OnlineBanking: case OrderPayWay.Wallet: changeshift.OnLineStordCard_Amount += o.PayAmount; changeshift.OnLineStordCard_Count++; break; default: changeshift.StordCardRecharge_Amount += o.PayAmount; changeshift.StordCardRecharge_Count++; break; } break; } } } #endregion using (DbOperator dboperator = ConnectionManager.CreateReadConnection()) { try { dboperator.BeginTransaction(); istatisticschangeshift.Delete(onduty.RecordID, dboperator); istatisticschangeshift.Insert(changeshift, dboperator); dboperator.CommitTransaction(); } catch (Exception ex) { TxtLogServices.WriteTxtLog("添加当班信息异常 异常信息:{0}", ex.Message); dboperator.RollbackTransaction(); } } } } } } } catch (Exception ex) { TxtLogServices.WriteTxtLog("当班统计异常 异常信息:{0}", ex.Message); } }
/// <summary> /// 停车时长统计 /// </summary> public void Statistics_LongTime(DateTime start, DateTime end) { try { IParking iparking = ParkingFactory.GetFactory(); IParkIORecord iorecordfactory = ParkIORecordFactory.GetFactory(); IStatistics_GatherLongTime gatherlongtimefactory = Statistics_GatherLongTimeFactory.GetFactory(); string strerror = string.Empty; List <BaseParkinfo> parks = iparking.QueryParkingAll(); //取得所有有效车场 if (parks != null && parks.Count > 0) { foreach (BaseParkinfo park in parks) { if (park.IsOnLineGathe == YesOrNo.Yes) { continue; } //近7天的统计数据. 如果没有则补上. int loop = (end - start).Days; while (loop >= 0) { #region 变量 DateTime dtNow = end; DateTime GatherTime = DateTime.Parse(dtNow.AddDays(-1 - loop).ToString("yyyy-MM-dd 00:00:00")); DateTime EndTime = DateTime.Parse(dtNow.AddDays(-1 - loop).ToString("yyyy-MM-dd 23:59:59")); int longtime1 = 0; int longtime2 = 0; int longtime3 = 0; int longtime4 = 0; int longtime5 = 0; int longtime6 = 0; int longtime7 = 0; int longtime8 = 0; int longtime9 = 0; int longtime10 = 0; int longtime11 = 0; int longtime12 = 0; int longtime13 = 0; int longtime14 = 0; int longtime15 = 0; int longtime16 = 0; int longtime17 = 0; int longtime18 = 0; int longtime19 = 0; int longtime20 = 0; int longtime21 = 0; int longtime22 = 0; int longtime23 = 0; int longtime24 = 0; #endregion #region 判断是否已统计过 //判断统计数据是否存在. if (gatherlongtimefactory.IsExists(park.PKID, GatherTime)) { loop--; continue; } #endregion #region 获取记录并生成统计数据 List <ParkIORecord> iorecordlist = iorecordfactory.GetCarEntranceTimeAndExitTime(park.PKID, GatherTime, EndTime); if (iorecordlist != null && iorecordlist.Count > 0) { foreach (ParkIORecord record in iorecordlist) { int CarInHour = 0; if (record.EntranceTime == DateTime.MinValue) { CarInHour = 24; } else { if (record.ExitTime == DateTime.MinValue) { record.ExitTime = EndTime; } TimeSpan ts = EndTime - record.EntranceTime; CarInHour = System.Convert.ToInt32(Math.Ceiling(ts.Seconds / 3600.0)); } switch (CarInHour) { case 1: longtime1++; break; case 2: longtime2++; break; case 3: longtime3++; break; case 4: longtime4++; break; case 5: longtime5++; break; case 6: longtime6++; break; case 7: longtime7++; break; case 8: longtime8++; break; case 9: longtime9++; break; case 10: longtime10++; break; case 11: longtime11++; break; case 12: longtime12++; break; case 13: longtime13++; break; case 14: longtime14++; break; case 15: longtime15++; break; case 16: longtime16++; break; case 17: longtime17++; break; case 18: longtime18++; break; case 19: longtime19++; break; case 20: longtime20++; break; case 21: longtime21++; break; case 22: longtime22++; break; case 23: longtime23++; break; case 24: longtime24++; break; } } #region 插入统计数据 string strSql = "insert into statistics_gatherlongtime(ParkingID,RecordID,GatherTime,LTime,Times,HaveUpdate,LastUpdateTime)" + " select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',1," + longtime1 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',2," + longtime2 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',3," + longtime3 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',4," + longtime4 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',5," + longtime5 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',6," + longtime6 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',7," + longtime7 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',8," + longtime8 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',9," + longtime9 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',10," + longtime10 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',11," + longtime11 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',12," + longtime12 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',13," + longtime13 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',14," + longtime14 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',15," + longtime15 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',16," + longtime16 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',17," + longtime17 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',18," + longtime18 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',19," + longtime19 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',20," + longtime20 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',21," + longtime21 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',22," + longtime22 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',23," + longtime23 + ",1,getdate()" + " union select '" + park.PKID + "','" + System.Guid.NewGuid().ToString() + "','" + GatherTime + "',24," + longtime24 + ",1,getdate()"; if (!gatherlongtimefactory.Insert(strSql)) { TxtLogServices.WriteTxtLog("插入停车时长统计信息异常 Sql:" + strSql); } #endregion } #endregion loop--; } } } } catch (Exception ex) { TxtLogServices.WriteTxtLog("统计停车时长信息异常 异常信息:" + ex.Message); } }