2022-05-19 15:01:08 +08:00
|
|
|
|
using DotNetCore.CAP;
|
|
|
|
|
|
using Furion;
|
2021-06-02 15:10:40 +08:00
|
|
|
|
using Furion.DependencyInjection;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
using Furion.DistributedIDGenerator;
|
2021-06-02 15:10:40 +08:00
|
|
|
|
using Furion.RemoteRequest.Extensions;
|
|
|
|
|
|
using Furion.TaskScheduler;
|
2022-05-19 15:01:08 +08:00
|
|
|
|
using Mapster;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
using Nirvana.Common;
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2022-07-12 17:53:04 +08:00
|
|
|
|
using System.Linq.Expressions;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2022-05-19 15:01:08 +08:00
|
|
|
|
using Waste.Application.SubscribeInfo;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
using Waste.Domain;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Waste.Application
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 投放记录管理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class ResultService : BaseInfoService, IResultService, ITransient
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ISqlSugarRepository<W_Result> repository;
|
|
|
|
|
|
private readonly SqlSugarClient dbClient;
|
|
|
|
|
|
private readonly ILoggerService _loggerService;
|
2022-05-19 15:01:08 +08:00
|
|
|
|
private readonly ICapPublisher _capBus;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
|
2022-05-19 15:01:08 +08:00
|
|
|
|
public ResultService(ISqlSugarRepository<W_Result> sqlSugarRepository, ILoggerService loggerService, ICapPublisher capPublisher)
|
2021-05-27 16:58:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
repository = sqlSugarRepository;
|
|
|
|
|
|
dbClient = repository.Context;
|
|
|
|
|
|
_loggerService = loggerService;
|
2022-05-19 15:01:08 +08:00
|
|
|
|
_capBus = capPublisher;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
}
|
2022-07-06 09:07:42 +08:00
|
|
|
|
|
2021-05-27 16:58:40 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取投放记录
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="param"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<PageParms<ResultList>> GetListAsync(QueryParams param)
|
|
|
|
|
|
{
|
|
|
|
|
|
RefAsync<int> totalnum = 0;
|
|
|
|
|
|
var temquery = dbClient.Queryable<W_Result>();
|
|
|
|
|
|
if (param.queryParam != null && param.queryParam.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<IConditionalModel> conModels = new List<IConditionalModel>();
|
|
|
|
|
|
param.queryParam.ForEach(x =>
|
|
|
|
|
|
{
|
2021-06-04 17:44:06 +08:00
|
|
|
|
var val = x.Value.ToStrEmpty();
|
2021-05-27 16:58:40 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(val))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (x.Name.ToStr().ToLower() == "facecode")
|
|
|
|
|
|
{
|
2022-01-20 13:51:01 +08:00
|
|
|
|
temquery = temquery.Where(t => SqlFunc.Subqueryable<W_Device>().Where(e => e.FacEcode.Contains(val) && t.DeviceId == e.Id).Any());
|
2021-05-27 16:58:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (x.Name.ToStr().ToLower() == "name")
|
|
|
|
|
|
{
|
2022-01-20 13:51:01 +08:00
|
|
|
|
temquery = temquery.Where(t => SqlFunc.Subqueryable<W_Device>().Where(e => e.Name.Contains(val) && t.DeviceId == e.Id).Any());
|
2021-05-27 16:58:40 +08:00
|
|
|
|
}
|
2022-07-12 17:53:04 +08:00
|
|
|
|
else if (x.Name.Equals("poststatus", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
{
|
|
|
|
|
|
var status = val.ToInt();
|
|
|
|
|
|
if (status >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
temquery = temquery.Where(t => SqlFunc.Subqueryable<W_ResultExt>().Where(e => e.Status == status && t.Id == e.ResultId).Any());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
temquery = temquery.Where(t => SqlFunc.Subqueryable<W_ResultExt>().Where(e => t.Id == e.ResultId).NotAny());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-05-27 16:58:40 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
conModels.Add(new ConditionalModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
FieldName = x.Name,
|
|
|
|
|
|
ConditionalType = (ConditionalType)x.Type,
|
|
|
|
|
|
FieldValue = val
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (conModels.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
temquery = temquery.Where(conModels);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-05-30 16:02:38 +08:00
|
|
|
|
//针对非平台类型,则可以查看下面所有的子账户设备
|
2021-05-27 16:58:40 +08:00
|
|
|
|
if (currentUser.AccountType != (int)AccountType.platform)
|
|
|
|
|
|
{
|
2021-05-30 16:02:38 +08:00
|
|
|
|
var sql = $"code like '{currentUser.BusinessCode}'+'%' and id = x.businessid";
|
|
|
|
|
|
temquery = temquery.Where(x => SqlFunc.Subqueryable<W_Business>().Where(sql).Any());
|
2021-05-27 16:58:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
string sorts = string.Format("{0} {1}", param.sort, param.order);
|
|
|
|
|
|
var query = await temquery.OrderBy(sorts)
|
|
|
|
|
|
.Select(x => new ResultList
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
|
BusinessId = x.BusinessId,
|
|
|
|
|
|
DeviceId = x.DeviceId,
|
|
|
|
|
|
WasteType = x.WasteType,
|
|
|
|
|
|
Tare = x.Tare,
|
|
|
|
|
|
GrossWeight = x.GrossWeight,
|
|
|
|
|
|
NetWeight = x.NetWeight,
|
|
|
|
|
|
Registration = x.Registration,
|
2021-08-13 17:30:59 +08:00
|
|
|
|
CreateTime = x.CreateTime,
|
2022-03-28 17:19:48 +08:00
|
|
|
|
PostStatus = -1
|
2021-05-27 16:58:40 +08:00
|
|
|
|
})
|
|
|
|
|
|
.Mapper((it, cache) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var allbus = cache.Get(list =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var ids = list.Where(e => e.BusinessId != Guid.Empty).Select(e => e.BusinessId).ToList();
|
2021-08-13 17:30:59 +08:00
|
|
|
|
return dbClient.Queryable<W_Business>().Where(e => ids.Contains(e.Id)).ToList();
|
2021-05-27 16:58:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
it.BusinessName = allbus.FirstOrDefault(e => e.Id == it.BusinessId)?.Name;
|
|
|
|
|
|
var alldev = cache.Get(list =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var ids = list.Where(e => e.DeviceId != Guid.Empty).Select(e => e.DeviceId).ToList();
|
2021-08-13 17:30:59 +08:00
|
|
|
|
return dbClient.Queryable<W_Device>().Where(e => ids.Contains(e.Id)).ToList();
|
2021-05-27 16:58:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
var dev = alldev.FirstOrDefault(e => e.Id == it.DeviceId);
|
|
|
|
|
|
if (dev != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
it.DeviceName = dev.Name;
|
|
|
|
|
|
it.DeviceFacEcode = dev.FacEcode;
|
|
|
|
|
|
it.DeviceEcode = dev.Ecode;
|
|
|
|
|
|
it.DeviceAddress = dev.Address;
|
|
|
|
|
|
}
|
2022-03-28 17:19:48 +08:00
|
|
|
|
var allres = cache.Get(list =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var ids = list.Select(e => e.Id).ToList();
|
|
|
|
|
|
return dbClient.Queryable<W_ResultExt>().Where(e => ids.Contains(e.ResultId)).ToList();
|
|
|
|
|
|
});
|
2021-08-13 17:30:59 +08:00
|
|
|
|
var res = allres.FirstOrDefault(e => e.ResultId == it.Id);
|
2022-03-28 17:19:48 +08:00
|
|
|
|
if (res != null)
|
2021-08-13 17:30:59 +08:00
|
|
|
|
{
|
|
|
|
|
|
it.PostStatus = res.Status;
|
|
|
|
|
|
}
|
2022-07-06 09:07:42 +08:00
|
|
|
|
var allext = cache.Get(list =>
|
|
|
|
|
|
{
|
2022-06-18 14:58:15 +08:00
|
|
|
|
var ids = list.Select(e => e.Id).ToList();
|
|
|
|
|
|
return dbClient.Queryable<W_MeasureResult>().Where(e => ids.Contains(e.ResultId)).ToList();
|
|
|
|
|
|
});
|
|
|
|
|
|
var ext = allext.FirstOrDefault(e => e.ResultId == it.Id);
|
|
|
|
|
|
it.WasteType = ext != null && !ext.WasteSType.IsEmpty() ? $"{ext.WasteSType}【{it.WasteType}】" : it.WasteType;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
})
|
|
|
|
|
|
.ToPageListAsync(param.offset, param.limit, totalnum);
|
|
|
|
|
|
return new PageParms<ResultList>
|
|
|
|
|
|
{
|
|
|
|
|
|
page = param.offset,
|
|
|
|
|
|
Items = query,
|
|
|
|
|
|
totalnum = totalnum,
|
|
|
|
|
|
limit = param.limit
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2022-07-06 09:07:42 +08:00
|
|
|
|
|
2022-07-12 17:53:04 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询历史投放记录
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<PageParms<ResultListByEquS2CDto>> GetListByEquAsync(ResultListByEquC2SDto input)
|
|
|
|
|
|
{
|
|
|
|
|
|
RefAsync<int> totalnum = 0;
|
|
|
|
|
|
Expression<Func<W_Result, bool>> exp = Expressionable.Create<W_Result>().AndIF(input.StartTime.HasValue, x => x.CreateTime >= input.StartTime).AndIF(input.EndTime.HasValue, x => x.CreateTime <= input.EndTime).And(x => x.DeviceId == input.DeviceId).ToExpression();
|
|
|
|
|
|
var query = await dbClient.Queryable<W_Result>()
|
|
|
|
|
|
.Where(exp)
|
|
|
|
|
|
.OrderBy(x => x.CreateTime, OrderByType.Desc)
|
|
|
|
|
|
.Select(x => new ResultListByEquS2SDto
|
|
|
|
|
|
{
|
|
|
|
|
|
CreateTime = x.CreateTime,
|
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
|
TrashCode = x.Registration,
|
|
|
|
|
|
WasteType = x.WasteType,
|
|
|
|
|
|
GrossWeight = x.GrossWeight
|
|
|
|
|
|
})
|
|
|
|
|
|
.Mapper((it, cache) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var allext = cache.Get(list =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var ids = list.Select(x => x.Id).ToList();
|
|
|
|
|
|
return dbClient.Queryable<W_MeasureResult>().Where(e => ids.Contains(e.ResultId)).ToList();
|
|
|
|
|
|
});
|
|
|
|
|
|
var ext = allext.FirstOrDefault(x => x.ResultId == it.Id);
|
|
|
|
|
|
if (ext != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
it.WasteSType = ext.WasteSType;
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.ToPageListAsync(input.offset, input.limit, totalnum);
|
|
|
|
|
|
var list = query.Adapt<List<ResultListByEquS2CDto>>();
|
|
|
|
|
|
return new PageParms<ResultListByEquS2CDto>
|
|
|
|
|
|
{
|
|
|
|
|
|
page = input.offset,
|
|
|
|
|
|
Items = list,
|
|
|
|
|
|
totalnum = totalnum,
|
|
|
|
|
|
limit = input.limit
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-28 17:19:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// wifi模块测量结果增加
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task InsertResultByWifiAsync(WifiPackage data)
|
|
|
|
|
|
{
|
|
|
|
|
|
//查找设备
|
|
|
|
|
|
var device = await dbClient.Queryable<W_Device>().FirstAsync(x => data.sn == x.Ecode);
|
|
|
|
|
|
// _loggerService.AddLogger($"接收到的数据,参数:{myPackage.ToJson()}", 3);
|
|
|
|
|
|
if (device == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//记录日志
|
|
|
|
|
|
_loggerService.AddLogger($"设备未找到,参数:{data.ToJson()}", 3);
|
2022-03-29 09:33:34 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
//计算净重,毛重-皮重=净重,如果净重小于等于0则不上报保存
|
|
|
|
|
|
decimal weight = (data.Weight.ToDecimal() - device.Tare).ToDecimal(2);
|
|
|
|
|
|
if (weight <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
//记录日志
|
|
|
|
|
|
_loggerService.AddLogger($"净重为0不上报,参数:{data.ToJson()}", 3);
|
|
|
|
|
|
return;
|
2022-03-28 17:19:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
var devicedata = await dbClient.Queryable<W_DeviceData>().FirstAsync(x => x.DeviceId == device.Id);
|
|
|
|
|
|
var resultid = IDGen.NextID();
|
|
|
|
|
|
DateTime time = DateTime.Now;
|
|
|
|
|
|
//检查设备是否为今天第一次上报
|
|
|
|
|
|
bool isfrist = false;
|
|
|
|
|
|
if (device.LastHeartTime.HasValue && device.LastHeartTime.Value.Date != DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
isfrist = true;
|
|
|
|
|
|
}
|
2022-06-18 14:58:15 +08:00
|
|
|
|
decimal currentweight = data.Weight.IsEmpty() ? 0 : data.Weight.ToDecimal();
|
2022-03-28 17:19:48 +08:00
|
|
|
|
//记录数据
|
|
|
|
|
|
await dbClient.Ado.UseStoredProcedure().ExecuteCommandAsync("Proc_InsertResult", new
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceid = device.Id,
|
|
|
|
|
|
businessid = device.Businessid,
|
|
|
|
|
|
resultid = resultid,
|
2022-05-19 15:01:08 +08:00
|
|
|
|
imei = devicedata != null ? devicedata.IMSI : "",
|
|
|
|
|
|
iccid = devicedata != null ? devicedata.ICCID : "",
|
|
|
|
|
|
imsi = devicedata != null ? devicedata.IMSI : "",
|
2022-03-28 17:19:48 +08:00
|
|
|
|
time = time,
|
|
|
|
|
|
latitude = "",
|
|
|
|
|
|
longitude = "",
|
|
|
|
|
|
sign = "",
|
|
|
|
|
|
city = "",
|
|
|
|
|
|
area = data.trashcode,
|
|
|
|
|
|
wastetype = data.WasteType,
|
2022-05-19 15:01:08 +08:00
|
|
|
|
weigth = currentweight,
|
2022-03-28 17:19:48 +08:00
|
|
|
|
isheart = data.IsHeart,
|
|
|
|
|
|
tare = device.Tare,
|
|
|
|
|
|
isfrist = isfrist
|
|
|
|
|
|
});
|
2022-05-19 15:01:08 +08:00
|
|
|
|
if (!data.IsHeart)
|
|
|
|
|
|
{
|
|
|
|
|
|
await SendMessageToThird(new SendThirdMessageSubscribeS2SDto
|
|
|
|
|
|
{
|
|
|
|
|
|
DeviceId = device.Id,
|
|
|
|
|
|
Time = time,
|
|
|
|
|
|
TrashCode = data.trashcode,
|
|
|
|
|
|
WasteType = data.WasteType,
|
|
|
|
|
|
Weight = currentweight
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2022-03-28 17:19:48 +08:00
|
|
|
|
}
|
2021-11-23 17:49:40 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新的4G模块测量结果增加
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="myPackage"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task InsertResultBy4GAsync(nMyPackage myPackage)
|
|
|
|
|
|
{
|
|
|
|
|
|
//查找设备
|
|
|
|
|
|
var device = await dbClient.Queryable<W_Device>().FirstAsync(x => myPackage.IMEI == x.Ecode);
|
|
|
|
|
|
// _loggerService.AddLogger($"接收到的数据,参数:{myPackage.ToJson()}", 3);
|
|
|
|
|
|
if (device == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//记录日志
|
|
|
|
|
|
_loggerService.AddLogger($"设备未找到,参数:{myPackage.ToJson()}", 3);
|
2022-05-26 13:54:25 +08:00
|
|
|
|
return;
|
2021-11-23 17:49:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
var devicedata = await dbClient.Queryable<W_DeviceData>().FirstAsync(x => x.DeviceId == device.Id);
|
|
|
|
|
|
var resultid = IDGen.NextID();
|
|
|
|
|
|
DateTime time = DateTime.Now;
|
|
|
|
|
|
if (myPackage.IsHeart)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.Longitude) || myPackage.Longitude.ToDecimal() == 0) myPackage.Longitude = devicedata != null ? devicedata.Longitude : "0";
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.Latitude) || myPackage.Latitude.ToDecimal() == 0) myPackage.Latitude = devicedata != null ? devicedata.Latitude : "0";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.IMSI)) myPackage.IMSI = devicedata != null ? devicedata.IMSI : "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.IMEI)) myPackage.IMEI = devicedata != null ? devicedata.IMEI : "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.ICCID)) myPackage.ICCID = devicedata != null ? devicedata.ICCID : "";
|
|
|
|
|
|
if (!string.IsNullOrEmpty(myPackage.Time) && myPackage.Time.Length == 14)
|
|
|
|
|
|
{
|
|
|
|
|
|
time = $"{myPackage.Time.Substring(0, 4)}-{myPackage.Time.Substring(4, 2)}-{myPackage.Time.Substring(6, 2)} {myPackage.Time.Substring(8, 2)}:{myPackage.Time.Substring(10, 2)}:{myPackage.Time.Substring(12, 2)}".ToDate();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//检查设备是否为今天第一次上报
|
|
|
|
|
|
bool isfrist = false;
|
|
|
|
|
|
if (device.LastHeartTime.HasValue && device.LastHeartTime.Value.Date != DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
isfrist = true;
|
|
|
|
|
|
}
|
2022-05-17 18:07:00 +08:00
|
|
|
|
var Weight = myPackage.Weight.IsEmpty() ? 0 : myPackage.Weight.ToDecimal();
|
2021-11-23 17:49:40 +08:00
|
|
|
|
//记录数据
|
|
|
|
|
|
await dbClient.Ado.UseStoredProcedure().ExecuteCommandAsync("Proc_InsertResult", new
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceid = device.Id,
|
|
|
|
|
|
businessid = device.Businessid,
|
|
|
|
|
|
resultid = resultid,
|
|
|
|
|
|
imei = myPackage.IMEI,
|
|
|
|
|
|
iccid = myPackage.ICCID,
|
|
|
|
|
|
imsi = myPackage.IMSI,
|
|
|
|
|
|
time = time,
|
|
|
|
|
|
latitude = myPackage.Latitude,
|
|
|
|
|
|
longitude = myPackage.Longitude,
|
|
|
|
|
|
sign = myPackage.GSLQ,
|
|
|
|
|
|
city = "",
|
|
|
|
|
|
area = myPackage.trashcode,
|
|
|
|
|
|
wastetype = myPackage.WasteType,
|
2022-05-17 18:07:00 +08:00
|
|
|
|
weigth = Weight,
|
2021-11-23 17:49:40 +08:00
|
|
|
|
isheart = myPackage.IsHeart,
|
|
|
|
|
|
tare = device.Tare,
|
|
|
|
|
|
isfrist = isfrist
|
|
|
|
|
|
});
|
2022-05-19 15:01:08 +08:00
|
|
|
|
if (!myPackage.IsHeart)
|
|
|
|
|
|
{
|
|
|
|
|
|
await SendMessageToThird(new SendThirdMessageSubscribeS2SDto
|
|
|
|
|
|
{
|
|
|
|
|
|
DeviceId = device.Id,
|
|
|
|
|
|
Time = time,
|
|
|
|
|
|
TrashCode = myPackage.trashcode,
|
|
|
|
|
|
WasteType = myPackage.WasteType,
|
|
|
|
|
|
Weight = Weight
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-07-06 09:07:42 +08:00
|
|
|
|
|
2022-05-19 15:01:08 +08:00
|
|
|
|
/// <summary>
|
2022-06-18 14:58:15 +08:00
|
|
|
|
/// 新的A8 4G模块测量结果增加
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="myPackage"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task InsertResultByA84GAsync(A8MyPackage myPackage)
|
|
|
|
|
|
{
|
2022-06-21 14:20:09 +08:00
|
|
|
|
//如果uuid不为空,并且以存在记录,则忽略
|
2022-07-07 15:20:09 +08:00
|
|
|
|
//if (!myPackage.IsHeart && !myPackage.UUID.IsEmpty() && await dbClient.Queryable<W_MeasureResult>().AnyAsync(x => x.UUID == myPackage.UUID))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// _loggerService.AddLogger($"A8记录重复,内容:{myPackage.ToJson()}", 1);
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//}
|
2022-06-18 14:58:15 +08:00
|
|
|
|
//查找设备
|
|
|
|
|
|
var device = await dbClient.Queryable<W_Device>().FirstAsync(x => myPackage.IMEI == x.Ecode);
|
|
|
|
|
|
// _loggerService.AddLogger($"接收到的数据,参数:{myPackage.ToJson()}", 3);
|
|
|
|
|
|
if (device == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//记录日志
|
|
|
|
|
|
_loggerService.AddLogger($"设备未找到,参数:{myPackage.ToJson()}", 3);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
var devicedata = await dbClient.Queryable<W_DeviceData>().FirstAsync(x => x.DeviceId == device.Id);
|
|
|
|
|
|
var resultid = IDGen.NextID();
|
|
|
|
|
|
DateTime time = DateTime.Now;
|
|
|
|
|
|
if (myPackage.IsHeart)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.Longitude) || myPackage.Longitude.ToDecimal() == 0) myPackage.Longitude = devicedata != null ? devicedata.Longitude : "0";
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.Latitude) || myPackage.Latitude.ToDecimal() == 0) myPackage.Latitude = devicedata != null ? devicedata.Latitude : "0";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.IMSI)) myPackage.IMSI = devicedata != null ? devicedata.IMSI : "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.IMEI)) myPackage.IMEI = devicedata != null ? devicedata.IMEI : "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.ICCID)) myPackage.ICCID = devicedata != null ? devicedata.ICCID : "";
|
|
|
|
|
|
if (!string.IsNullOrEmpty(myPackage.Time) && myPackage.Time.Length == 14)
|
|
|
|
|
|
{
|
|
|
|
|
|
time = $"{myPackage.Time.Substring(0, 4)}-{myPackage.Time.Substring(4, 2)}-{myPackage.Time.Substring(6, 2)} {myPackage.Time.Substring(8, 2)}:{myPackage.Time.Substring(10, 2)}:{myPackage.Time.Substring(12, 2)}".ToDate();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//检查设备是否为今天第一次上报
|
|
|
|
|
|
bool isfrist = false;
|
|
|
|
|
|
if (device.LastHeartTime.HasValue && device.LastHeartTime.Value.Date != DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
isfrist = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
var Weight = myPackage.Weight.IsEmpty() ? 0 : myPackage.Weight.ToDecimal();
|
|
|
|
|
|
decimal price = myPackage.Price.IsEmpty() ? 0 : myPackage.Price.ToDecimal();
|
|
|
|
|
|
decimal amount = myPackage.Amount.IsEmpty() ? 0 : myPackage.Amount.ToDecimal();
|
|
|
|
|
|
string wastestype = myPackage.WasteSType.ToStr();
|
|
|
|
|
|
//记录数据
|
|
|
|
|
|
await dbClient.Ado.UseStoredProcedure().ExecuteCommandAsync("Proc_InsertResult", new
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceid = device.Id,
|
|
|
|
|
|
businessid = device.Businessid,
|
|
|
|
|
|
resultid = resultid,
|
|
|
|
|
|
imei = myPackage.IMEI,
|
|
|
|
|
|
iccid = myPackage.ICCID,
|
|
|
|
|
|
imsi = myPackage.IMSI,
|
|
|
|
|
|
time = time,
|
|
|
|
|
|
latitude = myPackage.Latitude,
|
|
|
|
|
|
longitude = myPackage.Longitude,
|
|
|
|
|
|
sign = myPackage.GSLQ,
|
|
|
|
|
|
city = "",
|
|
|
|
|
|
area = myPackage.trashcode,
|
|
|
|
|
|
wastetype = myPackage.WasteType,
|
|
|
|
|
|
weigth = Weight,
|
|
|
|
|
|
isheart = myPackage.IsHeart,
|
|
|
|
|
|
tare = device.Tare,
|
|
|
|
|
|
isfrist = isfrist
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!myPackage.IsHeart)
|
|
|
|
|
|
{
|
|
|
|
|
|
//记录价格数据
|
|
|
|
|
|
if (!myPackage.UUID.IsEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
await dbClient.Insertable(new W_MeasureResult
|
|
|
|
|
|
{
|
|
|
|
|
|
ResultId = resultid,
|
|
|
|
|
|
WasteSType = wastestype,
|
|
|
|
|
|
Amount = amount,
|
|
|
|
|
|
OpUser = myPackage.OpUser.ToStr(),
|
|
|
|
|
|
Price = price,
|
|
|
|
|
|
UUID = myPackage.UUID
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
await SendMessageToThird(new SendThirdMessageSubscribeS2SDto
|
|
|
|
|
|
{
|
|
|
|
|
|
DeviceId = device.Id,
|
|
|
|
|
|
Time = time,
|
|
|
|
|
|
TrashCode = myPackage.trashcode,
|
|
|
|
|
|
WasteType = myPackage.WasteType,
|
|
|
|
|
|
Weight = Weight,
|
|
|
|
|
|
WasteSType = wastestype
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-07-06 09:07:42 +08:00
|
|
|
|
|
2022-06-18 14:58:15 +08:00
|
|
|
|
/// <summary>
|
2022-05-19 15:01:08 +08:00
|
|
|
|
/// 给第三方推送消息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private async Task SendMessageToThird(SendThirdMessageSubscribeS2SDto input)
|
|
|
|
|
|
{
|
2022-06-18 14:58:15 +08:00
|
|
|
|
if (input.Weight <= 0)
|
2022-05-26 13:54:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-05-19 15:01:08 +08:00
|
|
|
|
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>();
|
2022-07-07 15:20:09 +08:00
|
|
|
|
senddata.Body = configdata.Body.ToStr();
|
2022-05-19 15:01:08 +08:00
|
|
|
|
senddata.Url = configdata.Url.ToStr();
|
|
|
|
|
|
await _capBus.PublishAsync("third.service.sendmessage", senddata);
|
|
|
|
|
|
}
|
2021-11-23 17:49:40 +08:00
|
|
|
|
}
|
2022-07-06 09:07:42 +08:00
|
|
|
|
|
2021-05-27 16:58:40 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 增加测量记录
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="myPackage"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<ResultInfo> InsertResultAsync(MyPackage myPackage)
|
|
|
|
|
|
{
|
|
|
|
|
|
//查找设备
|
2021-11-23 17:49:40 +08:00
|
|
|
|
var device = await dbClient.Queryable<W_Device>().FirstAsync(x => myPackage.IMEI == x.Ecode);
|
2022-03-28 17:19:48 +08:00
|
|
|
|
// _loggerService.AddLogger($"接收到的数据,参数:{myPackage.ToJson()}", 3);
|
2021-05-27 16:58:40 +08:00
|
|
|
|
if (device == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//记录日志
|
|
|
|
|
|
_loggerService.AddLogger($"设备未找到,参数:{myPackage.ToJson()}", 3);
|
|
|
|
|
|
return new ResultInfo(ResultState.FAIL, "设备未找到");
|
|
|
|
|
|
}
|
2021-08-01 15:25:01 +08:00
|
|
|
|
var devicedata = await dbClient.Queryable<W_DeviceData>().FirstAsync(x => x.DeviceId == device.Id);
|
2021-05-27 16:58:40 +08:00
|
|
|
|
var resultid = IDGen.NextID();
|
|
|
|
|
|
DateTime time = DateTime.Now;
|
|
|
|
|
|
if (myPackage.IsHeart)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.Longitude) || myPackage.Longitude.ToDecimal() == 0) myPackage.Longitude = devicedata != null ? devicedata.Longitude : "0";
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.Latitude) || myPackage.Latitude.ToDecimal() == 0) myPackage.Latitude = devicedata != null ? devicedata.Latitude : "0";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.IMSI)) myPackage.IMSI = devicedata != null ? devicedata.IMSI : "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.IMEI)) myPackage.IMEI = devicedata != null ? devicedata.IMEI : "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(myPackage.ICCID)) myPackage.ICCID = devicedata != null ? devicedata.ICCID : "";
|
|
|
|
|
|
if (!string.IsNullOrEmpty(myPackage.Time) && myPackage.Time.Length == 14)
|
|
|
|
|
|
{
|
|
|
|
|
|
time = $"{myPackage.Time.Substring(0, 4)}-{myPackage.Time.Substring(4, 2)}-{myPackage.Time.Substring(6, 2)} {myPackage.Time.Substring(8, 2)}:{myPackage.Time.Substring(10, 2)}:{myPackage.Time.Substring(12, 2)}".ToDate();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//检查设备是否为今天第一次上报
|
|
|
|
|
|
bool isfrist = false;
|
|
|
|
|
|
if (device.LastHeartTime.HasValue && device.LastHeartTime.Value.Date != DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
isfrist = true;
|
|
|
|
|
|
}
|
2021-06-11 21:31:55 +08:00
|
|
|
|
|
|
|
|
|
|
if (myPackage.IsChecked && !string.IsNullOrEmpty(myPackage.Area) && myPackage.Area.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
//新的协议中此字段为垃圾桶编号
|
|
|
|
|
|
var areaBytes = Encoding.Default.GetBytes(myPackage.Area);
|
|
|
|
|
|
//长度为5个字节,后三位为垃圾桶编号(16进制)
|
|
|
|
|
|
if (areaBytes.Length == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
var typeBytes = new byte[3];
|
|
|
|
|
|
for (var i = 0; i < 3; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
typeBytes[i] = areaBytes[i + 2];
|
|
|
|
|
|
}
|
|
|
|
|
|
var typeHex = Convert.ToHexString(typeBytes);
|
|
|
|
|
|
myPackage.Area = Convert.ToInt32(typeHex, 16).ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
//000F000002.16进制
|
2022-03-28 17:19:48 +08:00
|
|
|
|
// var areaHex = Convert.ToHexString(areaBytes);
|
2021-06-11 21:31:55 +08:00
|
|
|
|
}
|
2022-05-19 15:01:08 +08:00
|
|
|
|
decimal weight = myPackage.Weight.IsEmpty() ? 0 : myPackage.Weight.ToDecimal();
|
2021-05-27 16:58:40 +08:00
|
|
|
|
//记录数据
|
|
|
|
|
|
await dbClient.Ado.UseStoredProcedure().ExecuteCommandAsync("Proc_InsertResult", new
|
|
|
|
|
|
{
|
|
|
|
|
|
deviceid = device.Id,
|
|
|
|
|
|
businessid = device.Businessid,
|
|
|
|
|
|
resultid = resultid,
|
|
|
|
|
|
imei = myPackage.IMEI,
|
|
|
|
|
|
iccid = myPackage.ICCID,
|
|
|
|
|
|
imsi = myPackage.IMSI,
|
|
|
|
|
|
time = time,
|
|
|
|
|
|
latitude = myPackage.Latitude,
|
|
|
|
|
|
longitude = myPackage.Longitude,
|
|
|
|
|
|
sign = myPackage.GSLQ,
|
|
|
|
|
|
city = myPackage.City,
|
|
|
|
|
|
area = myPackage.Area,
|
|
|
|
|
|
wastetype = myPackage.WasteType,
|
2022-05-19 15:01:08 +08:00
|
|
|
|
weigth = weight,
|
2021-05-27 16:58:40 +08:00
|
|
|
|
isheart = myPackage.IsHeart,
|
|
|
|
|
|
tare = device.Tare,
|
|
|
|
|
|
isfrist = isfrist
|
|
|
|
|
|
});
|
|
|
|
|
|
//上传垃圾数据
|
2021-07-29 19:10:19 +08:00
|
|
|
|
//if (myPackage.IsWeight && myPackage.Weight.ToDecimal() > 0)
|
2021-06-11 21:31:55 +08:00
|
|
|
|
//{
|
|
|
|
|
|
// var devicesecret = await repository.Change<W_SZDevice>().Context.Queryable<W_SZDevice>().FirstAsync(x => x.DeviceId == device.Id);
|
2021-07-29 19:10:19 +08:00
|
|
|
|
// if (devicesecret != null && !string.IsNullOrEmpty(devicesecret.Secret)
|
2021-06-11 21:31:55 +08:00
|
|
|
|
// && !string.IsNullOrEmpty(devicesecret.SecretHash)
|
|
|
|
|
|
// && !string.IsNullOrEmpty(devicesecret.DevId))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// int timestamp = GetTimestamp(time);
|
|
|
|
|
|
// await _suZhouService.PostGarbagesAsync(new GarbagePltC2SDto
|
|
|
|
|
|
// {
|
|
|
|
|
|
// Weight = myPackage.Weight.ToDouble(),
|
|
|
|
|
|
// secret = devicesecret.Secret,
|
|
|
|
|
|
// secrethash = devicesecret.SecretHash,
|
|
|
|
|
|
// ScanningTime = timestamp,
|
|
|
|
|
|
// DStatus = 0,
|
|
|
|
|
|
// deviceid = devicesecret.DevId,
|
2021-07-30 18:15:58 +08:00
|
|
|
|
// Trash = myPackage.Area,
|
2021-06-11 21:31:55 +08:00
|
|
|
|
// Type = TrashType(myPackage.WasteType)
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
2022-05-19 15:01:08 +08:00
|
|
|
|
if (!myPackage.IsHeart)
|
|
|
|
|
|
{
|
|
|
|
|
|
await SendMessageToThird(new SendThirdMessageSubscribeS2SDto
|
|
|
|
|
|
{
|
|
|
|
|
|
DeviceId = device.Id,
|
|
|
|
|
|
Time = time,
|
|
|
|
|
|
TrashCode = myPackage.Area,
|
|
|
|
|
|
WasteType = myPackage.WasteType,
|
|
|
|
|
|
Weight = weight
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2021-05-27 16:58:40 +08:00
|
|
|
|
return new ResultInfo(ResultState.SUCCESS, "success");
|
|
|
|
|
|
}
|
2021-06-11 21:31:55 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// byte转int
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="bt"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private static int ByteToInt(byte bt)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Convert.ToInt32(((int)bt).ToString("X2"), 16);
|
|
|
|
|
|
}
|
2022-07-06 09:07:42 +08:00
|
|
|
|
|
2021-05-27 16:58:40 +08:00
|
|
|
|
private static int GetTimestamp(DateTime time)
|
|
|
|
|
|
{
|
|
|
|
|
|
DateTime dateTimeStart = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 8, 0, 0));
|
|
|
|
|
|
int timestamp = Convert.ToInt32((time - dateTimeStart).TotalSeconds);
|
|
|
|
|
|
return timestamp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int TrashType(string type)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (type == "厨余垃圾") return 1;
|
|
|
|
|
|
else if (type == "可回收物") return 2;
|
|
|
|
|
|
else if (type == "有害垃圾") return 3;
|
|
|
|
|
|
else if (type == "其他垃圾") return 4;
|
|
|
|
|
|
else return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-07-06 09:07:42 +08:00
|
|
|
|
}
|