Example #1
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["UID"].ToString().Trim().Length <= 0 ||
                res["VID"] == null || res["VID"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                uid = res["UID"].ToString().Trim();
                vid = res["VID"].ToString().Trim();
                VehicleManager vm         = new VehicleManager();
                Hashtable      vehicle_ht = vm.GetVehicleInfoByID(vid);
                if (vehicle_ht == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "未找到相关车辆信息"));
                }
                Hashtable ht = new Hashtable();
                ht["VehicleID"] = vehicle_ht["ID"];
                ht["ParkingID"] = null;
                bool isSuccess = vm.AddOrEditVehicleInfo(ht, vehicle_ht["ID"].ToString());
                if (!isSuccess)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "解绑车辆与网点失败"));
                }
                else
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "success", "解绑车辆与网点成功"));
                }
            }
        }
Example #2
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["VID"] == null || res["UID"].ToString().Trim().Length <= 0 || res["VID"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                uid = res["UID"].ToString().Trim();
                vid = res["VID"].ToString().Trim();
                VehicleManager vm         = new VehicleManager();
                Hashtable      vehicle_ht = vm.GetVehicleInfoByID(vid);
                if (vehicle_ht == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "未找到相关车辆信息"));
                }
                Hashtable ht = new Hashtable();
                ht["ID"]          = vehicle_ht["ID"];
                ht["Electricity"] = 100;
                bool isSuccess = vm.AddOrEditVehicleInfo(ht, vehicle_ht["ID"].ToString());
                if (!isSuccess)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "车辆电池更换失败"));
                }
                else
                {
                    OPUserManager hum           = new OPUserManager();
                    Hashtable     userOperateHT = new Hashtable();
                    userOperateHT["ID"]              = CommonHelper.GetGuid;
                    userOperateHT["VehicleID"]       = vid;
                    userOperateHT["UserID"]          = uid;
                    userOperateHT["OperateType"]     = 8;
                    userOperateHT["OperateTypeText"] = "更换电池";
                    userOperateHT["Remark"]          = "";
                    userOperateHT["OperateTime"]     = SiteHelper.GetWebServerCurrentTime();
                    hum.AddUserOperate(userOperateHT);

                    return(SiteHelper.GetJsonFromHashTable(null, "success", "车辆电池更换成功"));
                }
            }
        }
Example #3
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["UID"].ToString().Trim().Length <= 0 ||
                res["VID"] == null || res["VID"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                uid = res["UID"].ToString().Trim();
                vid = res["VID"].ToString().Trim();
                //contentType,修改类型:01车辆名称,02车牌号,03车型,04车辆平台,05车辆模块编码,06车辆状态,07车架号
                if (res["ContentType"] != null && res["ContentType"].ToString().Trim().Length > 0)
                {
                    contentType = res["ContentType"].ToString().Trim();
                }
                if (res["Content"] != null && res["Content"].ToString().Trim().Length > 0)
                {
                    content = res["Content"].ToString().Trim();
                }
                VehicleManager vm         = new VehicleManager();
                Hashtable      vehicle_ht = vm.GetVehicleInfoByID(vid);
                if (vehicle_ht == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "未找到相关车辆信息"));
                }

                Hashtable ht = new Hashtable();
                if (!string.IsNullOrEmpty(contentType))
                {
                    switch (contentType)
                    {
                    case "01":
                        ht["Name"] = content;
                        break;

                    case "02":
                        ht["VehicleName"]   = content;
                        ht["LicenseNumber"] = content;
                        break;

                    case "03":
                        ht["Model"] = content;
                        break;

                    case "04":
                        ht["PlatformId"] = content;
                        break;

                    case "05":
                        ht["VehicleGPSNum"] = content;
                        break;

                    case "06":
                        ht["VehicleState"] = content;
                        break;

                    case "07":
                        ht["VehicleNum"] = content;
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    if (res["Name"] != null && res["Name"].ToString().Trim().Length > 0)
                    {
                        ht["Name"] = res["Name"].ToString().Trim();
                    }
                    if (res["VehicleName"] != null && res["VehicleName"].ToString().Trim().Length > 0)
                    {
                        ht["VehicleName"]   = res["VehicleName"].ToString().Trim();
                        ht["LicenseNumber"] = res["VehicleName"].ToString().Trim();
                    }
                    if (res["Model"] != null && res["Model"].ToString().Trim().Length > 0)
                    {
                        ht["Model"] = res["Model"].ToString().Trim();
                    }
                    if (res["PlatformId"] != null && res["PlatformId"].ToString().Trim().Length > 0)
                    {
                        ht["PlatformId"] = res["PlatformId"].ToString().Trim();
                    }
                    if (res["VehicleGPSNum"] != null && res["VehicleGPSNum"].ToString().Trim().Length > 0)
                    {
                        ht["VehicleGPSNum"] = res["VehicleGPSNum"].ToString().Trim();
                    }
                    if (res["VehicleState"] != null && res["VehicleState"].ToString().Trim().Length > 0)
                    {
                        ht["VehicleState"] = res["VehicleState"].ToString().Trim();
                    }
                    if (res["VehicleNum"] != null && res["VehicleNum"].ToString().Trim().Length > 0)
                    {
                        ht["VehicleNum"] = res["VehicleNum"].ToString().Trim();
                    }
                }
                bool isSuccess = vm.AddOrEditVehicleInfo(ht, vehicle_ht["ID"].ToString());
                if (!isSuccess)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "修改车辆信息失败"));
                }
                else
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "success", "修改车辆信息成功"));
                }
            }
        }
