Merge pull request 'dev_lx' (#15) from dev_lx into main

Reviewed-on: #15
pull/16/head
刘鑫 3 months ago
commit 64f52c312a
  1. 30
      WeiCloud.Fusion/.dockerignore
  2. 10
      WeiCloud.Fusion/AlarmService/Alarm.DomainService/DahAlarm/DahuaGeneralCtlService.cs
  3. 13
      WeiCloud.Fusion/AlarmService/AlarmService.API/.config/dotnet-tools.json
  4. 4
      WeiCloud.Fusion/AlarmService/AlarmService.API/AlarmService.API.csproj
  5. 52
      WeiCloud.Fusion/AlarmService/AlarmService.API/Dockerfile
  6. 2
      WeiCloud.Fusion/AlarmService/AlarmService.API/Program.cs
  7. 43
      WeiCloud.Fusion/AlarmService/AlarmService.API/Properties/launchSettings.json
  8. 32
      WeiCloud.Fusion/AspireApp/Manage.AppHost.AppHost/docker-compose.yml
  9. 52
      WeiCloud.Fusion/ParkingLotService/ParkingLotService.API/Dockerfile
  10. 52
      WeiCloud.Fusion/VideoService/Video.API/Dockerfile
  11. 15
      WeiCloud.Fusion/VideoService/Video.API/Program.cs
  12. 45
      WeiCloud.Fusion/VideoService/Video.API/Properties/launchSettings.json
  13. 4
      WeiCloud.Fusion/VideoService/Video.API/Video.API.csproj
  14. 21
      WeiCloud.Fusion/VideoService/Video.DomainService/Dahvision/DahuaGeneralCtlService.cs

@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**

@ -17,7 +17,10 @@ namespace Alarm.DomainService.DahAlarm
private readonly MQTTClient _mqttClient;
private readonly IMqttClientService _mqttClientService;
private readonly ITokenProviderService _tokenProviderService;
// private readonly HttpClient _http;
private string mqttHostIp;
private int mqttHostPort;
private int mqttTimeout;
private string mqttUsername;
@ -32,7 +35,7 @@ namespace Alarm.DomainService.DahAlarm
/// <param name="configuration"></param>
/// <param name="http"></param>
/// <param name="mQTTClient"></param>
public DahuaGeneralCtlService(ILogger<DahuaGeneralCtlService> logger, IConfiguration configuration, MQTTClient mQTTClient, IMqttClientService mqttClientService, ITokenProviderService tokenProviderService)
public DahuaGeneralCtlService(ILogger<DahuaGeneralCtlService> logger, IConfiguration configuration, MQTTClient mQTTClient, IMqttClientService mqttClientService, ITokenProviderService tokenProviderService, HttpClient http)
{
_logger = logger;
_configuration = configuration;
@ -47,6 +50,7 @@ namespace Alarm.DomainService.DahAlarm
topicName = _configuration["SubscribeMQTT:TopicName"]!;
_mqttClientService = mqttClientService;
_tokenProviderService = tokenProviderService;
// _http = http;
}
/// <summary>
@ -284,8 +288,8 @@ namespace Alarm.DomainService.DahAlarm
_logger.LogWarning("获取事件列表:token无效");
return new DaHApiResult<SubscriptionMapDto> { Success = false, Code = "1009", Msg = "token无效" };
}
// var url = $"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/evo-brm/1.0.0/device/1000014";
var url = $"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/evo-event/1.0.0/subscribe/subscribe-list?monitorType=url&category={name}";
var url = $"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/evo-brm/1.0.0/device/1000021";
//var url = $"https://{_configuration["DahuaAuth:Host"]}/evo-apigw/evo-event/1.0.0/subscribe/subscribe-list?monitorType=url&category={name}";
try
{

@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "9.0.8",
"commands": [
"dotnet-ef"
],
"rollForward": false
}
}
}

@ -5,6 +5,9 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<UserSecretsId>73a07bbb-9adc-481b-9e17-d583da60d474</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>
<ItemGroup>
@ -17,6 +20,7 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="NLog" Version="6.0.3" />
<PackageReference Include="NLog.Extensions.Logging" Version="6.0.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="6.0.3" />

