public ActionResult DynamicPathPlaning(string para, string orderId, string truckId, string name, string type) { string[] paraArray = para.Split('/'); const int STNum = 3, WorkHour = 11, AvgTime = 2; var staffManager = new StaffManager(); Guid id; //the website's id string location = string.Empty; //the website's location //get order's data List <LogisticsSystem.DTO.OrderListDto> datas = staffManager.GetOrderByWebsite(out id, out location, name, type).Where(p => long.Parse(p.OrderId) <= long.Parse(orderId)).ToList(); //避免处理期间有新的订单生成 //get truck's data var truck = staffManager.GetTruckByWebsite(id).Where(p => p.TruckId == Guid.Parse(truckId)).FirstOrDefault(); if (truck.ContainerHeight == "0") { truck.Volumn = (Convert.ToDouble(truck.ContainerLength) * Convert.ToDouble(truck.ContainerWidth) * Convert.ToDouble(truck.TruckHeight)).ToString("f2"); } else { truck.Volumn = (Convert.ToDouble(truck.ContainerLength) * Convert.ToDouble(truck.ContainerWidth) * Convert.ToDouble(truck.ContainerHeight)).ToString("f2"); } string[] locations = new string[paraArray.Length]; //the location matrix double[,] dist = new double[paraArray.Length, paraArray.Length]; //the distance matrix double[] valueCoefficient = new double[paraArray.Length]; //The Value Coefficient Matrix double[,] coefficients = new double[STNum, paraArray.Length]; //The Restraint Coefficient Matrix locations[0] = location; valueCoefficient[0] = 0; coefficients[0, 0] = double.MaxValue; coefficients[1, 0] = double.MaxValue; coefficients[2, 0] = double.MaxValue; //initialize matrix for (int i = 1; i < paraArray.Length; i++) { var num = int.Parse(paraArray[i]) - 1; valueCoefficient[i] = Convert.ToDouble(datas[num].Income); locations[i] = datas[num].Location; coefficients[0, i] = Convert.ToDouble(datas[num].CargoWeight) * Convert.ToDouble(datas[num].UnitNUm); coefficients[1, i] = Convert.ToDouble(datas[num].CargoVolume) * Convert.ToDouble(datas[num].UnitNUm); coefficients[2, i] = 0.25; } coefficients[0, paraArray.Length - 1] = Convert.ToDouble(truck.Load) * 1000; coefficients[1, paraArray.Length - 1] = Convert.ToDouble(truck.Volumn); coefficients[2, paraArray.Length - 1] = WorkHour - AvgTime; //calculate distance string key = ConfigurationManager.AppSettings["GdAppKey"]; string skey = ConfigurationManager.AppSettings["GdSecretKey"]; for (int i = 0; i < paraArray.Length; i++) { var aimLocation = locations[i]; locations.ToList().Remove(aimLocation); var orignLocationStr = string.Join("|", locations); List <string> distances = WebRequestService.CalcGroupDistance(orignLocationStr, aimLocation, key, skey, "1"); for (int j = 0; j < distances.Count; j++) { dist[i, j] = double.Parse(distances[j]); } dist[i, i] = 0; } //Analyze soulation DPP dPP = new DPP(); double _maxValue; List <string> soulation = dPP.GetSulotion(dist, valueCoefficient, coefficients, out _maxValue); string _path = string.Join("/", soulation); return(Json(new { path = _path.Trim('/'), maxValue = _maxValue }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> TakeOrder(Models.Front.OrderViewModel model) { if (ModelState.IsValid) { try { var userManager = new UserManager(); string barcode = BarcodeFactory.GetBarcode(); bool isInsurance = !(model.CargoValue == null || model.CargoValue == ""); string senderPostcode = string.Empty; //寄方邮编 string receiverPostcode = string.Empty; //收方邮编 string senderLocation = string.Empty; //寄方地址经纬度 string receiverLocation = string.Empty; //收方地址经纬度 string region = string.Empty; //寄方邮编 string jsonPath = Server.MapPath("~/App_Data/PostCode.json"); string province = model.SLocation.Trim().Split(' ')[0]; string city = model.SLocation.Trim().Split(' ')[1] == "市辖区" ? province : model.SLocation.Trim().Split(' ')[1]; string district = model.SLocation.Trim().Split(' ')[2]; string address = model.SAddress; string key = ConfigurationManager.AppSettings["PostCodeKey"].ToString(); string url = "http://v.juhe.cn/postcode/search"; region = Region.GetRegion(province); if (model.SAddress.Contains("乡") || model.SAddress.Contains("镇")) { string paddress = address.Contains("乡") ? address.Substring(0, address.IndexOf("乡") + 1) : address.Substring(0, address.IndexOf("镇") + 1); senderPostcode = WebRequestService.QueryPostCodeByName(url, key, province, city, district, paddress, jsonPath); } else { senderPostcode = WebRequestService.QueryPostCodeByName(url, key, province, city, district, jsonPath); } //收方邮编 string rprovince = model.RLocation.Trim().Split(' ')[0]; string rcity = model.RLocation.Trim().Split(' ')[1] == "市辖区" ? rprovince : model.RLocation.Trim().Split(' ')[1]; string rdistrict = model.RLocation.Trim().Split(' ')[2]; string raddress = model.RAddress; if (model.RAddress.Contains("乡") || model.RAddress.Contains("镇")) { string paddress = raddress.Contains("乡") ? raddress.Substring(0, raddress.IndexOf("乡") + 1) : raddress.Substring(0, raddress.IndexOf("镇") + 1); receiverPostcode = WebRequestService.QueryPostCodeByName(url, key, rprovince, rcity, rdistrict, paddress, jsonPath); } else { receiverPostcode = WebRequestService.QueryPostCodeByName(url, key, rprovince, rcity, rdistrict, jsonPath); } //寄方地址经纬度 string locationUrl = "https://restapi.amap.com/v3/geocode/geo"; string lkey = ConfigurationManager.AppSettings["GdAppKey"].ToString(); string sk = ConfigurationManager.AppSettings["GdSecretKey"].ToString(); senderLocation = WebRequestService.QueryGDLocationByName(locationUrl, lkey, sk, province + city + district + address, city); //收方地址经纬度 receiverLocation = WebRequestService.QueryGDLocationByName(locationUrl, lkey, sk, rprovince + rcity + rdistrict + raddress, rcity); double freight = MaverickCost.CalcFreight(Convert.ToDouble(model.CargoWeight) * Convert.ToDouble(model.CargoUnit), Convert.ToDouble(model.CargoVolume) * Convert.ToDouble(model.CargoUnit)); double serviceCharge = 0; //得到起始网点 var webLocations = userManager.GetAllWebSiteLocationByType("1", city); string origns = string.Join("|", webLocations.Values); List <string> res = WebRequestService.CalcGroupDistance(origns, senderLocation, lkey, sk); string min = res[1]; int minIndex = 0, flag = 0; Guid webSiteId = new Guid(); for (int i = 1; i < res.Count; i++) { if (int.Parse(res[i]) < int.Parse(min)) { min = res[i]; minIndex = i; } } foreach (var locationkey in webLocations.Keys) { if (minIndex == flag) { webSiteId = locationkey; break; } ++flag; } var orderInfo = new LogisticsSystem.DTO.OrderInfoDto() { SName = model.SenderName, SMobliePhone = model.SMobliePhone.Trim(), SProvince = province + city + district, SAddress = model.SAddress.Trim(), SPostCode = senderPostcode, STelPhone = string.IsNullOrEmpty(model.STelPhone) ? "NULL" : model.STelPhone.Trim(), SFirmName = string.IsNullOrEmpty(model.SCompany) ? "NULL" : model.SCompany.Trim(), SLocation = senderLocation, RName = model.ReceiverName.Trim(), RMobliePhone = model.RMobliePhone.Trim(), RProvince = rprovince + rcity + rdistrict, RAddress = raddress, RPostCode = receiverPostcode, RTelPhone = string.IsNullOrEmpty(model.RTelPhone) ? "NULL" : model.RTelPhone.Trim(), RFirmName = string.IsNullOrEmpty(model.RCompany) ? "NULL" : model.RCompany.Trim(), RLocation = receiverLocation, BarCode = barcode, Region = region, Freight = freight, IsInsured = isInsurance, CargoName = model.CargoName.Trim(), CargoWeight = model.CargoWeight.Trim(), CargoVolume = model.CargoVolume.Trim(), UitNum = model.CargoUnit.Trim(), PayType = model.PayType.Trim() == "1", Mark = string.IsNullOrEmpty(model.Mark) ? "NULL" : model.Mark.Trim().Replace(' ', ','), TakeTime = model.TakeTime.Trim(), Risk = string.IsNullOrEmpty(model.Risk) ? "NULL" : model.Risk.Trim(), CargoValue = string.IsNullOrEmpty(model.CargoValue) ? "NULL" : model.CargoValue.Trim(), ServiceCharge = serviceCharge, StartWebsiteId = webSiteId }; await userManager.CreateOrder(orderInfo); } catch (Exception error) { return(Content("<script>alert('" + error.Message + "');history.go(-1);</script>")); } } else { return(Content("<script>alert('数据丢失了!');history.go(-1);</script>")); } return(Content("<script>alert('下单成功,感谢对本公司的信任!');window.location.href='/User/MainPage';</script>")); }