105 lines
3.6 KiB
C#
105 lines
3.6 KiB
C#
using System.Reflection;
|
|
using Dlhis.Basic.Organization.Request;
|
|
using Dlhis.Basic.Organization.Response;
|
|
using Dlhis.Entity.Basic.Dto;
|
|
using Dlhis.Entity.Basic.Enums;
|
|
using Dlhis.Entity.Sys.Entities;
|
|
using Dlhis.Sys.Api;
|
|
using Dlhis.Sys.Api.Response;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Mapster;
|
|
|
|
namespace Dlhis.Basic.Organization.Services.Implements;
|
|
|
|
public class FactorySettingService : IFactorySettingService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly ITenantApi _tenantApi;
|
|
|
|
public FactorySettingService(IDbContext dbContext, ITenantApi tenantApi)
|
|
{
|
|
_dbContext = dbContext;
|
|
_tenantApi = tenantApi;
|
|
}
|
|
|
|
public async Task<List<FactorySettingResponse>> GetListAsync()
|
|
{
|
|
return await GetFactorySettingsAsync();
|
|
}
|
|
|
|
public async Task SaveAsync(FactorySettingSaveRequest request)
|
|
{
|
|
var setting = await _dbContext.Queryable<FactorySettingEntity>().Where(x => request.Factory == x.TenantId).SingleAsync();
|
|
if (setting == null)
|
|
{
|
|
setting = request.Adapt<FactorySettingEntity>();
|
|
setting.TenantId = request.Factory;
|
|
|
|
await _dbContext.InsertAsync(setting);
|
|
}
|
|
else
|
|
{
|
|
request.Adapt(setting);
|
|
setting.TenantId = request.Factory;
|
|
|
|
await _dbContext.UpdateAsync(setting);
|
|
}
|
|
}
|
|
|
|
public async Task<FactorySettingResponse> GetFactorySettingAsync(string factory)
|
|
{
|
|
var settings = await GetFactorySettingsAsync(factory);
|
|
var setting = settings.FirstOrDefault() ?? new FactorySettingResponse();
|
|
|
|
setting.UserQrCodeExpiration ??= 60 * 1000 * 60;
|
|
setting.FaceImageDetection ??= new FaceImageDetectionDto
|
|
{
|
|
Enable = true,
|
|
Detections = typeof(FaceQualityTypeEnumType).GetFields(BindingFlags.Public | BindingFlags.Static).Select(x => new FaceImageDetection
|
|
{
|
|
Type = Enum.Parse<FaceQualityTypeEnumType>(x!.GetValue(null)!.ToString()!),
|
|
Level = FaceQualityLevelEnumType.Medium
|
|
}).ToList()
|
|
};
|
|
|
|
return setting;
|
|
}
|
|
|
|
//************************************************************************************************************************************************************
|
|
|
|
private async Task<List<FactorySettingResponse>> GetFactorySettingsAsync(string factory = null)
|
|
{
|
|
List<TenantResponse> factories;
|
|
|
|
|
|
if (factory.IsPresent())
|
|
{
|
|
factories = new List<TenantResponse> { new() { Code = factory } };
|
|
}
|
|
else
|
|
{
|
|
var apiResult = await _tenantApi.GetMyTenantsAsync();
|
|
factories = apiResult.Data;
|
|
}
|
|
|
|
var factoryCodes = factories.Select(x => x.Code).ToList();
|
|
var settings = await _dbContext.Queryable<FactorySettingEntity>()
|
|
.Where(x => factoryCodes.Contains(x.TenantId))
|
|
.ToListAsync();
|
|
|
|
return factories.Select(item =>
|
|
{
|
|
var currentFactory = factories.FirstOrDefault(x => x.Code == item.Code);
|
|
var currentSetting = settings.FirstOrDefault(x => x.TenantId == item.Code);
|
|
return new FactorySettingResponse
|
|
{
|
|
Factory = currentFactory?.Code,
|
|
FactoryName = currentFactory?.Name,
|
|
EnableOutsourceDown = currentSetting?.EnableOutsourceDown ?? false,
|
|
UserQrCodeExpiration = currentSetting?.UserQrCodeExpiration,
|
|
FaceImageDetection = currentSetting?.FaceImageDetection
|
|
};
|
|
}).ToList();
|
|
}
|
|
} |