设备聚合服务,业务系统聚合服务
This commit is contained in:
parent
ee75cda031
commit
1512a9f5d4
@ -0,0 +1,22 @@
|
||||
using JiShe.ServicePro;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.IoT.BusinessSystemAggregation
|
||||
{
|
||||
/// <summary>
|
||||
/// 业务系统聚合服务
|
||||
/// </summary>
|
||||
public interface IBusinessSystemAggregationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 接收业务系统指令信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<HttpDataResult> ReceiveCommandInfoAsync(OpenApiRequest input);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
using JiShe.ServicePro.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace JiShe.IoT.DeviceAggregation.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备聚合新增设备
|
||||
/// </summary>
|
||||
public class CreateDeviceAggregationInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 表通信地址
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "设备地址不能为空")]
|
||||
public string DeviceAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物联网平台类型
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "物联网平台类型不能为空")]
|
||||
public IoTPlatformTypeEnum IoTPlatform { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 电表密码
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "电表密码不能为空")]
|
||||
public string PlatformPassword { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 集中器在物联网平台中对应的产品Id
|
||||
/// </summary>
|
||||
public string IoTPlatformProductId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 集中器在物联网平台中对应的设备Id或者名称
|
||||
/// </summary>
|
||||
public string IoTPlatformDeviceOpenInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物联网平台中对应的账号Id
|
||||
/// </summary>
|
||||
public string IoTPlatformAccountId { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
using JiShe.IoT.DeviceAggregation.Dto;
|
||||
using JiShe.ServicePro.Core;
|
||||
using JiShe.ServicePro.DeviceManagement.DeivceInfos.Dto;
|
||||
using JiShe.ServicePro.DeviceManagement.Meters.Dto;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp;
|
||||
|
||||
namespace JiShe.IoT.DeviceAggregation
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备聚合服务
|
||||
/// </summary>
|
||||
public interface IDeviceAggregationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> CreateAsync(CreateDeviceAggregationInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 删除设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
Task<bool> DeleteAsync(IdInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 根据设备ID查询设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
Task<DeviceManagementInfoDto> FindByIdAsync(IdInput input);
|
||||
}
|
||||
}
|
||||
@ -24,13 +24,6 @@ namespace JiShe.IoT.OneNETAggregation
|
||||
/// <summary>
|
||||
/// 获取OneNET产品列表
|
||||
/// </summary>
|
||||
Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input);
|
||||
|
||||
/// <summary>
|
||||
/// 接收业务系统指令信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<HttpDataResult> ReceiveBusinessSystemCommandInfoAsync(OpenApiRequest input);
|
||||
Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.ServicePro;
|
||||
using JiShe.ServicePro.Encrypt;
|
||||
using JiShe.ServicePro.Enums;
|
||||
using JiShe.ServicePro.Kafka.Consts;
|
||||
using JiShe.ServicePro.Kafka.Producer;
|
||||
using JiShe.ServicePro.ServerOptions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace JiShe.IoT.BusinessSystemAggregation
|
||||
{
|
||||
/// <summary>
|
||||
/// 业务系统聚合服务
|
||||
/// </summary>
|
||||
public class BusinessSystemAggregationService(IOptions<ServerApplicationOptions> options, IKafkaProducerService _producerService) :IoTAppService, IBusinessSystemAggregationService
|
||||
{
|
||||
ServerApplicationOptions srverOptions = options.Value;
|
||||
|
||||
/// <summary>
|
||||
/// 接收业务系统指令信息,缓存进Kafka
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
public async Task<HttpDataResult> ReceiveCommandInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, srverOptions.VerifySignatureToken);
|
||||
if (verifySignatureReult == false)//签名校验失败
|
||||
{
|
||||
return HttpDataResultExtensions.Failed<List<OneNetWorkshopProductListOutput>>("签名校验失败", -101, ResponeResultEnum.NotAllowed);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.Message))
|
||||
{
|
||||
return HttpDataResultExtensions.Failed<List<OneNetWorkshopProductListOutput>>("指令下发内容不能为空", -102, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
//将指令存储Kafka中
|
||||
await _producerService.ProduceAsync(KafkaTopicConsts.OneNETCommandIssuedEventName, $"{GuidGenerator.Create()}", input);
|
||||
|
||||
return HttpDataResultExtensions.Success("指令下发Kafka成功");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
using JiShe.IoT.DeviceAggregation.Dto;
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.ServicePro.Core;
|
||||
using JiShe.ServicePro.DeviceManagement.DeivceInfos;
|
||||
using JiShe.ServicePro.DeviceManagement.DeivceInfos.Dto;
|
||||
using JiShe.ServicePro.DeviceManagement.Meters.Dto;
|
||||
using JiShe.ServicePro.DeviceManagement.Permissions;
|
||||
using JiShe.ServicePro.OneNETManagement.OneNETDevices;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp;
|
||||
|
||||
namespace JiShe.IoT.DeviceAggregation
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备聚合服务
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="deviceAppService">设备服务</param>
|
||||
/// <param name="oneNETDeviceService">OneNET设备服务</param>
|
||||
public class DeviceAggregationService(ILogger<DeviceAggregationService> logger, IDeviceAppService deviceAppService, IOneNETDeviceService oneNETDeviceService) : IoTAppService, IDeviceAggregationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize(DeviceManagementPermissions.MeterManagement.Create)]
|
||||
public async Task<bool> CreateAsync(CreateDeviceAggregationInput input)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
CreateDeviceInput createDeviceInput = input.Adapt<CreateDeviceInput>();
|
||||
|
||||
var insertResult = await deviceAppService.CreateAsync(createDeviceInput);
|
||||
if (insertResult == null)
|
||||
{
|
||||
logger.LogError($"{nameof(CreateAsync)} 添加设备信息失败:{input.Serialize()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
//推送至OneNET平台
|
||||
var pushResult = await oneNETDeviceService.CreateDeviceInfoAsync(new CreateDeviceInfoInput()
|
||||
{
|
||||
DeviceName = $"{input.IoTPlatformProductId}{input.DeviceAddress}",
|
||||
ProductId = input.IoTPlatformProductId,
|
||||
OneNETAccountId = input.IoTPlatformAccountId,
|
||||
Description = input.DeviceAddress,
|
||||
});
|
||||
|
||||
if (pushResult == null || pushResult.Code != ServicePro.Enums.ResponeResultEnum.Success)
|
||||
{
|
||||
logger.LogError($"{nameof(CreateAsync)} 推送设备信息失败:{pushResult.Serialize()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdateDeviceInput updateDeviceInput = insertResult.Adapt<UpdateDeviceInput>();
|
||||
updateDeviceInput.IoTPlatformResponse = pushResult.Serialize();
|
||||
|
||||
var updateResult = await deviceAppService.UpdateAsync(updateDeviceInput);
|
||||
if (updateResult == null)
|
||||
{
|
||||
logger.LogError($"{nameof(CreateAsync)} 更新设备信息失败:{input.Serialize()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
[Authorize(DeviceManagementPermissions.MeterManagement.Delete)]
|
||||
public async Task<bool> DeleteAsync(IdInput input)
|
||||
{
|
||||
return await deviceAppService.DeleteAsync(input);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据设备ID查询设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public async Task<DeviceManagementInfoDto> FindByIdAsync(IdInput input)
|
||||
{
|
||||
return await deviceAppService.FindByIdAsync(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,14 +16,13 @@ using Microsoft.Extensions.Options;
|
||||
namespace JiShe.IoT.OneNETAggregation
|
||||
{
|
||||
/// <summary>
|
||||
/// 生产车间聚合服务
|
||||
/// OneNET聚合服务
|
||||
/// </summary>
|
||||
/// <param name="deviceAppService">设备管理信息服务</param>
|
||||
/// <param name="oneNETDeviceService">OneNET设备操作服务</param>
|
||||
/// <param name="_producerService">Kafka数据生产服务</param>
|
||||
/// <param name="oneNETDeviceService">OneNET设备操作服务</param>
|
||||
/// <param name="options">服务配置</param>
|
||||
/// <param name="logger"></param>
|
||||
public class OneNETAggregationService(IDeviceAppService deviceAppService, IOneNETDeviceService oneNETDeviceService, IKafkaProducerService _producerService, IOptions<ServerApplicationOptions> options, ILogger<OneNETAggregationService> logger) : IoTAppService, IOneNETAggregationService
|
||||
public class OneNETAggregationService(IDeviceAppService deviceAppService, IOneNETDeviceService oneNETDeviceService, IOptions<ServerApplicationOptions> options, ILogger<OneNETAggregationService> logger) : IoTAppService, IOneNETAggregationService
|
||||
{
|
||||
ServerApplicationOptions srverOptions = options.Value;
|
||||
|
||||
@ -84,7 +83,7 @@ namespace JiShe.IoT.OneNETAggregation
|
||||
CreateDeviceInput meterInfoEntity = new CreateDeviceInput()
|
||||
{
|
||||
DeviceAddress = productionEquipmentMessageBody.DeviceAddress,
|
||||
Password = productInfo.ProductAccesskey,
|
||||
PlatformPassword = productInfo.ProductAccesskey,
|
||||
IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId,
|
||||
IoTPlatformDeviceOpenInfo = productionEquipmentMessageBody.DeviceOpenInfo,
|
||||
DeviceName = productionEquipmentMessageBody.DeviceOpenInfo
|
||||
@ -141,38 +140,6 @@ namespace JiShe.IoT.OneNETAggregation
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收业务系统指令信息,缓存进Kafka
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
public async Task<HttpDataResult> ReceiveBusinessSystemCommandInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
bool verifySignatureReult = EncryptUtil.OpenApiVerifySignature(input.Message, input.Nonce, input.Timestamp, input.Signature, srverOptions.VerifySignatureToken);
|
||||
if (verifySignatureReult == false)//签名校验失败
|
||||
{
|
||||
return HttpDataResultExtensions.Failed<List<OneNetWorkshopProductListOutput>>("签名校验失败", -101, ResponeResultEnum.NotAllowed);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.Message))
|
||||
{
|
||||
return HttpDataResultExtensions.Failed<List<OneNetWorkshopProductListOutput>>("指令下发内容不能为空", -102, ResponeResultEnum.Fail);
|
||||
}
|
||||
|
||||
//将指令存储Kafka中
|
||||
await _producerService.ProduceAsync(KafkaTopicConsts.OneNETCommandIssuedEventName, $"{GuidGenerator.Create()}", input);
|
||||
|
||||
return HttpDataResultExtensions.Success("指令下发Kafka成功");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
using JiShe.IoT.BusinessSystemAggregation;
|
||||
using JiShe.IoT.CommonServices;
|
||||
using JiShe.IoT.CommonServices.Dto;
|
||||
using JiShe.IoT.DeviceAggregation;
|
||||
using JiShe.IoT.DeviceAggregation.Dto;
|
||||
using JiShe.IoT.OneNETAggregation;
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.ServicePro;
|
||||
using JiShe.ServicePro.Commons;
|
||||
using JiShe.ServicePro.Core;
|
||||
using JiShe.ServicePro.DeviceManagement.DeivceInfos.Dto;
|
||||
using JiShe.ServicePro.DeviceManagement.Meters.Dto;
|
||||
using JiShe.ServicePro.OneNETManagement.OneNETProducts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.IoT.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备聚合服务
|
||||
/// </summary>
|
||||
[Route("/Aggregation/Business")]
|
||||
public class BusinessSystemAggregationController : IoTController
|
||||
{
|
||||
private readonly IBusinessSystemAggregationService _businessSystemAggregationService;
|
||||
public BusinessSystemAggregationController(IBusinessSystemAggregationService businessSystemAggregationService)
|
||||
{
|
||||
_businessSystemAggregationService = businessSystemAggregationService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收业务系统指令信息
|
||||
/// </summary>
|
||||
[HttpPost(nameof(ReceiveCommandInfoAsync))]
|
||||
[SwaggerOperation(summary: "接收业务系统指令信息", Tags = new[] { "AggregationBusiness" })]
|
||||
public async Task<HttpDataResult> ReceiveCommandInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
return await _businessSystemAggregationService.ReceiveCommandInfoAsync(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
using JiShe.IoT.CommonServices;
|
||||
using JiShe.IoT.CommonServices.Dto;
|
||||
using JiShe.IoT.DeviceAggregation;
|
||||
using JiShe.IoT.DeviceAggregation.Dto;
|
||||
using JiShe.IoT.OneNETAggregation;
|
||||
using JiShe.IoT.OneNETAggregation.Dto;
|
||||
using JiShe.ServicePro;
|
||||
using JiShe.ServicePro.Commons;
|
||||
using JiShe.ServicePro.Core;
|
||||
using JiShe.ServicePro.DeviceManagement.DeivceInfos.Dto;
|
||||
using JiShe.ServicePro.DeviceManagement.Meters.Dto;
|
||||
using JiShe.ServicePro.OneNETManagement.OneNETProducts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiShe.IoT.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备聚合服务
|
||||
/// </summary>
|
||||
[Route("/Aggregation/Device")]
|
||||
public class DeviceAggregationController : IoTController
|
||||
{
|
||||
private readonly IDeviceAggregationService _deviceAggregationService;
|
||||
public DeviceAggregationController(IDeviceAggregationService deviceAggregationService)
|
||||
{
|
||||
_deviceAggregationService = deviceAggregationService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建设备信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost(nameof(CreateAsync))]
|
||||
[SwaggerOperation(summary: "创建设备信息", Tags = new[] { "AggregationDevice" })]
|
||||
public async Task<bool> CreateAsync(CreateDeviceAggregationInput input)
|
||||
{
|
||||
return await _deviceAggregationService.CreateAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除设备信息
|
||||
/// </summary>
|
||||
[HttpPost(nameof(DeleteAsync))]
|
||||
[SwaggerOperation(summary: "删除设备信息", Tags = new[] { "AggregationDevice" })]
|
||||
public async Task<bool> DeleteAsync(IdInput input)
|
||||
{
|
||||
return await _deviceAggregationService.DeleteAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据设备ID查询设备信息
|
||||
/// </summary>
|
||||
[HttpPost(nameof(FindByIdAsync))]
|
||||
[SwaggerOperation(summary: "根据设备ID查询设备信息", Tags = new[] { "AggregationDevice" })]
|
||||
public async Task<DeviceManagementInfoDto> FindByIdAsync(IdInput input)
|
||||
{
|
||||
return await _deviceAggregationService.FindByIdAsync(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,16 +45,6 @@ namespace JiShe.IoT.Controllers
|
||||
public async Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetProductListAsync(OpenApiRequest input)
|
||||
{
|
||||
return await _oneNETAggregationServiceService.GetProductListAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收业务系统指令信息
|
||||
/// </summary>
|
||||
[HttpPost(nameof(ReceiveBusinessSystemCommandInfoAsync))]
|
||||
[SwaggerOperation(summary: "接收业务系统指令信息", Tags = new[] { "AggregationOneNET" })]
|
||||
public async Task<HttpDataResult> ReceiveBusinessSystemCommandInfoAsync(OpenApiRequest input)
|
||||
{
|
||||
return await _oneNETAggregationServiceService.ReceiveBusinessSystemCommandInfoAsync(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user