Example #4
0
        /// <summary>
        /// 保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Save_Click(object sender, EventArgs e)
        {
            try
            {
                Hashtable ht = new Hashtable();

                #region 初始化车辆信息
                // 车辆名称
                ht["Name"] = Name.Value;
                // 车辆名称
                ht["VehicleName"] = LicenseNumber.Value;
                // 车牌号
                ht["LicenseNumber"] = LicenseNumber.Value;
                // 车辆颜色
                ht["VehicleColor"] = VehicleColor.Value;
                // 车辆排量
                ht["Displacement"] = Displacement.Value;
                // 车架号
                ht["VehicleNum"] = VehicleNum.Value;
                // 车辆GPS编号
                ht["VehicleGPSNum"] = VehicleGPSNum.Value;
                // 燃料方式
                ht["FuelStyle"] = FuelStyle.Value;
                // 平台
                ht["PlatformId"] = PlatformId.Value;
                // 公里数
                ht["Mileage"] = Mileage.Value;
                // 车辆品牌
                ht["Brand"] = Brand.Value;
                // 车辆型号
                ht["Model"] = this.drpVModel.Value.ToString();
                // 发动机号
                ht["EngineNum"] = EngineNum.Value;
                // 使用状态
                ht["UseState"] = UseState.Value;
                // 车辆状态
                ht["VehicleState"] = VehicleState.Value;
                // 车辆描述
                ht["VehicleRemark"] = VehicleRemark.Value;
                // 价格体系
                ht["PriceSystem"] = PriceSystem.Value;
                // 用户须知
                ht["TransportInformation"] = TransportInformation.Value;
                // 预计满电续航里程
                ht["ExpectRange"] = ExpectRange.Value;
                // 预计最高时速
                ht["ExpectHighestSpeed"] = ExpectHighestSpeed.Value;
                // 电量
                ht["Electricity"] = "0";
                if (!string.IsNullOrEmpty(Electricity.Value))
                {
                    ht["Electricity"] = Electricity.Value;
                }
                // 续航里程
                ht["Range"] = "0";
                if (!string.IsNullOrEmpty(Range.Value))
                {
                    ht["Range"] = Range.Value;
                }
                //车辆手机号
                ht["VehicleMobile"] = VehicleMobile.Value;
                ht["CityID"]        = CityID.Value;

                if (!string.IsNullOrEmpty(_key))
                {
                    ht["ID"] = _key;
                }
                else
                {
                    ht["ID"]         = CommonHelper.GetGuid;
                    ht["CreateTime"] = DateTime.Now;
                    ht["DeleteMark"] = "1";// 1 未删除,0 已删除
                    ht["Longitude"]  = "0";
                    ht["Latitude"]   = "0";
                }
                #endregion

                bool returnValue = vehicleManager.AddOrEditVehicleInfo(ht, _key);

                if (returnValue)
                {
                    ShowMsgHelper.AlertMsgNoFresh("操作成功!");
                }
                else
                {
                    ShowMsgHelper.Alert_Error("操作失败!");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["VID"] == null || res["Opr"] == null || res["UID"].ToString().Trim().Length <= 0 || res["VID"].ToString().Trim().Length <= 0 || res["Opr"].ToString().Trim().Length <= 0)
            {
                Hashtable result = new Hashtable();
                result["ErrCode"] = "00";//服务器异常
                return(SiteHelper.GetJsonFromHashTable(result, "faild", "参数不完整"));
            }
            else
            {
                uid = res["UID"].ToString().Trim();
                vid = res["VID"].ToString().Trim();
                //opr,0:开1:关
                opr = res["Opr"].ToString().Trim();
                VehicleManager vm = new VehicleManager();
                Hashtable      ht = vm.GetVehicleInfoByID(vid);
                if (ht == null)
                {
                    Hashtable result = new Hashtable();
                    result["ErrCode"] = "01";//车辆未找到
                    return(SiteHelper.GetJsonFromHashTable(result, "faild", "未找到相关车辆信息"));
                }
                else
                {
                    //客户占用车辆时禁止操作
                    if (ht["USESTATE"].ToString() == VehicleUseState.Order.GetHashCode().ToString() || ht["USESTATE"].ToString() == VehicleUseState.Reservation.GetHashCode().ToString())
                    {
                        Hashtable result = new Hashtable();
                        result["ErrCode"] = "02";//车辆已被占用
                        return(SiteHelper.GetJsonFromHashTable(result, "faild", "指令发送失败,车辆已被客户占用"));
                    }

                    string gpsnum    = SiteHelper.GetHashTableValueByKey(ht, "VehicleGPSNum");
                    bool   isSuccess = false;
                    if (opr == "0")
                    {
                        isSuccess = vm.OpenVehicle(vid);
                    }
                    else
                    {
                        isSuccess = vm.CloseVehicle(vid);
                    }
                    if (!isSuccess)
                    {
                        Hashtable result = new Hashtable();
                        result["ErrCode"] = "04";//指令发送失败
                        return(SiteHelper.GetJsonFromHashTable(result, "faild", "指令发送失败"));
                    }
                    else
                    {
                        Hashtable vht = new Hashtable();
                        vht["ID"]       = vid;
                        vht["UseState"] = opr == "0" ? 4 : 1;
                        vm.AddOrEditVehicleInfo(vht, vid);

                        OPUserManager hum           = new OPUserManager();
                        Hashtable     userOperateHT = new Hashtable();
                        userOperateHT["ID"]              = CommonHelper.GetGuid;
                        userOperateHT["VehicleID"]       = vid;
                        userOperateHT["UserID"]          = uid;
                        userOperateHT["OperateType"]     = opr == "0" ? 1 : 2;
                        userOperateHT["OperateTypeText"] = opr == "0" ? "开车" : "锁车";
                        userOperateHT["Remark"]          = "";
                        userOperateHT["OperateTime"]     = SiteHelper.GetWebServerCurrentTime();
                        hum.AddUserOperate(userOperateHT);

                        return(SiteHelper.GetJsonFromHashTable(null, "success", "指令发送成功"));
                    }
                }
            }
        }
Example #6
0
        public ApiResp Execute(System.Collections.Hashtable params_ht)
        {
            ApiResp resp = new ApiResp();

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

                string carId = "";
                if (jsonObj.IsDefined("carId"))
                {
                    carId = jsonObj.carId;
                }
                string csq = "";
                if (jsonObj.IsDefined("csq"))
                {
                    csq = jsonObj.csq;
                }
                string voltage = "";
                if (jsonObj.IsDefined("voltage"))
                {
                    voltage = jsonObj.voltage;
                }
                string dumpEle = "";
                if (jsonObj.IsDefined("dumpEle"))
                {
                    dumpEle = jsonObj.dumpEle;
                }

                VehicleManager vm         = new VehicleManager();
                Hashtable      vehicle_ht = vm.GetVehicleInfoByGPSNum(carId);
                if (vehicle_ht != null && vehicle_ht.Keys.Count > 0)
                {
                    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)
                    {
                        string    vid = vehicle_ht["ID"].ToString();
                        Hashtable ht  = new Hashtable();
                        if (!string.IsNullOrEmpty(dumpEle))
                        {
                            double power = -1;
                            double.TryParse(dumpEle, out power);
                            if (power >= 0 && power <= 1)
                            {
                                ht["Electricity"] = (int)(power * 100);
                            }
                        }
                        ht["LastUpdateTime"] = DateTime.Now;
                        bool result = false;
                        if (ht.Keys.Count > 0)
                        {
                            result = vm.AddOrEditVehicleInfo(ht, vid);
                        }
                        resp.Code = result ? "0" : "1";
                    }
                    else
                    {
                        resp.Code = "3";
                    }
                }
                return(resp);
            }
            catch
            {
                resp.Code = "1";
                return(resp);
            }
        }
