fix 修复已知问题

This commit is contained in:
2024-12-13 16:31:04 +08:00
parent 02a2971256
commit a33f86969b
17 changed files with 162 additions and 225 deletions

View File

@@ -45,6 +45,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.InfoCheck.Api", "Src\
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Jip.Api", "Src\Dlhis.Jip.Api\Dlhis.Jip.Api.csproj", "{841B7B43-5394-413F-9D68-A07EBDD6D4CD}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Jip.Api", "Src\Dlhis.Jip.Api\Dlhis.Jip.Api.csproj", "{841B7B43-5394-413F-9D68-A07EBDD6D4CD}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Dh.Api", "Src\Dlhis.Dh.Api\Dlhis.Dh.Api.csproj", "{E673CA04-3567-4E03-9A86-994F50291ACC}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -111,6 +113,10 @@ Global
{841B7B43-5394-413F-9D68-A07EBDD6D4CD}.Debug|Any CPU.Build.0 = Debug|Any CPU {841B7B43-5394-413F-9D68-A07EBDD6D4CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{841B7B43-5394-413F-9D68-A07EBDD6D4CD}.Release|Any CPU.ActiveCfg = Release|Any CPU {841B7B43-5394-413F-9D68-A07EBDD6D4CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{841B7B43-5394-413F-9D68-A07EBDD6D4CD}.Release|Any CPU.Build.0 = Release|Any CPU {841B7B43-5394-413F-9D68-A07EBDD6D4CD}.Release|Any CPU.Build.0 = Release|Any CPU
{E673CA04-3567-4E03-9A86-994F50291ACC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E673CA04-3567-4E03-9A86-994F50291ACC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E673CA04-3567-4E03-9A86-994F50291ACC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E673CA04-3567-4E03-9A86-994F50291ACC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -127,6 +133,7 @@ Global
{4D656761-8CE7-4316-A3DF-8C1722D69CCE} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A} {4D656761-8CE7-4316-A3DF-8C1722D69CCE} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A}
{A501D16E-638F-4156-989C-2BACCC2FAC2B} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A} {A501D16E-638F-4156-989C-2BACCC2FAC2B} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A}
{841B7B43-5394-413F-9D68-A07EBDD6D4CD} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A} {841B7B43-5394-413F-9D68-A07EBDD6D4CD} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A}
{E673CA04-3567-4E03-9A86-994F50291ACC} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7439494A-E2FD-4FEA-8ABF-74AE57A4A5A0} SolutionGuid = {7439494A-E2FD-4FEA-8ABF-74AE57A4A5A0}

View File