@ -0,0 +1,52 @@
# ===== build 阶段 =====
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
# 只拷贝 .csproj 做还原,最大化缓存命中
COPY ["AlarmService/AlarmService.API/AlarmService.API.csproj", "AlarmService/AlarmService.API/"]
COPY ["Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj", "Common.SharedService/Common.Shared.Application/"]
COPY ["WeiCloud.Core/WeiCloud.Core.csproj", "WeiCloud.Core/"]
COPY ["WeiCloud.Utils/WeiCloud.Utils.csproj", "WeiCloud.Utils/"]
COPY ["AlarmService/Alarm.Application/Alarm.Application.csproj", "AlarmService/Alarm.Application/"]
COPY ["AlarmService/Alarm.DomainService/Alarm.DomainService.csproj", "AlarmService/Alarm.DomainService/"]
COPY ["Common.SharedService/Common.Shared.DomainService/Common.Shared.DomainService.csproj", "Common.SharedService/Common.Shared.DomainService/"]
RUN dotnet restore "AlarmService/AlarmService.API/AlarmService.API.csproj"
# 再拷贝全部源码并发布(一次 publish 即可)
COPY . .
RUN dotnet publish "AlarmService/AlarmService.API/AlarmService.API.csproj" \
-c Release -o /app \
/p:PublishReadyToRun=true \
/p:UseAppHost=false
# ===== runtime 阶段 =====
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
# 健康检查工具
RUN apt-get update && apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
# 创建非 root 账户(存在则跳过,避免重复构建报错)
RUN set -eux; \
if ! getent group app >/dev/null; then groupadd -g 64198 app; fi; \
if ! id -u appuser >/dev/null 2>&1; then useradd -r -u 64198 -g app appuser; fi
# 拷贝发布产物并赋权
COPY --from=build /app ./
RUN chown -R appuser:app /app
# 对外只走 8080,TLS 在 Nginx 统一终止
ENV ASPNETCORE_URLS=http://+:8080 \
ASPNETCORE_ENVIRONMENT=Production
EXPOSE 8080
# 健康检查:你的服务需提供 /healthz
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD curl -fsS http://localhost:8080/healthz || exit 1
# 以非 root 运行
USER appuser
ENTRYPOINT ["dotnet", "AlarmService.API.dll"]

@ -117,6 +117,8 @@ namespace AlarmService.API
app.UseAuthorization();
app.MapControllers();
app.MapGet("/healthz", () => Results.Ok("OK"));
// 创建 Startup 实例
var startup = new Startup(builder.Configuration);
startup.Configure(app, app.Environment, builder.Configuration);

@ -1,33 +1,24 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49511",
"sslPort": 44376
}
},
{
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5283",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5283"
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7230;http://localhost:5283",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7230;http://localhost:5283"
},
"IIS Express": {
"commandName": "IISExpress",
@ -36,6 +27,26 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49511",
"sslPort": 44376
}
}
}

@ -0,0 +1,32 @@

version: "3.9"
services:
video-api:
image: lxxh1992/video-api:${VIDEO_TAG:-1.1}
container_name: video-api
restart: always
environment:
- ASPNETCORE_ENVIRONMENT=Production
healthcheck:
test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthz"]
interval: 30s
timeout: 3s
retries: 3
# 仅绑定到本机回环,避免对公网暴露端口
ports:
- "127.0.0.1:5001:8080"
alarmservice-api:
image: lxxh1992/alarmservice-api:${ALARM_TAG:-1.1}
container_name: alarmservice-api
restart: always
environment:
- ASPNETCORE_ENVIRONMENT=Production
healthcheck:
test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthz"]
interval: 30s
timeout: 3s
retries: 3
ports:
- "127.0.0.1:5002:8080"

@ -0,0 +1,52 @@
# ===== build 阶段 =====
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
# 只拷贝 .csproj 做还原,最大化缓存命中
COPY ["AlarmService/AlarmService.API/AlarmService.API.csproj", "AlarmService/AlarmService.API/"]
COPY ["Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj", "Common.SharedService/Common.Shared.Application/"]
COPY ["WeiCloud.Core/WeiCloud.Core.csproj", "WeiCloud.Core/"]
COPY ["WeiCloud.Utils/WeiCloud.Utils.csproj", "WeiCloud.Utils/"]
COPY ["AlarmService/Alarm.Application/Alarm.Application.csproj", "AlarmService/Alarm.Application/"]
COPY ["AlarmService/Alarm.DomainService/Alarm.DomainService.csproj", "AlarmService/Alarm.DomainService/"]
COPY ["Common.SharedService/Common.Shared.DomainService/Common.Shared.DomainService.csproj", "Common.SharedService/Common.Shared.DomainService/"]
RUN dotnet restore "AlarmService/AlarmService.API/AlarmService.API.csproj"
# 再拷贝全部源码并发布(一次 publish 即可)
COPY . .
RUN dotnet publish "AlarmService/AlarmService.API/AlarmService.API.csproj" \
-c Release -o /app \
/p:PublishReadyToRun=true \
/p:UseAppHost=false
# ===== runtime 阶段 =====
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
# 健康检查工具
RUN apt-get update && apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
# 创建非 root 账户(存在则跳过,避免重复构建报错)
RUN set -eux; \
if ! getent group app >/dev/null; then groupadd -g 64198 app; fi; \
if ! id -u appuser >/dev/null 2>&1; then useradd -r -u 64198 -g app appuser; fi
# 拷贝发布产物并赋权
COPY --from=build /app ./
RUN chown -R appuser:app /app
# 对外只走 8080,TLS 在 Nginx 统一终止
ENV ASPNETCORE_URLS=http://+:8080 \
ASPNETCORE_ENVIRONMENT=Production
EXPOSE 8080
# 健康检查:你的服务需提供 /healthz
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD curl -fsS http://localhost:8080/healthz || exit 1
# 以非 root 运行
USER appuser
ENTRYPOINT ["dotnet", "AlarmService.API.dll"]

