using BaseInfoClient.Response.Visitor; using Etor.Infrastructure.Common; using Etor.Infrastructure.Data; using Etor.Infrastructure.Serializer; using Etor.Infrastructure.WebApi; using ServiceClient; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; namespace BaseInfoClient.Extension { public static class QueryVisitorByOpenidOrId { public static async Task> QueryVisitorByOpenId(this BaseInfoHttpClient client , QueryMenJinVisitorRequest param, bool throwException = false) { try { var response = await client.CreateHttpClient().GetAsync( $"{client.BaseUrl}/api/visitor/v1/Request/QueryByOpenId?OwnerId={param.OwnerId}&Data.OpenId={param.OpenId}"); var content = await response.Content.ReadAsStringAsync(); var result = content.FromJsonTo>>(); return result.Data; } catch (Exception e) { LogHelper.Error("根据OwnerId获取住户", e); if (throwException) { BusinessException.Throw("获取住户信息失败"); } else { return new List(); } } return new List(); } public static async Task QueryVisitorById(this BaseInfoHttpClient client , QueryMenJinVisitorRequest param, bool throwException = false) { try { var response = await client.CreateHttpClient().GetAsync( $"{client.BaseUrl}/api/visitor/v1/Request/QueryById?OwnerId={param.OwnerId}&Data.Id={param.Id}&Data.Type={param.Type}"); var content = await response.Content.ReadAsStringAsync(); var result = content.FromJsonTo>(); return result.Data; } catch (Exception e) { LogHelper.Error("根据OwnerId获取住户", e); if (throwException) { BusinessException.Throw("获取住户信息失败"); } else { return new VisitorResponseItem(); } } return new VisitorResponseItem(); } /// /// 根据人脸ID获取访客信息 /// /// /// /// /// public static async Task QueryVisitorByFaceId(this BaseInfoHttpClient client , int ownerId,string faceId, bool throwException = false) { try { var response = await client.CreateHttpClient().GetAsync( $"{client.BaseUrl}/api/visitor/v1/Request/QueryByFaceId?OwnerId={ownerId}&Data.FaceId={faceId}"); var content = await response.Content.ReadAsStringAsync(); var result = content.FromJsonTo>(); return result.Data; } catch (Exception e) { LogHelper.Error("根据OwnerId获取住户", e); if (throwException) { BusinessException.Throw("获取住户信息失败"); } else { return new VisitorResponseItem(); } } return new VisitorResponseItem(); } /// /// 根据人脸ID获取访客信息 /// /// /// /// /// public static async Task> QueryVisitorProFace(this BaseInfoHttpClient client , int projectCode, string buildCode,string unit,int operaterID, int ownerID, bool throwException = false) { try { var response = await client.CreateHttpClient().GetAsync( $"{client.BaseUrl}/api/doorway/v1/device/GetFacesClient?OperaterID={operaterID}&OwnerID={ownerID}&Data.ProjectCode={projectCode}&Data.BuildCode={buildCode}&Data.Unit={unit}&Data.UserType=0"); var content = await response.Content.ReadAsStringAsync(); var result = content.FromJsonTo>>(); return result.Data; } catch (Exception e) { LogHelper.Error("根据OwnerId获取住户", e); if (throwException) { BusinessException.Throw("获取住户设备信息失败"); } else { return new List(); } } return new List(); } } }