private void Synchronization(DeviceAlarmEntity entity) { if (Constant.Sysc) { try { //同步报警信息的时候需要根据设备ID找到对应的门,这里实际上是门作为设备来处理的 var door = _doorService.GetById(entity.DeviceUUID); var requestXml = GetXml(entity, door); Log.Debug(this.GetType().ToString(), requestXml); var areaS = new Lkb.DeviceAlarmServiceImplService(); var responseXml = areaS.insertDeviceAlarm(requestXml); Log.Debug(this.GetType().ToString(), responseXml); var resultRes = responseXml.Deserial <ResultResponse>(); var syncLog = new SyncLogEntity(); syncLog.SyncType = SyncLogEnum.InsertDeviceAlarm.ToString(); syncLog.ResquestXml = requestXml; syncLog.ResponseXml = responseXml; syncLog.SyncTime = DateTime.Now; syncLog.SyncResult = 0; syncLog.CommunityId = entity.CommunityUUID; if (resultRes != null && resultRes.Header != null) { var header = resultRes.Header; if (header.RspCode.Equals("0")) { var entity2 = _alarmRepository.GetById(entity.AlarmUUID); entity2.SyncVersion += 1; entity2.SyncStatus = true; _alarmRepository.Update(entity2); syncLog.SyncResult = 1; } } _syncService.InsertSyncLog(syncLog); } catch (Exception ex) { Log.Error(null, ex.Message); } } }
private string GetXml(DeviceAlarmEntity entity, DoorDto door) { var flag = entity.SyncVersion == 0 ? "C" : "U"; //增|删|改,C|D|U if (entity.Deleted) { flag = "D"; } var AlarmTypeDict = _dictService.GetById(entity.AlarmType); var xmlBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); xmlBuilder.Append("<Tpp2Fpp>"); xmlBuilder.Append("<ReqHeader>"); xmlBuilder.AppendFormat("<ReqSeqNo>{0}</ReqSeqNo>", Utils.MakeRndName()); xmlBuilder.AppendFormat("<ReqSPID>{0}</ReqSPID>", DESHelper.Encrypt3Des(Constant.LkbAccount, Constant.DescKeyBytes)); xmlBuilder.AppendFormat("<ReqCode>{0}</ReqCode>", DESHelper.Encrypt3Des(Constant.LkbPassword, Constant.DescKeyBytes)); xmlBuilder.Append("</ReqHeader>"); xmlBuilder.Append("<ReqBody>"); xmlBuilder.Append("<deviceAlarm>"); xmlBuilder.AppendFormat("<uuid>{0}</uuid>", entity.AlarmUUID); xmlBuilder.AppendFormat("<occur_date>{0}</occur_date>", entity.OccurTime.ToString("yyyyMMddHHmmss")); xmlBuilder.AppendFormat("<cdate>{0}</cdate>", entity.CreateTime.ToString("yyyyMMddHHmmss")); xmlBuilder.AppendFormat("<type>{0}</type>", AlarmTypeDict.DictCode); xmlBuilder.AppendFormat("<status>{0}</status>", entity.Status); xmlBuilder.AppendFormat("<udate>{0}</udate>", entity.UpdateTime.HasValue?entity.UpdateTime.Value.ToString("yyyyMMddHHmmss"):""); xmlBuilder.AppendFormat("<mac>{0}</mac>", ""); xmlBuilder.AppendFormat("<area_uuid>{0}</area_uuid>", door.AreaUUID); xmlBuilder.AppendFormat("<account_uuid>{0}</account_uuid>", Constant.LkbAccount); xmlBuilder.AppendFormat("<device_uuid>{0}</device_uuid>", entity.DeviceUUID); //存的时候是不是存门ID xmlBuilder.AppendFormat("<remark>{0}</remark>", entity.Remark); xmlBuilder.AppendFormat("<cardno>{0}</cardno>", string.Format("0000{0}", entity.CardNo)); xmlBuilder.AppendFormat("<dev_date>{0}</dev_date>", ""); xmlBuilder.AppendFormat("<ctrl_mac>{0}</ctrl_mac>", ""); xmlBuilder.AppendFormat("<flag>{0}</flag>", flag); xmlBuilder.Append("</deviceAlarm>"); xmlBuilder.Append("</ReqBody> "); xmlBuilder.Append("</Tpp2Fpp> "); return(xmlBuilder.ToString()); }
public static DeviceAlarmEntity ToEntity(this DeviceAlarmDto model, DeviceAlarmEntity destination) { return(model.MapTo(destination)); }
public static DeviceAlarmDto ToModel(this DeviceAlarmEntity entity) { return(entity.MapTo <DeviceAlarmEntity, DeviceAlarmDto>()); }