Beispiel #1
0
        /// <summary>
        /// 绑定数据源
        /// </summary>
        private void DataBindGrid(bool isQuery = false)
        {
            VehicleAlarmManager alarmManager = new VehicleAlarmManager();
            int count     = 0;
            int pageIndex = isQuery ? 1 : PageControl1.PageIndex;
            KeyValuePair <StringBuilder, IList <SqlParam> > keyValue = InitCondition();
            DataTable dt = alarmManager.GetList(keyValue.Key, keyValue.Value, pageIndex, PageControl1.PageSize, ref count);

            ControlBindHelper.BindRepeaterList(dt, rp_Item);
            this.PageControl1.PageIndex   = pageIndex;
            this.PageControl1.RecordCount = Convert.ToInt32(count);
            this.PageControl1.PageChecking();
        }
Beispiel #2
0
        public string GetOperator(string operatorid, string operator_type)
        {
            //operator_type:异常处理人类型,1后台操作员,2网点操作员
            string operatorname = "";
            VehicleAlarmManager alarmManager = new VehicleAlarmManager();

            operatorname = alarmManager.GetOperator(operatorid, operator_type);
            if (operator_type == "1")
            {
                operatorname += "(后台操作员)";
            }
            else if (operator_type == "2")
            {
                operatorname += "(网点操作员)";
            }
            return(operatorname);
        }
