public List<RouteDataResponseItem> ClientSubmitRouteDataToCenterrServer([FromBody]List<RouteDataRequestItem> routeDatas) { if (routeDatas == null) { throw new BadRequestException(); } List<RouteData> dbItems = new List<RouteData>(); IPRepository ipr = new IPRepository(); foreach (var item in routeDatas) { if (item == null) { continue; } RouteData dbItem = new RouteData(); dbItem.GroupID = item.ParentUID; dbItem.T1 = item.T1; dbItem.T2 = item.T2; dbItem.T3 = item.T3; dbItem.RouteIP = item.RouteIP; dbItem.RouteDate = item.RouteDate; dbItem.SeqNoInGroup = item.SeqNo; dbItem.CreatedBy = Context.LoginName; dbItem.LastUpdatedBy = Context.LoginName; string ipBelongTo = ""; if (!String.IsNullOrWhiteSpace(item.RouteIP)) { var ipEntity = ipr.RetriveIP(item.RouteIP); if (ipEntity != null) { ipBelongTo = String.IsNullOrWhiteSpace(ipEntity.IPBelongTo) ? ipEntity.Country : ipEntity.IPBelongTo; dbItem.IPBelongTo = ipBelongTo; dbItem.IPBelongToProvince = ipEntity.Province; dbItem.IPBelongToCity = ipEntity.City; } } dbItems.Add(dbItem); } RouteDataRepository rdr = new RouteDataRepository(); var resultDbItems = rdr.AddRoutDatas(dbItems); List<RouteDataResponseItem> result = new List<RouteDataResponseItem>(); foreach (var item in resultDbItems) { RouteDataResponseItem rItem = new RouteDataResponseItem(); rItem.ParentUID = item.GroupID; rItem.SeqNo = (item.SeqNoInGroup.HasValue ? item.SeqNoInGroup.Value : 0); rItem.RouteIP = item.RouteIP; rItem.IPBelongTo = item.IPBelongTo; rItem.IPBelongToProvince = item.IPBelongToProvince; rItem.IPBelongToCity = item.IPBelongToCity; result.Add(rItem); } return result; }
public MonitorDataResponse MoniterServerSubmitToCenterrServer([FromBody]MonitorDataRequest monitorData) { if (monitorData == null) { throw new BadRequestException(); } // 查询客户端IP所属的运营商 IPRepository ipRep = new IPRepository(); var ipEntity = ipRep.RetriveIP(monitorData.ClientPublicIP); string realOperator = ipEntity == null ? null : ipEntity.IPBelongTo; string realOperatorProvince = null; string realOperatorCity = null; if (ipEntity != null) { realOperatorProvince = ipEntity.Province; realOperatorCity = ipEntity.City; } bool isSameProvice = false; if(String.IsNullOrWhiteSpace(realOperatorProvince) && String.IsNullOrWhiteSpace(monitorData.ExpectedOperatorProvice)) { isSameProvice = true; } else if(monitorData.ExpectedOperatorProvice.Equals(realOperatorProvince)) { isSameProvice = true; } var status = IPMonitorStatus.Pending; if (!String.IsNullOrEmpty(realOperator)) { realOperator = realOperator.Trim(); } if (String.IsNullOrEmpty(realOperator)) { if (ipEntity != null) { realOperator = ipEntity.IPBelongTo = ipEntity.Country; } status = IPMonitorStatus.Unknown; } else if (isSameProvice && isISPMatched(monitorData.ExpectedOperator,realOperator)) { status = IPMonitorStatus.Normal; } else { status = IPMonitorStatus.Exception; } ClientIP clientIP = new ClientIP { ClientProvince = monitorData.ClientProvince, ClientCity = monitorData.ClientCity, ClientDistinct = monitorData.ClientDistinct, ClientDetailAddr = monitorData.ClientDetailAddress, ClientRecordor = monitorData.ClientRecordor, ClientPublicIP = monitorData.ClientPublicIP, ClientPrivateIP = monitorData.ClientPrivateIP, SubmitFromServerIP = Context.ClientIP, Status = (int)status, ExpectedOperatorProvince = monitorData.ExpectedOperatorProvice, ExpectedOperatorCity = monitorData.ExpectedOperatorCity, ExpectedOperator = monitorData.ExpectedOperator, RealOperator = realOperator, RealOperatorProvince = realOperatorProvince, RealOperatorCity = realOperatorCity, UserName = Context.LoginName }; MonitorDataRepository mdr = new MonitorDataRepository(); clientIP = mdr.Add(clientIP); MonitorDataResponse response = new MonitorDataResponse(); response.UID = clientIP.ID; response.RealOperator = realOperator; response.RealOperatorProvince = realOperatorProvince; response.RealOperatorCity = realOperatorCity; return response; }