Beispiel #1
0
 public static void CreateModel(Model.EbikeOperatingInfo operInfo, ref Model.Ride ride)
 {
     ride.TerminalID = operInfo.TerminalID;
     ride.EventID    = operInfo.EventID;
     ride.StartTime  = operInfo.SamplingTime;
     ride.EndTime    = operInfo.SamplingTime + 30; //默认至少骑行30S
     ride.Duration   = 30;
 }
Beispiel #2
0
 public static void CreateModel(Model.EbikeOperatingInfo operInfo, ref Model.Charge charge)
 {
     charge.Duration     = 30;
     charge.EndTime      = operInfo.SamplingTime + 30;
     charge.StartTime    = operInfo.SamplingTime;
     charge.EndVoltage   = operInfo.Voltage;
     charge.StartVoltage = operInfo.Voltage;
     charge.EventID      = operInfo.EventID;
     charge.TerminalID   = operInfo.TerminalID;
 }
Beispiel #3
0
        public static int Add(Model.EbikeOperatingInfo model)
        {
            int result = 0;

            using (var context = new DefaultDbContext())
            {
                context.EbikeOperatingInfo.Add(model);

                result = context.SaveChanges();
            }
            return(result);
        }
Beispiel #4
0
        public static void ImportToDB()
        {
            ConnectionFactory factory = new ConnectionFactory();

            factory.Uri = new Uri(Config.RabbitMQConnectString);

            //在20断开WIFI后20S左右还是会退出程序
            factory.AutomaticRecoveryEnabled = true;
            factory.NetworkRecoveryInterval  = TimeSpan.FromSeconds(10);



            IConnection conn = factory.CreateConnection();

            IModel channel  = conn.CreateModel();
            var    consumer = new EventingBasicConsumer(channel);

            consumer.Received += (ch, ea) =>
            {
                var body = Encoding.UTF8.GetString(ea.Body);
                //JObject jobj = JObject.Parse(body);
                //SaveInfo
                Model.EbikeOperatingInfo ebikeOperInfo = JsonConvert.DeserializeObject <Model.EbikeOperatingInfo>(body);
                Add(ebikeOperInfo);

                if (ebikeOperInfo.AlarmNO != 0)
                {
                    Model.Alarm alarm = new Model.Alarm();
                    alarm.AlarmNO      = ebikeOperInfo.AlarmNO;
                    alarm.Parms        = ebikeOperInfo.AlarmParm;
                    alarm.SamplingTime = ebikeOperInfo.SamplingTime;
                    alarm.TerminalID   = ebikeOperInfo.TerminalID;
                    alarm.EventID      = ebikeOperInfo.EventID;

                    Business.Alarm.Add(alarm);
                }

                channel.BasicAck(ea.DeliveryTag, false);
            };
            String consumerTag = channel.BasicConsume("EBikeInfoToDB", false, consumer);
        }
Beispiel #5
0
        /// <summary>
        /// 注意此处的EventID,需要在调用时判断好
        /// </summary>
        /// <param name="operInfo"></param>
        /// <returns></returns>
        public static int UpdateOrCreate(Model.EbikeOperatingInfo operInfo)
        {
            int result = 0;

            using (var context = new DefaultDbContext())
            {
                var charge = context.Charge.FirstOrDefault(c => c.EventID == operInfo.EventID);
                if (charge == null)
                {
                    charge = new Model.Charge();
                    Business.Charge.CreateModel(operInfo, ref charge);

                    context.Charge.Add(charge);
                }
                else //更新充电时长
                {
                    Business.Charge.UpdateModel(operInfo, ref charge);
                    context.Charge.Update(charge);
                }
                result = context.SaveChanges();
            }
            return(result);
        }
Beispiel #6
0
 public static void UpdateModel(Model.EbikeOperatingInfo operInfo, ref Model.Charge charge)
 {
     charge.EndTime    = operInfo.SamplingTime;
     charge.EndVoltage = operInfo.Voltage;
     charge.Duration   = (int)(operInfo.SamplingTime - charge.StartTime);
 }
Beispiel #7
0
 public static void UpdateModel(Model.EbikeOperatingInfo operInfo, ref Model.Ride ride)
 {
     ride.EndTime  = operInfo.SamplingTime;
     ride.Duration = (int)(operInfo.SamplingTime - ride.StartTime);
 }
Beispiel #8
0
        public static void Update(JObject jobj)
        {
            long   terminalID     = (long)jobj["TerminalID"];
            string eventID        = jobj["EventID"].ToString();
            string preEventID     = jobj.GetValue("PreEventID") == null?"": jobj["PreEventID"].ToString();
            long   samplingTime   = (long)jobj["SamplingTime"];
            double staticVoltageA = Math.Round((double)jobj["StaticVoltageA"], 2);
            int    status         = (int)jobj["Status"];

            Model.EbikeOperatingInfo operInfo = new Model.EbikeOperatingInfo();
            operInfo.TerminalID   = terminalID;
            operInfo.EventID      = eventID;
            operInfo.PreEventID   = preEventID;
            operInfo.SamplingTime = samplingTime;
            operInfo.Voltage      = staticVoltageA;
            operInfo.Status       = status;


            //充电开始
            if (status == 4 || status == 8)
            {
                var charge = new Model.Charge();
                Business.Charge.CreateModel(operInfo, ref charge);

                using (var context = new DefaultDbContext())
                {
                    context.Charge.Add(charge);
                    context.SaveChanges();

                    if (!eventID.Equals(preEventID) && status == 8)
                    {
                        operInfo.EventID = operInfo.PreEventID; //修改事件ID为上一次事件ID
                        Business.Ride.UpdateOrCreate(operInfo);
                    }
                }
            }
            // 骑行开始
            else if (status == 1 || status == 7)
            {
                Model.Ride ride = new Model.Ride();

                Business.Ride.CreateModel(operInfo, ref ride);

                using (var context = new DefaultDbContext())
                {
                    context.Ride.Add(ride);
                    context.SaveChanges();

                    if (!eventID.Equals(preEventID) && status == 7)
                    {
                        //暂时不分析停车,因为停车时长暂时不主要分析
                        operInfo.EventID = operInfo.PreEventID; //修改事件ID为上一次事件ID
                        Business.Charge.UpdateOrCreate(operInfo);
                    }
                }
            }
            //更新充电时长
            else if (status == 5)
            {
                Business.Charge.UpdateOrCreate(operInfo);
            }
            //更新骑行时长
            else if (status == 2)
            {
                Business.Ride.UpdateOrCreate(operInfo);
            }
            //骑行结束
            else if (status == 3)
            {
                operInfo.EventID = operInfo.PreEventID;
                Business.Ride.UpdateOrCreate(operInfo);
            }
            //骑行结束
            else if (status == 6)
            {
                operInfo.EventID = operInfo.PreEventID;
                Business.Charge.UpdateOrCreate(operInfo);
            }
        }