Beispiel #3
0
        /// <summary>
        /// 越界报警短信通知
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            ICache cache = null;
            string type  = "越界";

            try
            {
                foreach (string saas in ConfigHelper.GetSaasList())
                {
                    try
                    {
                        MyWorkerRequest.CreateHttpContext(saas, "", "");

                        SmsInfoManager      sim       = new SmsInfoManager();
                        OPUserManager       oum       = new OPUserManager();
                        DataTable           users     = oum.GetReceiveSMSUsers();
                        VehicleAlarmManager vam       = new VehicleAlarmManager();
                        VehicleManager      vm        = new VehicleManager();
                        DataTable           dataTable = vam.GetOutAreaList();
                        if (dataTable != null && dataTable.Rows.Count > 0)
                        {
                            cache = CacheFactory.GetCache();
                            foreach (DataRow row in dataTable.Rows)
                            {
                                string    vehicleID  = row[0].ToString();
                                Hashtable vehicle    = vm.GetVehicleInfoByID(vehicleID);
                                string    gpsNum     = SiteHelper.GetHashTableValueByKey(vehicle, "VehicleGPSNum").ToUpper();
                                string    name       = SiteHelper.GetHashTableValueByKey(vehicle, "Name").ToUpper();
                                string    alarmCount = row[1].ToString();
                                if (!string.IsNullOrEmpty(alarmCount))
                                {
                                    int count = 0;
                                    int.TryParse(alarmCount, out count);
                                    if (count >= 4)
                                    {
                                        if (users != null && users.Rows.Count > 0)
                                        {
                                            foreach (DataRow user in users.Rows)
                                            {
                                                string mobile     = user[0].ToString();
                                                string key        = "out_area_alarm_" + mobile + "_" + vehicleID;
                                                string code_value = cache.Get <string>(key);
                                                if (string.IsNullOrEmpty(code_value))
                                                {
                                                    bool sendResult = sim.SendAlarm(mobile, gpsNum, name, type);
                                                    if (sendResult)
                                                    {
                                                        Logger.Warn(string.Format("车辆{0},{1}发生{2}报警,发送给{3}成功。", name, gpsNum, type, mobile));
                                                        DateTime dt = DateTime.Now.AddMinutes(20);
                                                        cache.Set(key, 1, dt - DateTime.Now);
                                                    }
                                                    else
                                                    {
                                                        Logger.Warn(string.Format("车辆{0},{1}发生{2}报警,发送给{3}失败。", name, gpsNum, type, mobile));
                                                    }
                                                }
                                                else
                                                {
                                                    Logger.Warn(string.Format("车辆{0},{1}发生{2}报警,发送给{3}未超过1小时。", name, gpsNum, type, mobile));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (cache != null)
                            {
                                cache.Dispose();
                            }
                        }
                    }
                    catch
                    {
                        if (cache != null)
                        {
                            cache.Dispose();
                        }
                        Logger.Info("车辆越界报警发送短信失败");
                    }
                }
            }
            catch
            {
                if (cache != null)
                {
                    cache.Dispose();
                }
                Logger.Info("车辆越界报警发送短信失败");
            }
        }
Beispiel #4
0
        public ApiResp Execute(Hashtable params_ht)
        {
            int     start = DateTime.Now.Millisecond;
            ApiResp resp  = new ApiResp();
            ICache  cache = null;

            try
            {
                cache = CacheFactory.GetCache();
                string  jsonData = params_ht["json"].ToString();
                dynamic jsonObj  = DynamicJson.Parse(jsonData);

                string carId = "";
                if (jsonObj.IsDefined("carId"))
                {
                    carId = jsonObj.carId;
                }
                double distance = 0.00;
                if (jsonObj.IsDefined("distance"))
                {
                    distance = jsonObj.distance;
                }

                if (jsonObj.IsDefined("data"))
                {
                    foreach (var item in jsonObj.data)
                    {
                        string acc = "";
                        if (item.IsDefined("acc"))
                        {
                            acc = item.acc;
                        }
                        double longitude = 0.00;
                        if (item.IsDefined("longitude"))
                        {
                            longitude = item.longitude;
                        }
                        double latitude = 0.00;
                        if (item.IsDefined("latitude"))
                        {
                            latitude = item.latitude;
                        }
                        double speed = 0.00;
                        if (item.IsDefined("speed"))
                        {
                            speed = item.speed;
                        }
                        string defend = "";
                        if (item.IsDefined("defend"))
                        {
                            defend = item.defend;
                        }
                        VehicleManager vm         = new VehicleManager();
                        Hashtable      vehicle_ht = vm.GetVehicleInfoByGPSNum(carId);
                        if (vehicle_ht != null && vehicle_ht.Keys.Count > 0)
                        {
                            string vid = vehicle_ht["ID"].ToString();
                            //车辆使用状态 1空闲,2预约中,3客户使用中,4运维操作中
                            string useState          = SiteHelper.GetHashTableValueByKey(vehicle_ht, "UseState");
                            string strLastUpdateTime = SiteHelper.GetHashTableValueByKey(vehicle_ht, "LastUpdateTime");
                            int    diffSecond        = 5;
                            if (!string.IsNullOrEmpty(strLastUpdateTime))
                            {
                                DateTime lastUpdateTime = DateTime.Parse(strLastUpdateTime);
                                diffSecond = SiteHelper.ExecDateDiffSecond(lastUpdateTime, DateTime.Now);
                            }
                            if (diffSecond > 3)
                            {
                                Hashtable ht = new Hashtable();
                                //车辆开关状态 LockState ,开:unlock,关:lock
                                //acc =1 &&  defend =0  启动 unlock
                                if (acc.Equals("1") && defend.Equals("0"))
                                {
                                    ht["LockState"] = "unlock";
                                }
                                //defend =1  设防  lock
                                if (defend.Equals("1"))
                                {
                                    ht["LockState"] = "lock";
                                }
                                if (longitude > 0)
                                {
                                    ht["Longitude"] = longitude;
                                }
                                if (latitude > 0)
                                {
                                    ht["Latitude"] = latitude;
                                }
                                ht["CurrentSpeed"]   = speed;
                                ht["Mileage"]        = distance / 1000.00;
                                ht["GPSTime"]        = DateTime.Now;
                                ht["LastUpdateTime"] = DateTime.Now;
                                bool result = false;
                                if (ht.Keys.Count > 0)
                                {
                                    result = vm.AddOrEditVehicleInfo(ht, vid);
                                }
                                Hashtable htAlarm = new Hashtable();
                                //超速
                                if (speed > 30)
                                {
                                    string overSpeedKey   = "over_speed_" + carId;
                                    string overSpeedValue = cache.Get <string>(overSpeedKey);
                                    if (string.IsNullOrEmpty(overSpeedValue))
                                    {
                                        Logger.Warn("超速报警," + vid + "," + carId + ",speed=" + speed + ",defend =" + defend + ",acc=" + acc);
                                        VehicleAlarmManager alarmManager = new VehicleAlarmManager();
                                        htAlarm["ID"]          = Guid.NewGuid().ToString();
                                        htAlarm["VehicleID"]   = vid;
                                        htAlarm["IMEI"]        = carId;
                                        htAlarm["AlarmType"]   = 6;
                                        htAlarm["Speed"]       = speed;
                                        htAlarm["AlarmTime"]   = DateTime.Now;
                                        htAlarm["AlarmStatus"] = 0;
                                        htAlarm["CreateTime"]  = DateTime.Now;
                                        if (alarmManager.AddOrEdit(htAlarm, null))
                                        {
                                            DateTime timeSpan = DateTime.Now.AddMinutes(1);
                                            cache.Set(overSpeedKey, 1, timeSpan - DateTime.Now);
                                            Logger.Warn("超速报警记录添加成功," + vid + "," + carId + ",speed=" + speed + ",defend =" + defend + ",acc=" + acc);
                                        }
                                        else
                                        {
                                            Logger.Warn("超速报警记录添加失败," + vid + "," + carId + ",speed=" + speed + ",defend =" + defend + ",acc=" + acc);
                                        }
                                    }
                                }
                                else
                                {
                                    if (speed >= 5 && "1".Equals(useState))
                                    {
                                        string moveKey   = "move_" + carId;
                                        string moveValue = cache.Get <string>(moveKey);
                                        if (string.IsNullOrEmpty(moveValue))
                                        {
                                            Logger.Warn("无单移动报警," + vid + "," + carId + ",speed=" + speed + ",defend =" + defend + ",acc=" + acc + ",useState=" + useState);
                                            VehicleAlarmManager alarmManager = new VehicleAlarmManager();
                                            htAlarm["ID"]          = Guid.NewGuid().ToString();
                                            htAlarm["VehicleID"]   = vid;
                                            htAlarm["IMEI"]        = carId;
                                            htAlarm["AlarmType"]   = 1;
                                            htAlarm["Speed"]       = speed;
                                            htAlarm["AlarmTime"]   = DateTime.Now;
                                            htAlarm["AlarmStatus"] = 0;
                                            htAlarm["CreateTime"]  = DateTime.Now;
                                            if (alarmManager.AddOrEdit(htAlarm, null))
                                            {
                                                DateTime timeSpan = DateTime.Now.AddMinutes(10);
                                                cache.Set(moveKey, 1, timeSpan - DateTime.Now);
                                                Logger.Warn("无单移动报警记录添加成功," + vid + "," + carId + ",speed=" + speed + ",defend =" + defend + ",acc=" + acc);
                                            }
                                            else
                                            {
                                                Logger.Warn("无单移动报警记录添加失败," + vid + "," + carId + ",speed=" + speed + ",defend =" + defend + ",acc=" + acc);
                                            }
                                        }
                                    }
                                }
                                string outAreaKey   = "out_area_" + carId;
                                string outAreaValue = cache.Get <string>(outAreaKey);
                                if (string.IsNullOrEmpty(outAreaValue) && latitude > 0 && longitude > 0)
                                {
                                    string serviceAreaKey = "Service_Area_" + vehicle_ht["CITYID"].ToString();
                                    string coordinates    = cache.Get <string>(serviceAreaKey);
                                    if (string.IsNullOrEmpty(coordinates))
                                    {
                                        ServiceAreaManager areaManager = new ServiceAreaManager();
                                        Hashtable          area_ht     = areaManager.GetServiceAreaByVehicleID(vid);
                                        if (area_ht != null && area_ht.Keys.Count > 0)
                                        {
                                            coordinates = SiteHelper.GetHashTableValueByKey(area_ht, "Coordinates");
                                            if (!string.IsNullOrEmpty(coordinates))
                                            {
                                                DateTime timeSpan = DateTime.Now.AddDays(10);
                                                cache.Set(serviceAreaKey, coordinates, timeSpan - DateTime.Now);
                                            }
                                        }
                                    }
                                    List <LatLng> area_pts = new List <LatLng>();
                                    if (!string.IsNullOrEmpty(coordinates))
                                    {
                                        foreach (string str in coordinates.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
                                        {
                                            string[] pt_arr = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                                            LatLng   pt     = new LatLng(double.Parse(pt_arr[1]), double.Parse(pt_arr[0]));
                                            area_pts.Add(pt);
                                        }
                                        LatLng vehicle_pt = new LatLng(latitude, longitude);
                                        //车辆GPS坐标转高德坐标
                                        vehicle_pt = SiteHelper.GPSToGCJ02(longitude.ToString(), latitude.ToString());
                                        vehicle_pt = new LatLng(Math.Round(vehicle_pt.latitude, 6), Math.Round(vehicle_pt.longitude, 6));
                                        bool isInPoly = SiteHelper.IsPtInPoly(vehicle_pt, area_pts);
                                        if (!isInPoly)
                                        {
                                            Logger.Warn("越界报警," + vid + "," + carId + ",speed=" + speed + ",defend =" + defend + ",acc=" + acc);
                                            VehicleAlarmManager alarmManager = new VehicleAlarmManager();
                                            htAlarm["ID"]          = Guid.NewGuid().ToString();
                                            htAlarm["VehicleID"]   = vid;
                                            htAlarm["IMEI"]        = carId;
                                            htAlarm["AlarmType"]   = 4;
                                            htAlarm["Speed"]       = speed;
                                            htAlarm["AlarmTime"]   = DateTime.Now;
                                            htAlarm["AlarmStatus"] = 0;
                                            htAlarm["CreateTime"]  = DateTime.Now;
                                            bool alarmResult = alarmManager.AddOrEdit(htAlarm, null);
                                            if (alarmResult)
                                            {
                                                //越界20分钟内有效
                                                DateTime dt = DateTime.Now.AddMinutes(20);
                                                cache.Set(outAreaKey, carId, dt - DateTime.Now);
                                                Logger.Warn("越界报警记录添加成功," + vid + "," + carId + ",speed=" + speed + ",defend =" + defend + ",acc=" + acc);
                                            }
                                            else
                                            {
                                                Logger.Warn("越界报警记录添加失败," + vid + "," + carId + ",speed=" + speed + ",defend =" + defend + ",acc=" + acc);
                                            }
                                        }
                                    }
                                }
                                int end = DateTime.Now.Millisecond;
                                Logger.Warn("小安盒子接口网关上报状态信息数据,耗时" + (end - start) + "ms," + vid + "," + carId + ",defend = " + defend + ",acc=" + acc + ",LockState=" + ht["LockState"]);
                                resp.Code    = result ? "0" : "1";
                                resp.Message = result ? "success" : "fail";
                            }
                            else
                            {
                                resp.Code = "3";
                            }
                        }
                    }
                }
                if (cache != null)
                {
                    cache.Dispose();
                }
                return(resp);
            }
            catch (Exception e)
            {
                Logger.Error("盒子上报状态信息报错:" + e);
                string message = e.Message;
                if (cache != null)
                {
                    cache.Dispose();
                }
                resp.Code    = "1";
                resp.Message = "fail";
                return(resp);
            }
        }
Beispiel #5
0
        public ApiResp Execute(System.Collections.Hashtable params_ht)
        {
            ApiResp resp = new ApiResp();

            resp.Code    = "0";
            resp.Message = "success";
            string jsonData = params_ht["json"].ToString();
            ICache cache    = null;

            try
            {
                dynamic jsonObj = DynamicJson.Parse(jsonData);
                string  carId   = "";
                if (jsonObj.IsDefined("carId"))
                {
                    carId = jsonObj.carId;
                }
                double alarm = 0;
                if (jsonObj.IsDefined("alarm"))
                {
                    alarm = jsonObj.alarm;
                }
                Logger.Warn("告警信息:" + carId + ",参数:" + jsonData);

                VehicleManager      vm           = new VehicleManager();
                VehicleAlarmManager alarmManager = new VehicleAlarmManager();
                Hashtable           vehicle_ht   = vm.GetVehicleIByGPSNum(carId);
                if (alarm == 6 && vehicle_ht != null && vehicle_ht.Keys.Count > 0)
                {
                    string cacheKey = "alarm_" + carId + "_" + alarm;
                    cache = CacheFactory.GetCache();
                    if (!string.IsNullOrEmpty(cache.Get <string>(cacheKey)))
                    {
                        cache.Dispose();
                        Logger.Warn("断电告警10分钟内," + carId);
                        resp.Code    = "1";
                        resp.Message = "";
                        return(resp);
                    }
                    int alarmType = 0;
                    //if (alarm == 3)
                    //{
                    //    振动
                    //    alarmType = 7;
                    //}
                    if (alarm == 6)
                    {
                        //断电
                        alarmType = 2;
                    }
                    string vid = vehicle_ht["ID"].ToString();
                    //车辆使用状态 1空闲,2预约中,3客户使用中,4运维操作中
                    string    useState = SiteHelper.GetHashTableValueByKey(vehicle_ht, "UseState");
                    Hashtable ht       = new Hashtable();
                    ht["ID"]          = Guid.NewGuid().ToString();
                    ht["VehicleID"]   = vid;
                    ht["IMEI"]        = carId;
                    ht["AlarmType"]   = alarmType;
                    ht["AlarmTime"]   = DateTime.Now;
                    ht["AlarmStatus"] = 0;
                    ht["CreateTime"]  = DateTime.Now;

                    bool result = false;
                    if (ht.Keys.Count > 0 && !"4".Equals(useState))
                    {
                        Logger.Warn("告警信息,参数:" + jsonData + ",车辆状态:" + useState + "(1空闲,2预约中,3客户使用中,4运维操作中)");
                        result = alarmManager.AddOrEdit(ht, null);
                        if (result)
                        {
                            DateTime dt = DateTime.Now.AddMinutes(10);
                            cache.Set(cacheKey, carId, dt - DateTime.Now);
                            cache.Dispose();
                        }
                    }
                    resp.Code    = result ? "0" : "1";
                    resp.Message = result ? "success" : "fail";
                }
                if (cache != null)
                {
                    cache.Dispose();
                }
                return(resp);
            }
            catch (Exception e)
            {
                if (cache != null)
                {
                    cache.Dispose();
                }
                Logger.Error("告警信息,参数:" + jsonData + ",异常:" + e);
                resp.Code    = "1";
                resp.Message = e.Message;
                return(resp);
            }
        }