/api/open/getdevinfo接口增加去重处理,这个不能去掉
This commit is contained in:
parent
d905211c24
commit
7cb0918326
|
|
@ -55,13 +55,61 @@ namespace Waste.Application.ThirdApiInfo
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<ResultInfo> GetDevInfoAsync(GetDevInfoRequestDto data)
|
public async Task<ResultInfo> GetDevInfoAsync(GetDevInfoRequestDto data)
|
||||||
{
|
{
|
||||||
|
|
||||||
//更新上报记录结果
|
//更新上报记录结果
|
||||||
|
Guid resultid = Guid.Empty;
|
||||||
|
//这里进行去重处理
|
||||||
|
if (!string.IsNullOrEmpty(data.ResultId) && Guid.TryParse(data.ResultId, out resultid))
|
||||||
|
{
|
||||||
var device = await dbClient.Queryable<W_Device>().FirstAsync(x => x.Ecode == data.ECode);
|
var device = await dbClient.Queryable<W_Device>().FirstAsync(x => x.Ecode == data.ECode);
|
||||||
if (device == null)
|
if (device == null)
|
||||||
{
|
{
|
||||||
return new ResultInfo(ResultState.FAIL, "设备未找到");
|
return new ResultInfo(ResultState.FAIL, "设备未找到");
|
||||||
}
|
}
|
||||||
if(device.Status == (int)DeviceStatus.Error)
|
var devicesecret = await dbClient.Queryable<W_SZDevice>().FirstAsync(x => x.DeviceId == device.Id);
|
||||||
|
if (devicesecret == null || string.IsNullOrEmpty(devicesecret.Secret)
|
||||||
|
|| string.IsNullOrEmpty(devicesecret.SecretHash)
|
||||||
|
|| string.IsNullOrEmpty(devicesecret.DevId))
|
||||||
|
{
|
||||||
|
return new ResultInfo(ResultState.FAIL, "设备还未获取验证信息");
|
||||||
|
}
|
||||||
|
int timestamp = _suZhouService.GetUTCTimestamp();
|
||||||
|
int noncestr = _suZhouService.GetNonce();
|
||||||
|
var result = await dbClient.Queryable<W_Result>().FirstAsync(x => x.Id == resultid);
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return new ResultInfo(ResultState.SUCCESS, "记录id未找到");
|
||||||
|
}
|
||||||
|
var returndata = new GetDevInfoResponseDto
|
||||||
|
{
|
||||||
|
DeviceId = devicesecret.DevId,
|
||||||
|
noncestr = noncestr,
|
||||||
|
timestamp = timestamp,
|
||||||
|
Secret = devicesecret.Secret,
|
||||||
|
SecretHash = devicesecret.SecretHash,
|
||||||
|
UserId = UserId,
|
||||||
|
PostUrl = ApiUrl,
|
||||||
|
ScanningTime = timestamp,
|
||||||
|
ResultId = resultid,
|
||||||
|
trash = result.Registration,
|
||||||
|
Weight = result.GrossWeight.ToDouble(),
|
||||||
|
status = 0,
|
||||||
|
IsSuccessed = true,
|
||||||
|
type = TrashType(result.WasteType)
|
||||||
|
};
|
||||||
|
string[] paramlist = new string[] {
|
||||||
|
returndata.Weight.ToString(),returndata.trash,returndata.type.ToString(),returndata.ScanningTime.ToString(),returndata.status.ToString()};
|
||||||
|
returndata.sign = _suZhouService.GetUserApiSign(returndata.Secret, paramlist);
|
||||||
|
return new ResultInfo(ResultState.SUCCESS, "success", returndata);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var device = await dbClient.Queryable<W_Device>().FirstAsync(x => x.Ecode == data.ECode);
|
||||||
|
if (device == null)
|
||||||
|
{
|
||||||
|
return new ResultInfo(ResultState.FAIL, "设备未找到");
|
||||||
|
}
|
||||||
|
if (device.Status == (int)DeviceStatus.Error)
|
||||||
{
|
{
|
||||||
return new ResultInfo(ResultState.FAIL, "设备已停止运行");
|
return new ResultInfo(ResultState.FAIL, "设备已停止运行");
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +152,7 @@ namespace Waste.Application.ThirdApiInfo
|
||||||
}
|
}
|
||||||
//检查是否为15分钟内第一次上报
|
//检查是否为15分钟内第一次上报
|
||||||
//如果是巴城的设备则不使用这个限制
|
//如果是巴城的设备则不使用这个限制
|
||||||
if(device.Businessid != Guid.Parse("39FCB9DE-404E-68F5-384B-EE2462EAB87C"))
|
if (device.Businessid != Guid.Parse("39FCB9DE-404E-68F5-384B-EE2462EAB87C"))
|
||||||
{
|
{
|
||||||
var time15 = DateTime.Now.AddMinutes(-15);
|
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))
|
if (await dbClient.Queryable<W_DeviceResult>().AnyAsync(x => x.DeviceId == device.Id && x.LastTrash == returndata.trash && x.LastHeartTime > time15))
|
||||||
|
|
@ -156,6 +204,7 @@ namespace Waste.Application.ThirdApiInfo
|
||||||
_loggerService.AddLogger($"{data.ECode},{device.Name},发送的数据:{returndata.ToJson()}", 1);
|
_loggerService.AddLogger($"{data.ECode},{device.Name},发送的数据:{returndata.ToJson()}", 1);
|
||||||
return new ResultInfo(ResultState.SUCCESS, "success", returndata);
|
return new ResultInfo(ResultState.SUCCESS, "success", returndata);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 16进制转汉字
|
/// 16进制转汉字
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue