public ActionResult AddShop(string keyValue, POS_ShopEntity entity) { //微信火星转百度 double Lon = double.Parse(entity.wxLon); double Lat = double.Parse(entity.wxLat); double bdLat, bdLon; MapConverter.GCJ02ToBD09(Lat, Lon, out bdLat, out bdLon); entity.bdLat = bdLat.ToString(); entity.bdLon = bdLon.ToString(); entity.OpenId = CurrentWxUser.OpenId; entity.NickName = CurrentWxUser.NickName; //根据坐标获取省市县信息 string url = @"http://restapi.amap.com/v3/geocode/regeo?location=" + Lon + "," + Lat + "&key=cf3dd05a8192fd1839628b39e589c89e&radius=1000&extensions=all";//output=XML& string responseJson = HttpClientHelper.Get(url); RestLocation restLocation = JsonConvert.DeserializeObject <RestLocation>(responseJson.Replace("[]", "\"\"")); entity.Province = restLocation.regeocode.addressComponent.province; entity.City = restLocation.regeocode.addressComponent.city; entity.CityCode = restLocation.regeocode.addressComponent.citycode; entity.District = restLocation.regeocode.addressComponent.district; //插入店铺表 posShopBll.SaveForm(keyValue, entity); return(Content("true")); }
public static void getCoordinate(string location, out double wxLat, out double wxLon, out double bdLat, out double bdLon) { string[] jw = location.Split(','); //微信转换百度坐标 wxLon = 0; wxLat = 0; bdLon = 0; bdLat = 0; if (jw.Length == 2) { wxLon = double.Parse(jw[0]); //经度 wxLat = double.Parse(jw[1]); //维度 MapConverter.GCJ02ToBD09(wxLat, wxLon, out bdLat, out bdLon); } }
/// <summary> /// 批量(新增) /// </summary> /// <param name="dtSource">实体对象</param> /// <returns></returns> public string BatchAddEntity(DataTable dtSource) { for (int i = 0; i < dtSource.Rows.Count; i++) { string CustomerName = dtSource.Rows[i][0].ToString(); //名称 string CustomerCapital = dtSource.Rows[i][1].ToString(); //注册资金 DateTime?CustomerBuildTime = null; if (!string.IsNullOrEmpty(dtSource.Rows[i][2].ToString())) { CustomerBuildTime = Convert.ToDateTime(dtSource.Rows[i][2].ToString()); //成立日期 } string CustomerWebsite = dtSource.Rows[i][3].ToString(); //网站 string CustomerMailbox = dtSource.Rows[i][4].ToString(); //邮箱 string CustomerScope = dtSource.Rows[i][5].ToString(); //经营范围 string CustomerAddress = dtSource.Rows[i][6].ToString(); //地址 string CustomerContacts = dtSource.Rows[i][7].ToString(); //法定代表人 string CustomerTelphone = dtSource.Rows[i][8].ToString(); //联系电话 string CustomerContactsSpare = dtSource.Rows[i][9].ToString(); //备用联系人 string CustomerTelphoneSpare = dtSource.Rows[i][10].ToString(); //备用联系方式 string CustomerDescription = dtSource.Rows[i][11].ToString(); //备注 try { IRepository db = new RepositoryFactory().BaseRepository().BeginTrans(); if (!string.IsNullOrEmpty(CustomerName)) { #region 重复导入判断 var shop_Data = db.FindEntity <POS_ShopEntity>(t => t.ShopName == CustomerName); if (shop_Data != null) { return(CustomerName + "店铺重复导入!"); } var company_Data = db.FindEntity <POS_OfficeCompanyEntity>(t => t.CompanyName == CustomerName); if (company_Data != null) { return(CustomerName + "公司重复导入!"); } #endregion #region 根据地址转换,获取坐标 RestApi restApi = new RestApi(); string url = @"http://restapi.amap.com/v3/geocode/geo?address=" + CustomerAddress + "&key=cf3dd05a8192fd1839628b39e589c89e";//output=XML& string responseJson = HttpClientHelper.Get(url); restApi = JsonConvert.DeserializeObject <RestApi>(responseJson.Replace("[]", "\"\"")); List <GeocodesItem> geo = restApi.geocodes; string wxLonStr = ""; //118.358518 string wxLatStr = ""; //35.049133 string bdLatStr = ""; string bdLonStr = ""; string Province = ""; string CityCode = ""; string City = ""; string District = ""; if (geo != null) { string location = geo[0].location; string district = geo[0].district; if (!string.IsNullOrEmpty(location) && !string.IsNullOrEmpty(district)) { string[] jw = location.Split(','); if (jw.Length == 2) { wxLonStr = jw[0]; wxLatStr = jw[1]; double wxLon = double.Parse(wxLonStr); double wxLat = double.Parse(wxLatStr); //微信转换百度坐标 double bdLat, bdLon; MapConverter.GCJ02ToBD09(wxLat, wxLon, out bdLat, out bdLon); bdLonStr = bdLon.ToString(); bdLatStr = bdLat.ToString(); } } Province = geo[0].province; CityCode = geo[0].citycode; City = geo[0].city; District = district; } #endregion #region 先查看当前坐标,是否与写字楼坐标一致 var office_Data = db.FindEntity <POS_OfficeEntity>(t => t.wxLat == wxLatStr && t.wxLon == wxLonStr); if (office_Data != null) { #region 如果一致,添加写字楼公司信息 POS_OfficeCompanyEntity officeCompanyEntity = new POS_OfficeCompanyEntity() { OfficeId = office_Data.Id, OfficeName = office_Data.OfficeName, CompanyName = CustomerName, CompanyAddress = CustomerAddress, Capital = CustomerCapital, //注册资金 BuildTime = CustomerBuildTime, //成立日期 Website = CustomerWebsite, //网站 Mailbox = CustomerMailbox, //邮箱 Scope = CustomerScope, //经营范围 Contacts = CustomerContacts, //法定代表人 Telphone = CustomerTelphone, //联系电话 ContactsSpare = CustomerContactsSpare, //备用联系人 TelphoneSpare = CustomerTelphoneSpare, //备用联系方式 Description = CustomerDescription, //备注 IsSee = 0, State = 0 }; officeCompanyEntity.Create(); db.Insert <POS_OfficeCompanyEntity>(officeCompanyEntity); #endregion } else { #region 判断一个坐标点上是否已经存在店铺信息 var zb_Data = db.FindEntity <POS_ShopEntity>(t => t.wxLat == wxLatStr && t.wxLon == wxLonStr); //如果已经存在店铺信息,添加公司信息 if (zb_Data != null) { #region 判断是否添加过写字楼信息 var shopOffice = db.FindEntity <POS_OfficeEntity>(t => t.wxLat == wxLatStr && t.wxLon == wxLonStr); if (shopOffice != null) { #region 存在写字楼,直接将当前数据插入该写字楼对应的写字楼公司表,并转移当前店铺信息到公司表 POS_OfficeCompanyEntity officeCompanyEntity = new POS_OfficeCompanyEntity() { OfficeId = shopOffice.Id, OfficeName = shopOffice.OfficeName, CompanyName = CustomerName, CompanyAddress = CustomerAddress, Capital = CustomerCapital, //注册资金 BuildTime = CustomerBuildTime, //成立日期 Website = CustomerWebsite, //网站 Mailbox = CustomerMailbox, //邮箱 Scope = CustomerScope, //经营范围 Contacts = CustomerContacts, //法定代表人 Telphone = CustomerTelphone, //联系电话 ContactsSpare = CustomerContactsSpare, //备用联系人 TelphoneSpare = CustomerTelphoneSpare, //备用联系方式 Description = CustomerDescription, //备注 IsSee = 0, State = 0 }; officeCompanyEntity.Create(); db.Insert <POS_OfficeCompanyEntity>(officeCompanyEntity); //处理当前的店铺信息,转换成公司信息 POS_OfficeCompanyEntity companyEntity = new POS_OfficeCompanyEntity() { OfficeId = shopOffice.Id, OfficeName = shopOffice.OfficeName, CompanyName = zb_Data.ShopName, CompanyAddress = zb_Data.ShopAddress, Capital = CustomerCapital, //注册资金 BuildTime = CustomerBuildTime, //成立日期 Website = CustomerWebsite, //网站 Mailbox = CustomerMailbox, //邮箱 Scope = zb_Data.Scope, //经营范围 Contacts = zb_Data.Contacts, //法定代表人 Telphone = zb_Data.Telphone, //联系电话 ContactsSpare = CustomerContactsSpare, //备用联系人 TelphoneSpare = CustomerTelphoneSpare, //备用联系方式 Description = CustomerDescription, //备注 IsSee = 0, State = 0 }; companyEntity.Create(); db.Insert <POS_OfficeCompanyEntity>(companyEntity); #endregion } else { #region 如果尚未添加写字楼,第一次先添加写字楼信息,再添加公司信息,将当店铺信息转移成公司信息 RestPoi restAPoi = new RestPoi(); //http://restapi.amap.com/v3/place/text?&keywords=山东省临沂市临工路100号&city=临沂&output=xml&offset=1&page=1&types=120000&key=cf3dd05a8192fd1839628b39e589c89e string urlPoi = @"http://restapi.amap.com/v3/place/text?keywords=" + CustomerAddress + "&city=" + City + "&offset=1&page=1&types=120000&key=cf3dd05a8192fd1839628b39e589c89e";//output=XML& string responseJsonPoi = HttpClientHelper.Get(urlPoi); restAPoi = JsonConvert.DeserializeObject <RestPoi>(responseJsonPoi.Replace("[]", "\"\"")); List <Pois> pois = restAPoi.pois; string OfficeName = ""; if (pois.Count != 0) { OfficeName = pois[0].name;//根据高德接口通过地址获取写字楼名称 } POS_OfficeEntity officeEntity = new POS_OfficeEntity() { wxLon = wxLonStr, wxLat = wxLatStr, bdLon = bdLonStr, bdLat = bdLatStr, Province = Province, CityCode = CityCode, City = City, District = District, OfficeName = OfficeName, OfficeAddress = CustomerAddress, IsSee = 0, State = 0 }; officeEntity.Create(); db.Insert <POS_OfficeEntity>(officeEntity); //再添加公司信息 POS_OfficeCompanyEntity officeCompanyEntity = new POS_OfficeCompanyEntity() { OfficeId = officeEntity.Id, OfficeName = officeEntity.OfficeName, CompanyName = CustomerName, CompanyAddress = CustomerAddress, Capital = CustomerCapital, //注册资金 BuildTime = CustomerBuildTime, //成立日期 Website = CustomerWebsite, //网站 Mailbox = CustomerMailbox, //邮箱 Scope = CustomerScope, //经营范围 Contacts = CustomerContacts, //法定代表人 Telphone = CustomerTelphone, //联系电话 ContactsSpare = CustomerContactsSpare, //备用联系人 TelphoneSpare = CustomerTelphoneSpare, //备用联系方式 Description = CustomerDescription, //备注 IsSee = 0, State = 0 }; officeCompanyEntity.Create(); db.Insert <POS_OfficeCompanyEntity>(officeCompanyEntity); //处理当前的店铺信息,转换成公司信息 POS_OfficeCompanyEntity companyEntity = new POS_OfficeCompanyEntity() { OfficeId = officeEntity.Id, OfficeName = officeEntity.OfficeName, CompanyName = zb_Data.ShopName, CompanyAddress = zb_Data.ShopAddress, Capital = CustomerCapital, //注册资金 BuildTime = CustomerBuildTime, //成立日期 Website = CustomerWebsite, //网站 Mailbox = CustomerMailbox, //邮箱 Scope = zb_Data.Scope, //经营范围 Contacts = zb_Data.Contacts, //法定代表人 Telphone = zb_Data.Telphone, //联系电话 ContactsSpare = CustomerContactsSpare, //备用联系人 TelphoneSpare = CustomerTelphoneSpare, //备用联系方式 Description = CustomerDescription, //备注 IsSee = 0, State = 0 }; companyEntity.Create(); db.Insert <POS_OfficeCompanyEntity>(companyEntity); #endregion } //删除当前店铺信息,因为已经转移成写字楼公司信息 db.Delete <POS_ShopEntity>(zb_Data.Id); #endregion } else { #region 存在,直接添加店铺信息 POS_ShopEntity entity = new POS_ShopEntity(); entity.wxLon = wxLonStr; entity.wxLat = wxLatStr; entity.bdLon = bdLonStr; entity.bdLat = bdLatStr; entity.Province = Province; entity.CityCode = CityCode; entity.City = City; entity.District = District; entity.ShopName = CustomerName; //店铺名称 entity.ShopAddress = CustomerAddress; //地址 entity.Capital = CustomerCapital; //注册资金 entity.BuildTime = CustomerBuildTime; //成立日期 entity.Website = CustomerWebsite; //网站 entity.Mailbox = CustomerMailbox; //邮箱 entity.Scope = CustomerScope; //经营范围 entity.Contacts = CustomerContacts; //法定代表人 entity.Telphone = CustomerTelphone; //联系电话 entity.ContactsSpare = CustomerContactsSpare; //备用联系人 entity.TelphoneSpare = CustomerTelphoneSpare; //备用联系方式 entity.Description = CustomerDescription; //备注 entity.IsSee = 0; entity.State = 0; //entity.SellerId = OperatorProvider.Provider.Current().UserId; //entity.SellerName = OperatorProvider.Provider.Current().UserName; entity.Create(); db.Insert <POS_ShopEntity>(entity); #endregion } #endregion } #endregion } db.Commit(); } catch (Exception ex) { int j = i + 2; return("执行到第" + j + "行。" + CustomerName + ex.Message); } } return("导入成功"); }