@@ -2,6 +2,8 @@
using Dlhis.Basic.Appointment.Response; using Dlhis.Basic.Appointment.Response;
using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Request;
using Dlhis.Basic.Organization.Services; using Dlhis.Basic.Organization.Services;
using Dlhis.Dh.Api;
using Dlhis.Dh.Api.Requests;
using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Entities;
using Dlhis.Entity.Device.Enums; using Dlhis.Entity.Device.Enums;
@@ -24,16 +26,22 @@ public class AppointmentService : IAppointmentService
private readonly IDbContext _dbContext; private readonly IDbContext _dbContext;
private readonly IDataProtectionProvider _dataProtectionProvider; private readonly IDataProtectionProvider _dataProtectionProvider;
private readonly ICurrentUser _currentUser; private readonly ICurrentUser _currentUser;
private readonly IDhApi _dhApi;
private readonly ILogger<AppointmentService> _logger;
private readonly IGainfoFaceService _gainfoFaceService; private readonly IGainfoFaceService _gainfoFaceService;
public AppointmentService(IDbContext dbContext, public AppointmentService(IDbContext dbContext,
IDataProtectionProvider dataProtectionProvider, IDataProtectionProvider dataProtectionProvider,
ICurrentUser currentUser, ICurrentUser currentUser,
IGainfoFaceService gainfoFaceService) IDhApi dhApi,
IGainfoFaceService gainfoFaceService,
ILogger<AppointmentService> logger)
{ {
_dbContext = dbContext; _dbContext = dbContext;
_dataProtectionProvider = dataProtectionProvider; _dataProtectionProvider = dataProtectionProvider;
_currentUser = currentUser; _currentUser = currentUser;
_dhApi = dhApi;
_logger = logger;
_gainfoFaceService = gainfoFaceService; _gainfoFaceService = gainfoFaceService;
} }
@@ -44,7 +52,11 @@ public class AppointmentService : IAppointmentService
return await _dbContext.Queryable<VisitorAppointmentEntity>() return await _dbContext.Queryable<VisitorAppointmentEntity>()
.WhereIF(request.SearchDateTimePeriod.HasValue(), .WhereIF(request.SearchDateTimePeriod.HasValue(),
x => x.Date >= request.SearchDateTimePeriod.Start && x.Date <= request.SearchDateTimePeriod.End) x => x.Date >= request.SearchDateTimePeriod.Start && x.Date <= request.SearchDateTimePeriod.End)
.WhereIF(request.Search.IsPresent(), x => x.Code == request.Search) .WhereIF(request.Search.IsPresent(), x => x.Code == request.Search ||
SqlFunc.Subqueryable<VisitorAppointmentDetailEntity>()
.Where(p => p.No != x.No)
.Where(p => p.IdNo == request.Search || p.Name == request.Search).Any()
)
.Where(x => x.Factory == factory) .Where(x => x.Factory == factory)
.Select<AppointmentPageResponse>() .Select<AppointmentPageResponse>()
.ToPageListAsync(request); .ToPageListAsync(request);
@@ -94,6 +106,19 @@ public class AppointmentService : IAppointmentService
detail.ArrivedTime = DateTime.Now; detail.ArrivedTime = DateTime.Now;
await _dbContext.UpdateAsync(detail); await _dbContext.UpdateAsync(detail);
try
{
await _dhApi.SendFaceAsync(new FaceRequest
{
IdNo = detail.IdNo,
Face = request.Base64Image
});
}
catch (Exception e)
{
_logger.LogError(e, "上传face数据到大华失败:{msg}", e.Message);
}
} }
public async Task GenerateTaskAndUpdateFaceAsync(long detailId, string base64, DeviceTaskEnumType deviceTaskType) public async Task GenerateTaskAndUpdateFaceAsync(long detailId, string base64, DeviceTaskEnumType deviceTaskType)

View File

@@ -26,6 +26,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Dlhis.Dh.Api\Dlhis.Dh.Api.csproj" />
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" /> <ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
<ProjectReference Include="..\Dlhis.InfoCheck.Api\Dlhis.InfoCheck.Api.csproj" /> <ProjectReference Include="..\Dlhis.InfoCheck.Api\Dlhis.InfoCheck.Api.csproj" />
<ProjectReference Include="..\Dlhis.Jip.Api\Dlhis.Jip.Api.csproj" /> <ProjectReference Include="..\Dlhis.Jip.Api\Dlhis.Jip.Api.csproj" />

View File

