示例#1
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);
            }
        }