public static IStatistics_Gather GetFactory() { if (factory == null) { Type type = Type.GetType("Common." + SystemDefaultConfig.DatabaseProvider + "Repository.Statistics.Statistics_GatherDAL,Common." + SystemDefaultConfig.DatabaseProvider + "Repository", true); factory = (IStatistics_Gather)Activator.CreateInstance(type); } return(factory); }
/// <summary> /// 当班统计 /// </summary> public void Statistics_OnDuty(string ParkingID) { 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(); BaseParkinfo parking = iparking.QueryParkingByParkingID(ParkingID); 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); } }
public bool DeleteGatherTime(string parkingid, DateTime start, DateTime end) { IStatistics_Gather gatherfactory = Statistics_GatherFactory.GetFactory(); return(gatherfactory.DeleteGatherTime(parkingid, start, end)); }
public void Statistics_DailyByHour(BaseParkinfo park, DateTime startdate, DateTime enddate) { int hours = 0; int maxhours = 23; List <Statistics_Gather> gathers = new List <Statistics_Gather>(); List <DateTime> DeleteGather = new List <DateTime>(); if (startdate.ToString("yyyyMMdd") == startdate.ToString("yyyyMMdd")) { maxhours = startdate.Hour; } IParkIORecord iorecordfactory = ParkIORecordFactory.GetFactory(); IStatistics_Gather gatherfactory = Statistics_GatherFactory.GetFactory(); IParkOrder iorder = ParkOrderFactory.GetFactory(); while (hours <= maxhours) { Statistics_Gather gather = new Statistics_Gather(); DateTime tempstartdate = startdate.AddHours(hours); DateTime tempenddate = enddate.AddHours(hours); gather.StatisticsGatherID = System.Guid.NewGuid().ToString(); gather.ParkingID = park.PKID; gather.ParkingName = park.PKName; gather.GatherTime = tempstartdate; if (startdate.ToString("yyyyMMdd") == startdate.ToString("yyyyMMdd")) { if (hours == maxhours || hours == maxhours - 1) { DeleteGather.Add(tempstartdate); } else { if (gatherfactory.IsExistsGather(park.PKID, tempstartdate)) { hours++; continue; } } } else { if (gatherfactory.IsExistsGather(park.PKID, tempstartdate)) { hours++; continue; } } //查询进场数 gather.Entrance_Count = iorecordfactory.EntranceCountByParkingID(park.PKID, tempstartdate, tempenddate); //查询出场数 gather.Exit_Count = iorecordfactory.ExitCountByParkingID(park.PKID, tempstartdate, tempenddate); #region 进场卡片类型 List <KeyValue> _InCardType = iorecordfactory.GetInCardTypeByParkingID(park.PKID, tempstartdate, tempenddate); if (_InCardType != null && _InCardType.Count > 0) { foreach (KeyValue k in _InCardType) { switch (k.KeyName) { case "0": gather.VIPCard = k.Key_Value; break; case "1": gather.StordCard = k.Key_Value; break; case "2": gather.MonthCard = k.Key_Value; break; case "3": gather.TempCard = k.Key_Value; break; case "4": gather.JobCard = k.Key_Value; break; default: break; } } } #endregion #region 统计放行类型 List <KeyValue> _ReleaseType = iorecordfactory.GetReleaseTypeByParkingID(park.PKID, tempstartdate, tempenddate); if (_ReleaseType != null && _ReleaseType.Count > 0) { foreach (var s in _ReleaseType) { switch (s.KeyName) { case "0": gather.ReleaseType_Normal = s.Key_Value; break; case "1": gather.ReleaseType_Charge = s.Key_Value; break; case "2": gather.ReleaseType_Free = s.Key_Value; break; case "3": gather.ReleaseType_Catch = s.Key_Value; break; } } } #endregion #region 统计费用相关 List <ParkOrder> _orderfee = iorder.GetOrdersByParkingID(park.PKID, tempstartdate, tempenddate); if (_orderfee != null && _orderfee.Count > 0) { foreach (ParkOrder o in _orderfee) { gather.Receivable_Amount += o.Amount; gather.Real_Amount += o.PayAmount; gather.Diff_Amount += o.UnPayAmount; //支付方式(1.现金、2.微信、3.支付宝、4.网银、5.电子钱包、6.优免卷7.余额 switch (o.PayWay) { case OrderPayWay.Cash: gather.Cash_Amount += o.PayAmount; gather.Cash_Count++; if (o.DiscountAmount > 0) { gather.CashDiscount_Amount += o.DiscountAmount; gather.CashDiscount_Count++; gather.Discount_Amount += o.DiscountAmount; gather.Discount_Count++; } break; case OrderPayWay.WeiXin: case OrderPayWay.Alipay: case OrderPayWay.OnlineBanking: case OrderPayWay.Wallet: gather.OnLine_Amount += o.PayAmount; gather.OnLine_Count++; if (o.DiscountAmount > 0) { gather.OnLineDiscount_Amount += o.DiscountAmount; gather.OnLineDiscount_Count++; gather.Discount_Amount += o.DiscountAmount; gather.Discount_Count++; } break; case OrderPayWay.PreferentialTicket: gather.Discount_Amount += o.DiscountAmount; gather.Discount_Count++; break; case OrderPayWay.ValueCard: gather.StordCard_Amount += o.PayAmount; gather.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: gather.OnLineTemp_Amount += o.PayAmount; gather.OnLineTemp_Count++; break; default: gather.Temp_Amount += o.PayAmount; gather.Temp_Count++; break; } break; //月卡续期 case OrderType.MonthCardPayment: switch (o.PayWay) { case OrderPayWay.WeiXin: case OrderPayWay.Alipay: case OrderPayWay.OnlineBanking: case OrderPayWay.Wallet: gather.OnLineMonthCardExtend_Amount += o.PayAmount; gather.OnLineMonthCardExtend_Count++; break; default: gather.MonthCardExtend_Amount += o.PayAmount; gather.MonthCardExtend_Count++; break; } break; //VIP卡续期 case OrderType.VIPCardRenewal: gather.VIPExtend_Count++; break; //储值卡充值 case OrderType.ValueCardRecharge: switch (o.PayWay) { case OrderPayWay.WeiXin: case OrderPayWay.Alipay: case OrderPayWay.OnlineBanking: case OrderPayWay.Wallet: gather.OnLineStordCard_Amount += o.PayAmount; gather.OnLineStordCard_Count++; break; default: gather.StordCardRecharge_Amount += o.PayAmount; gather.StordCardRecharge_Count++; break; } break; } } } #endregion gathers.Add(gather); hours++; } if (gathers != null) { using (DbOperator dboperator = ConnectionManager.CreateReadConnection()) { try { dboperator.BeginTransaction(); foreach (DateTime d in DeleteGather) { gatherfactory.DeleteGather(park.PKID, d, dboperator); } foreach (Statistics_Gather g in gathers) { if (!gatherfactory.Insert(g, dboperator)) { throw new Exception("插入日统计数据失败"); } } dboperator.CommitTransaction(); } catch (Exception ex) { Common.Services.TxtLogServices.WriteTxtLog("添加日统计(按小时统计)异常 异常信息:{0}", ex.Message); dboperator.RollbackTransaction(); } } } }