/// <summary> /// 请求海康服务器图片资源 /// </summary> /// <param name="picSvr"></param> /// <param name="picPath"></param> /// <returns></returns> public ActionResult GetHikImagePath(string picSvr, string picPath) { string imagePath = string.Empty; var pitem = pdata.GetItemValue("Hikappkey"); //海康服务器密钥 var baseurl = pdata.GetItemValue("HikBaseUrl"); //海康服务器地址 var HikHttpsIP = pdata.GetItemValue("HikHttpsIP"); //海康平台访问IP string Key = string.Empty; string Signature = string.Empty; if (!string.IsNullOrEmpty(pitem)) { Key = pitem.Split('|')[0]; Signature = pitem.Split('|')[1]; } string Url = "/artemis/api/video/v1/events/picture";//接口地址 var model = new { svrIndexCode = picSvr, picUri = picPath, netProtocol = "http" }; HttpUtillibKbs.SetPlatformInfo(Key, Signature, HikHttpsIP, 443, true); byte[] result = HttpUtillibKbs.HttpPost(Url, JsonConvert.SerializeObject(model), 20); string UserMsg = System.Text.Encoding.UTF8.GetString(result); dynamic imageObj = JsonConvert.DeserializeObject <dynamic>(UserMsg); if (imageObj != null && imageObj.code.ToString() == "0") { imagePath = imageObj.data.picUrl; } return(Content(imagePath)); }
/// <summary> /// 批量录入人脸 /// </summary> public bool SaveFace(List <TemporaryUserEntity> insertList, List <TemporaryUserEntity> updateList, string baseUrl, string Key, string Signature) { //开始事物 var res = DbFactory.Base().BeginTrans(); try { string url = "/artemis/api/resource/v1/face/single/add"; //res.Insert<TemporaryUserEntity>(insertList); // 批量导入添加人脸信息 res.Update <TemporaryUserEntity>(updateList); res.Commit(); //循环调用人脸接口增加 foreach (var insert in updateList) { var model = new { personId = insert.USERID, faceData = insert.ImgData }; HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseUrl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(url, JsonConvert.SerializeObject(model), 20); Thread.Sleep(1000);//控制上传照片速度,否则cpu处理不过来 //string msg = System.Text.Encoding.UTF8.GetString(result); //string msg = SocketHelper.LoadCameraList(model, baseUrl, url, Key, Signature); } return(true); } catch (Exception e) { res.Rollback(); return(false); } }
/// <summary> /// 电厂用户批量分配卡号 /// </summary> private void SetLoadUserCarNo1(List <TemporaryUserEntity> list, string baseUrl, string Key, string Signature) { var url = "/artemis/api/cis/v1/card/bindings"; List <cardList1> cardList = new List <cardList1>(); if (list.Count > 0 && list.Count < 50) { foreach (var Item in list) {//批量开卡最大支持50张卡 cardList1 entity = new cardList1(); entity.cardNo = Item.Tel.Trim(); entity.personId = Item.USERID; entity.cardType = 1; cardList.Add(entity); } var model = new { startDate = Convert.ToDateTime(list[0].startTime).ToString("yyyy-MM-dd"), endDate = Convert.ToDateTime(list[0].EndTime).ToString("yyyy-MM-dd"), cardList }; //string msg = SocketHelper.LoadCameraList(model, baseUrl, url, Key, Signature); HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseUrl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(url, JsonConvert.SerializeObject(model), 20); //string msg = System.Text.Encoding.UTF8.GetString(result); //parkList2 pl = JsonConvert.DeserializeObject<parkList2>(msg); //if (pl != null && pl.code == "0") //{ // //UploadUserlimits(list, baseUrl, Key, Signature); //} } }
/// <summary> /// 给新添加的人员单个分配卡号 /// </summary> private void SetLoadUserCarNo(TemporaryUserEntity Item, string baseUrl, string Key, string Signature) { var url = "/artemis/api/cis/v1/card/bindings"; List <cardList1> cardList = new List <cardList1>(); List <TemporaryUserEntity> list = new List <TemporaryUserEntity>(); list.Add(Item); cardList1 entity = new cardList1(); string time = DateTime.Now.ToString("yyyyMMddHHmmss"); var no = Str.PinYin(Item.UserName).ToUpper() + time;//卡号唯一 if (Item.Istemporary == 0) { no = Item.Tel.Trim(); } //非临时人员 entity.cardNo = no; entity.personId = Item.USERID; entity.cardType = 1; cardList.Add(entity); var model = new { startDate = Convert.ToDateTime(Item.startTime).ToString("yyyy-MM-dd"), endDate = Convert.ToDateTime(Item.EndTime).ToString("yyyy-MM-dd"), cardList }; HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseUrl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(url, JsonConvert.SerializeObject(model), 20); if (result != null) { string msg = System.Text.Encoding.UTF8.GetString(result); } }
/// <summary> /// 单个添加人脸 /// </summary> public void SaveSingleFace(TemporaryUserEntity insert) { DataItemDetailService data = new DataItemDetailService(); var pitem = data.GetItemValue("Hikappkey"); //密钥 var baseurl = data.GetItemValue("HikBaseUrl"); //海康地址 string Key = string.Empty; string Signature = string.Empty; string url = "/artemis/api/resource/v1/face/single/add"; if (!string.IsNullOrEmpty(pitem)) { Key = pitem.Split('|')[0]; Signature = pitem.Split('|')[1]; } var model = new { personId = insert.USERID, faceData = insert.ImgData }; HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseurl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(url, JsonConvert.SerializeObject(model), 20); //string msg = System.Text.Encoding.UTF8.GetString(result); //string msg = SocketHelper.LoadCameraList(model, baseurl, url, Key, Signature); }
/// <summary> /// 将临时人员信息上传到海康平台 /// </summary> /// <param name="entity"></param> /// <param name="list"></param> public AddJurisdictionEntity InsertTempUserHiK(TemporaryUserEntity entity, List <TemporaryUserEntity> list) { DataItemDetailService data = new DataItemDetailService(); var pitem = data.GetItemValue("Hikappkey"); //密钥 var baseurl = data.GetItemValue("HikBaseUrl"); //海康地址 string Key = string.Empty; string Signature = string.Empty; string no = new Random().Next(10, 888888).ToString(); if (!string.IsNullOrEmpty(pitem)) { Key = pitem.Split('|')[0]; Signature = pitem.Split('|')[1]; } string Url = "/artemis/api/resource/v1/person/single/add"; foreach (var item in list) { //人脸信息(base64必须为jpg格式) List <FaceEntity> faces = new List <FaceEntity>(); FaceEntity face = new FaceEntity(); face.faceData = item.ImgData; faces.Add(face); string orgcode = "root000000"; if (item.Istemporary == 0) { orgcode = item.Groupsid; } var model = new { personId = item.USERID, personName = item.UserName, gender = "1", orgIndexCode = orgcode, birthday = "1990-01-01", phoneNo = item.Tel, email = "*****@*****.**", certificateType = "990", certificateNo = no, jobNo = item.Tel, faces }; //string msg = SocketHelper.LoadCameraList(model, baseurl, Url, Key, Signature); HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseurl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(Url, JsonConvert.SerializeObject(model), 20); if (result != null) { string msg = System.Text.Encoding.UTF8.GetString(result); parkList1 pl = JsonConvert.DeserializeObject <parkList1>(msg); if (pl != null && pl.code == "0") { SetLoadUserCarNo(item, baseurl, Key, Signature); } } } //添加权限 return(UploadUserlimits(list, baseurl, Key, Signature)); }
/// <summary> /// 单条同步更换海康人脸信息 /// </summary> public string UpdateHumanFace(TemporaryUserEntity entity, string baseUrl, string Key, string Signature) { string res = string.Empty; try { string url = "/artemis/api/resource/v2/person/advance/personList"; var model = new { personIds = entity.USERID, pageNo = 1, pageSize = 100 }; //查询人脸图片唯一标识 //string msg = SocketHelper.LoadCameraList(model, baseUrl, url, Key, Signature); HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseUrl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(url, JsonConvert.SerializeObject(model), 20); string msg = System.Text.Encoding.UTF8.GetString(result); UserPicEntity re = JsonConvert.DeserializeObject <UserPicEntity>(msg); if (re != null && re.data.list.Count > 0) { string picfileid = string.Empty; foreach (var item in re.data.list) { foreach (var items in item.personPhoto) { picfileid = items.personPhotoIndexCode; } } //更换人脸图片 string upurl = "/artemis/api/resource/v1/face/single/update"; var delmodel = new { faceId = picfileid, faceData = entity.ImgData }; HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseUrl, 443, true); byte[] result1 = HttpUtillibKbs.HttpPost(upurl, JsonConvert.SerializeObject(delmodel), 20); msg = System.Text.Encoding.UTF8.GetString(result1); } else if (!string.IsNullOrEmpty(entity.ImgData)) {//没查到人脸唯一标示,表示人脸上传未成功就重新上传人脸信息 List <FacedataEntity> FaceList = new List <FacedataEntity>(); FacedataEntity faces = new FacedataEntity(); faces.UserId = entity.USERID; faces.ImgData = entity.ImgData; FaceList.Add(faces); res = SocketHelper.UploadFace(FaceList, baseUrl, Key, Signature, 1); } } catch (Exception) { } return(res); }
/// <summary> /// 根据出入权限配置快捷下载(IC卡号、人脸) /// </summary> public void downloadUserlimits(List <resourceInfos1> resourceInfos, string baseUrl, string Key, string Signature) { var url = "/artemis/api/acps/v1/authDownload/configuration/shortcut"; var model = new { taskType = 5, resourceInfos }; HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseUrl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(url, JsonConvert.SerializeObject(model), 20); //string msgs = System.Text.Encoding.UTF8.GetString(result); }
/// <summary> /// 同步修改海康人员信息 /// </summary> /// <param name="item"></param> /// <returns></returns> public string HikUpdateUserInfo(UserEntity item) { DataItemDetailBLL data = new DataItemDetailBLL(); var pitem = data.GetItemValue("Hikappkey"); //海康服务器密钥 var baseurl = data.GetItemValue("HikBaseUrl"); //海康服务器地址 string HikHttps = data.GetItemValue("HikHttps"); //海康1.4及以上版本https string Key = string.Empty; string Signature = string.Empty; if (!string.IsNullOrEmpty(pitem)) { Key = pitem.Split('|')[0]; Signature = pitem.Split('|')[1]; } string Url = "/artemis/api/resource/v1/person/single/update"; int Gender = item.Gender == "男" ? 1 : 0; var model = new { personId = item.UserId, personName = item.RealName, orgIndexCode = item.DepartmentId, gender = Gender, phoneNo = item.Mobile, certificateType = "111", certificateNo = item.IdentifyID, jobNo = item.EnCode }; string rtnMsg = string.Empty; if (!string.IsNullOrEmpty(HikHttps)) { HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseurl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(Url, JsonConvert.SerializeObject(model), 20); if (result != null) { rtnMsg = System.Text.Encoding.UTF8.GetString(result); } } else { rtnMsg = SocketHelper.LoadCameraList(model, baseurl, Url, Key, Signature); } return(rtnMsg); }
/// <summary> /// 获取电子围栏内所有摄像头信息 /// </summary> public string GetElectricFenceCameraList(SafeworkcontrolEntity data) { string ComerId = string.Empty; try { //三维监控点位服务接口地址 DataItemDetailBLL pdata = new DataItemDetailBLL(); var ThreeDApi = pdata.GetItemValue("kbsThreeMonitoringPoints"); space sp = new space(); spacedata sds = new spacedata(); List <spacegeo> geolist = new List <spacegeo>(); List <spacepnt> pntlist = new List <spacepnt>(); var comList = new KbscameramanageBLL().GetPageList("").Where(a => a.State == "在线" && a.CameraType == "枪机" && a.MonitoringArea != null).ToList(); spacegeo geo = new spacegeo(); geo.id = data.ID; if (data.Areacode != null) {//电子围栏坐标点 PositionsEntity alist = JsonConvert.DeserializeObject <PositionsEntity>(data.Areacode); List <double> dlist = new List <double>(); if (data.Areastate == 0) {//矩形 geo.type = 1; geo.distance = 0; //第一个点 dlist.Add(alist.positions[0].x); dlist.Add(alist.positions[0].z); //第二个点 dlist.Add(alist.positions[1].x); dlist.Add(alist.positions[0].z); //第三个点 dlist.Add(alist.positions[1].x); dlist.Add(alist.positions[1].z); //第四个点 dlist.Add(alist.positions[0].x); dlist.Add(alist.positions[1].z); //回到原点 dlist.Add(alist.positions[0].x); dlist.Add(alist.positions[0].z); geo.coor = dlist; geolist.Add(geo); } else if (data.Areastate == 1) {//圆形 geo.type = 0; dlist.Add(alist.positions[0].x); dlist.Add(alist.positions[0].z); geo.distance = Convert.ToInt32(data.Radius); geo.coor = dlist; geolist.Add(geo); } else if (data.Areastate == 2) {//手绘多边形 foreach (var ac in alist.positions) { dlist.Add(ac.x); dlist.Add(ac.z); } //闭合回到原点 dlist.Add(alist.positions[0].x); dlist.Add(alist.positions[0].z); geo.coor = dlist; geo.type = 1; geo.distance = 0; geolist.Add(geo); } foreach (var com in comList) {//摄像头坐标点集 PositionsEntity alist1 = JsonConvert.DeserializeObject <PositionsEntity>(com.MonitoringArea); if (alist1.floorID == alist.floorID) { List <double> dlist1 = new List <double>(); foreach (var ac in alist1.positions) { dlist1.Add(ac.x); dlist1.Add(ac.z); } //闭合回到原点 dlist1.Add(alist1.positions[0].x); dlist1.Add(alist1.positions[0].z); spacepnt pnt = new spacepnt() { id = com.CameraId, x = 0, y = 0, coor = dlist1 }; pntlist.Add(pnt); } } } sds.geo = geolist; sds.pnt = pntlist; sp.type = "2"; sp.data = sds; string rtn = HttpUtillibKbs.HttpThreeDPost(ThreeDApi, JsonConvert.SerializeObject(sp)); List <RtnSpace> rss = JsonConvert.DeserializeObject <List <RtnSpace> >(rtn); foreach (var item in rss) { if (string.IsNullOrEmpty(item.pntId)) { continue; } ComerId += item.pntId + ','; } return(ComerId); } catch (Exception er) { return(ComerId); } }
/// <summary> /// 添加出入权限配置 /// </summary> private AddJurisdictionEntity UploadUserlimits(List <TemporaryUserEntity> list, string baseUrl, string Key, string Signature) { AddJurisdictionEntity Juentity = new AddJurisdictionEntity(); if (list.Count > 0) { var url = "/artemis/api/acps/v1/auth_config/add"; List <personDatas1> personDatas = new List <personDatas1>(); personDatas1 entity = new personDatas1(); List <string> codes = new List <string>(); foreach (var item in list) { //将所有人放集合做一次任务下发 codes.Add(item.USERID); //人员Id } entity.indexCodes = codes; entity.personDataType = "person"; personDatas.Add(entity); #region 查询设备唯一编号 string Qres = list[0].PassPostId == null ? "" : list[0].PassPostId; string qc = string.Empty; var qclist = Qres.Split(','); for (int i = 0; i < qclist.Length; i++) { if (string.IsNullOrEmpty(qclist[i])) { continue; } qc += "'" + qclist[i] + "'" + ","; } string sql = string.Format("select t.itemname,t.itemvalue,t.itemcode from base_dataitem d join BASE_DATAITEMDETAIL t on d.itemid=t.itemid where d.itemcode in ({0}) order by t.sortcode asc", qc.TrimEnd(',')); #endregion if (!string.IsNullOrEmpty(Qres)) {//授权门岗不能为空 DataTable dt = this.BaseRepository().FindTable(sql); if (dt.Rows.Count > 0) { List <resourceInfos1> resourceInfos = new List <resourceInfos1>();//设备信息集合 for (int i = 0; i < dt.Rows.Count; i++) { List <int> nos = new List <int>(); if (dt.Rows[i][2].ToString() == "1") {//门禁通道 nos.Add(1); nos.Add(2); } else {//门禁 nos.Add(1); } resourceInfos1 entity1 = new resourceInfos1(); entity1.resourceIndexCode = dt.Rows[i][1].ToString();//设备唯一编号 entity1.resourceType = "acsDevice"; entity1.channelNos = nos; resourceInfos.Add(entity1); } string stime = Convert.ToDateTime(list[0].startTime).ToString("yyyy-MM-ddTHH:mm:ss+08:00", DateTimeFormatInfo.InvariantInfo);//ISO8601时间格式 string etime = Convert.ToDateTime(list[0].EndTime).ToString("yyyy-MM-ddTHH:mm:ss+08:00", DateTimeFormatInfo.InvariantInfo); var model = new { personDatas, resourceInfos, startTime = stime, // "2019-12-01T17:30:08+08:00", endTime = etime //"2019-12-19T17:30:08+08:00" }; HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseUrl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(url, JsonConvert.SerializeObject(model), 20); if (result != null) { string msgs = System.Text.Encoding.UTF8.GetString(result); JurisdictionEntity p1 = JsonConvert.DeserializeObject <JurisdictionEntity>(msgs); if (p1 != null && p1.code == "0") { Juentity.taskId = p1.data.taskId; Juentity.resourceInfos = resourceInfos; Juentity.type = "add"; } } } } } return(Juentity); }
/// <summary> /// 删除对应设备中出入权限配置记录 /// </summary> public AddJurisdictionEntity DelEquipmentRecord(List <TemporaryUserEntity> list, string baseUrl, string Key, string Signature) { AddJurisdictionEntity Juentity = new AddJurisdictionEntity(); if (list.Count > 0) { var url = "/artemis/api/acps/v1/auth_config/delete"; List <personDatas1> personDatas = new List <personDatas1>(); personDatas1 entity = new personDatas1(); List <string> codes = new List <string>(); foreach (var Item in list) { codes.Add(Item.USERID);//人员Id } entity.indexCodes = codes; entity.personDataType = "person"; personDatas.Add(entity); #region 查询设备唯一编号 string Qres = list[0].PassPostId == null ? "" : list[0].PassPostId; string qc = string.Empty; var qclist = Qres.Split(','); for (int i = 0; i < qclist.Length; i++) { if (string.IsNullOrEmpty(qclist[i])) { continue; } qc += "'" + qclist[i] + "'" + ","; } string sql = string.Format("select t.itemname,t.itemvalue,t.itemcode from base_dataitem d join BASE_DATAITEMDETAIL t on d.itemid=t.itemid where d.itemcode in ({0}) order by t.sortcode asc", qc.TrimEnd(',')); #endregion if (!string.IsNullOrEmpty(qc)) { //出入权限 DataTable dt = this.BaseRepository().FindTable(sql); if (dt.Rows.Count > 0) { List <resourceInfos1> resourceInfos = new List <resourceInfos1>();//设备信息集合 for (int i = 0; i < dt.Rows.Count; i++) { List <int> nos = new List <int>(); if (dt.Rows[i][2].ToString() == "1") {//门禁通道 nos.Add(1); nos.Add(2); } else {//门禁 nos.Add(1); } resourceInfos1 entity1 = new resourceInfos1(); entity1.resourceIndexCode = dt.Rows[i][1].ToString();//设备唯一编号 entity1.resourceType = "acsDevice"; entity1.channelNos = nos; resourceInfos.Add(entity1); } var model = new { personDatas, resourceInfos }; // string msgs = SocketHelper.LoadCameraList(model, baseUrl, url, Key, Signature); HttpUtillibKbs.SetPlatformInfo(Key, Signature, baseUrl, 443, true); byte[] result = HttpUtillibKbs.HttpPost(url, JsonConvert.SerializeObject(model), 20); if (result != null) { string msgs = System.Text.Encoding.UTF8.GetString(result); JurisdictionEntity p1 = JsonConvert.DeserializeObject <JurisdictionEntity>(msgs); if (p1 != null && p1.code == "0") { Juentity.taskId = p1.data.taskId; Juentity.resourceInfos = resourceInfos; Juentity.type = "del"; } } } } } return(Juentity); }