Пример #1
0
        private void AddOrderHeader(string orderID, decimal rateAmount, List <Op_PassCar> passCarList, List <Op_MonthCar> monthCarList, DorllyOrderModel model)
        {
            decimal        monthAmount    = monthCarList.Sum(a => a.Amount) / 100;
            decimal        cashAmount     = passCarList.Sum(a => a.ActualPay) / 100;
            decimal        prepayAmount   = passCarList.Sum(a => a.Prepay) / 100;
            decimal        discountAmount = passCarList.Sum(a => a.DiscountVal) / 100;
            Op_OrderHeader oh             = new Op_OrderHeader();

            oh.RowPointer = orderID;
            //订单编号
            var time    = DateTime.Now.ToString("yyyyMMdd");
            var orderNo = model.Op_OrderHeader.Where(a => a.OrderNo.Contains(time)).Max(a => a.OrderNo);

            if (string.IsNullOrEmpty(orderNo))
            {
                oh.OrderNo = DateTime.Now.ToString("yyyyMMdd") + "00001";
            }
            else
            {
                oh.OrderNo = (long.Parse(orderNo) + 1).ToString();
            }
            oh.OrderType            = _orderType;
            oh.CustNo               = _customer;
            oh.OrderTime            = _lastCheckTime;
            oh.ARDate               = _lastCheckTime;
            oh.DaysofMonth          = 1;
            oh.OrderStatus          = "0";
            oh.ARAmount             = Math.Round(monthAmount + cashAmount + prepayAmount + discountAmount, 2);
            oh.ReduceAmount         = 0;
            oh.PaidinAmount         = 0;
            oh.ODTaxAmount          = rateAmount;
            oh.Remark               = "";
            oh.OrderCreator         = _userName;
            oh.OrderCreateDate      = DateTime.Now;
            oh.OrderLastReviser     = _userName;
            oh.OrderLastRevisedDate = DateTime.Now;
            model.Op_OrderHeader.Add(oh);
        }
