消息推送
This commit is contained in:
parent
cec7b64efe
commit
9f32101ead
|
|
@ -265,7 +265,11 @@ namespace Nirvana.Common
|
|||
int month = now.Month - birthdate.Month;
|
||||
return month <= 0 ? age*12 : age*12+month;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时间戳
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetTimeStamp(this DateTime time)
|
||||
{
|
||||
int t = Convert.ToInt32((time.ToUniversalTime().Ticks - 621355968000000000) / 10000000);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
using Mapster;
|
||||
using Nirvana.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Waste.Application.SubscribeInfo;
|
||||
using Waste.Domain;
|
||||
|
||||
namespace Waste.Application
|
||||
|
|
@ -18,6 +20,9 @@ namespace Waste.Application
|
|||
.Map(dest=>dest.time,src=>src.CreateTime.ToString("yyyy-MM-dd"))
|
||||
.Map(dest=>dest.type,src=>src.WasteType)
|
||||
;
|
||||
config.ForType<SendThirdMessageSubscribeS2SDto, SendThirdMessageSubscriDto>()
|
||||
.Map(dest => dest.Time, src => src.Time.GetTimeStamp())
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nirvana.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Waste.Application.SubscribeInfo;
|
||||
|
||||
namespace Waste.Application.ResultInfos
|
||||
{
|
||||
|
|
@ -38,5 +35,21 @@ namespace Waste.Application.ResultInfos
|
|||
{
|
||||
return await _resultService.InsertResultAsync(myPackage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// wifi模块测量结果增加
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public async Task InsertResultByWifiAsync(WifiPackage data)
|
||||
{
|
||||
await _resultService.InsertResultByWifiAsync(data);
|
||||
}
|
||||
|
||||
public async Task<string> RecvResult(SendMessageToThirdS2CDto data)
|
||||
{
|
||||
var getdata = data;
|
||||
return await Task.FromResult("success");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using Furion;
|
||||
using DotNetCore.CAP;
|
||||
using Furion;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DistributedIDGenerator;
|
||||
using Furion.RemoteRequest.Extensions;
|
||||
using Furion.TaskScheduler;
|
||||
using Mapster;
|
||||
using Nirvana.Common;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
|
@ -10,6 +12,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Waste.Application.SubscribeInfo;
|
||||
using Waste.Domain;
|
||||
|
||||
namespace Waste.Application
|
||||
|
|
@ -22,16 +25,14 @@ namespace Waste.Application
|
|||
private readonly ISqlSugarRepository<W_Result> repository;
|
||||
private readonly SqlSugarClient dbClient;
|
||||
private readonly ILoggerService _loggerService;
|
||||
private readonly ISuZhouService _suZhouService;
|
||||
private readonly IBusinessApiService _businessApiService;
|
||||
private readonly ICapPublisher _capBus;
|
||||
|
||||
public ResultService(ISqlSugarRepository<W_Result> sqlSugarRepository, ILoggerService loggerService, ISuZhouService suZhouService, IBusinessApiService businessApiService)
|
||||
public ResultService(ISqlSugarRepository<W_Result> sqlSugarRepository, ILoggerService loggerService, ICapPublisher capPublisher)
|
||||
{
|
||||
repository = sqlSugarRepository;
|
||||
dbClient = repository.Context;
|
||||
_loggerService = loggerService;
|
||||
_suZhouService = suZhouService;
|
||||
_businessApiService = businessApiService;
|
||||
_capBus = capPublisher;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取投放记录
|
||||
|
|
@ -169,6 +170,7 @@ namespace Waste.Application
|
|||
{
|
||||
isfrist = true;
|
||||
}
|
||||
decimal currentweight= data.Weight.IsEmpty() ? 0 : data.Weight.ToDecimal();
|
||||
//记录数据
|
||||
await dbClient.Ado.UseStoredProcedure().ExecuteCommandAsync("Proc_InsertResult", new
|
||||
{
|
||||
|
|
@ -185,12 +187,22 @@ namespace Waste.Application
|
|||
city = "",
|
||||
area = data.trashcode,
|
||||
wastetype = data.WasteType,
|
||||
weigth = data.Weight,
|
||||
weigth = currentweight,
|
||||
isheart = data.IsHeart,
|
||||
tare = device.Tare,
|
||||
isfrist = isfrist
|
||||
});
|
||||
|
||||
if (!data.IsHeart)
|
||||
{
|
||||
await SendMessageToThird(new SendThirdMessageSubscribeS2SDto
|
||||
{
|
||||
DeviceId = device.Id,
|
||||
Time = time,
|
||||
TrashCode = data.trashcode,
|
||||
WasteType = data.WasteType,
|
||||
Weight = currentweight
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -254,6 +266,37 @@ namespace Waste.Application
|
|||
tare = device.Tare,
|
||||
isfrist = isfrist
|
||||
});
|
||||
if (!myPackage.IsHeart)
|
||||
{
|
||||
await SendMessageToThird(new SendThirdMessageSubscribeS2SDto
|
||||
{
|
||||
DeviceId = device.Id,
|
||||
Time = time,
|
||||
TrashCode = myPackage.trashcode,
|
||||
WasteType = myPackage.WasteType,
|
||||
Weight = Weight
|
||||
});
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 给第三方推送消息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
private async Task SendMessageToThird(SendThirdMessageSubscribeS2SDto input)
|
||||
{
|
||||
var configdata = await dbClient.Queryable<W_DeviceConfig>().Where(x => x.DeviceId == input.DeviceId).Select(x => new W_DeviceConfig
|
||||
{
|
||||
Body = x.Body,
|
||||
Url = x.Url
|
||||
}).FirstAsync();
|
||||
if (configdata != null && !configdata.Url.IsEmpty())
|
||||
{
|
||||
var senddata = input.Adapt<SendThirdMessageSubscriDto>();
|
||||
senddata.Body = configdata.Body.ToStr();
|
||||
senddata.Url = configdata.Url.ToStr();
|
||||
await _capBus.PublishAsync("third.service.sendmessage", senddata);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 增加测量记录
|
||||
|
|
@ -315,6 +358,7 @@ namespace Waste.Application
|
|||
// var areaHex = Convert.ToHexString(areaBytes);
|
||||
|
||||
}
|
||||
decimal weight = myPackage.Weight.IsEmpty() ? 0 : myPackage.Weight.ToDecimal();
|
||||
//记录数据
|
||||
await dbClient.Ado.UseStoredProcedure().ExecuteCommandAsync("Proc_InsertResult", new
|
||||
{
|
||||
|
|
@ -331,7 +375,7 @@ namespace Waste.Application
|
|||
city = myPackage.City,
|
||||
area = myPackage.Area,
|
||||
wastetype = myPackage.WasteType,
|
||||
weigth = myPackage.Weight,
|
||||
weigth = weight,
|
||||
isheart = myPackage.IsHeart,
|
||||
tare = device.Tare,
|
||||
isfrist = isfrist
|
||||
|
|
@ -358,6 +402,17 @@ namespace Waste.Application
|
|||
// });
|
||||
// }
|
||||
//}
|
||||
if (!myPackage.IsHeart)
|
||||
{
|
||||
await SendMessageToThird(new SendThirdMessageSubscribeS2SDto
|
||||
{
|
||||
DeviceId = device.Id,
|
||||
Time = time,
|
||||
TrashCode = myPackage.Area,
|
||||
WasteType = myPackage.WasteType,
|
||||
Weight = weight
|
||||
});
|
||||
}
|
||||
return new ResultInfo(ResultState.SUCCESS, "success");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,45 @@ namespace Waste.Application.SubscribeInfo
|
|||
/// <summary>
|
||||
/// 发送第三方消息
|
||||
/// </summary>
|
||||
public class SendThirdMessageSubscriDto
|
||||
public class SendThirdMessageSubscribeS2SDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备ID
|
||||
/// </summary>
|
||||
public Guid DeviceId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 垃圾类别
|
||||
/// </summary>
|
||||
public string WasteType { get; set; }
|
||||
/// <summary>
|
||||
/// 重量,单位KG
|
||||
/// </summary>
|
||||
public decimal Weight { get; set; }
|
||||
/// <summary>
|
||||
/// 垃圾桶编号
|
||||
/// </summary>s
|
||||
public string TrashCode { get; set; }
|
||||
/// <summary>
|
||||
/// 上报时间
|
||||
/// </summary>
|
||||
public DateTime Time { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送第三方消息
|
||||
/// </summary>
|
||||
public class SendThirdMessageSubscriDto: SendMessageToThirdS2CDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 推送地址
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 推送给第三方的信息
|
||||
/// </summary>
|
||||
public class SendMessageToThirdS2CDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 垃圾类别
|
||||
|
|
@ -104,12 +142,13 @@ namespace Waste.Application.SubscribeInfo
|
|||
/// </summary>
|
||||
public long Time { get; set; }
|
||||
/// <summary>
|
||||
/// 推送地址
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
/// <summary>
|
||||
/// 额外信息
|
||||
/// </summary>
|
||||
public string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备ID
|
||||
/// </summary>
|
||||
public Guid DeviceId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using Furion.DependencyInjection;
|
|||
using Furion.DistributedIDGenerator;
|
||||
using Furion.Logging.Extensions;
|
||||
using Furion.RemoteRequest.Extensions;
|
||||
using Mapster;
|
||||
using Newtonsoft.Json;
|
||||
using Nirvana.Common;
|
||||
using SqlSugar;
|
||||
|
|
@ -263,8 +264,9 @@ namespace Waste.Application.SubscribeInfo
|
|||
public async Task SeedThirdMessageAsync(SendThirdMessageSubscriDto data)
|
||||
{
|
||||
string errmsg = string.Empty;
|
||||
var senddata = data.Adapt<SendMessageToThirdS2CDto>();
|
||||
var response = await data.Url
|
||||
.SetBody(data, "application/json", Encoding.UTF8)
|
||||
.SetBody(senddata, "application/json", Encoding.UTF8)
|
||||
.OnException((res, errors) =>
|
||||
{
|
||||
errmsg = errors;
|
||||
|
|
|
|||
|
|
@ -1901,6 +1901,13 @@
|
|||
<param name="myPackage"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Waste.Application.ResultInfos.ResultAppService.InsertResultByWifiAsync(Waste.Application.WifiPackage)">
|
||||
<summary>
|
||||
wifi模块测量结果增加
|
||||
</summary>
|
||||
<param name="data"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Waste.Application.ResultService">
|
||||
<summary>
|
||||
投放记录管理
|
||||
|
|
@ -1927,6 +1934,13 @@
|
|||
<param name="myPackage"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Waste.Application.ResultService.SendMessageToThird(Waste.Application.SubscribeInfo.SendThirdMessageSubscribeS2SDto)">
|
||||
<summary>
|
||||
给第三方推送消息
|
||||
</summary>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Waste.Application.ResultService.InsertResultAsync(Waste.Application.MyPackage)">
|
||||
<summary>
|
||||
增加测量记录
|
||||
|
|
@ -2079,37 +2093,72 @@
|
|||
版本号
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Waste.Application.SubscribeInfo.SendThirdMessageSubscriDto">
|
||||
<member name="T:Waste.Application.SubscribeInfo.SendThirdMessageSubscribeS2SDto">
|
||||
<summary>
|
||||
发送第三方消息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscriDto.WasteType">
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscribeS2SDto.DeviceId">
|
||||
<summary>
|
||||
设备ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscribeS2SDto.WasteType">
|
||||
<summary>
|
||||
垃圾类别
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscriDto.Weight">
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscribeS2SDto.Weight">
|
||||
<summary>
|
||||
重量,单位KG
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscriDto.TrashCode">
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscribeS2SDto.TrashCode">
|
||||
<summary>
|
||||
垃圾桶编号
|
||||
</summary>
|
||||
</summary>s
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscriDto.Time">
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscribeS2SDto.Time">
|
||||
<summary>
|
||||
上报时间
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Waste.Application.SubscribeInfo.SendThirdMessageSubscriDto">
|
||||
<summary>
|
||||
发送第三方消息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscriDto.Url">
|
||||
<summary>
|
||||
推送地址
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendThirdMessageSubscriDto.Body">
|
||||
<member name="T:Waste.Application.SubscribeInfo.SendMessageToThirdS2CDto">
|
||||
<summary>
|
||||
推送给第三方的信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendMessageToThirdS2CDto.WasteType">
|
||||
<summary>
|
||||
垃圾类别
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendMessageToThirdS2CDto.Weight">
|
||||
<summary>
|
||||
重量,单位KG
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendMessageToThirdS2CDto.TrashCode">
|
||||
<summary>
|
||||
垃圾桶编号
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendMessageToThirdS2CDto.Time">
|
||||
<summary>
|
||||
上报时间
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Waste.Application.SubscribeInfo.SendMessageToThirdS2CDto.Body">
|
||||
<summary>
|
||||
额外信息
|
||||
</summary>
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue