private Domain.AggregatesModel.DeviceAggregate.Device CreateDevice(CreateDeviceCommand request, Domain.AggregatesModel.DeviceTypeAggregate.DeviceType deviceType) { if (nameof(Terminal).Equals(deviceType.Code, StringComparison.InvariantCultureIgnoreCase)) { Terminal terminal = new Terminal(request.TentantId, request.DeviceName, request.EquipNum, request.Enabled, request.ModelCode, request.DeviceIP, request.DevicePort, request.ServerIP, request.ServerPort, request.Description, null, request.Connection, request.RegionId, null); if (deviceType.Channels != null) { foreach (var channel in deviceType.Channels) { //添加回路 terminal.AddChannel(terminal.Id, channel.PortNumber, channel.PortType); if (channel.PortNumber < 6) { //添加设备定时任务 for (int taskId = 1; taskId <= 3; taskId++) { terminal.AddTimedTask(terminal.Id, channel.PortNumber, false, taskId.ToString(), execAction: ExecAction.On); terminal.AddTimedTask(terminal.Id, channel.PortNumber, false, taskId.ToString(), execAction: ExecAction.Off); } } } } //添加控制器 if (deviceType.Controllers != null) { foreach (var controller in deviceType.Controllers) { terminal.AddController(terminal.Id, controller.ControllerCode, controllerStatus: controller.ControllerStatus, description: controller.Description); } } //添加传感器 if (deviceType.Sensors != null) { foreach (var sensor in deviceType.Sensors) { terminal.AddSensor(terminal.Id, sensor.SensorCode); } } //添加配件 if (deviceType.Parts != null) { foreach (var part in deviceType.Parts) { terminal.AddPart(terminal.Id, part.PartCode, enabled: part.Enabled); } } //添加设备功能 if (deviceType.Functions != null) { foreach (var function in deviceType.Functions) { terminal.AddFunction(terminal.Id, function.FunctionCode, function.CallbackCodes, function.SettingTypeName, setting: function.Setting); } } //TODO:添加负载 terminal.AddLoad(terminal.TentantId, "补光灯", $"{terminal.EquipNum}_{nameof(DeviceCode.FillLight)}_1", nameof(DeviceCode.FillLight), 1, parentId: terminal.Id); for (int channelIndex = 1; channelIndex < 9; channelIndex++) { string key = $"{terminal.EquipNum}_{nameof(DeviceCode.Camera)}_{channelIndex}"; terminal.AddLoad(terminal.TentantId, "摄像机" + channelIndex, $"{terminal.EquipNum}_{nameof(DeviceCode.Camera)}_{channelIndex}", nameof(DeviceCode.Camera), 2, parentId: terminal.Id); } terminal.AddLoad(terminal.TentantId, "光通", $"{terminal.EquipNum}_{nameof(DeviceCode.Optical)}_1", nameof(DeviceCode.Optical), 3, parentId: terminal.Id); terminal.AddLoad(terminal.TentantId, "加热电源", $"{terminal.EquipNum}_{nameof(DeviceCode.Heater)}_1", nameof(DeviceCode.Heater), 4, parentId: terminal.Id); terminal.AddLoad(terminal.TentantId, "风扇", $"{terminal.EquipNum}_{nameof(DeviceCode.Fan)}_1", nameof(DeviceCode.Fan), 5, parentId: terminal.Id); //添加警报器 if (deviceType.Alarms != null) { foreach (var alarm in deviceType.Alarms) { terminal.AddAlarm(terminal.Id, alarm.AlarmCode, alarm.TargetCode, alarm.NormalValue); } } //TODO:设置默认位置 terminal.SetLocation(0, 0, false); return(terminal); } else { throw new DeviceDomainException("不支持的设备类型"); } }