Пример #2
0
        private decimal AddOrderDetail(string orderID, List <Op_PassCar> passCarList, List <Op_MonthCar> monthCarList, DorllyOrderModel model)
        {
            decimal        rateAmount  = 0;
            var            feeObject   = model.Mstr_Service.Where(a => a.SRVNo == _feeID).FirstOrDefault();
            decimal        rate        = model.Mstr_TaxRate.Where(a => a.SRVNo == _feeID).FirstOrDefault().Rate ?? 0;
            Op_OrderDetail orderDetail = new Op_OrderDetail();

            //不变
            orderDetail.RefRP          = orderID;
            orderDetail.ODSRVTypeNo1   = feeObject.SRVTypeNo1;
            orderDetail.ODSRVTypeNo2   = feeObject.SRVTypeNo2;
            orderDetail.ODContractSPNo = feeObject.SRVSPNo;
            orderDetail.ODSRVNo        = feeObject.SRVNo;
            //orderDetail.ResourceNo = _parkingCode;
            orderDetail.ODFeeStartDate    = _lastCheckTime;
            orderDetail.ODFeeEndDate      = DateTime.Parse(_lastCheckTime.ToShortDateString()).AddDays(1).AddSeconds(-1);
            orderDetail.BillingDays       = 1;
            orderDetail.ODQTY             = 1;
            orderDetail.ODUnit            = "天";
            orderDetail.ODTaxRate         = rate;
            orderDetail.ODCANo            = feeObject.CANo;
            orderDetail.ReduceAmount      = 0;
            orderDetail.ODPaidAmount      = 0;
            orderDetail.IsLateFee         = false;
            orderDetail.ODCreateDate      = DateTime.Now;
            orderDetail.ODCreator         = _userName;
            orderDetail.ODLastRevisedDate = DateTime.Now;
            orderDetail.ODLastReviser     = _userName;
            //月租车收入
            decimal monthAmount = Math.Round(monthCarList.Sum(a => a.Amount) / 100, 2);

            if (monthAmount > 0)
            {
                var detail = JsonConvert.DeserializeObject <Op_OrderDetail>(JsonConvert.SerializeObject(orderDetail));
                detail.RowPointer   = Guid.NewGuid().ToString();
                detail.ResourceNo   = _parkingCode + "_Card";
                detail.ResourceName = "月租车充值_" + _lastCheckTime.ToString("yyyy-MM-dd");
                detail.ODUnitPrice  = monthAmount;
                detail.ODARAmount   = monthAmount;
                detail.ODTaxAmount  = monthAmount - Math.Round(monthAmount / (1 + rate), 2);
                rateAmount         += monthAmount - Math.Round(monthAmount / (1 + rate), 2);
                model.Op_OrderDetail.Add(detail);
            }
            //现金支付
            decimal cashAmount = Math.Round(passCarList.Sum(a => a.ActualPay) / 100, 2);

            if (cashAmount > 0)
            {
                var detail = JsonConvert.DeserializeObject <Op_OrderDetail>(JsonConvert.SerializeObject(orderDetail));
                detail.RowPointer   = Guid.NewGuid().ToString();
                detail.ResourceNo   = _parkingCode + "_Cash";
                detail.ResourceName = "现金支付_" + _lastCheckTime.ToString("yyyy-MM-dd");
                detail.ODUnitPrice  = cashAmount;
                detail.ODARAmount   = cashAmount;
                detail.ODTaxAmount  = cashAmount - Math.Round(cashAmount / (1 + rate), 2);
                rateAmount         += cashAmount - Math.Round(cashAmount / (1 + rate), 2);
                model.Op_OrderDetail.Add(detail);
            }
            //电子支付
            decimal prepayAmount = Math.Round(passCarList.Sum(a => a.Prepay) / 100, 2);

            if (prepayAmount > 0)
            {
                var detail = JsonConvert.DeserializeObject <Op_OrderDetail>(JsonConvert.SerializeObject(orderDetail));
                detail.RowPointer   = Guid.NewGuid().ToString();
                detail.ResourceNo   = _parkingCode + "_Elec";
                detail.ResourceName = "电子支付_" + _lastCheckTime.ToString("yyyy-MM-dd");
                detail.ODUnitPrice  = prepayAmount;
                detail.ODARAmount   = prepayAmount;
                detail.ODTaxAmount  = prepayAmount - Math.Round(prepayAmount / (1 + rate), 2);
                rateAmount         += prepayAmount - Math.Round(prepayAmount / (1 + rate), 2);
                model.Op_OrderDetail.Add(detail);
            }
            //优惠券
            decimal discountAmount = Math.Round(passCarList.Sum(a => a.DiscountVal) / 100, 2);

            if (discountAmount > 0)
            {
                var detail = JsonConvert.DeserializeObject <Op_OrderDetail>(JsonConvert.SerializeObject(orderDetail));
                detail.RowPointer   = Guid.NewGuid().ToString();
                detail.ResourceNo   = _parkingCode + "_Apex";
                detail.ResourceName = "优惠券_" + _lastCheckTime.ToString("yyyy-MM-dd");
                detail.ODUnitPrice  = discountAmount;
                detail.ODARAmount   = discountAmount;
                detail.ODTaxAmount  = discountAmount - Math.Round(discountAmount / (1 + rate), 2);
                rateAmount         += discountAmount - Math.Round(discountAmount / (1 + rate), 2);
                model.Op_OrderDetail.Add(detail);
            }
            return(rateAmount);
        }