@ -0,0 +1,52 @@
# ===== build 阶段 =====
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
# 仅拷贝 csproj 提升缓存命中
COPY ["VideoService/Video.API/Video.API.csproj", "VideoService/Video.API/"]
COPY ["Common.SharedService/Common.Shared.Application/Common.Shared.Application.csproj", "Common.SharedService/Common.Shared.Application/"]
COPY ["WeiCloud.Core/WeiCloud.Core.csproj", "WeiCloud.Core/"]
COPY ["WeiCloud.Utils/WeiCloud.Utils.csproj", "WeiCloud.Utils/"]
COPY ["VideoService/Video.Application/Video.Application.csproj", "VideoService/Video.Application/"]
COPY ["VideoService/Video.DomainService/Video.DomainService.csproj", "VideoService/Video.DomainService/"]
COPY ["Common.SharedService/Common.Shared.DomainService/Common.Shared.DomainService.csproj", "Common.SharedService/Common.Shared.DomainService/"]
RUN dotnet restore "VideoService/Video.API/Video.API.csproj"
# 再拷贝全部源码并发布
COPY . .
RUN dotnet publish "VideoService/Video.API/Video.API.csproj" \
-c Release -o /app \
/p:PublishReadyToRun=true \
/p:UseAppHost=false
# ===== runtime 阶段 =====
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
# 健康检查用 curl
RUN apt-get update && apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
# 创建非 root 账户(存在则跳过)
RUN set -eux; \
if ! getent group app >/dev/null; then groupadd -g 64198 app; fi; \
if ! id -u appuser >/dev/null 2>&1; then useradd -r -u 64198 -g app appuser; fi
# 拷贝发布产物并赋权
COPY --from=build /app ./
RUN chown -R appuser:app /app
# 对外只走 8080,TLS 在 Nginx 统一终止
ENV ASPNETCORE_URLS=http://+:8080 \
ASPNETCORE_ENVIRONMENT=Production
EXPOSE 8080
# 健康检查:需要你的服务实现 /healthz
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD curl -fsS http://localhost:8080/healthz || exit 1
# 以非 root 运行
USER appuser
ENTRYPOINT ["dotnet", "Video.API.dll"]

@ -113,6 +113,20 @@ namespace Video.API
#endregion CAP注册
// 开发环境宽松策略;生产再收紧
builder.Services.AddCors(options =>
{
options.AddPolicy("DevCors", policy =>
{
// 如果不走 Cookie/鉴权,最简单:
policy
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.SetPreflightMaxAge(TimeSpan.FromHours(1));
});
});
// 设置全局默认请求体大小限制
builder.WebHost.ConfigureKestrel(options =>
{
@ -139,6 +153,7 @@ namespace Video.API
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapGet("/healthz", () => Results.Ok("OK"));
app.MapControllers();
// 创建 Startup 实例

@ -1,33 +1,24 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:2357",
"sslPort": 44365
}
},
{
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5224",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5224"
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7161;http://localhost:5224",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7161;http://localhost:5224"
},
"IIS Express": {
"commandName": "IISExpress",
@ -36,6 +27,26 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:2357",
"sslPort": 44365
}
}
}
}

@ -5,6 +5,9 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<UserSecretsId>90a4021f-e10a-4236-abb4-4bac4779e5d1</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>
<ItemGroup>
@ -12,6 +15,7 @@
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="8.3.5" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="8.3.5" />
<PackageReference Include="DotNetCore.CAP.RedisStreams" Version="8.3.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="NLog" Version="6.0.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="6.0.3" />
<PackageReference Include="Quartz" Version="3.15.0" />

@ -13,24 +13,25 @@ namespace Video.DomainService
private readonly ILogger<DahuaGeneralCtlService> _logger;
private readonly IConfiguration _configuration;
private readonly ITokenProviderService _tokenProviderService;
// private readonly HttpClient _http;
private readonly HttpClient _http;
public DahuaGeneralCtlService(ILogger<DahuaGeneralCtlService> logger, IConfiguration configuration, ITokenProviderService tokenProviderService)
public DahuaGeneralCtlService(ILogger<DahuaGeneralCtlService> logger, IConfiguration configuration, ITokenProviderService tokenProviderService, HttpClient http)
{
_logger = logger;
_configuration = configuration;
_tokenProviderService = tokenProviderService;
//_http = http;
_http = http;
_http = http;
}
/// <summary>
/// 开发测试的时候,忽略证书
/// </summary>
private static readonly HttpClient _http = new HttpClient(new HttpClientHandler
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
});
///// <summary>
///// 开发测试的时候,忽略证书
///// </summary>
//private static readonly HttpClient _http = new HttpClient(new HttpClientHandler
//{
// ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
//});
/// <summary>
/// hls等录像回放

Loading…
Cancel
Save