fix 设备查询优化
This commit is contained in:
@@ -14,7 +14,6 @@ using Mapster;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
@@ -34,6 +33,7 @@ public class DeviceService : IDeviceService
|
||||
.LeftJoin<DeviceRegistryEntity>((d, dt, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||
.LeftJoin<BusinessPlaceEntity>((d, dt, dr, bp) => dr.BusinessPlaceCode == bp.Code)
|
||||
.WhereIF(request.Type.HasValue, (d, dt) => d.Type == request.Type)
|
||||
.WhereIF(request.Search.IsPresent(), (d) => d.UniqueNo == request.Search || d.DeployPlace.Contains(request.Search))
|
||||
.Select((d, dt, dr, bp) => new DevicePageResponse
|
||||
{
|
||||
FuncsStr = d.Funcs.ToString(),
|
||||
@@ -139,13 +139,13 @@ public class DeviceService : IDeviceService
|
||||
var form = lst[i];
|
||||
if (form.UniqueNo.IsEmpty())
|
||||
{
|
||||
errs.Add($"第{i+1}条的第一列的设备唯一码不能缺少!");
|
||||
errs.Add($"第{i + 1}条的第一列的设备唯一码不能缺少!");
|
||||
continue;
|
||||
}
|
||||
if (form.PlaceeCode != null)
|
||||
{
|
||||
var place = places.Where(x => x.Code == form.PlaceeCode).FirstOrDefault();
|
||||
if(place == null)
|
||||
if (place == null)
|
||||
{
|
||||
errs.Add($"该设备{form.UniqueNo}配置的营业点营业点不存在!");
|
||||
continue;
|
||||
@@ -160,7 +160,7 @@ public class DeviceService : IDeviceService
|
||||
continue;
|
||||
}
|
||||
var entity = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == form.TemplateCode).FirstAsync();
|
||||
if(entity == null)
|
||||
if (entity == null)
|
||||
{
|
||||
errs.Add($"设备{form.UniqueNo}配置的模板{form.TemplateCode}不存在!");
|
||||
continue;
|
||||
@@ -168,23 +168,23 @@ public class DeviceService : IDeviceService
|
||||
|
||||
var template = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == form.TemplateCode).FirstAsync();
|
||||
|
||||
var templateJobj = JObject.Parse(template.Template);
|
||||
var jobj = JObject.Parse(form.ConnectionInfo);
|
||||
if(templateJobj.Count != jobj.Count)
|
||||
var templateJobj = JObject.Parse(template.Template);
|
||||
var jobj = JObject.Parse(form.ConnectionInfo);
|
||||
if (templateJobj.Count != jobj.Count)
|
||||
{
|
||||
errs.Add($"设备{form.UniqueNo}的连接参数字段数与模板不一致!");
|
||||
continue;
|
||||
}
|
||||
var a = false;
|
||||
foreach (var item in templateJobj)
|
||||
{
|
||||
if (!jobj.ContainsKey(item.Key))
|
||||
{
|
||||
errs.Add($"设备{form.UniqueNo}的连接参数字段数与模板不一致!");
|
||||
continue;
|
||||
errs.Add($"设备{form.UniqueNo}的连接参数需要和模板一致.缺失{item.Key}!");
|
||||
a = true;
|
||||
}
|
||||
var a = false;
|
||||
foreach (var item in templateJobj)
|
||||
{
|
||||
if (!jobj.ContainsKey(item.Key))
|
||||
{
|
||||
errs.Add($"设备{form.UniqueNo}的连接参数需要和模板一致.缺失{item.Key}!");
|
||||
a = true;
|
||||
}
|
||||
}
|
||||
if (a)
|
||||
}
|
||||
if (a)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -196,7 +196,7 @@ public class DeviceService : IDeviceService
|
||||
var regis = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.Where(x => x.DeviceUniqueNo == form.UniqueNo)
|
||||
.FirstAsync();
|
||||
if(regis == null)
|
||||
if (regis == null)
|
||||
{
|
||||
var custCode = places.Where(x => x.Code == form.PlaceeCode).Select(x => x.CustomCode).FirstOrDefault();
|
||||
regis = new DeviceRegistryEntity
|
||||
@@ -206,10 +206,10 @@ public class DeviceService : IDeviceService
|
||||
RegisterTime = DateTime.Now,
|
||||
BusinessPlaceCode = form.PlaceeCode,
|
||||
BusinessPlaceCustomCode = custCode
|
||||
};
|
||||
};
|
||||
await _dbContext.InsertAsync(regis);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user