Example #7
0
        public ApiResp Execute(System.Collections.Hashtable params_ht)
        {
            ApiResp resp = new ApiResp();

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

                string carId = "";
                if (jsonObj.IsDefined("carId"))
                {
                    carId = jsonObj.carId;//车辆ID
                }
                string latitude = "";
                if (jsonObj.IsDefined("body.latitude"))
                {
                    latitude = jsonObj.body.latitude;//纬度
                }
                string longitude = "";
                if (jsonObj.IsDefined("body.longitude"))
                {
                    longitude = jsonObj.body.longitude;//经度
                }
                string elevation = "";
                if (jsonObj.IsDefined("body.elevation"))
                {
                    elevation = jsonObj.body.elevation;//海拔
                }
                string speed = "";
                if (jsonObj.IsDefined("body.speed"))
                {
                    speed = jsonObj.body.speed;//车速
                }
                string direction = "";
                if (jsonObj.IsDefined("body.direction"))
                {
                    direction = jsonObj.body.direction;//方向
                }
                string time = "";
                if (jsonObj.IsDefined("body.time"))
                {
                    time = jsonObj.body.time;//时间
                }
                string surplusPercent = "";
                if (jsonObj.IsDefined("body.surplusPercent"))
                {
                    surplusPercent = jsonObj.body.surplusPercent;//剩余电量百分比
                }
                string surplusDistance = "";
                if (jsonObj.IsDefined("body.surplusDistance"))
                {
                    surplusDistance = jsonObj.body.surplusDistance;//剩余续航里程
                }
                string distance = "";
                if (jsonObj.IsDefined("body.distance"))
                {
                    distance = jsonObj.body.distance;//总行驶里程
                }
                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();
                    Hashtable ht  = new Hashtable();
                    if (!string.IsNullOrEmpty(longitude))
                    {
                        ht["Longitude"] = longitude;
                    }
                    if (!string.IsNullOrEmpty(latitude))
                    {
                        ht["Latitude"] = latitude;
                    }
                    if (!string.IsNullOrEmpty(speed))
                    {
                        ht["CurrentSpeed"] = speed;
                    }
                    if (!string.IsNullOrEmpty(time))
                    {
                        ht["GPSTime"] = DateTime.Now;
                    }
                    if (!string.IsNullOrEmpty(surplusPercent))
                    {
                        ht["Electricity"] = surplusPercent;
                    }
                    if (!string.IsNullOrEmpty(surplusDistance))
                    {
                        ht["ExpectRange"] = surplusDistance;
                    }
                    if (!string.IsNullOrEmpty(distance))
                    {
                        ht["Mileage"] = distance;
                    }

                    bool result = false;
                    if (ht.Keys.Count > 0)
                    {
                        result = vm.AddOrEditVehicleInfo(ht, vid);
                    }
                    resp.Code = result ? "0" : "1";
                }
                return(resp);
            }
            catch
            {
                resp.Code = "1";
                return(resp);
            }
        }