Пример #3
0
        /// <summary>
        /// 定时触发事件
        /// 在时间段内返回的数据重复
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RollingRepeatModel_Elapse(object sender, ElapsedEventArgs e)
        {
            try
            {
                if (_lastCheckTime < DateTime.Now.AddDays(-2) && isRun == false)
                {
                    isRun        = true;
                    passCarList  = new List <Op_PassCar>();
                    monthCarList = new List <Op_MonthCar>();
                    DateTime startTime = _lastCheckTime;
                    DateTime endTime   = _lastCheckTime.AddDays(1).AddSeconds(-1);
                    int      count     = 0;
                    logger.Info(string.Format("本次同步开始【开始时间:{0};结束时间:{1}】...", startTime, endTime));
                    //数据同步
                    while (startTime < endTime)
                    {
                        //请求参数处理
                        DateTime tempTime = startTime.AddSeconds(_passSeconds);
                        if (tempTime >= endTime)
                        {
                            tempTime = endTime;
                        }
                        logger.Info(string.Format("开始第{0}次数据请求,", ++count));
                        RequestParam param = new RequestParam();
                        param.parkingCode = _parkingCode;
                        param.retLimit    = _limit.ToString();
                        param.startTime   = startTime.ToString("yyyy-MM-dd HH:mm:ss");
                        param.endTime     = tempTime.ToString("yyyy-MM-dd HH:mm:ss");
                        param.requestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        param.signature   = FormsAuthentication.HashPasswordForStoringInConfigFile(string.Format("endTime={0}&" +
                                                                                                                 "parkingCode={1}&" +
                                                                                                                 "requestTime={2}&" +
                                                                                                                 "retLimit={3}&" +
                                                                                                                 "startTime={4}&{5}",
                                                                                                                 param.endTime,
                                                                                                                 param.parkingCode,
                                                                                                                 param.requestTime,
                                                                                                                 param.retLimit,
                                                                                                                 param.startTime,
                                                                                                                 _md5Key), "MD5").ToLower();
                        var strParam = JsonConvert.SerializeObject(param);
                        logger.Info(string.Format("请求过车数据,开始时间:{0}-结束时间:{1}", startTime, tempTime));
                        PassCarRepeatPost(strParam);
                        logger.Info(string.Format("请求月租数据,开始时间:{0}-结束时间:{1}", startTime, tempTime));
                        MonthCarRepeatPost(strParam);
                        startTime = tempTime.AddMilliseconds(1);
                        Thread.Sleep(500);
                    }
                    logger.Info("同步完成,处理数据...");
                    //同步完成
                    DorllyOrderModel model = new DorllyOrderModel();
                    logger.Info(string.Format("原始数据处理...【过车数据{0}条,月租充值{1}条】", passCarList.Count(), monthCarList.Count));

                    //保存原始数据
                    passCarList = passCarList.GroupBy(a => a.UniqueID).Select(a => a.First()).ToList();
                    foreach (var item in passCarList)
                    {
                        model.Op_PassCar.AddOrUpdate(item);
                    }
                    monthCarList = monthCarList.GroupBy(a => a.CarNo).Select(a => a.First()).ToList();
                    foreach (var item in monthCarList)
                    {
                        model.Op_MonthCar.AddOrUpdate(item);
                    }
                    logger.Info("订单数据处理...");
                    string  orderID    = Guid.NewGuid().ToString();
                    decimal rateAmount = AddOrderDetail(orderID, passCarList, monthCarList, model); //订单明细填充
                    AddOrderHeader(orderID, rateAmount, passCarList, monthCarList, model);          //订单主体填充
                    logger.Info("数据提交...");
                    model.SaveChanges();
                    logger.Info("配置处理...");
                    _lastCheckTime = endTime.AddSeconds(1);
                    //ConfigurationManager.AppSettings.Set("LastCheckTime", _lastCheckTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    //ConfigurationManager.RefreshSection("appSettings");
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    config.AppSettings.Settings["LastCheckTime"].Value = _lastCheckTime.ToString("yyyy-MM-dd HH:mm:ss");
                    config.Save(ConfigurationSaveMode.Modified);
                    ConfigurationManager.RefreshSection("appSettings");
                    passCarList.Clear();
                    monthCarList.Clear();
                    logger.Info("处理结束,将进行下一次同步!");
                    //this.Stop();
                    isRun = false;
                }
            }
            catch (Exception ex)
            {
                logger.Debug("本次同步异常,详情见下面异常描述,等待下次同步!");
                logger.Debug(ex.ToString());
                logger.Debug(ex.InnerException.Message);
                isRun = false;
                //this.Stop();
            }
        }