zhaoy 8 months ago
parent
commit
bf0c7d5406
4 changed files with 64 additions and 0 deletions
  1. +11
    -0
      BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs
  2. +40
    -0
      BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs
  3. +1
    -0
      BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs
  4. +12
    -0
      BPA.SAAS.KitChenManage.Application/TestServices.cs

+ 11
- 0
BPA.SAAS.KitChenManage.Application/Device/DevicePushRecodeServices.cs View File

@@ -42,6 +42,17 @@ namespace BPA.SAAS.KitChenManage.Application.Device
return await _devicePushRecodeService.Add(input);
}
/// <summary>
/// 下发数据(对外接口)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/add_alm")]
[AllowAnonymous]
public async Task<bool> Add_alm(List<DevicePushRecodeDtoInput> input)
{
return await _devicePushRecodeService.Add_alm(input);
}
/// <summary>
/// 修改
/// </summary>
/// <param name="id"></param>


+ 40
- 0
BPA.SAAS.KitChenManage.Application/Device/Services/DevicePushRecodeService.cs View File

@@ -91,6 +91,46 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
};
return util;
}
public async Task<bool> Add_alm(List<DevicePushRecodeDtoInput> input)
{
var data = input.Adapt<List<BPA_DevicePushRecode>>();
string groupId = App.HttpContext.Request.Headers["groupId"].ToString();
if (string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商id不能为空");
for (int i = 0; i < input.Count; i++)
{
var DataResore = await commDefaultHandle.GetParm(input[i].Type, input[i].Data.ToString(), input[i].DeviceId, input[i].ProductName, input[i].ProductVersion, input[i].DeviceAutoKey.ToString());
if (DataResore == null) throw Oops.Oh("解析参数失败");
string Topic = DataResore.TopicsStr;
if (string.IsNullOrEmpty(Topic)) throw Oops.Oh("请配置相关topic");
//var maxmessageId=_db.Queryable<BPA_DevicePushRecode>().Max(x => x.MessageId);
if (string.IsNullOrWhiteSpace(input[i].MessageId)) input[i].MessageId = Guid.NewGuid().ToString();
// var messageId = Guid.NewGuid().ToString();
data[i].Topic = Topic;
data[i].Status = 0;
data[i].DataResore = JsonConvert.SerializeObject(DataResore.Data);
data[i].DeviceAutoKey = input[i].DeviceAutoKey;
data[i].Description = "下发中,等待设备响应";
data[i].MessageId = input[i].MessageId;
data[i].TopicRely = DataResore.TopicsStrRely;
data[i].DescriptionRely = "等待回调";
var respush = await mqttServer.Publish(Topic, new PushData() { Data = data[i].DataResore, DeviceId = input[i].DeviceAutoKey }, input[i].MessageId);
if (respush != "success")
{
data[i].Description = respush;
data[i].Status = 2;
}
var res = await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync();
//周期性任务 (10 秒后执行1次任务)
var trigger = TriggerBuilder.Default.WithInterval(TimeSpan.FromSeconds(10)).WithRepeatCount(1).Build();
TaskServicesManager.GetOrAdd(input[i].MessageId.ToString(), async (provider, token) => {
await CallBackDevicePushRecode(input[i].MessageId.ToString(), groupId);
}, trigger);
//订阅回复数据下发topics
await mqttServer.Subscribe(DataResore.TopicsStrRely);
await BindMqReceived(input[i].MessageId.ToString(), groupId);
}
return true;
}
/// <summary>
/// 添加
/// </summary>


+ 1
- 0
BPA.SAAS.KitChenManage.Application/Device/Services/IDevicePushRecodeService.cs View File

@@ -17,6 +17,7 @@ namespace BPA.SAAS.KitChenManage.Application.Device.Services
/// <param name="input"></param>
/// <returns></returns>
Task<PageUtil> Page(DevicePushRecodeDtoPageInput input);
Task<bool> Add_alm(List<DevicePushRecodeDtoInput> input);
/// <summary>
/// 添加
/// </summary>


+ 12
- 0
BPA.SAAS.KitChenManage.Application/TestServices.cs View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SAAS.KitChenManage.Application
{
public class TestServices: IDynamicApiController
{
}
}

Loading…
Cancel
Save