fix 处理已知问题
This commit is contained in:
@@ -12,7 +12,6 @@ using Kurisu.Core.Result;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dlhis.Basic.BusinessShift.Services.Implements;
|
||||
|
||||
@@ -241,7 +240,6 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
||||
foreach (var item in registries)
|
||||
{
|
||||
item.BusinessPlaceCode = request.PlaceCode;
|
||||
item.BusinessPlaceCustomCode = place.CustomCode;
|
||||
}
|
||||
|
||||
await _dbContext.UpdateAsync(registries);
|
||||
|
||||
@@ -38,36 +38,4 @@ public static class TimePeriodExtensions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static bool IsPresent1(this TimePeriod period, DateTime dateTime)
|
||||
{
|
||||
DateTime start;
|
||||
DateTime end;
|
||||
|
||||
if (period.IsCrossDay())
|
||||
{
|
||||
var currentStart = DateTime.Today.Add(period.Start.Value.ToTimeSpan());
|
||||
var endOfDay = DateTime.Today.AddHours(23).AddMinutes(59).AddSeconds(59);
|
||||
|
||||
if (dateTime >= currentStart && dateTime <= endOfDay)
|
||||
{
|
||||
start = DateTime.Today.Add(period.Start.Value.ToTimeSpan());
|
||||
end = DateTime.Today.AddDays(1).Add(period.End.Value.ToTimeSpan());
|
||||
}
|
||||
else
|
||||
{
|
||||
//第二天
|
||||
start = DateTime.Today.AddDays(-1).Add(period.Start.Value.ToTimeSpan());
|
||||
end = DateTime.Today.Add(period.End.Value.ToTimeSpan());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
start = DateTime.Today.Add(period.Start.Value.ToTimeSpan());
|
||||
end = DateTime.Today.Add(period.End.Value.ToTimeSpan());
|
||||
}
|
||||
|
||||
return dateTime >= start && dateTime <= end;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 **********************************************************
|
||||
|
||||
@@ -47,12 +47,12 @@ public class GainfoPermissionService : IGainfoPermissionService
|
||||
return await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceRegistryEntity>((x, dr) => x.UniqueNo == dr.DeviceUniqueNo)
|
||||
.LeftJoin<BusinessPlaceEntity>((x, dr, place) => dr.BusinessPlaceCode == place.Code)
|
||||
.LeftJoin<BusinessPlaceShiftRelationshipEntity>((x, dr, place, ps) => x.Code == ps.PlaceCode)
|
||||
.LeftJoin<BusinessShiftEntity>((x, dr, place, ps, s) => s.Code == ps.ShiftCode)
|
||||
.LeftJoin<BusinessPlaceShiftRelationshipEntity>((x, dr, place, ps) => x.Code == ps.PlaceCode)
|
||||
.LeftJoin<BusinessShiftEntity>((x, dr, place, ps, s) => s.Code == ps.ShiftCode)
|
||||
.Where(x => x.Type == DeviceTypeEnumType.Meal)
|
||||
.Where(x => deviceCodes.Contains(x.Code))
|
||||
.Where((x, dr) => !string.IsNullOrEmpty(dr.BusinessPlaceCustomCode))
|
||||
.Select((x, dr, place, ps, s) => new BusinessPlaceResponse
|
||||
.Where((x, dr) => dr.BusinessPlaceCode.HasValue)
|
||||
.Select((x, dr, place, ps, s) => new BusinessPlaceResponse
|
||||
{
|
||||
Id = place.Id,
|
||||
Code = place.Code,
|
||||
|
||||
@@ -15,17 +15,19 @@ public static class TimePeriodExtensions
|
||||
|
||||
if (period.IsCrossDay())
|
||||
{
|
||||
//period = [22:00:00,03:00:00]
|
||||
var currentStart = DateTime.Today.Add(period.Start.Value.ToTimeSpan());
|
||||
var endOfDay = DateTime.Today.AddHours(23).AddMinutes(59).AddSeconds(59);
|
||||
var endOfDay = DateTime.Today.AddDays(1).AddSeconds(-1);
|
||||
|
||||
//assume is left range . then currentStart is 2024-04-16 22:00:00 and endOfDay is 2024-04-16 23:59:59
|
||||
if (dateTime >= currentStart && dateTime <= endOfDay)
|
||||
{
|
||||
start = DateTime.Today.Add(period.Start.Value.ToTimeSpan());
|
||||
end = DateTime.Today.AddDays(1).Add(period.End.Value.ToTimeSpan());
|
||||
start = currentStart; //2024-04-16 22:00:00
|
||||
end = DateTime.Today.AddDays(1).Add(period.End.Value.ToTimeSpan());//2024-04-17 03:00:00
|
||||
}
|
||||
else
|
||||
{
|
||||
//第二天
|
||||
|
||||
start = DateTime.Today.AddDays(-1).Add(period.Start.Value.ToTimeSpan());
|
||||
end = DateTime.Today.Add(period.End.Value.ToTimeSpan());
|
||||
}
|
||||
|
||||
@@ -34,11 +34,5 @@ public class DeviceRegistryEntity : SugarBaseEntity, ITenantId
|
||||
[SugarColumn(IsNullable = true, ColumnDescription = "营业点code")]
|
||||
public Guid? BusinessPlaceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 营业点手工号(可为空)
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true, ColumnDescription = "营业点手工号")]
|
||||
public string BusinessPlaceCustomCode { get; set; }
|
||||
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user