fix 处理已知问题
This commit is contained in:
@@ -3,7 +3,6 @@ using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Basic.Device.Services;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
||||
@@ -216,9 +216,9 @@ public class DevicesController : ControllerBase
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("bulkUploads")]
|
||||
public async Task<List<string>> BulkUploadsAsync(ImportListRequest request)
|
||||
[HttpPost("import")]
|
||||
public async Task Import(List<DeviceImportRequest> request)
|
||||
{
|
||||
return await _deviceService.BulkUploadsAsync(request);
|
||||
await _deviceService.ImportAsync(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Dlhis.Basic.Device.Request
|
||||
{
|
||||
public class BulkUploadsRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备信息文件
|
||||
/// </summary>
|
||||
public IFormFile FormFile { get; set; }
|
||||
}
|
||||
}
|
||||
9
Src/Dlhis.Basic/Device/Request/DeviceImportRequest.cs
Normal file
9
Src/Dlhis.Basic/Device/Request/DeviceImportRequest.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
public class DeviceImportRequest : DeviceSaveRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 营业点code
|
||||
/// </summary>
|
||||
public Guid? BusinessPlaceCode { get; set; }
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request
|
||||
{
|
||||
public class ImportDeviceSaveRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备唯一号
|
||||
/// </summary>
|
||||
public string UniqueNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模板code
|
||||
/// </summary>
|
||||
public Guid TemplateCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 供应商信息
|
||||
/// </summary>
|
||||
public string Supplier { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备功能
|
||||
/// </summary>
|
||||
public List<DeviceFuncEnumType> Funcs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备类型 DeviceTypeEnumType
|
||||
/// </summary>
|
||||
public DeviceTypeEnumType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 心跳间隔
|
||||
/// </summary>
|
||||
public int HeartbeatInterval { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 部署点
|
||||
/// </summary>
|
||||
public string DeployPlace { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部署坐标
|
||||
/// </summary>
|
||||
public string DeployPosition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部署方向
|
||||
/// </summary>
|
||||
public string DeployDirection { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接信息
|
||||
/// </summary>
|
||||
public string ConnectionInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
public bool Enable { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否作为考勤设备
|
||||
/// </summary>
|
||||
public bool AsAttendance { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 营业点code
|
||||
/// </summary>
|
||||
public Guid? PlaceeCode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Dlhis.Basic.Device.Request
|
||||
{
|
||||
public class ImportListRequest
|
||||
{
|
||||
public List<ImportDeviceSaveRequest> Imports { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public interface IDeviceService : IScopeDependency
|
||||
|
||||
Task<List<RecentNumberResponse>> GetRecentNumbersAsync();
|
||||
|
||||
Task<List<string>> BulkUploadsAsync(ImportListRequest request);
|
||||
Task ImportAsync(List<DeviceImportRequest> request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
LastHeartbeatTime = DateTime.Now,
|
||||
RegisterTime = DateTime.Now,
|
||||
BusinessPlaceCode = businessPlace?.Code,
|
||||
BusinessPlaceCustomCode = businessPlace?.CustomCode,
|
||||
TenantId = device.TenantId,
|
||||
CreatedBy = 1,
|
||||
CreateTime = DateTime.Now,
|
||||
@@ -73,18 +72,11 @@ public class DeviceConnectService : IDeviceConnectService
|
||||
if (request.BusinessPlaceCode.HasValue)
|
||||
{
|
||||
var businessPlace = await _dbContext.Queryable<BusinessPlaceEntity>().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync();
|
||||
businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中");
|
||||
businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中");
|
||||
}
|
||||
|
||||
//更新营业点信息
|
||||
registry.BusinessPlaceCode = businessPlace.Code;
|
||||
registry.BusinessPlaceCustomCode = businessPlace.CustomCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新营业点信息
|
||||
registry.BusinessPlaceCode = null;
|
||||
registry.BusinessPlaceCustomCode = null;
|
||||
}
|
||||
//更新营业点信息
|
||||
registry.BusinessPlaceCode = request.BusinessPlaceCode;
|
||||
|
||||
await _dbContext.UpdateAsync(registry);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using System.Diagnostics;
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
@@ -103,7 +104,6 @@ public class DeviceService : IDeviceService
|
||||
LastHeartbeatTime = DateTime.Now,
|
||||
RegisterTime = DateTime.Now,
|
||||
BusinessPlaceCode = null,
|
||||
BusinessPlaceCustomCode = null,
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(registry);
|
||||
@@ -137,92 +137,42 @@ public class DeviceService : IDeviceService
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<string>> BulkUploadsAsync(ImportListRequest request)
|
||||
public async Task ImportAsync(List<DeviceImportRequest> request)
|
||||
{
|
||||
true.ThrowIfTrue("设备导入功能暂时停用.");
|
||||
var businessPlaces = await _dbContext.Queryable<BusinessPlaceEntity>().ToListAsync();
|
||||
|
||||
var errs = new List<string>();
|
||||
var lst = request.Imports;
|
||||
var places = await _dbContext.Queryable<BusinessPlaceEntity>().ToListAsync();
|
||||
|
||||
for (int i = 0; i < lst.Count; i++)
|
||||
var message = new List<string>();
|
||||
await _dbContext.Client.Ado.BeginTranAsync();
|
||||
try
|
||||
{
|
||||
var form = lst[i];
|
||||
if (form.UniqueNo.IsEmpty())
|
||||
for (int i = 0; i < request.Count; i++)
|
||||
{
|
||||
errs.Add($"第{i + 1}条的第一列的设备唯一码不能缺少!");
|
||||
continue;
|
||||
}
|
||||
if (form.PlaceeCode != null)
|
||||
{
|
||||
var place = places.Where(x => x.Code == form.PlaceeCode).FirstOrDefault();
|
||||
if (place == null)
|
||||
var row = i + 1;
|
||||
try
|
||||
{
|
||||
errs.Add($"该设备{form.UniqueNo}配置的营业点营业点不存在!");
|
||||
continue;
|
||||
var item = request[i];
|
||||
await SaveAsync(item);
|
||||
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == item.UniqueNo).FirstAsync();
|
||||
businessPlaces.Any(x => x.Code == item.BusinessPlaceCode).ThrowIfFalse("营业点不存在");
|
||||
registry.BusinessPlaceCode = item.BusinessPlaceCode;
|
||||
await _dbContext.UpdateAsync(registry);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message.Add($"第{row}列:{ex.Message}");
|
||||
}
|
||||
}
|
||||
//插入
|
||||
var exists = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == form.UniqueNo)
|
||||
.AnyAsync();
|
||||
if (exists)
|
||||
{
|
||||
errs.Add($"设备唯一号{form.UniqueNo}已经存在!");
|
||||
continue;
|
||||
}
|
||||
var entity = await _dbContext.Queryable<DeviceTemplateEntity>().Where(x => x.Code == form.TemplateCode).FirstAsync();
|
||||
if (entity == null)
|
||||
{
|
||||
errs.Add($"设备{form.UniqueNo}配置的模板{form.TemplateCode}不存在!");
|
||||
continue;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
errs.Add($"设备{form.UniqueNo}的连接参数字段数与模板不一致!");
|
||||
continue;
|
||||
}
|
||||
var a = false;
|
||||
foreach (var item in templateJobj)
|
||||
{
|
||||
if (!jobj.ContainsKey(item.Key))
|
||||
{
|
||||
errs.Add($"设备{form.UniqueNo}的连接参数需要和模板一致.缺失{item.Key}!");
|
||||
a = true;
|
||||
}
|
||||
}
|
||||
if (a)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var saveEntity = form.Adapt<DeviceEntity>();
|
||||
saveEntity.Code = Guid.NewGuid();
|
||||
await _dbContext.InsertAsync(saveEntity);
|
||||
//保存注册信息
|
||||
var regis = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.Where(x => x.DeviceUniqueNo == form.UniqueNo)
|
||||
.FirstAsync();
|
||||
if (regis == null)
|
||||
{
|
||||
var custCode = places.Where(x => x.Code == form.PlaceeCode).Select(x => x.CustomCode).FirstOrDefault();
|
||||
regis = new DeviceRegistryEntity
|
||||
{
|
||||
DeviceUniqueNo = form.UniqueNo,
|
||||
LastHeartbeatTime = DateTime.Now,
|
||||
RegisterTime = DateTime.Now,
|
||||
BusinessPlaceCode = form.PlaceeCode,
|
||||
BusinessPlaceCustomCode = custCode
|
||||
};
|
||||
await _dbContext.InsertAsync(regis);
|
||||
}
|
||||
message.ThrowIfExists(message.Join("\r\n"));
|
||||
|
||||
await _dbContext.Client.Ado.CommitTranAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await _dbContext.Client.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
|
||||
//******************************************************** help methods **********************************************************
|
||||
|
||||
Reference in New Issue
Block a user