|
|
|
@ -1,10 +1,8 @@
|
|
|
|
|
using Application.Domain.Entities;
|
|
|
|
|
using Application.Models;
|
|
|
|
|
using Infrastructure.Application;
|
|
|
|
|
using Infrastructure.Data;
|
|
|
|
|
using Infrastructure.Domain;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using System;
|
|
|
|
@ -47,52 +45,6 @@ namespace IoT.Shared.Services
|
|
|
|
|
this._iotTiggerRepo = iotTiggerRepo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 服务端响应节点上传数据
|
|
|
|
|
|
|
|
|
|
public void UpdateProduct(string message)
|
|
|
|
|
{
|
|
|
|
|
using var scope = this._services.CreateScope();
|
|
|
|
|
var repo = scope.ServiceProvider.GetService<IRepository<Product>>();
|
|
|
|
|
var model = message.FromJson<Product>();
|
|
|
|
|
var entity = repo.Table().Include(o => o.Apis).ThenInclude(o => o.Parameters).FirstOrDefault(o => o.Id == model.Id);
|
|
|
|
|
if (entity == null)
|
|
|
|
|
{
|
|
|
|
|
repo.Add(model);
|
|
|
|
|
repo.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateDevice(string message)
|
|
|
|
|
{
|
|
|
|
|
var model = message.FromJson<Device>();
|
|
|
|
|
using var scope = this._services.CreateScope();
|
|
|
|
|
var repo = scope.ServiceProvider.GetService<IRepository<Device>>();
|
|
|
|
|
var device = repo.Table().Include(o => o.Data).FirstOrDefault(o => o.Id == model.Id);
|
|
|
|
|
if (device == null)
|
|
|
|
|
{
|
|
|
|
|
device = new Device
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
ProductId = model.ProductId,
|
|
|
|
|
};
|
|
|
|
|
repo.Add(device);
|
|
|
|
|
}
|
|
|
|
|
device.From(model);
|
|
|
|
|
foreach (var data in model.Data)
|
|
|
|
|
{
|
|
|
|
|
var data2 = device.Data.FirstOrDefault(o => o.Id == data.Id);
|
|
|
|
|
if (data2 == null)
|
|
|
|
|
{
|
|
|
|
|
data2 = new Data
|
|
|
|
|
{
|
|
|
|
|
Id = data.Id,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
data2.From(data);
|
|
|
|
|
}
|
|
|
|
|
repo.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateList<T>(string message, Expression<Func<T, bool>> predicate) where T : BaseEntity
|
|
|
|
|
{
|
|
|
|
|
using var scope = this._services.CreateScope();
|
|
|
|
@ -106,8 +58,6 @@ namespace IoT.Shared.Services
|
|
|
|
|
repo.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion 服务端响应节点上传数据
|
|
|
|
|
|
|
|
|
|
#region private
|
|
|
|
|
|
|
|
|
|
public void Update<T>(string message) where T : BaseEntity
|
|
|
|
@ -156,14 +106,5 @@ namespace IoT.Shared.Services
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion private
|
|
|
|
|
|
|
|
|
|
#region 后台编辑
|
|
|
|
|
|
|
|
|
|
public void EditCommand(EditCommandModel model)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion 后台编辑
|
|
|
|
|
}
|
|
|
|
|
}
|