- 增加 WasteAuthorizeAttribute 授权验证Filter
- 投放记录列表接口加上 WasteAuthorizeAttribute
This commit is contained in:
parent
83d37092ac
commit
ae0310a514
|
|
@ -10,7 +10,7 @@ namespace Nirvana.Common
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 常用公共类
|
/// 常用公共类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Common
|
public static class Common
|
||||||
{
|
{
|
||||||
#region Stopwatch计时器
|
#region Stopwatch计时器
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -293,5 +293,13 @@ namespace Nirvana.Common
|
||||||
return BitConverter.ToInt64(buffer, 0);
|
return BitConverter.ToInt64(buffer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static T GetListValue<T>(this IList<T> list, int index, T def = default)
|
||||||
|
{
|
||||||
|
if (list.Count > index)
|
||||||
|
{
|
||||||
|
return list[index];
|
||||||
|
}
|
||||||
|
return def;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Nirvana.Common;
|
using Nirvana.Common;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Waste.Application
|
namespace Waste.Application
|
||||||
|
|
@ -41,7 +39,7 @@ namespace Waste.Application
|
||||||
}
|
}
|
||||||
string ip = request.HttpContext.Connection.RemoteIpAddress.ToString();
|
string ip = request.HttpContext.Connection.RemoteIpAddress.ToString();
|
||||||
var res = await _businessApiService.IsWhiteIP(appid, ip);
|
var res = await _businessApiService.IsWhiteIP(appid, ip);
|
||||||
if(res.code != ApiResultState.SUCCESS)
|
if (res.code != ApiResultState.SUCCESS)
|
||||||
{
|
{
|
||||||
var jsonresult = new JsonResult(res);
|
var jsonresult = new JsonResult(res);
|
||||||
context.Result = jsonresult;
|
context.Result = jsonresult;
|
||||||
|
|
@ -59,4 +57,34 @@ namespace Waste.Application
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class WasteAuthorizeAttribute : Attribute, IAsyncActionFilter, IAsyncPageFilter
|
||||||
|
{
|
||||||
|
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||||
|
{
|
||||||
|
if (OperatorProvider.Provider.GetCurrent() != null && (OperatorProvider.Provider.GetCurrent().UserId != Guid.Empty || OperatorProvider.Provider.GetCurrent().IsSuper))
|
||||||
|
{
|
||||||
|
_ = await next.Invoke();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Result = new StatusCodeResult(401);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
|
||||||
|
{
|
||||||
|
if (OperatorProvider.Provider.GetCurrent() != null && (OperatorProvider.Provider.GetCurrent().UserId != Guid.Empty || OperatorProvider.Provider.GetCurrent().IsSuper))
|
||||||
|
{
|
||||||
|
_ = await next.Invoke();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Result = new StatusCodeResult(401);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ namespace Waste.Application
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="param"></param>
|
/// <param name="param"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[WasteAuthorize]
|
||||||
public async Task<PageParms<ResultList>> GetListAsync(QueryParams param)
|
public async Task<PageParms<ResultList>> GetListAsync(QueryParams param)
|
||||||
{
|
{
|
||||||
RefAsync<int> totalnum = 0;
|
RefAsync<int> totalnum = 0;
|
||||||
|
|
|
||||||
|
|
@ -158,10 +158,24 @@ namespace Waste.Application.ThirdApiInfo
|
||||||
{
|
{
|
||||||
return new ResultInfo(ResultState.FAIL, "设备还未获取验证信息");
|
return new ResultInfo(ResultState.FAIL, "设备还未获取验证信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// trash@1@62942200205496@4.964 trash@垃圾种类@垃圾桶编号@垃圾重量
|
||||||
|
if (!string.IsNullOrEmpty(data.data) && data.data.StartsWith("trash@"))
|
||||||
|
{
|
||||||
|
var arr = data.data.Split('@');
|
||||||
|
var type = arr.GetListValue(1);
|
||||||
|
returndata.trash = arr.GetListValue(2);
|
||||||
|
var weight = arr.GetListValue(3);
|
||||||
|
|
||||||
|
var result = await UpdateDevInfo(data, returndata, device, type, weight);
|
||||||
|
if (result != null) return result;
|
||||||
|
|
||||||
|
}
|
||||||
//解析协议,IC卡数据@垃圾桶编号@厨余垃圾@7.91
|
//解析协议,IC卡数据@垃圾桶编号@厨余垃圾@7.91
|
||||||
// 00000000003031 40 0F00010009 40 C6E4CBFBC0ACBBF8 40 31352E39
|
// 00000000003031 40 0F00010009 40 C6E4CBFBC0ACBBF8 40 31352E39
|
||||||
// 00000000003031 40 000F000002 40 C6E4CBFBC0ACBBF8 40 35312E30 0D0A
|
// 00000000003031 40 000F000002 40 C6E4CBFBC0ACBBF8 40 35312E30 0D0A
|
||||||
if (!string.IsNullOrEmpty(data.data) && data.data.Length > 52)
|
else if (!string.IsNullOrEmpty(data.data) && data.data.Length > 52)
|
||||||
{
|
{
|
||||||
data.data = data.data.Replace(" ", "");
|
data.data = data.data.Replace(" ", "");
|
||||||
//收到的为16进制,对数据进行解析,0-4预留,5-垃圾种类,6-垃圾桶大小,7-@,8-12垃圾桶编号,13@,14-21垃圾种类汉字,22@,23-结束重量, OD OA 回车换行
|
//收到的为16进制,对数据进行解析,0-4预留,5-垃圾种类,6-垃圾桶大小,7-@,8-12垃圾桶编号,13@,14-21垃圾种类汉字,22@,23-结束重量, OD OA 回车换行
|
||||||
|
|
@ -173,65 +187,9 @@ namespace Waste.Application.ThirdApiInfo
|
||||||
returndata.trash = HextToDec(trashhex).ToString(); //垃圾桶编号使用10进制
|
returndata.trash = HextToDec(trashhex).ToString(); //垃圾桶编号使用10进制
|
||||||
var type = GetChsFromHex(typehex);
|
var type = GetChsFromHex(typehex);
|
||||||
var weight = GetChsFromHex(weighthex);
|
var weight = GetChsFromHex(weighthex);
|
||||||
returndata.type = TrashType(type);
|
|
||||||
returndata.Weight = weight.ToDouble();
|
|
||||||
//计算净重,毛重-皮重=净重,如果净重小于等于0则不上报保存
|
|
||||||
returndata.Weight = (returndata.Weight - device.Tare.ToDouble()).ToDouble(2);
|
|
||||||
if (returndata.Weight <= 0)
|
|
||||||
{
|
|
||||||
_loggerService.AddLogger($"{data.ECode},{device.Name},重量小于等于0:{returndata.ToJson()}", 1);
|
|
||||||
return new ResultInfo(ResultState.FAIL, "无效的重量");
|
|
||||||
}
|
|
||||||
//检查是否为15分钟内第一次上报
|
|
||||||
//如果是巴城的设备则不使用这个限制
|
|
||||||
if (device.Businessid != Guid.Parse("39FCB9DE-404E-68F5-384B-EE2462EAB87C"))
|
|
||||||
{
|
|
||||||
var time15 = DateTime.Now.AddMinutes(-15);
|
|
||||||
if (await dbClient.Queryable<W_DeviceResult>().AnyAsync(x => x.DeviceId == device.Id && x.LastTrash == returndata.trash && x.LastHeartTime > time15))
|
|
||||||
{
|
|
||||||
_loggerService.AddLogger($"{data.ECode},{device.Name},重复垃圾桶编号的数据:{returndata.ToJson()}", 1);
|
|
||||||
return new ResultInfo(ResultState.FAIL, "15分钟内同一垃圾桶编号上报");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
returndata.IsSuccessed = true;
|
|
||||||
//记录数据
|
|
||||||
data.IMEI = data.IMEI.ToStr();
|
|
||||||
data.ICCID = data.ICCID.ToStr();
|
|
||||||
data.IMSI = data.IMSI.ToStr();
|
|
||||||
await _capBus.PublishAsync("result.service.insert", new ResultS2SDto
|
|
||||||
{
|
|
||||||
BusinessId = device.Businessid,
|
|
||||||
DeviceId = device.Id,
|
|
||||||
gslq = data.GSLQ,
|
|
||||||
iccid = data.ICCID,
|
|
||||||
imei = data.IMEI,
|
|
||||||
imsi = data.IMSI,
|
|
||||||
LastHeartTime = device.LastHeartTime,
|
|
||||||
latitude = data.Latitude,
|
|
||||||
longtitude = data.Longitude,
|
|
||||||
ResultId = returndata.ResultId,
|
|
||||||
Tare = device.Tare,
|
|
||||||
trash = returndata.trash,
|
|
||||||
wastetype = type,
|
|
||||||
weight = weight
|
|
||||||
});
|
|
||||||
|
|
||||||
//推送数据给第三方
|
var result = await UpdateDevInfo(data, returndata, device, type, weight);
|
||||||
await _resultService.SendMessageToThird(new SendThirdMessageSubscribeS2SDto
|
if (result != null) return result;
|
||||||
{
|
|
||||||
DeviceId = device.Id,
|
|
||||||
WasteSType = "",
|
|
||||||
Time = DateTime.Now,
|
|
||||||
TrashCode = returndata.trash,
|
|
||||||
WasteType = type,
|
|
||||||
Weight = weight.ToDecimal(),
|
|
||||||
faccode = device.FacEcode,
|
|
||||||
ecode = device.Ecode,
|
|
||||||
province = device.Province,
|
|
||||||
city = device.City,
|
|
||||||
area = device.Area,
|
|
||||||
address = device.Address
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -584,5 +542,70 @@ namespace Waste.Application.ThirdApiInfo
|
||||||
{
|
{
|
||||||
return ((int)bt).ToString("X2");
|
return ((int)bt).ToString("X2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<ResultInfo> UpdateDevInfo(GetDevInfoRequestDto data, GetDevInfoResponseDto returndata, W_Device device,
|
||||||
|
string type, string weight)
|
||||||
|
{
|
||||||
|
returndata.type = TrashType(type);
|
||||||
|
returndata.Weight = weight.ToDouble();
|
||||||
|
//计算净重,毛重-皮重=净重,如果净重小于等于0则不上报保存
|
||||||
|
returndata.Weight = (returndata.Weight - device.Tare.ToDouble()).ToDouble(2);
|
||||||
|
if (returndata.Weight <= 0)
|
||||||
|
{
|
||||||
|
_loggerService.AddLogger($"{data.ECode},{device.Name},重量小于等于0:{returndata.ToJson()}", 1);
|
||||||
|
return new ResultInfo(ResultState.FAIL, "无效的重量");
|
||||||
|
}
|
||||||
|
//检查是否为15分钟内第一次上报
|
||||||
|
//如果是巴城的设备则不使用这个限制
|
||||||
|
if (device.Businessid != Guid.Parse("39FCB9DE-404E-68F5-384B-EE2462EAB87C"))
|
||||||
|
{
|
||||||
|
var time15 = DateTime.Now.AddMinutes(-15);
|
||||||
|
if (await dbClient.Queryable<W_DeviceResult>().AnyAsync(x => x.DeviceId == device.Id && x.LastTrash == returndata.trash && x.LastHeartTime > time15))
|
||||||
|
{
|
||||||
|
_loggerService.AddLogger($"{data.ECode},{device.Name},重复垃圾桶编号的数据:{returndata.ToJson()}", 1);
|
||||||
|
return new ResultInfo(ResultState.FAIL, "15分钟内同一垃圾桶编号上报");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
returndata.IsSuccessed = true;
|
||||||
|
//记录数据
|
||||||
|
data.IMEI = data.IMEI.ToStr();
|
||||||
|
data.ICCID = data.ICCID.ToStr();
|
||||||
|
data.IMSI = data.IMSI.ToStr();
|
||||||
|
await _capBus.PublishAsync("result.service.insert", new ResultS2SDto
|
||||||
|
{
|
||||||
|
BusinessId = device.Businessid,
|
||||||
|
DeviceId = device.Id,
|
||||||
|
gslq = data.GSLQ,
|
||||||
|
iccid = data.ICCID,
|
||||||
|
imei = data.IMEI,
|
||||||
|
imsi = data.IMSI,
|
||||||
|
LastHeartTime = device.LastHeartTime,
|
||||||
|
latitude = data.Latitude,
|
||||||
|
longtitude = data.Longitude,
|
||||||
|
ResultId = returndata.ResultId,
|
||||||
|
Tare = device.Tare,
|
||||||
|
trash = returndata.trash,
|
||||||
|
wastetype = type,
|
||||||
|
weight = weight
|
||||||
|
});
|
||||||
|
|
||||||
|
//推送数据给第三方
|
||||||
|
await _resultService.SendMessageToThird(new SendThirdMessageSubscribeS2SDto
|
||||||
|
{
|
||||||
|
DeviceId = device.Id,
|
||||||
|
WasteSType = "",
|
||||||
|
Time = DateTime.Now,
|
||||||
|
TrashCode = returndata.trash,
|
||||||
|
WasteType = type,
|
||||||
|
Weight = weight.ToDecimal(),
|
||||||
|
faccode = device.FacEcode,
|
||||||
|
ecode = device.Ecode,
|
||||||
|
province = device.Province,
|
||||||
|
city = device.City,
|
||||||
|
area = device.Area,
|
||||||
|
address = device.Address
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue