车间生产服务

This commit is contained in:
ChenYi 2025-07-23 11:47:23 +08:00
parent eebcd74b3b
commit 85214ab407
7 changed files with 95 additions and 26 deletions

View File

@ -37,13 +37,12 @@
"TreeModelClusterList": [ "47.110.53.196:6667", "47.110.60.222:6667", "47.110.62.104:6667" ],
"TableModelClusterList": [ "47.110.53.196:6667", "47.110.60.222:6667", "47.110.62.104:6667" ],
"PoolSize": 32,
"TableModelDataBaseName": "energy",
"DataBaseName": "jisheiotdata",
"OpenDebugMode": true,
"UseTableSessionPoolByDefault": false
},
"ServerApplicationOptions": {
"ServerTagName": "JiSheCollectBus10",
"SystemType": "Energy",
"FirstCollectionTime": "2025-04-28 15:07:00",
"AutomaticVerificationTime": "16:07:00",
"AutomaticTerminalVersionTime": "17:07:00",

View File

@ -56,7 +56,7 @@
"TreeModelClusterList": [ "172.21.40.198:6667", "172.21.40.197:6667", "172.21.40.199:6667" ],
"TableModelClusterList": [ "172.21.40.198:6667", "172.21.40.197:6667", "172.21.40.199:6667" ],
"PoolSize": 32,
"TableModelDataBaseName": "energy",
"DataBaseName": "jisheiotdata",
"OpenDebugMode": false,
"UseTableSessionPoolByDefault": false
},

View File

@ -18,16 +18,23 @@ namespace JiShe.IoT.Workshop.Dto
/// 表计类型
/// 电表= 1,水表= 2,燃气表= 3,热能表= 4,水表流量计=5燃气表流量计=6,特殊电表=7
/// </summary>
public MeterTypeEnum MeterType { get; set; }
public MeterTypeEnum? MeterType { get; set; }
/// <summary>
/// 集中器地址
/// 设备地址
/// </summary>
public string FocusAddress { get; set; }
public string DeviceAddress { get; set; }
/// <summary>
/// 表通信地址
/// 物联网平台唯一设备标识
/// CTWing唯一设备标识为设备Id=CTWing产品Id+推送的设备序列号(集中器地址)
/// OneNET唯一设备标识为推送的设备名称为了保持统一因此推送的设备名称=OneNET产品Id+推送的设备序列号(集中器地址)
/// </summary>
public string MeterAddress { get; set; }
public string DeviceOpenInfo { get; set; }
/// <summary>
/// 物联网平台对应的产品Id
/// </summary>
public string IoTPlatformProductId { get; set; }
}
}

View File

@ -19,13 +19,13 @@ namespace JiShe.IoT.Workshop
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<HttpDataResult> ReceiveWorkshopProductionEquipment(ProductionEquipmentInput input);
Task<HttpDataResult> ReceiveOneNetProductionEquipmentInfoAsync(ProductionEquipmentInput input);
/// <summary>
/// 生产车间获取OneNET产品列表
/// </summary>
Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> OneNetProductListForWorkshopAsync(OneNetWorkshopProductListInput input);
Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetOneNetProductListAsync(OneNetWorkshopProductListInput input);
}
}

View File

