Browse Source

提交

master
gwbvipvip 7 months ago
parent
commit
2db47b9b7a
5 changed files with 102 additions and 70 deletions
  1. +52
    -0
      BPA.KitChen.StoreManagement.Application/Service/Device/DevicePushRecodeServices.cs
  2. +18
    -0
      BPA.KitChen.StoreManagement.Application/Service/Device/Dtos/PushData.cs
  3. +0
    -12
      BPA.KitChen.StoreManagement.Application/Service/Device/Services/Class1.cs
  4. +25
    -53
      BPA.KitChen.StoreManagement.Application/Service/Device/Services/DevicePushRecodeService.cs
  5. +7
    -5
      BPA.KitChen.StoreManagement.Application/Service/Device/Services/IDevicePushRecodeService.cs

+ 52
- 0
BPA.KitChen.StoreManagement.Application/Service/Device/DevicePushRecodeServices.cs View File

@@ -0,0 +1,52 @@
using BPA.KitChen.StoreManagement.Application.BaseDto;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos
{
[ApiDescriptionSettings("DevicePushRecode", Tag = "设备下发")]
public class DevicePushRecodeServices: IDynamicApiController
{
IDevicePushRecodeService _devicePushRecodeService;
public DevicePushRecodeServices(IDevicePushRecodeService devicePushRecodeService)
{
_devicePushRecodeService= devicePushRecodeService;
}
/// <summary>
/// 分页
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/page")]
public async Task<PageUtil> Page(DevicePushRecodeDtoPageInput input)
{
return await _devicePushRecodeService.Page(input);
}
/// <summary>
/// 添加
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/add")]
public async Task<bool> Add(DevicePushRecodeDtoInput input)
{
return await _devicePushRecodeService.Add(input);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/delete")]
public async Task<bool> Delete(List<string> input)
{
return await _devicePushRecodeService.Delete(input);
}
}
}

+ 18
- 0
BPA.KitChen.StoreManagement.Application/Service/Device/Dtos/PushData.cs View File

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

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos
{
public class PushData: IMessage
{
public object Data { get; set; }
/// <summary>
/// 设备AutoKey
/// </summary>
public int DeviceId { get; set; }
}
}

+ 0
- 12
BPA.KitChen.StoreManagement.Application/Service/Device/Services/Class1.cs View File

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

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Services
{
internal class Class1
{
}
}

+ 25
- 53
BPA.KitChen.StoreManagement.Application/Service/Device/Services/DevicePushRecodeService.cs View File

@@ -1,16 +1,12 @@

using BPA.KitChen.StoreManagement.Application.BaseDto;
using BPA.KitChen.StoreManagement.Application.Service.Device.Dtos;
using BPA.KitChen.StoreManagement.Application.BaseDto;
using BPA.KitChen.StoreManagement.Core.Entity;
using BPA.KitChen.StoreManagement.SqlSugar;
using BPA.KitChen.StoreManagement.Core.Enum;
using BPA.Message;
using BPA.Message.IOT;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.LinqBuilder;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using MQTTnet;
using MQTTnet.Client;
@@ -23,42 +19,38 @@ using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Services
namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos
{

[ApiDescriptionSettings("设备下发", Tag = "设备下发", SplitCamelCase = false)]
public class DevicePushRecodeService: IDynamicApiController, ITransient, IDevicePushRecodeService
public class DevicePushRecodeService: IDevicePushRecodeService, ITransient
{
private readonly SqlSugarScope _db;
private readonly ISqlSugarClient _db;
private readonly IMqttClient _mqttClient;
public DevicePushRecodeService(ISqlSugarClient db, IMqttClient mqttClient)
{
_db = SqlSugarDb.Db;
_db = db;
_mqttClient=mqttClient;
}


/// <summary>
/// 分页
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/page")]
public async Task<PageUtil> Page(DevicePushRecodeDtoPageInput input)
{
RefAsync<int> total = 0;
var res = await _db.Queryable<BPA_DevicePushRecode>().Where(x=>x.Type== input.Type)
.Select(t => new
{
CreateAt = t.CreateAt,
CreateBy = t.CreateBy,
Id = t.Id,
DeviceId = t.DeviceId,
DeviceName= t.DeviceName,
Type =t.Type,
Topic=t.Topic,
DataResore=t.DataResore,
}).OrderBy(x => x.CreateAt, OrderByType.Desc).ToPageListAsync(input.Current, input.PageSize, total);
var res = await _db.Queryable<BPA_DevicePushRecode>().Where(x => x.Type == input.Type)
.Select(t => new
{
CreateAt = t.CreateAt,
CreateBy = t.CreateBy,
Id = t.Id,
DeviceId = t.DeviceId,
DeviceName = t.DeviceName,
Type = t.Type,
Topic = t.Topic,
DataResore = t.DataResore,
t.Status
}).OrderBy(x => x.CreateAt, OrderByType.Desc).ToPageListAsync(input.Current, input.PageSize, total);
PageUtil util = new PageUtil()
{
Total = total,
@@ -67,14 +59,11 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device.Services
};
return util;
}


/// <summary>
/// 添加
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/add")]
public async Task<bool> Add(DevicePushRecodeDtoInput input)
{
var data = input.Adapt<BPA_DevicePushRecode>();
@@ -83,19 +72,16 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device.Services
data.Topic= Topic;
data.DataResore = JsonConvert.SerializeObject(JsonConvert.DeserializeObject<dynamic>(input.Data.ToString()));
var res=await Push(Topic, new PushData() { Data=input.Data, DeviceId= input.DeviceAutoKey });
if (res)
{
await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync();
}
data.Status = res ? CommonStatus.ENABLE : CommonStatus.DISABLE;
await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync();
return res;
}

/// <summary>
/// 删除
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/api/devicepushrecode/delete")]
public async Task<bool> Delete(List<string> input)
{
try
@@ -111,8 +97,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device.Services
throw Oops.Oh("删除失败");
}
}

private async Task<bool> Push(string Topic, PushData data)
private async Task<bool> Push(string Topic,PushData data)
{
try
{
@@ -130,21 +115,8 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device.Services
//每次下发暂停200毫秒 by 王刚 2022-06-08 测试提出修改
// Thread.Sleep(200);
//string aa = bPAPackage.Serialize(false);
var thisData = new
{
MessageId = MessageID.TMC_PUSH_INGREDIENTS,
ClientId = data.DeviceId,
//ClientType = Procuct
MessageVersion = 0x30,
Timestamp = DateTime.Now,
Message = data.Data.ToString()
};

var applictionmessage = new MqttApplicationMessageBuilder()
.WithTopic(Topic)
.WithPayload(JsonConvert.SerializeObject(thisData))
.WithAtLeastOnceQoS().Build();
await _mqttClient.PublishAsync(applictionmessage);
var applictionmessage = new MqttApplicationMessageBuilder().WithTopic(Topic).WithPayload(bPAPackage.Serialize(false)).WithAtLeastOnceQoS().Build();
await _mqttClient.PublishAsync(applictionmessage);
return true;
}
catch (Exception e)


+ 7
- 5
BPA.KitChen.StoreManagement.Application/Service/Device/Services/IDevicePushRecodeService.cs View File

@@ -1,9 +1,11 @@

using BPA.KitChen.StoreManagement.Application.BaseDto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using BPA.KitChen.StoreManagement.Application.BaseDto;
using BPA.KitChen.StoreManagement.Application.Service.Device.Dtos;

namespace BPA.KitChen.StoreManagement.Application.Service.Device.Services
namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos
{
public interface IDevicePushRecodeService
{


Loading…
Cancel
Save