public static bool Add(BaseEmployee employee, EmployeePlate plate, BaseCard card, ParkGrant parkGrant, DbOperator dbOperator) { if (employee == null) { throw new ArgumentNullException("employee"); } if (plate == null) { throw new ArgumentNullException("plate"); } if (card == null) { throw new ArgumentNullException("card"); } if (parkGrant == null) { throw new ArgumentNullException("parkGrant"); } bool result = BaseEmployeeServices.AddOrUpdateBaseEmployee(employee, dbOperator); if (!result) { throw new MyException("保存人员信息失败"); } result = BaseCardServices.AddOrUpdateCard(card, dbOperator); if (!result) { throw new MyException("保存卡信息失败"); } result = EmployeePlateServices.AddOrUpdateEmployeePlate(plate, dbOperator); if (!result) { throw new MyException("保存车牌信息失败"); } parkGrant.PlateID = plate.PlateID; parkGrant.CardID = card.CardID; result = AddOrderUpdateParkGrant(parkGrant, dbOperator); if (!result) { throw new MyException("保存授权失败"); } if (result) { OperateLogServices.AddOperateLog <BaseEmployee>(employee, OperateType.Add); OperateLogServices.AddOperateLog <EmployeePlate>(plate, OperateType.Add); OperateLogServices.AddOperateLog <BaseCard>(card, OperateType.Add); OperateLogServices.AddOperateLog <ParkGrant>(parkGrant, OperateType.Add); } return(result); }
public static bool DAAdd(List <DAAddMonth> listmonth) { if (listmonth.Count == 0) { throw new ArgumentNullException("employee"); } using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { dbOperator.BeginTransaction(); try { foreach (var obj in listmonth) { bool result = BaseEmployeeServices.AddOrUpdateBaseEmployee(obj.employye, dbOperator); if (!result) { throw new MyException("保存人员信息失败"); } result = BaseCardServices.AddOrUpdateCard(obj.card, dbOperator); if (!result) { throw new MyException("保存卡信息失败"); } result = EmployeePlateServices.AddOrUpdateEmployeePlate(obj.plate, dbOperator); if (!result) { throw new MyException("保存车牌信息失败"); } obj.grant.PlateID = obj.plate.PlateID; obj.grant.CardID = obj.card.CardID; result = AddOrderUpdateParkGrant(obj.grant, dbOperator); if (!result) { throw new MyException("保存授权失败"); } dbOperator.CommitTransaction(); } return(true); } catch { dbOperator.RollbackTransaction(); throw; } } }
public static EmployeePlate GenerateEmployeePlateModel(BaseEmployee employee, string villageId, string plateNo) { EmployeePlate model = new EmployeePlate(); model.PlateNo = plateNo; string errorMsg = string.Empty; EmployeePlate dbPlate = EmployeePlateServices.GetEmployeePlateNumberByPlateNumber(villageId, model.PlateNo, out errorMsg); if (!string.IsNullOrWhiteSpace(errorMsg)) { throw new MyException("获取车牌失败"); } if (dbPlate != null) { dbPlate.EmployeeID = employee.EmployeeID; return(dbPlate); } model.Color = PlateColor.Blue; model.PlateID = GuidGenerator.GetGuidString(); model.EmployeeID = employee.EmployeeID; return(model); }
public static decimal CalculateMonthlyRentExpiredWaitPayAmount(DateTime start, string grantId) { ParkGrant grant = ParkGrantServices.QueryByGrantId(grantId); if (grant == null) { throw new MyException("获取授权失败"); } if (grant.BeginDate == DateTime.MinValue || grant.EndDate == DateTime.MinValue || (grant.EndDate != DateTime.MinValue && grant.EndDate.Date >= DateTime.Now.Date)) { return(0); } ParkCarType carType = ParkCarTypeServices.QueryParkCarTypeByRecordId(grant.CarTypeID); if (carType == null) { throw new MyException("获取车类失败"); } if (carType.BaseTypeID != BaseCarType.MonthlyRent) { return(0); } DateTime startDate = grant.EndDate.AddDays(1).Date; DateTime endDate = start.Date; List <string> plateNos = new List <string>(); EmployeePlate plate = EmployeePlateServices.Query(grant.PlateID); if (plate == null) { throw new MyException("获取车牌号失败"); } plateNos.Add(plate.PlateNo); if (!string.IsNullOrWhiteSpace(grant.PKLot)) { List <ParkGrant> sameGrants = ParkGrantServices.QueryByParkingAndLotAndCarType(grant.PKID, grant.PKLot, BaseCarType.MonthlyRent, grant.GID); foreach (var item in sameGrants) { int lot1 = grant.PKLot.Split(',').Length; int lot2 = item.PKLot.Split(',').Length; if (lot1 != lot2) { continue; } EmployeePlate plate1 = EmployeePlateServices.Query(item.PlateID); if (plate1 == null) { throw new MyException("获取车牌号失败"); } plateNos.Add(plate1.PlateNo); } } IParkOrder factory = ParkOrderFactory.GetFactory(); return(factory.QueryMonthExpiredNotPayAmount(startDate, endDate, grant.PKID, plateNos)); }
/// <summary> /// 续期或续费 /// </summary> /// <param name="grantId"></param> /// <param name="renewalMonth"></param> /// <param name="payTotalMoney"></param> /// <param name="operatorId"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public static bool RenewalsOrRecharge(string grantId, int renewalMonth, decimal payTotalMoney, string operatorId, DateTime startDate, DateTime endDate) { lock (parkGrant_lock) { ParkGrant grant = ParkGrantServices.QueryByGrantId(grantId); if (grant == null) { throw new MyException("获取授权信息失败"); } if (endDate != null && endDate != DateTime.MinValue) { endDate = endDate.Date.AddDays(1).AddSeconds(-1); } string errorMsg = string.Empty; BaseCard card = BaseCardServices.GetBaseCard(grant.CardID, out errorMsg); if (card == null || !string.IsNullOrWhiteSpace(errorMsg)) { throw new MyException("获取卡失败"); } ParkCarType carType = ParkCarTypeServices.QueryParkCarTypeByRecordId(grant.CarTypeID); if (carType == null) { throw new MyException("获取卡类失败"); } List <ParkGrant> operateTargets = new List <ParkGrant>(); List <string> ioRecords = new List <string>(); using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { bool renewalsResult = false; dbOperator.BeginTransaction(); switch (carType.BaseTypeID) { case BaseCarType.StoredValueCar: { IBaseCard factory = BaseCardFactory.GetFactory(); if (payTotalMoney > 0) { ParkOrder order = ParkOrderServices.AddStoredValueCarOrder(grant.PKID, payTotalMoney, card, operatorId, dbOperator); if (order == null) { throw new MyException("创建充值订单失败"); } decimal cardtotalmoney = card.Balance + payTotalMoney; if (order.NewMoney != cardtotalmoney) { throw new MyException("充值金额计算错误"); } renewalsResult = factory.Recharge(card.CardID, payTotalMoney, dbOperator); if (!renewalsResult) { throw new MyException("卡充值失败【更改卡余额失败】"); } } renewalsResult = factory.SetEndDate(card.CardID, endDate, dbOperator); if (!renewalsResult) { throw new MyException("卡充值失败【更改有效期失败】"); } break; } case BaseCarType.VIPCar: { ParkOrder order = ParkOrderServices.AddVipCardOrder(grant.PKID, grantId, grant.BeginDate, grant.EndDate, startDate, endDate, renewalMonth, operatorId, dbOperator); if (order == null) { throw new MyException("充值失败【创建充值订单失败】"); } IParkGrant factory = ParkGrantFactory.GetFactory(); renewalsResult = factory.Renewals(grant.GID, startDate, endDate, dbOperator); if (!renewalsResult) { throw new MyException("修改车辆有效期失败"); } break; } case BaseCarType.MonthlyRent: { int pkLotQuantity = 1; if (!string.IsNullOrWhiteSpace(grant.PKLot)) { pkLotQuantity = grant.PKLot.TrimEnd(',').Split(',').Length; } decimal amount = ParkOrderServices.CalculateMonthlyRentExpiredWaitPayAmount(startDate, grantId); //if (payTotalMoney != ((carType.Amount * renewalMonth * pkLotQuantity) + amount)) // throw new MyException("凭证续期金额计算有误"); List <ParkGrant> shareCardGrants = new List <ParkGrant>(); if (!string.IsNullOrWhiteSpace(grant.PKLot)) { shareCardGrants = ParkGrantServices.QueryByParkingAndLotAndCarType(grant.PKID, grant.PKLot, BaseCarType.MonthlyRent, grant.GID); } IParkGrant factory = ParkGrantFactory.GetFactory(); renewalsResult = factory.Renewals(grant.GID, startDate, endDate, dbOperator); if (!renewalsResult) { throw new MyException("修改车辆有效期失败"); } //修改多车多位的有效期 foreach (var item in shareCardGrants) { if (string.IsNullOrWhiteSpace(item.PKLot)) { continue; } int len1 = item.PKLot.TrimEnd(',').Split(',').Length; int len2 = grant.PKLot.TrimEnd(',').Split(',').Length; if (len1 != len2) { continue; } item.BeginDate = startDate; item.EndDate = endDate; factory.Update(item, dbOperator); operateTargets.Add(item); } //过期转临停订单处理 if (grant.EndDate.Date < DateTime.Now.Date) { List <string> plateNos = new List <string>(); EmployeePlate plate = EmployeePlateServices.Query(grant.PlateID); if (plate == null) { throw new MyException("授权车牌信息不存在"); } plateNos.Add(plate.PlateNo); foreach (var item in shareCardGrants) { if (string.IsNullOrWhiteSpace(item.PKLot)) { continue; } int len1 = item.PKLot.TrimEnd(',').Split(',').Length; int len2 = grant.PKLot.TrimEnd(',').Split(',').Length; if (len1 != len2) { continue; } EmployeePlate otherplate = EmployeePlateServices.Query(item.PlateID); if (otherplate == null) { throw new MyException("多车多位存在无效的车牌"); } plateNos.Add(otherplate.PlateNo); } if (plateNos.Count > 0 && grant.EndDate != DateTime.MinValue) { IParkIORecord ioRecord = ParkIORecordFactory.GetFactory(); ioRecords = ioRecord.QueryMonthExpiredNotPayAmountIORecordIds(grant.EndDate.AddDays(1).Date, startDate, grant.PKID, plateNos); if (ioRecords.Count > 0) { bool result = ioRecord.UpdateIORecordEnterType(ioRecords, 0, dbOperator); if (!result) { throw new MyException("修改进出记录类型失败"); } result = ParkOrderServices.AddExpiredToProStopOrder(ioRecords, operatorId, dbOperator); if (!result) { throw new MyException("创建月卡转临停订单失败"); } } } } ParkOrder order = ParkOrderServices.AddMonthlyRentOrderCS(grant.PKID, carType.CarTypeID, grant.GID, grant.BeginDate, grant.EndDate, startDate, endDate, renewalMonth, pkLotQuantity, operatorId, payTotalMoney, dbOperator); if (order == null) { throw new MyException("续期失败【创建续期订单失败】"); } break; } //case BaseCarType.WorkCar: // { // IParkGrant factory = ParkGrantFactory.GetFactory(); // renewalsResult = factory.Renewals(grant.GID, startDate, endDate, dbOperator); // if (!renewalsResult) throw new MyException("修改卡结束时间错误"); // break; // } default: throw new MyException("选择的车辆不能续期和充值"); } dbOperator.CommitTransaction(); string remark = string.Format("grantId:{0};renewalMonth:{1};payTotalMoney:{2};operatorId:{3};startDate:{4};endDate:{5}", grantId, renewalMonth, payTotalMoney, operatorId, startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd")); OperateLogServices.AddOperateLog(OperateType.Update, remark); if (ioRecords.Count > 0) { string updateIORecord = string.Format("修改IORecord表,RecordIDs:{0},EnterType:0", string.Join(",", ioRecords)); OperateLogServices.AddOperateLog(OperateType.Update, updateIORecord); } return(renewalsResult); } catch (Exception ex) { dbOperator.RollbackTransaction(); throw ex; } } } }