@@ -1,27 +1,33 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. # 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器,以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。
# 此阶段用于在快速模式(默认为调试配置)下从 VS 运行时
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app WORKDIR /app
EXPOSE 80 EXPOSE 80
# 此阶段用于生成服务项目
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG BUILD_CONFIGURATION=Release ARG BUILD_CONFIGURATION=Release
WORKDIR /src WORKDIR /src
COPY ["Src/Dlhis.Basic/Dlhis.Basic.csproj", "Src/Dlhis.Basic/"] COPY ["Src/Dlhis.Basic/Dlhis.Basic.csproj", "Src/Dlhis.Basic/"]
COPY ["Src/Dlhis.Dh.Api/Dlhis.Dh.Api.csproj", "Src/Dlhis.Dh.Api/"]
COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"] COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"]
COPY ["Src/Dlhis.DataPermission.Model/Dlhis.DataPermission.Model.csproj", "Src/Dlhis.DataPermission.Model/"] COPY ["Src/Dlhis.DataPermission.Model/Dlhis.DataPermission.Model.csproj", "Src/Dlhis.DataPermission.Model/"]
COPY ["Src/Dlhis.InfoCheck.Api/Dlhis.InfoCheck.Api.csproj", "Src/Dlhis.InfoCheck.Api/"] COPY ["Src/Dlhis.InfoCheck.Api/Dlhis.InfoCheck.Api.csproj", "Src/Dlhis.InfoCheck.Api/"]
COPY ["Src/Dlhis.Scheduled.Api/Dlhis.Scheduled.Api.csproj", "Src/Dlhis.Scheduled.Api/"] COPY ["Src/Dlhis.Jip.Api/Dlhis.Jip.Api.csproj", "Src/Dlhis.Jip.Api/"]
COPY ["Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj", "Src/Dlhis.Sys.Api/"] COPY ["Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj", "Src/Dlhis.Sys.Api/"]
RUN dotnet restore "./Src/Dlhis.Basic/./Dlhis.Basic.csproj" RUN dotnet restore "./Src/Dlhis.Basic/Dlhis.Basic.csproj"
COPY . . COPY . .
WORKDIR "/src/Src/Dlhis.Basic" WORKDIR "/src/Src/Dlhis.Basic"
RUN dotnet build "./Dlhis.Basic.csproj" -c $BUILD_CONFIGURATION -o /app/build RUN dotnet build "./Dlhis.Basic.csproj" -c $BUILD_CONFIGURATION -o /app/build
# 此阶段用于发布要复制到最终阶段的服务项目
FROM build AS publish FROM build AS publish
ARG BUILD_CONFIGURATION=Release ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Dlhis.Basic.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false RUN dotnet publish "./Dlhis.Basic.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# 此阶段在生产中使用,或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值)
FROM base AS final FROM base AS final
WORKDIR /app WORKDIR /app
COPY --from=publish /app/publish . COPY --from=publish /app/publish .

View File

@@ -23,17 +23,6 @@ public class GainfoPermissionsController : ControllerBase
_gainfoPermissions = gainfoPermissions; _gainfoPermissions = gainfoPermissions;
} }
/// <summary>
/// 根据用户查看餐饮点
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("placesByGainfo")]
public async Task<Pagination<BusinessPlaceResponse>> GetPlaceByGainfoAsync([FromQuery] DeviceAssRequest request)
{
return await _gainfoPermissions.GetPlaceByGainfoAsync(request);
}
/// <summary> /// <summary>
/// 根据档案号 设备组查询设备 /// 根据档案号 设备组查询设备
/// </summary> /// </summary>
@@ -57,16 +46,6 @@ public class GainfoPermissionsController : ControllerBase
return await _gainfoPermissions.GetAssignDeviceCodesAsync(request); return await _gainfoPermissions.GetAssignDeviceCodesAsync(request);
} }
/// <summary>
/// 当前绑定的设备组信息
/// </summary>
/// <returns></returns>
[HttpGet("assignGroups")]
public async Task<List<DeviceGroupTreeResponse>> GetAssignGroupAsync(string userNo)
{
return await _gainfoPermissions.GetAssignGroupAsync(userNo);
}
/// <summary> /// <summary>
/// 权限重置 /// 权限重置
/// </summary> /// </summary>

View File

@@ -9,13 +9,9 @@ namespace Dlhis.Basic.Organization.Services;
public interface IGainfoPermissionService : IScopeDependency public interface IGainfoPermissionService : IScopeDependency
{ {
Task<Pagination<BusinessPlaceResponse>> GetPlaceByGainfoAsync(DeviceAssRequest request);
Task<List<GetDevicesUnderGroupByUserNoResponse>> GetDevicesUnderGroupByUserNoAsync(string userNo, Guid deviceGroupCode); Task<List<GetDevicesUnderGroupByUserNoResponse>> GetDevicesUnderGroupByUserNoAsync(string userNo, Guid deviceGroupCode);
Task<Pagination<GainfoDevicePermissionResponse>> GetAssignDeviceCodesAsync(DeviceAssRequest request); Task<Pagination<GainfoDevicePermissionResponse>> GetAssignDeviceCodesAsync(DeviceAssRequest request);
Task<List<DeviceGroupTreeResponse>> GetAssignGroupAsync(string userNo);
Task<DevicePermissionAssignResponse> ResetPermissionsAsync(string userNo, DeviceTaskEnumType type, List<Guid> deviceCodes); Task<DevicePermissionAssignResponse> ResetPermissionsAsync(string userNo, DeviceTaskEnumType type, List<Guid> deviceCodes);
} }

