/// <summary> /// 删除哨位终端数据 /// </summary> /// <param name="fp"></param> /// <param name="db"></param> private void DeleteSentinelFingerInfo(AllInOneContext.AllInOneContext db, Sentinel sen) { //移除已下发到位台的指纹 var sentinelFingers = db.Set <SentinelFingerPrintMapping>().Where(t => t.SentinelId.Equals(sen.SentinelId)).ToList(); if (sentinelFingers != null && sentinelFingers.Count > 0) { Guid ascsServerType = Guid.Parse("A0002016-E009-B019-E001-ABCD11300206"); var service = db.ServiceInfo.Include(t => t.ServerInfo). FirstOrDefault(t => t.ServiceTypeId.Equals(ascsServerType) && t.ServerInfo.OrganizationId.Equals(sen.DeviceInfo.OrganizationId)); if (service != null) { Task.Run(() => { try { _logger.LogInformation("清除哨位指纹 Begin..."); ASCSApi ascs = new ASCSApi(service); var sentinelCode = Int32.Parse(sen.DeviceInfo.Organization.OrganizationCode); var r = ascs.CleanFinger(sentinelCode, 0); db.Set <SentinelFingerPrintMapping>().RemoveRange(sentinelFingers); _logger.LogInformation("清除哨位指纹End,结果:{0}...", r.Success); } catch (Exception ex) { _logger.LogError("清除哨位指纹结果异常:{0}\r\n{1}", ex.Message, ex.StackTrace); } }); } } }
///// <summary> ///// 更新指纹 ///// </summary> ///// <param name="figure"></param> ///// <returns></returns> //[HttpPut] //[Route("~/Infrastructure/Staff/fingerprint")] //public IActionResult UpdateFingerprint([FromBody]Fingerprint figure) //{ // try // { // using (var db = new AllInOneContext.AllInOneContext()) // { // db.Set<Fingerprint>().Update(figure); // db.SaveChanges(); // return new NoContentResult(); // } // } // catch (DbUpdateException dbEx) // { // return BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message }); // } // catch (Exception ex) // { // return BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message }); // } //} ///// <summary> ///// 删除指纹 ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //[HttpDelete] //[Route("~/Infrastructure/Staff/fingerprint/id={id}")] //public IActionResult DeleteFingerprint(Guid id) //{ // try // { // using (var db = new AllInOneContext.AllInOneContext()) // { // var fp = db.Set<Fingerprint>().FirstOrDefault(t => t.FingerprintId.Equals(id)); // if (fp != null) // { // //查找关联的哨位,删除下发记录 // DeleteFingerDispatch(fp, db); // //删除数据库中记录 // db.Set<Fingerprint>().Remove(fp); // db.SaveChanges(); // return new NoContentResult(); // } // else // return NotFound(); // } // } // catch (DbUpdateException dbEx) // { // return BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message }); // } // catch (Exception ex) // { // return BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message }); // } //} /// <summary> /// 删除哨位终端数据 /// </summary> /// <param name="fp"></param> /// <param name="db"></param> private void DeleteFingerDispatch(Fingerprint fp, AllInOneContext.AllInOneContext db) { //var sentinels = db.Sentinel.Include(t => t.DeviceInfo).Include(t => t.FingerDispatch).ToList().Where(t => t.FingerDispatch != null // && t.FingerDispatch.Exists(f => f.FingerprintId.Equals(fp.FingerprintId))).ToList(); //foreach (var sen in sentinels) //{ // //调用哨位所在 // Guid ascsServerType = Guid.Parse("A0002016-E009-B019-E001-ABCD11300206"); // var service = db.ServiceInfo.Include(t => t.ServerInfo). // FirstOrDefault(t => t.ServiceTypeId.Equals(ascsServerType) && t.ServerInfo.OrganizationId.Equals(sen.DeviceInfo.OrganizationId)); // if (service != null) // { // try // { // ASCSApi ascs = new ASCSApi(service); // var r = ascs.CleanFinger(sen.DeviceInfo.IPDeviceCode, fp.FingerprintNo); // //移除已下发到位台的指纹 // db.Set<SentinelFingerPrintMapping>().RemoveRange( // db.Set<SentinelFingerPrintMapping>().Where(t => t.FingerprintId.Equals(fp.FingerprintId))); // _logger.LogInformation("删除下发到哨位的指纹结果:{0}...", r.Success); // } // catch (Exception ex) // { // _logger.LogError("删除下发到哨位的指纹异常:{0}\r\n{1}", ex.Message, ex.StackTrace); // } // return; // } //} //获取下发了该指纹的哨位台 var sentinels = db.SentinelFingerPrintMapping.Include(t => t.Sentinel).ThenInclude(t => t.DeviceInfo) .ThenInclude(t => t.Organization) .Where(t => t.FingerprintId.Equals(fp.FingerprintId)).ToList().Select(t => t.Sentinel).ToList(); foreach (var sen in sentinels) { Guid ascsServerType = Guid.Parse("A0002016-E009-B019-E001-ABCD11300206"); var deviceOrg = db.Organization.FirstOrDefault(t => t.OrganizationId.Equals(sen.DeviceInfo.OrganizationId)); var service = db.ServiceInfo.Include(t => t.ServerInfo). FirstOrDefault(t => t.ServiceTypeId.Equals(ascsServerType) && (t.ServerInfo.OrganizationId.Equals(deviceOrg.ParentOrganizationId) || t.ServerInfo.OrganizationId.Equals(deviceOrg.OrganizationId))); if (service != null) { try { ASCSApi ascs = new ASCSApi(service); //var sentinelCode = Int32.Parse(sen.DeviceInfo.Organization.OrganizationCode); //var r = ascs.CleanFinger(sentinelCode, fp.FingerprintNo); var r = ascs.CleanFinger(sen.DeviceInfo.IPDeviceCode, fp.FingerprintNo); //移除已下发到位台的指纹 db.SentinelFingerPrintMapping.RemoveRange( db.SentinelFingerPrintMapping.Where(t => t.FingerprintId.Equals(fp.FingerprintId)).ToList()); _logger.LogInformation("删除下发到哨位的指纹结果:{0}...", r.Success); } catch (Exception ex) { _logger.LogError("删除下发到哨位的指纹异常:{0}\r\n{1}", ex.Message, ex.StackTrace); } return; } } }