feat 设备连接注册,sap人事范围,部门
This commit is contained in:
36
Src/Dlhis.Basic/Device/Services/IDeviceConnectService.cs
Normal file
36
Src/Dlhis.Basic/Device/Services/IDeviceConnectService.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services;
|
||||
|
||||
public interface IDeviceConnectService
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备注册
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> ResigterAsync(DeviceResigterRequest request);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取尚未设置营业点的设备
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<DeviceNotSetBusinessPlaceResponse>> GetNotSetBusinessPlaceDevicesAsync();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置设备营业点
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task SetResigterBusinessPlaceAsync(DeviceSetResigterBusinessPlaceRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 设备心跳
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task HeartbeatAsync(DeviceHeartbeatRequest request);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
public class DeviceConnectService : IDeviceConnectService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public DeviceConnectService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<string> ResigterAsync(DeviceResigterRequest request)
|
||||
{
|
||||
var device = await GetEnableDeviceAsync(request.UniqueNo);
|
||||
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
|
||||
if (registry == null)
|
||||
{
|
||||
registry = new DeviceRegistryEntity()
|
||||
{
|
||||
DeviceUniqueNo = request.UniqueNo,
|
||||
LastHeartbeatTime = DateTime.Now,
|
||||
};
|
||||
await _dbContext.InsertAsync(registry);
|
||||
|
||||
return "设备注册成功";
|
||||
}
|
||||
|
||||
return "请勿重复注册设备";
|
||||
}
|
||||
|
||||
public async Task<List<DeviceNotSetBusinessPlaceResponse>> GetNotSetBusinessPlaceDevicesAsync()
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
devices = devices.Where(x => x.Funcs.Any(item => item == DeviceFuncEnumType.Meal)).ToList();
|
||||
|
||||
return devices.Adapt<List<DeviceNotSetBusinessPlaceResponse>>();
|
||||
}
|
||||
|
||||
public async Task SetResigterBusinessPlaceAsync(DeviceSetResigterBusinessPlaceRequest request)
|
||||
{
|
||||
var device = await GetEnableDeviceAsync(request.UniqueNo);
|
||||
if (device.Funcs?.Any(x => x == DeviceFuncEnumType.Meal) != true)
|
||||
{
|
||||
throw new UserFriendlyException("当前设备无用餐功能,无法设置");
|
||||
}
|
||||
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
|
||||
registry.ThrowIfNull($"{request.UniqueNo}的设备注册信息不存在,无法设置营业点");
|
||||
|
||||
var businessPlace = await _dbContext.Queryable<CanteenBusinessPlaceEntity>().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync();
|
||||
businessPlace.ThrowIfNull("营业点不存在,无法设置到设备注册信息中");
|
||||
|
||||
//更新营业点信息
|
||||
registry.BusinessPlaceCode = businessPlace.Code;
|
||||
registry.BusinessPlaceCustomCode = businessPlace.CustomCode;
|
||||
|
||||
await _dbContext.UpdateAsync(registry);
|
||||
//todo 通知设备重新获取
|
||||
}
|
||||
|
||||
public async Task HeartbeatAsync(DeviceHeartbeatRequest request)
|
||||
{
|
||||
var registry = await _dbContext.Queryable<DeviceRegistryEntity>().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync();
|
||||
registry.ThrowIfNull($"{request.UniqueNo}的设备注册信息不存在,心跳无效");
|
||||
|
||||
registry.LastHeartbeatTime = DateTime.Now;
|
||||
await _dbContext.UpdateAsync(registry);
|
||||
}
|
||||
|
||||
//******************************************************** help methods **********************************************************
|
||||
|
||||
/// <summary>
|
||||
/// 获取启用的设备
|
||||
/// </summary>
|
||||
/// <param name="uniqueNo"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<DeviceEntity> GetEnableDeviceAsync(string uniqueNo)
|
||||
{
|
||||
var device = await _dbContext.Queryable<DeviceEntity>()
|
||||
.Where(x => x.UniqueNo == uniqueNo)
|
||||
.FirstAsync();
|
||||
|
||||
device.ThrowIfNull($"未知的设备唯一编码{uniqueNo}");
|
||||
device.Enable.ThrowIfFalse("设备尚未启用");
|
||||
|
||||
return device;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using Dlhis.Basic.Device.Request;
|
||||
using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
@@ -30,7 +32,6 @@ public class DeviceService : IDeviceService
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
public async Task SaveAsync(DeviceSaveRequest request)
|
||||
{
|
||||
await CheckUniqueNoExistsAsync(request);
|
||||
@@ -56,7 +57,7 @@ public class DeviceService : IDeviceService
|
||||
}
|
||||
}
|
||||
|
||||
//******************************************************** help method **********************************************************
|
||||
//******************************************************** help methods **********************************************************
|
||||
|
||||
/// <summary>
|
||||
/// 检查设备模板是否存在
|
||||
@@ -116,5 +117,6 @@ public class DeviceService : IDeviceService
|
||||
|
||||
exists.ThrowIfTrue("唯一号已经存在");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user