@ -1,12 +1,15 @@
using JiShe.IoT.Workshop.Dto;
using JiShe.ServicePro;
using JiShe.ServicePro.Core;
using JiShe.ServicePro.DeviceManagement.Focuses;
using JiShe.ServicePro.DeviceManagement.Meters;
using JiShe.ServicePro.Encrypt;
using JiShe.ServicePro.Enums;
using JiShe.ServicePro.OneNET.Provider.Interface;
using JiShe.ServicePro.OneNETManagement.OneNETProducts;
using JiShe.ServicePro.ServerOptions;
using Mapster.Utils;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
@ -20,7 +23,7 @@ namespace JiShe.IoT.Workshop
/// <summary>
/// 生产车间服务
/// </summary>
public class ProductionWorkshopService(IFocusAppService focusAppService, IMeterAppService meterAppService, IOptions<ServerApplicationOptions> options ) : IoTAppService,IProductionWorkshopService
public class ProductionWorkshopService(IFocusAppService focusAppService, IMeterAppService meterAppService, IOneNETRequestService oneNETRequestService, IOptions<ServerApplicationOptions> options, ILogger<ProductionWorkshopService> logger) : IoTAppService, IProductionWorkshopService
{
ServerApplicationOptions srverOptions = options.Value;
@ -30,7 +33,7 @@ namespace JiShe.IoT.Workshop
/// <param name="input"></param>
/// <returns></returns>
[AllowAnonymous]
public async Task<HttpDataResult> ReceiveWorkshopProductionEquipment(ProductionEquipmentInput input)
public async Task<HttpDataResult> ReceiveOneNetProductionEquipmentInfoAsync(ProductionEquipmentInput input)
{
try
@ -40,12 +43,70 @@ namespace JiShe.IoT.Workshop
{
return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed);
}
ProductionEquipmentMessageBody productionEquipmentMessageBody = input.Message.Deserialize<ProductionEquipmentMessageBody>();
if (productionEquipmentMessageBody.MeterType.HasValue == false)
{
return HttpDataResultExtensions.Failed("设备类型不能为空", -103, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId))
{
return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -104, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.IoTPlatformProductId))
{
return HttpDataResultExtensions.Failed("物联网平台产品Id不能为空", -105, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.DeviceAddress))
{
return HttpDataResultExtensions.Failed("设备地址不能为空", -106, ResponeResultEnum.Fail);
}
if (string.IsNullOrWhiteSpace(productionEquipmentMessageBody.DeviceOpenInfo))
{
return HttpDataResultExtensions.Failed("物联网平台唯一设备标识,不能为空", -107, ResponeResultEnum.Fail);
}
var productInfo = await FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
.Where(e => e.IsEnabled == true && e.IoTPlatformProductId == productionEquipmentMessageBody.IoTPlatformProductId)
.FirstAsync();
if (productInfo == null)
{
return HttpDataResultExtensions.Failed("没有找到对应的产品信息", -108, ResponeResultEnum.Fail);
}
FocusInfo focusInfoEntity = new FocusInfo() {
FocusAddress = productionEquipmentMessageBody.DeviceAddress,
Name = productionEquipmentMessageBody.DeviceOpenInfo,
IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId,
BusinessSystem = BusinessSystemEnum.Energy,
IoTPlatform = IoTPlatformTypeEnum.OneNET,
IoTPlatformDeviceOpenInfo = productionEquipmentMessageBody.DeviceOpenInfo,
PlatformPassword = productInfo.ProductAccesskey,
};
focusInfoEntity.CreateId(GuidGenerator.Create());
MeterInfo meterInfoEntity = new MeterInfo() { MeterAddress = productionEquipmentMessageBody.DeviceAddress,
Password = productInfo.ProductAccesskey,
BusinessSystem = BusinessSystemEnum.Energy,
IoTPlatformProductId = productionEquipmentMessageBody.IoTPlatformProductId,
IoTPlatformDeviceOpenInfo = productionEquipmentMessageBody.DeviceOpenInfo,
};
//oneNETRequestService
return HttpDataResultExtensions.Failed("签名校验失败", -101, ResponeResultEnum.NotAllowed);
}
catch (Exception)
catch (Exception ex)
{
throw;
logger.LogError($"{nameof(ReceiveOneNetProductionEquipmentInfoAsync)} 生产车间数据推送发生异常:{ex.Serialize()}");
return HttpDataResultExtensions.Failed("生产车间数据推送发生异常", -101, ResponeResultEnum.Exception);
}
}
@ -53,7 +114,7 @@ namespace JiShe.IoT.Workshop
/// 生产车间获取OneNET产品列表
/// </summary>
[AllowAnonymous]
public async Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> OneNetProductListForWorkshopAsync(OneNetWorkshopProductListInput input)
public async Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetOneNetProductListAsync(OneNetWorkshopProductListInput input)
{
try
@ -63,7 +124,9 @@ namespace JiShe.IoT.Workshop
{
return HttpDataResultExtensions.Failed<List<OneNetWorkshopProductListOutput>>("签名校验失败", -101, ResponeResultEnum.NotAllowed);
}
ProductionEquipmentMessageBody productionEquipmentMessageBody = input.Message.Deserialize<ProductionEquipmentMessageBody>();
var pageListQuery = FreeSqlDbContext.Instance.Select<OneNETProductInfos>()
.Where(e => e.IsEnabled == true)
.OrderByDescending(e => e.CreationTime);

View File

@ -10,7 +10,7 @@
//"TreeModelClusterList": [ "192.168.111.37:6667" ],
//"TableModelClusterList": [ "192.168.111.37:6667" ],
"PoolSize": 32,
"TableModelDataBaseName": "energy",
"DataBaseName": "jisheiotdata",
"OpenDebugMode": true,
"UseTableSessionPoolByDefault": false
}

View File

@ -26,25 +26,25 @@ namespace JiShe.IoT.Controllers
}
/// <summary>
/// 接收车间生产设备信息
/// 接收车间生产OneNET设备信息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("WorkshopProductionEquipment")]
[SwaggerOperation(summary: "车间生产设备信息", Tags = new[] { "Workshop" })]
public async Task ReceiveWorkshopProductionEquipment(ProductionEquipmentInput input)
[HttpPost(nameof(ReceiveOneNetProductionEquipmentInfoAsync))]
[SwaggerOperation(summary: "接收车间生产OneNET设备信息", Tags = new[] { "Workshop" })]
public async Task ReceiveOneNetProductionEquipmentInfoAsync(ProductionEquipmentInput input)
{
await _productionWorkshopService.ReceiveWorkshopProductionEquipment(input);
await _productionWorkshopService.ReceiveOneNetProductionEquipmentInfoAsync(input);
}
/// <summary>
/// 生产车间获取OneNET产品列表
/// </summary>
[HttpPost(nameof(OneNetProductListForWorkshopAsync))]
[HttpPost(nameof(GetOneNetProductListAsync))]
[SwaggerOperation(summary: "生产车间获取OneNET产品列表", Tags = new[] { "Workshop" })]
public async Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> OneNetProductListForWorkshopAsync(OneNetWorkshopProductListInput input)
public async Task<HttpDataResult<List<OneNetWorkshopProductListOutput>>> GetOneNetProductListAsync(OneNetWorkshopProductListInput input)
{
return await _productionWorkshopService.OneNetProductListForWorkshopAsync(input);
return await _productionWorkshopService.GetOneNetProductListAsync(input);
}
}
}