View File

@@ -29,44 +29,6 @@ public class GainfoPermissionService : IGainfoPermissionService
_dbContext = dbContext; _dbContext = dbContext;
} }
public async Task<Pagination<BusinessPlaceResponse>> GetPlaceByGainfoAsync(DeviceAssRequest request)
{
var gainfo = await _gainfoStore.Queryable()
.Where(x => x.No == request.UserNo)
.SingleAsync();
if (gainfo == null)
{
return new Pagination<BusinessPlaceResponse>();
}
//用户所有deviceCode权限
var deviceCodes = await _devicePermissionAnalyzeService.GetAssignDeviceCodesAsync(gainfo.Code);
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) => place.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) => dr.BusinessPlaceCode.HasValue)
.Select((x, dr, place, ps, s) => new BusinessPlaceResponse
{
Id = place.Id,
Code = place.Code,
Status = place.Status,
Name = place.Name,
Catalog = place.Catalog,
CustomCode = place.CustomCode,
Source = place.Source,
ShiftCode = s.Code,
ShiftName = s.Name
})
.Distinct()
.ToPageListAsync(request);
}
public async Task<List<GetDevicesUnderGroupByUserNoResponse>> GetDevicesUnderGroupByUserNoAsync(string userNo, Guid deviceGroupCode) public async Task<List<GetDevicesUnderGroupByUserNoResponse>> GetDevicesUnderGroupByUserNoAsync(string userNo, Guid deviceGroupCode)
{ {
@@ -129,6 +91,7 @@ public class GainfoPermissionService : IGainfoPermissionService
var page = await _dbContext.Queryable<DeviceEntity>() var page = await _dbContext.Queryable<DeviceEntity>()
.LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo) .LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
.WhereIF(request.DeviceType.HasValue, d => d.Type == request.DeviceType) .WhereIF(request.DeviceType.HasValue, d => d.Type == request.DeviceType)
.WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search)
.Where(d => codes.Contains(d.Code)) .Where(d => codes.Contains(d.Code))
.Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true) .Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true)
.ToPageListAsync(request); .ToPageListAsync(request);
@@ -239,21 +202,4 @@ public class GainfoPermissionService : IGainfoPermissionService
var deleteCount = type == DeviceTaskEnumType.Delete ? tasks.Count : 0; var deleteCount = type == DeviceTaskEnumType.Delete ? tasks.Count : 0;
return new DevicePermissionAssignResponse(addCount, deleteCount); return new DevicePermissionAssignResponse(addCount, deleteCount);
} }
public async Task<List<DeviceGroupTreeResponse>> GetAssignGroupAsync(string userNo)
{
//(DeviceAssignmentTypeEnumType.Group, AssignTypeEnumType.User, userNo
var groups = await _devicePermissionAnalyzeService.GetAssignmentsAsync(new DeviceGetAssignmentsRequest
{
UniqueType = DeviceAssignmentTypeEnumType.Group,
AssignType = AssignTypeEnumType.User,
AssignValue = userNo
});
return await _dbContext.Queryable<DeviceGroupEntity>()
.Where(x => groups.Contains(x.Code))
.Select<DeviceGroupTreeResponse>()
.ToListAsync();
}
} }

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Kurisu.RemoteCall" Version="0.4.8" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,13 @@
using Dlhis.Dh.Api.Requests;
using Dlhis.Dh.Api.ResultHandlers;
using Kurisu.RemoteCall.Attributes;
namespace Dlhis.Dh.Api;
[EnableRemoteClient(Name = "dh-service", BaseUrl = "https://10.32.0.100")]
public interface IDhApi
{
[Post("/evo-apigw/evo-visitor/1.0.0/card/visitor/custom-face")]
[RequestResultHandler(typeof(DhResultHandler))]
Task SendFaceAsync(FaceRequest request);
}

View File