Example #8
0
        public ApiResp Execute(System.Collections.Hashtable params_ht)
        {
            ApiResp resp = new ApiResp();

            try
            {
                string carId           = SiteHelper.GetHashTableValueByKey(params_ht, "carId");           //车辆ID
                string latitude        = SiteHelper.GetHashTableValueByKey(params_ht, "latitude");        //纬度
                string longitude       = SiteHelper.GetHashTableValueByKey(params_ht, "longitude");       //经度
                string elevation       = SiteHelper.GetHashTableValueByKey(params_ht, "elevation");       //海拔
                string speed           = SiteHelper.GetHashTableValueByKey(params_ht, "speed");           //车速
                string direction       = SiteHelper.GetHashTableValueByKey(params_ht, "direction");       //方向
                string time            = SiteHelper.GetHashTableValueByKey(params_ht, "time");            //时间
                string surplusPercent  = SiteHelper.GetHashTableValueByKey(params_ht, "surplusPercent");  //剩余电量百分比
                string surplusDistance = SiteHelper.GetHashTableValueByKey(params_ht, "surplusDistance"); //剩余续航里程
                string distance        = SiteHelper.GetHashTableValueByKey(params_ht, "distance");        //总行驶里程

                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();
                    Hashtable ht  = new Hashtable();
                    if (!string.IsNullOrEmpty(longitude))
                    {
                        ht["Longitude"] = string.Format("{0}", decimal.Parse(longitude) / 1000000);
                    }
                    if (!string.IsNullOrEmpty(latitude))
                    {
                        ht["Latitude"] = string.Format("{0}", decimal.Parse(latitude) / 1000000);
                    }
                    if (!string.IsNullOrEmpty(speed))
                    {
                        ht["CurrentSpeed"] = speed;
                    }
                    if (!string.IsNullOrEmpty(time))
                    {
                        ht["GPSTime"] = DateTime.Now;
                    }
                    if (!string.IsNullOrEmpty(surplusPercent))
                    {
                        ht["Electricity"] = surplusPercent;
                    }
                    if (!string.IsNullOrEmpty(surplusDistance))
                    {
                        ht["ExpectRange"] = surplusDistance;
                    }
                    if (!string.IsNullOrEmpty(distance))
                    {
                        ht["Mileage"] = distance;
                    }
                    bool result = vm.AddOrEditVehicleInfo(ht, vid);
                    resp.Code = result ? "0" : "1";
                }
                return(resp);
            }
            catch
            {
                resp.Code = "1";
                return(resp);
            }
        }
Example #9
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);
            }
        }