/// <summary> /// 更新设施 /// </summary> /// <param name="facility">设施更新数据</param> /// <returns></returns> public async Task <XResponseMessage> ProcessAsync(FacilityModel facility) { if (facility == null) { return(null); } if (!_facilityService.CheckCode(facility.Serialnum)) { return(ResultHelper.CreateMessage("设施不存在", ErrorType.FacilityNotExists)); } var facilityType = await _facilityTypeService.GetByIdAsync(facility.FacilityType); //不存在的设施类型无法更新 if (facilityType == null) { return(ResultHelper.CreateMessage("设施类型不存在", ErrorType.FacilityTypeNotExists)); } var item = await _facilityService.GetFacilityByIdAsny(facility.Serialnum); //数据库中存在该设施并且创建时间大于最新的更新时间 if (item == null || !(facility.CreateTime > item.UpdateTime)) { return(null); } item.Serialnum = facility.Serialnum; item.Name = facility.Name; item.FarmSerialnum = facility.Farm; item.FacilityTypeSerialnum = facility.FacilityType; item.UpdateTime = facility.CreateTime ?? DateTime.Now; item.FarmSerialnum = facility.Farm; try { var result = await _facilityService.UpdateFacilityAsnyc(item); LogHelper.Info("[设施]设施{0}{1}更新{2}", item.Name, item.Serialnum, result); return(ResultHelper.CreateMessage($"更新设施{(result ? "成功" : "失败")}", result ? ErrorType.NoError : ErrorType.InternalError)); } catch (AggregateException ex) { return(ResultHelper.CreateExceptionMessage(ex, "更新设施失败")); } return(null); }
public async Task <XResponseMessage> ProcessAsync(ManageDataBlock manageDataBlock) { if (manageDataBlock == null) { return(null); } if (manageDataBlock.FacilityAdd != null) { try { return (await AhnqIotContainer.Container.Resolve <FacilityAddProcess>() .ProcessAsync(manageDataBlock.FacilityAdd)); } catch (AggregateException ex) { return(ResultHelper.CreateExceptionMessage(ex, "添加设施失败", ErrorType.InternalError)); } } if (manageDataBlock.FacilityUpdate != null) { try { return (await AhnqIotContainer.Container.Resolve <FacilityUpdateProcess>() .ProcessAsync(manageDataBlock.FacilityUpdate)); } catch (AggregateException ex) { return(ResultHelper.CreateExceptionMessage(ex, "更新设施失败", ErrorType.InternalError)); } } if (manageDataBlock.DeviceAdd != null) { try { return (await AhnqIotContainer.Container.Resolve <DeviceAddProcess>() .ProcessAsync(manageDataBlock.DeviceAdd)); } catch (AggregateException ex) { return(ResultHelper.CreateExceptionMessage(ex, "添加设备失败", ErrorType.InternalError)); } } if (manageDataBlock.DeviceUpdate != null) { try { return (await AhnqIotContainer.Container.Resolve <DeviceUpdateProcess>() .ProcessAsync(manageDataBlock.DeviceUpdate)); } catch (AggregateException ex) { return(ResultHelper.CreateExceptionMessage(ex, "更新设备失败", ErrorType.InternalError)); } } if (manageDataBlock.MediaAdd != null) { try { return (await AhnqIotContainer.Container.Resolve <MediaAddProcess>().ProcessAsync(manageDataBlock.MediaAdd)); } catch (AggregateException ex) { return(ResultHelper.CreateExceptionMessage(ex, "添加视频设备失败", ErrorType.InternalError)); } } if (manageDataBlock.MediaUpdate != null) { try { return (await AhnqIotContainer.Container.Resolve <MediaUpdateProcess>() .ProcessAsync(manageDataBlock.MediaUpdate)); } catch (AggregateException ex) { return(ResultHelper.CreateExceptionMessage(ex, "更新视频设备失败", ErrorType.InternalError)); } } //旧版本 await AhnqIotContainer.Container.Resolve <FacilityAddProcess>().ProcessAsync(manageDataBlock.FacilityAddDatas); await AhnqIotContainer.Container.Resolve <FacilityUpdateProcess>() .ProcessAsync(manageDataBlock.FacilityUpdateDatas); return(null); }