fix 修复已知问题
This commit is contained in:
@@ -45,6 +45,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.InfoCheck.Api", "Src\
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Jip.Api", "Src\Dlhis.Jip.Api\Dlhis.Jip.Api.csproj", "{841B7B43-5394-413F-9D68-A07EBDD6D4CD}"
|
||||
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
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -127,6 +133,7 @@ Global
|
||||
{4D656761-8CE7-4316-A3DF-8C1722D69CCE} = {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}
|
||||
{E673CA04-3567-4E03-9A86-994F50291ACC} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7439494A-E2FD-4FEA-8ABF-74AE57A4A5A0}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using Dlhis.Basic.Appointment.Response;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
using Dlhis.Dh.Api;
|
||||
using Dlhis.Dh.Api.Requests;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
@@ -24,16 +26,22 @@ public class AppointmentService : IAppointmentService
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IDataProtectionProvider _dataProtectionProvider;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IDhApi _dhApi;
|
||||
private readonly ILogger<AppointmentService> _logger;
|
||||
private readonly IGainfoFaceService _gainfoFaceService;
|
||||
|
||||
public AppointmentService(IDbContext dbContext,
|
||||
IDataProtectionProvider dataProtectionProvider,
|
||||
ICurrentUser currentUser,
|
||||
IGainfoFaceService gainfoFaceService)
|
||||
IDhApi dhApi,
|
||||
IGainfoFaceService gainfoFaceService,
|
||||
ILogger<AppointmentService> logger)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_dataProtectionProvider = dataProtectionProvider;
|
||||
_currentUser = currentUser;
|
||||
_dhApi = dhApi;
|
||||
_logger = logger;
|
||||
_gainfoFaceService = gainfoFaceService;
|
||||
}
|
||||
|
||||
@@ -44,7 +52,11 @@ public class AppointmentService : IAppointmentService
|
||||
return await _dbContext.Queryable<VisitorAppointmentEntity>()
|
||||
.WhereIF(request.SearchDateTimePeriod.HasValue(),
|
||||
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)
|
||||
.Select<AppointmentPageResponse>()
|
||||
.ToPageListAsync(request);
|
||||
@@ -94,6 +106,19 @@ public class AppointmentService : IAppointmentService
|
||||
|
||||
detail.ArrivedTime = DateTime.Now;
|
||||
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)
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Dlhis.Dh.Api\Dlhis.Dh.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.InfoCheck.Api\Dlhis.InfoCheck.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Jip.Api\Dlhis.Jip.Api.csproj" />
|
||||
|
||||
@@ -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
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
|
||||
|
||||
# 此阶段用于生成服务项目
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
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.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.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/"]
|
||||
RUN dotnet restore "./Src/Dlhis.Basic/./Dlhis.Basic.csproj"
|
||||
RUN dotnet restore "./Src/Dlhis.Basic/Dlhis.Basic.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Src/Dlhis.Basic"
|
||||
RUN dotnet build "./Dlhis.Basic.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
# 此阶段用于发布要复制到最终阶段的服务项目
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./Dlhis.Basic.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# 此阶段在生产中使用,或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值)
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
|
||||
@@ -23,17 +23,6 @@ public class GainfoPermissionsController : ControllerBase
|
||||
_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>
|
||||
@@ -57,16 +46,6 @@ public class GainfoPermissionsController : ControllerBase
|
||||
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>
|
||||
|
||||
@@ -9,13 +9,9 @@ namespace Dlhis.Basic.Organization.Services;
|
||||
|
||||
public interface IGainfoPermissionService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<BusinessPlaceResponse>> GetPlaceByGainfoAsync(DeviceAssRequest request);
|
||||
|
||||
Task<List<GetDevicesUnderGroupByUserNoResponse>> GetDevicesUnderGroupByUserNoAsync(string userNo, Guid deviceGroupCode);
|
||||
|
||||
Task<Pagination<GainfoDevicePermissionResponse>> GetAssignDeviceCodesAsync(DeviceAssRequest request);
|
||||
|
||||
Task<List<DeviceGroupTreeResponse>> GetAssignGroupAsync(string userNo);
|
||||
|
||||
Task<DevicePermissionAssignResponse> ResetPermissionsAsync(string userNo, DeviceTaskEnumType type, List<Guid> deviceCodes);
|
||||
}
|
||||
@@ -29,44 +29,6 @@ public class GainfoPermissionService : IGainfoPermissionService
|
||||
_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)
|
||||
{
|
||||
@@ -129,6 +91,7 @@ public class GainfoPermissionService : IGainfoPermissionService
|
||||
var page = await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceRegistryEntity>((d, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||
.WhereIF(request.DeviceType.HasValue, d => d.Type == request.DeviceType)
|
||||
.WhereIF(request.Search.IsPresent(), d => d.UniqueNo == request.Search)
|
||||
.Where(d => codes.Contains(d.Code))
|
||||
.Select((d, dr) => new GainfoDevicePermissionResponse { Factory = d.TenantId }, true)
|
||||
.ToPageListAsync(request);
|
||||
@@ -239,21 +202,4 @@ public class GainfoPermissionService : IGainfoPermissionService
|
||||
var deleteCount = type == DeviceTaskEnumType.Delete ? tasks.Count : 0;
|
||||
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();
|
||||
}
|
||||
}
|
||||
13
Src/Dlhis.Dh.Api/Dlhis.Dh.Api.csproj
Normal file
13
Src/Dlhis.Dh.Api/Dlhis.Dh.Api.csproj
Normal 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>
|
||||
13
Src/Dlhis.Dh.Api/IDhApi.cs
Normal file
13
Src/Dlhis.Dh.Api/IDhApi.cs
Normal 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);
|
||||
}
|
||||
14
Src/Dlhis.Dh.Api/Requests/FaceRequest.cs
Normal file
14
Src/Dlhis.Dh.Api/Requests/FaceRequest.cs
Normal 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;
|
||||
}
|
||||
43
Src/Dlhis.Dh.Api/ResultHandlers/DhResultHandler.cs
Normal file
43
Src/Dlhis.Dh.Api/ResultHandlers/DhResultHandler.cs
Normal 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": "请求成功"
|
||||
// }
|
||||
@@ -35,6 +35,6 @@ public enum AssignTypeEnumType
|
||||
/// <summary>
|
||||
/// 租户/基地
|
||||
/// </summary>
|
||||
[Description("租户/基地")]
|
||||
[Description("厂区")]
|
||||
Tenant = 5
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.Net;
|
||||
using Kurisu.RemoteCall.Abstractions;
|
||||
using Polly;
|
||||
using Polly.Extensions.Http;
|
||||
|
||||
namespace Dlhis.Middle.Apis.Handlers;
|
||||
|
||||
@@ -16,7 +19,15 @@ public class HealthzClientHandler : IHttpRemoteCallPolicyHandler
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Kurisu.RemoteCall" Version="0.4.4" />
|
||||
<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="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.8" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,136 +1,13 @@
|
||||
using Dlhis.Middle.Entities;
|
||||
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.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Middle.Packs;
|
||||
|
||||
public class SqlSugarPack : BaseAppPack
|
||||
{
|
||||
private const string _infoTemplate = "ExecuteCommand[{ms}] Timeout[{timeout}] \r\n {sql}";
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSqlSugar();
|
||||
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;
|
||||
}));
|
||||
services.AddSqlSugar(DbType.Sqlite);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Dlhis.Middle.BackgroundServices;
|
||||
using Dlhis.Middle.Entities;
|
||||
using Dlhis.Middle.Services;
|
||||
using Kurisu.AspNetCore;
|
||||
using Kurisu.AspNetCore.Authentication.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
@@ -32,6 +33,7 @@ public class Startup : DefaultStartup
|
||||
|
||||
services.AddRemoteCall(App.ActiveTypes);
|
||||
services.AddMemoryCache();
|
||||
services.AddUserInfo();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -157,20 +157,22 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
.LeftJoin<DeviceUploadLogEntity>((os, x) => os.Code == x.UserUniqueNo)
|
||||
.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, gasap) => gasap.Code == os.SapCode)
|
||||
.WhereIF(request.Search.IsPresent(), (os, x, device, ga, gasap) =>
|
||||
.LeftJoin<GainfoEntity>((os, x, device, ga, gaSap) => gaSap.Code == os.SapCode)
|
||||
.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.DeviceUniqueNo == request.Search
|
||||
|| os.Supplier == request.Search
|
||||
|| os.SapCode == request.Search
|
||||
).OrderBy((os, x, device, ga, gasap) => x.ModifiedTime, OrderByType.Desc)
|
||||
.Select((os, x, device, ga, gasap) => new DeviceUploadLogResponse
|
||||
).OrderBy((os, x, device, ga, gaSap) => x.ModifiedTime, OrderByType.Desc)
|
||||
.Select((os, x, device, ga, gaSap) => new DeviceUploadLogResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
OriginUserUniqueNo = x.UserUniqueNo,
|
||||
OutsourceSupplier = os.Supplier,
|
||||
SapUserCode = os.SapCode,
|
||||
SapUserName = gasap.Name,
|
||||
SapUserName = gaSap.Name,
|
||||
DeviceUniqueNo = x.DeviceUniqueNo,
|
||||
RaiseDateTime = x.RaiseDateTime,
|
||||
CreateTime = x.CreateTime,
|
||||
@@ -198,7 +200,8 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
||||
.LeftJoin<GainfoEntity>((x, device, ga) => x.UserUniqueNo == ga.Code)
|
||||
.LeftJoin<OutsourceEntity>((x, device, ga, os) => x.UserUniqueNo == os.Code)
|
||||
.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))
|
||||
.WhereIF(request.Sync.HasValue, x => x.Sync == request.Sync)
|
||||
.WhereIF(request.IsOutsource.HasValue && request.IsOutsource.Value,
|
||||
|
||||
Reference in New Issue
Block a user