diff --git a/.gitignore b/.gitignore
index 6166492..c4374d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,5 @@
/.vs
/WasteConsoleTest/WasteConsoleTest/obj
/WasteConsoleTest/WasteConsoleTest/bin
+/Waste.CreateDB/bin/Debug/net5.0
+/Waste.CreateDB/obj
diff --git a/Waste.Application/SubscribeInfo/Dtos/SubscribeDto.cs b/Waste.Application/SubscribeInfo/Dtos/SubscribeDto.cs
new file mode 100644
index 0000000..c7f5878
--- /dev/null
+++ b/Waste.Application/SubscribeInfo/Dtos/SubscribeDto.cs
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Waste.Application.SubscribeInfo
+{
+ ///
+ /// 测量记录
+ ///
+ public class ResultS2SDto
+ {
+ ///
+ /// 设备ID
+ ///
+ public Guid DeviceId { get; set; }
+ ///
+ /// 最近使用时间
+ ///
+ public DateTime? LastHeartTime { get; set; }
+ ///
+ /// 记录ID
+ ///
+ public Guid ResultId { get; set; }
+ ///
+ /// 设备服务商ID
+ ///
+ public Guid BusinessId { get; set; }
+ ///
+ /// 设备的IMEI
+ ///
+ public string imei { get; set; }
+ ///
+ /// ICCID
+ ///
+ public string iccid { get; set; }
+ ///
+ /// IMSI
+ ///
+ public string imsi { get; set; }
+ ///
+ /// 纬度
+ ///
+ public decimal latitude { get; set; }
+ ///
+ /// 经度
+ ///
+ public decimal longtitude { get; set; }
+ ///
+ /// 信号强度
+ ///
+ public int gslq { get; set; }
+ ///
+ /// 垃圾类型
+ ///
+ public string wastetype { get; set; }
+ ///
+ /// 垃圾桶编号
+ ///
+ public string trash { get; set; }
+ ///
+ /// 毛重
+ ///
+ public string weight { get; set; }
+ ///
+ /// 皮重
+ ///
+ public decimal Tare { get; set; }
+ }
+ ///
+ /// 设备版本信息
+ ///
+ public class DeviceVerS2SDto
+ {
+ ///
+ /// 设备机器码
+ ///
+ public string ecode { get; set; }
+ ///
+ /// 版本号
+ ///
+ public string ver { get; set; }
+ }
+}
diff --git a/Waste.Application/SubscribeInfo/ISubscribeService.cs b/Waste.Application/SubscribeInfo/ISubscribeService.cs
new file mode 100644
index 0000000..aacda7f
--- /dev/null
+++ b/Waste.Application/SubscribeInfo/ISubscribeService.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Waste.Application.ThirdApiInfo;
+
+namespace Waste.Application.SubscribeInfo
+{
+ ///
+ /// CAP订阅相关接口
+ ///
+ public interface ISubscribeService
+ {
+ ///
+ /// 添加记录
+ ///
+ ///
+ ///
+ Task InsertResultAsync(ResultS2SDto data);
+ ///
+ /// 更新记录上报结果
+ ///
+ ///
+ ///
+ Task UpdateStatusAsync(UpdateStatusDto data);
+ ///
+ /// 更新设备开机信息
+ ///
+ ///
+ ///
+ Task UpdateRegInfoAsync(Guid deviceid);
+ ///
+ /// 心跳数据上报
+ ///
+ ///
+ ///
+ Task UpdateHeartInfoAsync(DevHeartRequestDto data);
+
+ ///
+ /// 更新设备版本信息
+ ///
+ ///
+ ///
+ Task UpdateVersionAsync(DeviceVerS2SDto data);
+ }
+}
diff --git a/Waste.Application/SubscribeInfo/SubscribeService.cs b/Waste.Application/SubscribeInfo/SubscribeService.cs
new file mode 100644
index 0000000..1490470
--- /dev/null
+++ b/Waste.Application/SubscribeInfo/SubscribeService.cs
@@ -0,0 +1,228 @@
+using DotNetCore.CAP;
+using Furion.DependencyInjection;
+using Furion.DistributedIDGenerator;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Waste.Application.ThirdApiInfo;
+using Waste.Domain;
+
+namespace Waste.Application.SubscribeInfo
+{
+ ///
+ /// CAP订阅相关接口
+ ///
+ public class SubscribeService : ISubscribeService, ICapSubscribe, ITransient
+ {
+ private readonly ISqlSugarRepository repository;
+ private readonly SqlSugarClient dbClient;
+ public SubscribeService(ISqlSugarRepository sqlSugarRepository)
+ {
+ repository = sqlSugarRepository;
+ dbClient = repository.Context;
+ }
+ ///
+ /// 添加记录
+ ///
+ ///
+ ///
+ [CapSubscribe("result.service.insert")]
+ public async Task InsertResultAsync(ResultS2SDto data)
+ {
+ bool isfrist = false;
+ if (data.LastHeartTime.HasValue && data.LastHeartTime.Value.Date != DateTime.Now.Date)
+ {
+ isfrist = true;
+ }
+ await dbClient.Ado.UseStoredProcedure().ExecuteCommandAsync("Proc_InsertResult", new
+ {
+ deviceid = data.DeviceId,
+ businessid = data.BusinessId,
+ resultid = data.ResultId,
+ imei = data.imei,
+ iccid = data.iccid,
+ imsi = data.imsi,
+ time = DateTime.Now,
+ latitude = data.latitude,
+ longitude = data.longtitude,
+ sign = data.gslq,
+ city = "",
+ area = data.trash,
+ wastetype = data.wastetype,
+ weigth = data.weight,
+ isheart = 0,
+ tare = data.Tare,
+ isfrist = isfrist
+ });
+ }
+
+
+ ///
+ /// 更新记录上报结果
+ ///
+ ///
+ ///
+ [CapSubscribe("result.service.update")]
+ public async Task UpdateStatusAsync(UpdateStatusDto data)
+ {
+ Guid resultid = Guid.Empty;
+ if (!string.IsNullOrEmpty(data.ResultId) && Guid.TryParse(data.ResultId, out resultid))
+ {
+ if (await dbClient.Queryable().AnyAsync(x => x.ResultId == resultid))
+ {
+ await dbClient.Updateable().SetColumns(x => new W_ResultExt
+ {
+ Status = data.status
+ }).Where(x => x.ResultId == resultid).ExecuteCommandAsync();
+ }
+ else
+ {
+ var insertdata = new W_ResultExt
+ {
+ Id = IDGen.NextID(),
+ Status = data.status,
+ CreateTime = DateTime.Now,
+ ResultId = resultid
+ };
+ await dbClient.Insertable(insertdata).ExecuteCommandAsync();
+ }
+ }
+ }
+
+ ///
+ /// 心跳数据上报
+ ///
+ ///
+ ///
+ [CapSubscribe("device.service.postheart")]
+ public async Task UpdateHeartInfoAsync(DevHeartRequestDto data)
+ {
+ var device = await dbClient.Queryable().FirstAsync(x => x.Ecode == data.ECode);
+ if (device == null)
+ {
+ return;
+ }
+ if (await dbClient.Queryable().AnyAsync(x => x.DeviceId == device.Id))
+ {
+ //更新设备心跳信息
+ if (data.Latitude == 0 || data.Longitude == 0)
+ {
+ await dbClient.Updateable()
+ .SetColumns(x => new W_DeviceData
+ {
+ LastBeatTime = DateTime.Now
+ })
+ .Where(x => x.DeviceId == device.Id).ExecuteCommandAsync();
+ }
+ else
+ {
+ string longitude = data.Longitude.ToString();
+ string Latitude = data.Latitude.ToString();
+ await dbClient.Updateable()
+ .SetColumns(x => new W_DeviceData
+ {
+ LastBeatTime = DateTime.Now,
+ Longitude = longitude,
+ Latitude = Latitude
+ })
+ .Where(x => x.DeviceId == device.Id).ExecuteCommandAsync();
+ }
+ }
+ else
+ {
+ var insertdata = new W_DeviceData
+ {
+ DeviceId = device.Id,
+ Sign = data.GSLQ.ToString(),
+ IMSI = data.IMSI,
+ ICCID = data.ICCID,
+ IMEI = data.IMEI,
+ LastBeatTime = DateTime.Now,
+ Latitude = data.Latitude.ToString(),
+ Longitude = data.Longitude.ToString()
+ };
+ await dbClient.Insertable(insertdata).ExecuteCommandAsync();
+ }
+
+ }
+
+ ///
+ /// 更新设备开机信息
+ ///
+ ///
+ ///
+ [CapSubscribe("device.service.update")]
+ public async Task UpdateRegInfoAsync(Guid deviceid)
+ {
+ //更新开机时间
+ if (await dbClient.Queryable().AnyAsync(x => x.DeviceId == deviceid))
+ {
+ await dbClient.Updateable()
+ .SetColumns(x => new W_DeviceData
+ {
+ LastStartTime = DateTime.Now
+ })
+ .Where(x => x.DeviceId == deviceid).ExecuteCommandAsync();
+ }
+ else
+ {
+ var insertdata = new W_DeviceData
+ {
+ DeviceId = deviceid,
+ Sign = "",
+ IMSI = "",
+ ICCID = "",
+ IMEI = "",
+ Latitude = "0",
+ Longitude = "0",
+ LastStartTime = DateTime.Now
+ };
+ await dbClient.Insertable(insertdata).ExecuteCommandAsync();
+ }
+ }
+
+ ///
+ /// 更新设备版本信息
+ ///
+ ///
+ ///
+ [CapSubscribe("device.service.updatever")]
+ public async Task UpdateVersionAsync(DeviceVerS2SDto data)
+ {
+ var deivce = await dbClient.Queryable().Select(x=>new W_Device { Id=x.Id}).FirstAsync(x => x.Ecode == data.ecode);
+ if(deivce == null)
+ {
+ return;
+ }
+ //更新版本号
+ if (await dbClient.Queryable().AnyAsync(x => x.DeviceId == deivce.Id))
+ {
+ await dbClient.Updateable()
+ .SetColumns(x => new W_DeviceData
+ {
+ Version = data.ver
+ })
+ .Where(x => x.DeviceId == deivce.Id).ExecuteCommandAsync();
+ }
+ else
+ {
+ var insertdata = new W_DeviceData
+ {
+ DeviceId = deivce.Id,
+ Sign = "",
+ IMSI = "",
+ ICCID = "",
+ IMEI = "",
+ Latitude = "0",
+ Longitude = "0",
+ LastStartTime = DateTime.Now,
+ Version = data.ver
+ };
+ await dbClient.Insertable(insertdata).ExecuteCommandAsync();
+ }
+ }
+ }
+}
diff --git a/Waste.Application/ThirdApiInfo/IOpenService.cs b/Waste.Application/ThirdApiInfo/IOpenService.cs
index 77ef8bd..bfd4341 100644
--- a/Waste.Application/ThirdApiInfo/IOpenService.cs
+++ b/Waste.Application/ThirdApiInfo/IOpenService.cs
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Waste.Application.SubscribeInfo;
namespace Waste.Application.ThirdApiInfo
{
@@ -37,5 +38,11 @@ namespace Waste.Application.ThirdApiInfo
///
///
Task UpdateStatusAsync(UpdateStatusDto data);
+ ///
+ /// 更新设备版本信息
+ ///
+ ///
+ ///
+ Task UpdateVersionAsync(DeviceVerS2SDto data);
}
}
diff --git a/Waste.Application/ThirdApiInfo/OpenAppService.cs b/Waste.Application/ThirdApiInfo/OpenAppService.cs
index 796274f..e7b35e9 100644
--- a/Waste.Application/ThirdApiInfo/OpenAppService.cs
+++ b/Waste.Application/ThirdApiInfo/OpenAppService.cs
@@ -14,6 +14,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Waste.Application.SubscribeInfo;
namespace Waste.Application.ThirdApiInfo
{
@@ -83,7 +84,7 @@ namespace Waste.Application.ThirdApiInfo
///
[HttpPost]
[Route("api/reportbug/Post")]
- public async Task