@@ -0,0 +1,14 @@
using Newtonsoft.Json;
namespace Dlhis.Dh.Api.Requests;
public class FaceRequest
{
[JsonProperty("v_certificateNumber")]
public string IdNo { get; set; }
public string Face { get; set; }
[JsonProperty("faceFile")]
public string FaceFile => "data:image/jpeg;base64," + Face;
}

View File

@@ -0,0 +1,43 @@
using System.Net;
using Kurisu.RemoteCall.Abstractions;
using Mapster;
using Newtonsoft.Json;
namespace Dlhis.Dh.Api.ResultHandlers;
public class DhResultHandler : IRemoteCallResultHandler
{
/// <inheritdoc />
public TResult Handle<TResult>(HttpStatusCode statusCode, string responseBody)
{
var apiResult = JsonConvert.DeserializeObject<DhResponse>(responseBody)!;
var isSuccessStatusCode = ((int)statusCode >= 200) && ((int)statusCode <= 299);
if (!isSuccessStatusCode || apiResult.Success == false)
{
if (!string.IsNullOrEmpty(apiResult.ErrMsg))
{
throw new Exception(apiResult.ErrMsg);
}
throw new HttpRequestException(statusCode + " " + (int)statusCode);
}
return responseBody.Adapt<TResult>();
}
}
public class DhResponse
{
public bool Success { get; set; }
public string Code { get; set; }
public string ErrMsg { get; set; }
}
// {
// "success": true,
// "code": "0",
// "errMsg": "请求成功"
// }

View File

@@ -35,6 +35,6 @@ public enum AssignTypeEnumType
/// <summary> /// <summary>
/// 租户/基地 /// 租户/基地
/// </summary> /// </summary>
[Description("租户/基地")] [Description("厂区")]
Tenant = 5 Tenant = 5
} }

View File

@@ -1,4 +1,7 @@
using System.Net;
using Kurisu.RemoteCall.Abstractions; using Kurisu.RemoteCall.Abstractions;
using Polly;
using Polly.Extensions.Http;
namespace Dlhis.Middle.Apis.Handlers; namespace Dlhis.Middle.Apis.Handlers;
@@ -16,7 +19,15 @@ public class HealthzClientHandler : IHttpRemoteCallPolicyHandler
}; };
return handler; return handler;
}); })
//.SetHandlerLifetime(TimeSpan.FromMinutes(5))
.AddPolicyHandler(
HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(x => x.StatusCode != HttpStatusCode.OK)
//.OrResult(msg => msg.StatusCode != HttpStatusCode.OK)
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
);
return builder; return builder;
} }

View File

@@ -19,6 +19,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Kurisu.RemoteCall" Version="0.4.4" /> <PackageReference Include="Kurisu.RemoteCall" Version="0.4.4" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.6" /> <PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.36" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.8" /> <PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.8" />
</ItemGroup> </ItemGroup>

View File

@@ -1,136 +1,13 @@
using Dlhis.Middle.Entities; using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
using Kurisu.AspNetCore.Authentication.Abstractions;
using Kurisu.AspNetCore.DataAccess.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Attributes;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Options;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Startup; using Kurisu.AspNetCore.Startup;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using SqlSugar; using SqlSugar;
namespace Dlhis.Middle.Packs; namespace Dlhis.Middle.Packs;
public class SqlSugarPack : BaseAppPack public class SqlSugarPack : BaseAppPack
{ {
private const string _infoTemplate = "ExecuteCommand[{ms}] Timeout[{timeout}] \r\n {sql}";
public override void ConfigureServices(IServiceCollection services) public override void ConfigureServices(IServiceCollection services)
{ {
services.AddSqlSugar(); services.AddSqlSugar(DbType.Sqlite);
services.Replace(ServiceDescriptor.Scoped(typeof(ISqlSugarClient), sp =>
{
var options = sp.GetService<IOptions<SqlSugarOptions>>().Value;
var logger = sp.GetService<ILogger<SqlSugarClient>>();
var currentUser = sp.GetService<ICurrentUser>();
var sugarOptions = sp.GetService<ISqlSugarOptionsService>();
var configs = new List<ConnectionConfig>
{
new()
{
ConfigId = "db-main",
ConnectionString = options.DefaultConnectionString,
DbType = DbType.Sqlite,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
MoreSettings = new ConnMoreSettings
{
DisableNvarchar = true,
},
ConfigureExternalServices = new ConfigureExternalServices
{
EntityService = (c, p) =>
{
if (!p.IsPrimarykey && c.PropertyType.IsGenericType && c.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)
|| (!p.IsPrimarykey && p.PropertyInfo.PropertyType == typeof(string)))
{
p.IsNullable = true;
}
}
}
}
};
ISqlSugarClient db = new SqlSugarClient(configs);
db.Ado.CommandTimeOut = options.Timeout;
db.Aop.OnLogExecuted = (sql, parameters) =>
{
var ms = db.Ado.SqlExecutionTime.Milliseconds;
//警告慢sql
if (ms >= options.SlowSqlTime * 1000)
logger.LogWarning(message: _infoTemplate, ms, options.Timeout, sql);
if (options.EnableSqlLog)
{
sql = UtilMethods.GetSqlString(DbType.MySql, sql, parameters);
logger.LogInformation(message: _infoTemplate, ms, options.Timeout, sql);
}
};
//软删除
db.QueryFilter.AddTableFilter<ISoftDeleted>(x => x.IsDeleted == false);
//增删改
db.Aop.DataExecuting = (oldValue, model) =>
{
if (sugarOptions.IgnoreTenant == false //启用租户
&& currentUser != null //用户信息存在
&& model.PropertyName == nameof(ITenantId.TenantId) //当前为租户字段
&& typeof(ITenantId).IsAssignableFrom(model.EntityValue.GetType())) //继承ITenantId
{
var tenant = currentUser.GetStringTenantId();
model.SetValue(tenant);
}
//处理人员和时间字段
switch (model.OperationType)
{
case DataFilterType.InsertByObject:
{
if (model.IsAnyAttribute<InsertDateTimeGenerationAttribute>())
{
model.SetValue(DateTime.Now);
}
if (currentUser != null && model.IsAnyAttribute<InsertUserGenerationAttribute>())
{
if ((int)model.EntityColumnInfo.PropertyInfo.GetValue(model.EntityValue) == 0)
{
model.SetValue(currentUser.GetStringSubjectId());
}
}
break;
}
case DataFilterType.UpdateByObject:
{
if (model.IsAnyAttribute<UpdateDateTimeGenerationAttribute>())
{
model.SetValue(DateTime.Now);
}
if (currentUser != null && model.IsAnyAttribute<UpdateUserGenerationAttribute>())
{
if ((int)model.EntityColumnInfo.PropertyInfo.GetValue(model.EntityValue) == 0)
{
model.SetValue(currentUser.GetStringSubjectId());
}
}
break;
}
}
};
return db;
}));
} }
} }

View File

@@ -2,6 +2,7 @@ using Dlhis.Middle.BackgroundServices;
using Dlhis.Middle.Entities; using Dlhis.Middle.Entities;
using Dlhis.Middle.Services; using Dlhis.Middle.Services;
using Kurisu.AspNetCore; using Kurisu.AspNetCore;
using Kurisu.AspNetCore.Authentication.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Startup; using Kurisu.AspNetCore.Startup;
using Microsoft.IdentityModel.Logging; using Microsoft.IdentityModel.Logging;
@@ -32,6 +33,7 @@ public class Startup : DefaultStartup
services.AddRemoteCall(App.ActiveTypes); services.AddRemoteCall(App.ActiveTypes);
services.AddMemoryCache(); services.AddMemoryCache();
services.AddUserInfo();
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -157,20 +157,22 @@ public class DeviceUploadLogService : IDeviceUploadLogService
.LeftJoin<DeviceUploadLogEntity>((os, x) => os.Code == x.UserUniqueNo) .LeftJoin<DeviceUploadLogEntity>((os, x) => os.Code == x.UserUniqueNo)
.LeftJoin<DeviceEntity>((os, x, device) => x.DeviceUniqueNo == device.UniqueNo) .LeftJoin<DeviceEntity>((os, x, device) => x.DeviceUniqueNo == device.UniqueNo)
.LeftJoin<GainfoEntity>((os, x, device, ga) => os.Code == ga.Code) .LeftJoin<GainfoEntity>((os, x, device, ga) => os.Code == ga.Code)
.LeftJoin<GainfoEntity>((os, x, device, ga, gasap) => gasap.Code == os.SapCode) .LeftJoin<GainfoEntity>((os, x, device, ga, gaSap) => gaSap.Code == os.SapCode)
.WhereIF(request.Search.IsPresent(), (os, x, device, ga, gasap) => .WhereIF(request.SearchDateTimePeriod.HasValue(), (os, x) => x.RaiseDateTime >= request.SearchDateTimePeriod.Start
&& x.RaiseDateTime <= request.SearchDateTimePeriod.End)
.WhereIF(request.Search.IsPresent(), (os, x, device, ga, gaSap) =>
x.UserUniqueNo == request.Search x.UserUniqueNo == request.Search
|| x.DeviceUniqueNo == request.Search || x.DeviceUniqueNo == request.Search
|| os.Supplier == request.Search || os.Supplier == request.Search
|| os.SapCode == request.Search || os.SapCode == request.Search
).OrderBy((os, x, device, ga, gasap) => x.ModifiedTime, OrderByType.Desc) ).OrderBy((os, x, device, ga, gaSap) => x.ModifiedTime, OrderByType.Desc)
.Select((os, x, device, ga, gasap) => new DeviceUploadLogResponse .Select((os, x, device, ga, gaSap) => new DeviceUploadLogResponse
{ {
Id = x.Id, Id = x.Id,
OriginUserUniqueNo = x.UserUniqueNo, OriginUserUniqueNo = x.UserUniqueNo,
OutsourceSupplier = os.Supplier, OutsourceSupplier = os.Supplier,
SapUserCode = os.SapCode, SapUserCode = os.SapCode,
SapUserName = gasap.Name, SapUserName = gaSap.Name,
DeviceUniqueNo = x.DeviceUniqueNo, DeviceUniqueNo = x.DeviceUniqueNo,
RaiseDateTime = x.RaiseDateTime, RaiseDateTime = x.RaiseDateTime,
CreateTime = x.CreateTime, CreateTime = x.CreateTime,
@@ -198,7 +200,8 @@ public class DeviceUploadLogService : IDeviceUploadLogService
.LeftJoin<GainfoEntity>((x, device, ga) => x.UserUniqueNo == ga.Code) .LeftJoin<GainfoEntity>((x, device, ga) => x.UserUniqueNo == ga.Code)
.LeftJoin<OutsourceEntity>((x, device, ga, os) => x.UserUniqueNo == os.Code) .LeftJoin<OutsourceEntity>((x, device, ga, os) => x.UserUniqueNo == os.Code)
.LeftJoin<GainfoEntity>((x, device, ga, os, gasap) => gasap.Code == os.SapCode) .LeftJoin<GainfoEntity>((x, device, ga, os, gasap) => gasap.Code == os.SapCode)
.WhereIF(request.SearchDateTimePeriod.HasValue(), x => x.RaiseDateTime >= request.SearchDateTimePeriod.Start && x.RaiseDateTime <= request.SearchDateTimePeriod.End) .WhereIF(request.SearchDateTimePeriod.HasValue(), x => x.RaiseDateTime >= request.SearchDateTimePeriod.Start
&& x.RaiseDateTime <= request.SearchDateTimePeriod.End)
.Where((x, device) => x.Type == type && !SqlFunc.IsNullOrEmpty(x.UserUniqueNo)) .Where((x, device) => x.Type == type && !SqlFunc.IsNullOrEmpty(x.UserUniqueNo))
.WhereIF(request.Sync.HasValue, x => x.Sync == request.Sync) .WhereIF(request.Sync.HasValue, x => x.Sync == request.Sync)
.WhereIF(request.IsOutsource.HasValue && request.IsOutsource.Value, .WhereIF(request.IsOutsource.HasValue && request.IsOutsource.Value,