Commit 455610a76f5e3484ebc3f92e2601d5ba0d417093
1 parent
85d15837
2026-10-12代码提交
Showing
31 changed files
with
1464 additions
and
53 deletions
.gitignore
| @@ -289,6 +289,14 @@ D//**/* | @@ -289,6 +289,14 @@ D//**/* | ||
| 289 | /D:/** | 289 | /D:/** |
| 290 | /D:/**/* | 290 | /D:/**/* |
| 291 | 291 | ||
| 292 | +# 美国版一键部署密钥、密码与本地发布目录 | ||
| 293 | +美国版/scripts/.deploy-us-test | ||
| 294 | +美国版/scripts/.deploy-us-password | ||
| 295 | +美国版/Food Labeling Management Code/Yi.Abp.Net8/_publish-ustest/ | ||
| 296 | +美国版/Food Labeling Management Code/Yi.Abp.Net8/_publish-usprod/ | ||
| 297 | +美国版/Food Labeling Management Code/Yi.Abp.Net8/_publish-teustest/ | ||
| 298 | +泰额版/Food Labeling Management Code/Yi.Abp.Net8/_publish-tetest/ | ||
| 299 | + | ||
| 292 | # macOS 系统文件 | 300 | # macOS 系统文件 |
| 293 | .DS_Store | 301 | .DS_Store |
| 294 | .DS_Store? | 302 | .DS_Store? |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/Services/ThTenantProvisioningAppService.cs
| @@ -159,12 +159,8 @@ public class ThTenantProvisioningAppService : ApplicationService, IThTenantProvi | @@ -159,12 +159,8 @@ public class ThTenantProvisioningAppService : ApplicationService, IThTenantProvi | ||
| 159 | var initializing = false; | 159 | var initializing = false; |
| 160 | if (input.InitializeDatabase) | 160 | if (input.InitializeDatabase) |
| 161 | { | 161 | { |
| 162 | - TenantDatabaseBootstrapper.EnsureDatabaseCreated( | ||
| 163 | - _dbConnOptions, | ||
| 164 | - dbType, | ||
| 165 | - connectionString, | ||
| 166 | - databaseName); | ||
| 167 | - | 162 | + // 建库/CodeFirst/Seed 放到后台:HTTP 里同步 CREATE DATABASE 跨区会接近前端 10s 超时。 |
| 163 | + // InitAsync 内仍会 CREATE DATABASE + 建表。 | ||
| 168 | _backgroundInitializer.Enqueue(created.Id); | 164 | _backgroundInitializer.Enqueue(created.Id); |
| 169 | initializing = true; | 165 | initializing = true; |
| 170 | } | 166 | } |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json
| @@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
| 21 | //应用启动:SelfUrl 供 Program.cs UseUrls 绑定;用 0.0.0.0 避免写成固定局域网 IP 在本机无该网卡时启动失败(WinError 10049) | 21 | //应用启动:SelfUrl 供 Program.cs UseUrls 绑定;用 0.0.0.0 避免写成固定局域网 IP 在本机无该网卡时启动失败(WinError 10049) |
| 22 | "App": { | 22 | "App": { |
| 23 | "SelfUrl": "http://192.168.31.87:19002", | 23 | "SelfUrl": "http://192.168.31.87:19002", |
| 24 | - "CorsOrigins": "http://localhost:19002;http://localhost:18000;http://localhost:5666;http://localhost:5173;http://localhost:5174;http://localhost:3000;http://127.0.0.1:19002" | 24 | + "CorsOrigins": "http://localhost:19002;http://localhost:18000;http://localhost:5666;http://localhost:5173;http://localhost:5174;http://localhost:3000;http://127.0.0.1:19002;http://flus-tetest.3flabeling.com;https://flus-tetest.3flabeling.com;http://flusapi-tetest.3flabeling.com;https://flusapi-tetest.3flabeling.com" |
| 25 | }, | 25 | }, |
| 26 | //配置 | 26 | //配置 |
| 27 | "Settings": { | 27 | "Settings": { |
| @@ -67,9 +67,9 @@ | @@ -67,9 +67,9 @@ | ||
| 67 | "DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle", "PostgreSQL" ], | 67 | "DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle", "PostgreSQL" ], |
| 68 | 68 | ||
| 69 | "DbConnOptions": { | 69 | "DbConnOptions": { |
| 70 | - "Url": "server=rm-bp19ohrgc6111ynzh1o.mysql.rds.aliyuncs.com;port=3306;database=antis-foodlabeling-host;uid=netteam;pwd=netteam;CharSet=utf8mb4;", | 70 | + "Url": "server=rm-bp19ohrgc6111ynzh1o.mysql.rds.aliyuncs.com;port=3306;database=antis-foodlabeling-test-host;uid=netteam;pwd=netteam;CharSet=utf8mb4;", |
| 71 | // 高权限:仅建库/授权;租户连接串仍用 FoodLabeling:TenantDatabase 的 netteam | 71 | // 高权限:仅建库/授权;租户连接串仍用 FoodLabeling:TenantDatabase 的 netteam |
| 72 | - "AdminConnectionString": "server=rm-bp19ohrgc6111ynzh1o.mysql.rds.aliyuncs.com;port=3306;database=antis-foodlabeling-host;uid=javateam;pwd=javateam2026;CharSet=utf8mb4;", | 72 | + "AdminConnectionString": "server=rm-bp19ohrgc6111ynzh1o.mysql.rds.aliyuncs.com;port=3306;database=antis-foodlabeling-test-host;uid=javateam;pwd=javateam2026;CharSet=utf8mb4;", |
| 73 | "DbType": "MySql", | 73 | "DbType": "MySql", |
| 74 | "EnabledReadWrite": false, | 74 | "EnabledReadWrite": false, |
| 75 | "EnabledCodeFirst": false, | 75 | "EnabledCodeFirst": false, |
泰额版/Food Labeling Management Code/Yi.Vben5.Vue3/apps/web-antd/src/api/request.ts
| @@ -47,6 +47,7 @@ function createRequestClient(baseURL: string) { | @@ -47,6 +47,7 @@ function createRequestClient(baseURL: string) { | ||
| 47 | const client = new RequestClient({ | 47 | const client = new RequestClient({ |
| 48 | // 鍚庣鍦板潃 | 48 | // 鍚庣鍦板潃 |
| 49 | baseURL, | 49 | baseURL, |
| 50 | + timeout: 60_000, | ||
| 50 | // 娑堟伅鎻愮ず绫诲瀷 | 51 | // 娑堟伅鎻愮ず绫诲瀷 |
| 51 | errorMessageMode: 'message', | 52 | errorMessageMode: 'message', |
| 52 | // 鏄惁杩斿洖鍘熺敓鍝嶅簲 姣斿锛氶渶瑕佽幏鍙栧搷搴斿ご鏃朵娇鐢ㄨ灞炴€? | 53 | // 鏄惁杩斿洖鍘熺敓鍝嶅簲 姣斿锛氶渶瑕佽幏鍙栧搷搴斿ご鏃朵娇鐢ㄨ灞炴€? |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Dashboard/DashboardOverviewOutputDto.cs
| @@ -17,9 +17,6 @@ public class DashboardOverviewOutputDto | @@ -17,9 +17,6 @@ public class DashboardOverviewOutputDto | ||
| 17 | /// <summary>活跃用户数</summary> | 17 | /// <summary>活跃用户数</summary> |
| 18 | public DashboardMetricCardDto ActiveUsers { get; set; } = new(); | 18 | public DashboardMetricCardDto ActiveUsers { get; set; } = new(); |
| 19 | 19 | ||
| 20 | - /// <summary>标签数量</summary> | ||
| 21 | - public DashboardMetricCardDto Labels { get; set; } = new(); | ||
| 22 | - | ||
| 23 | /// <summary>公司数(<c>fl_partner</c>,按 Token 可见范围)</summary> | 20 | /// <summary>公司数(<c>fl_partner</c>,按 Token 可见范围)</summary> |
| 24 | public DashboardMetricCardDto Companies { get; set; } = new(); | 21 | public DashboardMetricCardDto Companies { get; set; } = new(); |
| 25 | 22 |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AccountStructureCascadeDeleteHelper.cs
| @@ -278,15 +278,40 @@ public static class AccountStructureCascadeDeleteHelper | @@ -278,15 +278,40 @@ public static class AccountStructureCascadeDeleteHelper | ||
| 278 | 278 | ||
| 279 | var bindings = await db.Queryable<UserLocationDbEntity>() | 279 | var bindings = await db.Queryable<UserLocationDbEntity>() |
| 280 | .Where(x => !x.IsDeleted) | 280 | .Where(x => !x.IsDeleted) |
| 281 | - .Select(x => new { x.Id, x.LocationId }) | 281 | + .Select(x => new { x.Id, x.UserId, x.LocationId }) |
| 282 | .ToListAsync(); | 282 | .ToListAsync(); |
| 283 | 283 | ||
| 284 | - var bindingIds = bindings | 284 | + var hitBindings = bindings |
| 285 | .Where(x => | 285 | .Where(x => |
| 286 | { | 286 | { |
| 287 | var key = TeamMemberListScopeHelper.NormalizeScopeKey(x.LocationId); | 287 | var key = TeamMemberListScopeHelper.NormalizeScopeKey(x.LocationId); |
| 288 | return !string.IsNullOrEmpty(key) && normalizedKeys.Contains(key); | 288 | return !string.IsNullOrEmpty(key) && normalizedKeys.Contains(key); |
| 289 | }) | 289 | }) |
| 290 | + .ToList(); | ||
| 291 | + | ||
| 292 | + if (hitBindings.Count == 0) | ||
| 293 | + { | ||
| 294 | + return; | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + var companyAdminUserIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
| 298 | + foreach (var userId in hitBindings.Select(x => x.UserId).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct()) | ||
| 299 | + { | ||
| 300 | + if (Guid.TryParse(userId.Trim(), out var userGuid) | ||
| 301 | + && await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, userGuid)) | ||
| 302 | + { | ||
| 303 | + companyAdminUserIds.Add(TeamMemberListScopeHelper.NormalizeScopeKey(userId)); | ||
| 304 | + } | ||
| 305 | + } | ||
| 306 | + | ||
| 307 | + if (companyAdminUserIds.Count > 0) | ||
| 308 | + { | ||
| 309 | + await RebindCompanyAdminsToRemainingLocationsAsync( | ||
| 310 | + db, locationIds, companyAdminUserIds, now, modifierId); | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + var bindingIds = hitBindings | ||
| 314 | + .Where(x => !companyAdminUserIds.Contains(TeamMemberListScopeHelper.NormalizeScopeKey(x.UserId))) | ||
| 290 | .Select(x => x.Id) | 315 | .Select(x => x.Id) |
| 291 | .Distinct(StringComparer.OrdinalIgnoreCase) | 316 | .Distinct(StringComparer.OrdinalIgnoreCase) |
| 292 | .ToList(); | 317 | .ToList(); |
| @@ -306,4 +331,73 @@ public static class AccountStructureCascadeDeleteHelper | @@ -306,4 +331,73 @@ public static class AccountStructureCascadeDeleteHelper | ||
| 306 | .Where(x => bindingIds.Contains(x.Id)) | 331 | .Where(x => bindingIds.Contains(x.Id)) |
| 307 | .ExecuteCommandAsync(); | 332 | .ExecuteCommandAsync(); |
| 308 | } | 333 | } |
| 334 | + | ||
| 335 | + /// <summary> | ||
| 336 | + /// 删除门店时:Company Admin 改绑到该公司剩余门店,避免账号从范围里消失。 | ||
| 337 | + /// </summary> | ||
| 338 | + private static async Task RebindCompanyAdminsToRemainingLocationsAsync( | ||
| 339 | + ISqlSugarClient db, | ||
| 340 | + IReadOnlyList<Guid> deletedLocationIds, | ||
| 341 | + HashSet<string> companyAdminUserIds, | ||
| 342 | + DateTime now, | ||
| 343 | + string? modifierId) | ||
| 344 | + { | ||
| 345 | + var deletedLocs = await db.Queryable<LocationAggregateRoot>() | ||
| 346 | + .Where(x => deletedLocationIds.Contains(x.Id)) | ||
| 347 | + .ToListAsync(); | ||
| 348 | + var partnerNames = deletedLocs | ||
| 349 | + .Select(x => x.Partner?.Trim()) | ||
| 350 | + .Where(x => !string.IsNullOrWhiteSpace(x)) | ||
| 351 | + .Distinct(StringComparer.OrdinalIgnoreCase) | ||
| 352 | + .ToList(); | ||
| 353 | + if (partnerNames.Count == 0) | ||
| 354 | + { | ||
| 355 | + return; | ||
| 356 | + } | ||
| 357 | + | ||
| 358 | + var remaining = await db.Queryable<LocationAggregateRoot>() | ||
| 359 | + .Where(x => !x.IsDeleted && !deletedLocationIds.Contains(x.Id)) | ||
| 360 | + .ToListAsync(); | ||
| 361 | + var remainingIds = remaining | ||
| 362 | + .Where(x => partnerNames.Any(n => | ||
| 363 | + string.Equals(n, x.Partner?.Trim(), StringComparison.OrdinalIgnoreCase))) | ||
| 364 | + .Select(x => TeamMemberListScopeHelper.NormalizeScopeKey(x.Id.ToString("D"))) | ||
| 365 | + .Where(x => !string.IsNullOrEmpty(x)) | ||
| 366 | + .Distinct(StringComparer.OrdinalIgnoreCase) | ||
| 367 | + .ToList(); | ||
| 368 | + if (remainingIds.Count == 0) | ||
| 369 | + { | ||
| 370 | + return; | ||
| 371 | + } | ||
| 372 | + | ||
| 373 | + foreach (var userKey in companyAdminUserIds) | ||
| 374 | + { | ||
| 375 | + if (!Guid.TryParse(userKey, out var userGuid)) | ||
| 376 | + { | ||
| 377 | + continue; | ||
| 378 | + } | ||
| 379 | + | ||
| 380 | + var existing = await LocationScopeBindingHelper.ResolveBoundLocationIdsForUserAsync(db, userGuid); | ||
| 381 | + var existingSet = new HashSet<string>(existing, StringComparer.OrdinalIgnoreCase); | ||
| 382 | + var toInsert = remainingIds.Where(id => !existingSet.Contains(id)).ToList(); | ||
| 383 | + if (toInsert.Count == 0) | ||
| 384 | + { | ||
| 385 | + continue; | ||
| 386 | + } | ||
| 387 | + | ||
| 388 | + var rows = toInsert.Select(locationId => new UserLocationDbEntity | ||
| 389 | + { | ||
| 390 | + Id = Guid.NewGuid().ToString("D"), | ||
| 391 | + IsDeleted = false, | ||
| 392 | + CreationTime = now, | ||
| 393 | + CreatorId = modifierId, | ||
| 394 | + LastModificationTime = now, | ||
| 395 | + LastModifierId = modifierId, | ||
| 396 | + UserId = TeamMemberListScopeHelper.UserKey(userGuid), | ||
| 397 | + LocationId = locationId, | ||
| 398 | + ConcurrencyStamp = string.Empty | ||
| 399 | + }).ToList(); | ||
| 400 | + await db.Insertable(rows).ExecuteCommandAsync(); | ||
| 401 | + } | ||
| 402 | + } | ||
| 309 | } | 403 | } |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/GroupListScopeHelper.cs
| @@ -43,21 +43,28 @@ public static class GroupListScopeHelper | @@ -43,21 +43,28 @@ public static class GroupListScopeHelper | ||
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | var db = dbContext.SqlSugarClient; | 45 | var db = dbContext.SqlSugarClient; |
| 46 | + var isCompanyAdmin = await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, currentUser); | ||
| 46 | var locationIds = await LocationScopeBindingHelper.ResolveBoundLocationIdsForUserAsync( | 47 | var locationIds = await LocationScopeBindingHelper.ResolveBoundLocationIdsForUserAsync( |
| 47 | db, currentUser.Id.Value); | 48 | db, currentUser.Id.Value); |
| 49 | + if (locationIds.Count == 0 && isCompanyAdmin) | ||
| 50 | + { | ||
| 51 | + locationIds = await LocationScopeBindingHelper.ResolveSoftDeletedBoundLocationIdsForUserAsync( | ||
| 52 | + db, currentUser.Id.Value); | ||
| 53 | + } | ||
| 54 | + | ||
| 48 | if (locationIds.Count == 0) | 55 | if (locationIds.Count == 0) |
| 49 | { | 56 | { |
| 50 | return new GroupListScope(); | 57 | return new GroupListScope(); |
| 51 | } | 58 | } |
| 52 | 59 | ||
| 53 | var partnerIds = await LocationScopeBindingHelper.ResolvePartnerIdsFromLocationIdsAsync( | 60 | var partnerIds = await LocationScopeBindingHelper.ResolvePartnerIdsFromLocationIdsAsync( |
| 54 | - db, locationIds); | 61 | + db, locationIds, includeDeleted: isCompanyAdmin); |
| 55 | if (partnerIds.Count == 0) | 62 | if (partnerIds.Count == 0) |
| 56 | { | 63 | { |
| 57 | return new GroupListScope(); | 64 | return new GroupListScope(); |
| 58 | } | 65 | } |
| 59 | 66 | ||
| 60 | - if (await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, currentUser)) | 67 | + if (isCompanyAdmin) |
| 61 | { | 68 | { |
| 62 | return new GroupListScope { AllowedPartnerIds = partnerIds }; | 69 | return new GroupListScope { AllowedPartnerIds = partnerIds }; |
| 63 | } | 70 | } |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelEntityPartnerScopeHelper.cs
| @@ -540,6 +540,13 @@ public static class LabelEntityPartnerScopeHelper | @@ -540,6 +540,13 @@ public static class LabelEntityPartnerScopeHelper | ||
| 540 | string? groupId, | 540 | string? groupId, |
| 541 | List<string>? scopedLocationIds) | 541 | List<string>? scopedLocationIds) |
| 542 | { | 542 | { |
| 543 | + if (string.IsNullOrWhiteSpace(partnerId) | ||
| 544 | + && string.IsNullOrWhiteSpace(groupId) | ||
| 545 | + && scopedLocationIds is { Count: 0 }) | ||
| 546 | + { | ||
| 547 | + return new List<string>(); | ||
| 548 | + } | ||
| 549 | + | ||
| 543 | var pid = await ProductListScopeHelper.ResolveFilterPartnerIdAsync( | 550 | var pid = await ProductListScopeHelper.ResolveFilterPartnerIdAsync( |
| 544 | db, partnerId, groupId, scopedLocationIds); | 551 | db, partnerId, groupId, scopedLocationIds); |
| 545 | return await ResolveScopedPartnerIdsForListAsync(db, pid); | 552 | return await ResolveScopedPartnerIdsForListAsync(db, pid); |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelTemplateLabelIdHelper.cs
| 1 | using System.Text.Json; | 1 | using System.Text.Json; |
| 2 | using System.Text.RegularExpressions; | 2 | using System.Text.RegularExpressions; |
| 3 | +using FoodLabeling.Application.Contracts.Dtos.Label; | ||
| 3 | using FoodLabeling.Application.Contracts.Dtos.LabelTemplate; | 4 | using FoodLabeling.Application.Contracts.Dtos.LabelTemplate; |
| 4 | 5 | ||
| 5 | namespace FoodLabeling.Application.Helpers; | 6 | namespace FoodLabeling.Application.Helpers; |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelTemplateScopeHelper.cs
| @@ -518,12 +518,8 @@ public static class LabelTemplateScopeHelper | @@ -518,12 +518,8 @@ public static class LabelTemplateScopeHelper | ||
| 518 | 518 | ||
| 519 | if (scopedLocationIds.Count == 0) | 519 | if (scopedLocationIds.Count == 0) |
| 520 | { | 520 | { |
| 521 | - // 无可见门店:保留 Location=ALL(及无 location 关联)的模板 | ||
| 522 | - return query.Where(t => | ||
| 523 | - t.AppliedLocationType == ScopeAll | ||
| 524 | - || !SqlFunc.Subqueryable<FlLabelTemplateLocationDbEntity>() | ||
| 525 | - .Where(l => l.TemplateId == t.Id) | ||
| 526 | - .Any()); | 521 | + // 非平台管理员且无可见门店:禁止漏出其它公司 Location=ALL 模板 |
| 522 | + return query.Where(_ => false); | ||
| 527 | } | 523 | } |
| 528 | 524 | ||
| 529 | if (!hasExtendedScope) | 525 | if (!hasExtendedScope) |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LocationScopeBindingHelper.cs
| @@ -56,6 +56,46 @@ public static class LocationScopeBindingHelper | @@ -56,6 +56,46 @@ public static class LocationScopeBindingHelper | ||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | /// <summary> | 58 | /// <summary> |
| 59 | + /// Company Admin 活跃绑定被门店删除清掉后,用软删 <c>userlocation</c> 找回原公司门店 Id。 | ||
| 60 | + /// </summary> | ||
| 61 | + public static async Task<List<string>> ResolveSoftDeletedBoundLocationIdsForUserAsync( | ||
| 62 | + ISqlSugarClient db, | ||
| 63 | + Guid userId) | ||
| 64 | + { | ||
| 65 | + var userKey = TeamMemberListScopeHelper.UserKey(userId); | ||
| 66 | + var userIdStr = userId.ToString("D"); | ||
| 67 | + | ||
| 68 | + var rows = await db.Ado.SqlQueryAsync<string>( | ||
| 69 | + """ | ||
| 70 | + SELECT LocationId | ||
| 71 | + FROM userlocation | ||
| 72 | + WHERE IsDeleted = 1 | ||
| 73 | + AND ( | ||
| 74 | + UserId = @UserIdD | ||
| 75 | + OR UserId = @UserIdLower | ||
| 76 | + OR LOWER(TRIM(UserId)) = @UserIdLower | ||
| 77 | + ) | ||
| 78 | + """, | ||
| 79 | + new | ||
| 80 | + { | ||
| 81 | + UserIdD = userIdStr, | ||
| 82 | + UserIdLower = userKey | ||
| 83 | + }); | ||
| 84 | + | ||
| 85 | + var locationIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
| 86 | + foreach (var locationId in rows) | ||
| 87 | + { | ||
| 88 | + var locKey = TeamMemberListScopeHelper.NormalizeScopeKey(locationId); | ||
| 89 | + if (!string.IsNullOrEmpty(locKey)) | ||
| 90 | + { | ||
| 91 | + locationIds.Add(locKey); | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + return locationIds.OrderBy(x => x, StringComparer.Ordinal).ToList(); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /// <summary> | ||
| 59 | /// App 可选门店 Id:Company Admin 展开为绑定 Company 下全部门店;其它角色为 <c>userlocation</c> 绑定。 | 99 | /// App 可选门店 Id:Company Admin 展开为绑定 Company 下全部门店;其它角色为 <c>userlocation</c> 绑定。 |
| 60 | /// </summary> | 100 | /// </summary> |
| 61 | public static Task<List<string>> ResolveAppAccessibleLocationIdsForUserAsync( | 101 | public static Task<List<string>> ResolveAppAccessibleLocationIdsForUserAsync( |
| @@ -72,20 +112,29 @@ public static class LocationScopeBindingHelper | @@ -72,20 +112,29 @@ public static class LocationScopeBindingHelper | ||
| 72 | ICurrentUser? currentUser) | 112 | ICurrentUser? currentUser) |
| 73 | { | 113 | { |
| 74 | var locationIds = await ResolveBoundLocationIdsForUserAsync(db, userId); | 114 | var locationIds = await ResolveBoundLocationIdsForUserAsync(db, userId); |
| 115 | + var isCompanyAdmin = currentUser?.Id == userId | ||
| 116 | + ? await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, currentUser) | ||
| 117 | + : await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, userId); | ||
| 75 | if (locationIds.Count == 0) | 118 | if (locationIds.Count == 0) |
| 76 | { | 119 | { |
| 77 | - return locationIds; | 120 | + if (!isCompanyAdmin) |
| 121 | + { | ||
| 122 | + return locationIds; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + locationIds = await ResolveSoftDeletedBoundLocationIdsForUserAsync(db, userId); | ||
| 126 | + if (locationIds.Count == 0) | ||
| 127 | + { | ||
| 128 | + return locationIds; | ||
| 129 | + } | ||
| 78 | } | 130 | } |
| 79 | 131 | ||
| 80 | - var isCompanyAdmin = currentUser?.Id == userId | ||
| 81 | - ? await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, currentUser) | ||
| 82 | - : await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, userId); | ||
| 83 | if (!isCompanyAdmin) | 132 | if (!isCompanyAdmin) |
| 84 | { | 133 | { |
| 85 | return locationIds; | 134 | return locationIds; |
| 86 | } | 135 | } |
| 87 | 136 | ||
| 88 | - var partnerIds = await ResolvePartnerIdsFromLocationIdsAsync(db, locationIds); | 137 | + var partnerIds = await ResolvePartnerIdsFromLocationIdsAsync(db, locationIds, includeDeleted: true); |
| 89 | if (partnerIds.Count == 0) | 138 | if (partnerIds.Count == 0) |
| 90 | { | 139 | { |
| 91 | return locationIds; | 140 | return locationIds; |
| @@ -514,9 +563,18 @@ public static class LocationScopeBindingHelper | @@ -514,9 +563,18 @@ public static class LocationScopeBindingHelper | ||
| 514 | /// <summary> | 563 | /// <summary> |
| 515 | /// 根据已绑定门店反推适用的 Company Id(<c>fl_partner.Id</c>)。 | 564 | /// 根据已绑定门店反推适用的 Company Id(<c>fl_partner.Id</c>)。 |
| 516 | /// </summary> | 565 | /// </summary> |
| 566 | + public static Task<List<string>> ResolvePartnerIdsFromLocationIdsAsync( | ||
| 567 | + ISqlSugarClient db, | ||
| 568 | + IReadOnlyList<string> locationIds) => | ||
| 569 | + ResolvePartnerIdsFromLocationIdsAsync(db, locationIds, includeDeleted: false); | ||
| 570 | + | ||
| 571 | + /// <summary> | ||
| 572 | + /// 根据门店反推 Company Id;<paramref name="includeDeleted"/> 用于门店已软删但仍需找回原公司。 | ||
| 573 | + /// </summary> | ||
| 517 | public static async Task<List<string>> ResolvePartnerIdsFromLocationIdsAsync( | 574 | public static async Task<List<string>> ResolvePartnerIdsFromLocationIdsAsync( |
| 518 | ISqlSugarClient db, | 575 | ISqlSugarClient db, |
| 519 | - IReadOnlyList<string> locationIds) | 576 | + IReadOnlyList<string> locationIds, |
| 577 | + bool includeDeleted) | ||
| 520 | { | 578 | { |
| 521 | var ids = NormalizeIds(locationIds); | 579 | var ids = NormalizeIds(locationIds); |
| 522 | if (ids.Count == 0) | 580 | if (ids.Count == 0) |
| @@ -531,7 +589,8 @@ public static class LocationScopeBindingHelper | @@ -531,7 +589,8 @@ public static class LocationScopeBindingHelper | ||
| 531 | } | 589 | } |
| 532 | 590 | ||
| 533 | var locs = await db.Queryable<LocationAggregateRoot>() | 591 | var locs = await db.Queryable<LocationAggregateRoot>() |
| 534 | - .Where(x => !x.IsDeleted && guidList.Contains(x.Id)) | 592 | + .Where(x => guidList.Contains(x.Id)) |
| 593 | + .WhereIF(!includeDeleted, x => !x.IsDeleted) | ||
| 535 | .ToListAsync(); | 594 | .ToListAsync(); |
| 536 | if (locs.Count == 0) | 595 | if (locs.Count == 0) |
| 537 | { | 596 | { |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/PartnerScopeHelper.cs
| @@ -41,13 +41,20 @@ public static class PartnerScopeHelper | @@ -41,13 +41,20 @@ public static class PartnerScopeHelper | ||
| 41 | var db = dbContext.SqlSugarClient; | 41 | var db = dbContext.SqlSugarClient; |
| 42 | var locationIds = await LocationScopeBindingHelper.ResolveBoundLocationIdsForUserAsync( | 42 | var locationIds = await LocationScopeBindingHelper.ResolveBoundLocationIdsForUserAsync( |
| 43 | db, currentUser.Id.Value); | 43 | db, currentUser.Id.Value); |
| 44 | + var isCompanyAdmin = await TeamMemberRoleHelper.IsCompanyAdminUserAsync(db, currentUser); | ||
| 45 | + if (locationIds.Count == 0 && isCompanyAdmin) | ||
| 46 | + { | ||
| 47 | + locationIds = await LocationScopeBindingHelper.ResolveSoftDeletedBoundLocationIdsForUserAsync( | ||
| 48 | + db, currentUser.Id.Value); | ||
| 49 | + } | ||
| 50 | + | ||
| 44 | if (locationIds.Count == 0) | 51 | if (locationIds.Count == 0) |
| 45 | { | 52 | { |
| 46 | return new PartnerScopeFilter(); | 53 | return new PartnerScopeFilter(); |
| 47 | } | 54 | } |
| 48 | 55 | ||
| 49 | var allowedIds = await LocationScopeBindingHelper.ResolvePartnerIdsFromLocationIdsAsync( | 56 | var allowedIds = await LocationScopeBindingHelper.ResolvePartnerIdsFromLocationIdsAsync( |
| 50 | - db, locationIds); | 57 | + db, locationIds, includeDeleted: isCompanyAdmin); |
| 51 | return new PartnerScopeFilter { AllowedPartnerIds = allowedIds }; | 58 | return new PartnerScopeFilter { AllowedPartnerIds = allowedIds }; |
| 52 | } | 59 | } |
| 53 | 60 |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DashboardAppService.cs
| @@ -92,11 +92,6 @@ public class DashboardAppService : ApplicationService, IDashboardAppService | @@ -92,11 +92,6 @@ public class DashboardAppService : ApplicationService, IDashboardAppService | ||
| 92 | var peoplePrevWeek = await DashboardScopeHelper.CountScopedRegisteredUsersAsync( | 92 | var peoplePrevWeek = await DashboardScopeHelper.CountScopedRegisteredUsersAsync( |
| 93 | db, scopeLocationIds, activeOnly: false, createdBefore: weekStart); | 93 | db, scopeLocationIds, activeOnly: false, createdBefore: weekStart); |
| 94 | 94 | ||
| 95 | - var labels = await DashboardScopeHelper.CountScopedLabelsAsync( | ||
| 96 | - db, _dbContext, CurrentUser, createdBefore: null); | ||
| 97 | - var labelsPrevWeek = await DashboardScopeHelper.CountScopedLabelsAsync( | ||
| 98 | - db, _dbContext, CurrentUser, createdBefore: weekStart); | ||
| 99 | - | ||
| 100 | var products = await DashboardScopeHelper.CountLocationListScopedProductsAsync( | 95 | var products = await DashboardScopeHelper.CountLocationListScopedProductsAsync( |
| 101 | db, CurrentUser, _dbContext); | 96 | db, CurrentUser, _dbContext); |
| 102 | // fl_product 当前实体未映射 CreationTime,无法按时间切分对比,先回退为同口径总量对比 | 97 | // fl_product 当前实体未映射 CreationTime,无法按时间切分对比,先回退为同口径总量对比 |
| @@ -243,7 +238,6 @@ public class DashboardAppService : ApplicationService, IDashboardAppService | @@ -243,7 +238,6 @@ public class DashboardAppService : ApplicationService, IDashboardAppService | ||
| 243 | var labelsCard = BuildMetricCard("labels", "Labels", labels, labelsPrevWeek); | 238 | var labelsCard = BuildMetricCard("labels", "Labels", labels, labelsPrevWeek); |
| 244 | var activeTemplatesCard = BuildMetricCard("activeTemplates", "Active Templates", activeTemplates, activeTemplatesPrevWeek); | 239 | var activeTemplatesCard = BuildMetricCard("activeTemplates", "Active Templates", activeTemplates, activeTemplatesPrevWeek); |
| 245 | var activeUsersCard = BuildMetricCard("activeUsers", "Active Users", activeUsers, activeUsersPrevWeek); | 240 | var activeUsersCard = BuildMetricCard("activeUsers", "Active Users", activeUsers, activeUsersPrevWeek); |
| 246 | - var labelsCard = BuildMetricCard("labels", "Labels", labels, labelsPrevWeek); | ||
| 247 | var companiesCard = BuildMetricCard("companies", "Companies", companies, companiesPrevWeek); | 241 | var companiesCard = BuildMetricCard("companies", "Companies", companies, companiesPrevWeek); |
| 248 | var regionsCard = BuildMetricCard("regions", "Regions", regions, regionsPrevWeek); | 242 | var regionsCard = BuildMetricCard("regions", "Regions", regions, regionsPrevWeek); |
| 249 | var locationsCard = BuildMetricCard("locations", "Locations", locations, locationsPrevWeek); | 243 | var locationsCard = BuildMetricCard("locations", "Locations", locations, locationsPrevWeek); |
| @@ -256,7 +250,6 @@ public class DashboardAppService : ApplicationService, IDashboardAppService | @@ -256,7 +250,6 @@ public class DashboardAppService : ApplicationService, IDashboardAppService | ||
| 256 | Labels = labelsCard, | 250 | Labels = labelsCard, |
| 257 | ActiveTemplates = activeTemplatesCard, | 251 | ActiveTemplates = activeTemplatesCard, |
| 258 | ActiveUsers = activeUsersCard, | 252 | ActiveUsers = activeUsersCard, |
| 259 | - Labels = labelsCard, | ||
| 260 | Companies = companiesCard, | 253 | Companies = companiesCard, |
| 261 | Regions = regionsCard, | 254 | Regions = regionsCard, |
| 262 | Locations = locationsCard, | 255 | Locations = locationsCard, |
美国版/Food Labeling Management Code/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json
| @@ -20,8 +20,8 @@ | @@ -20,8 +20,8 @@ | ||
| 20 | }, | 20 | }, |
| 21 | //应用启动:SelfUrl 供 Program.cs UseUrls 绑定;用 0.0.0.0 避免写成固定局域网 IP 在本机无该网卡时启动失败(WinError 10049) | 21 | //应用启动:SelfUrl 供 Program.cs UseUrls 绑定;用 0.0.0.0 避免写成固定局域网 IP 在本机无该网卡时启动失败(WinError 10049) |
| 22 | "App": { | 22 | "App": { |
| 23 | - "SelfUrl": "http://192.168.31.88:19003", | ||
| 24 | - "CorsOrigins": "http://localhost:19003;http://localhost:18000;http://localhost:5666;http://localhost:5174;http://localhost:5173;http://localhost:3000" | 23 | + "SelfUrl": "http://localhost:19001", |
| 24 | + "CorsOrigins": "http://localhost:19001;http://localhost:18000;http://localhost:5666;http://localhost:5174;http://localhost:5173;http://localhost:3000;http://flus-test.3flabeling.com;https://flus-test.3flabeling.com;http://flus.3flabeling.com;https://flus.3flabeling.com;http://flus-teustest.3flabeling.com;https://flus-teustest.3flabeling.com;http://flus-test.3ffoodsafety.com;https://flus-test.3ffoodsafety.com;http://flus.3ffoodsafety.com;https://flus.3ffoodsafety.com" | ||
| 25 | }, | 25 | }, |
| 26 | //配置 | 26 | //配置 |
| 27 | "Settings": { | 27 | "Settings": { |
| @@ -31,6 +31,7 @@ | @@ -31,6 +31,7 @@ | ||
| 31 | "DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle", "PostgreSQL" ], | 31 | "DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle", "PostgreSQL" ], |
| 32 | 32 | ||
| 33 | "DbConnOptions": { | 33 | "DbConnOptions": { |
| 34 | + // 美国版数据库:本地/测试 antis-foodlabeling-test-us;正式 antis-foodlabeling-us(由正式环境部署脚本改写) | ||
| 34 | "Url": "server=rm-bp19ohrgc6111ynzh1o.mysql.rds.aliyuncs.com;port=3306;database=antis-foodlabeling-test-us;uid=netteam;pwd=netteam;CharSet=utf8mb4;", | 35 | "Url": "server=rm-bp19ohrgc6111ynzh1o.mysql.rds.aliyuncs.com;port=3306;database=antis-foodlabeling-test-us;uid=netteam;pwd=netteam;CharSet=utf8mb4;", |
| 35 | "DbType": "Mysql", | 36 | "DbType": "Mysql", |
| 36 | "EnabledReadWrite": false,//是否启用读写分离 | 37 | "EnabledReadWrite": false,//是否启用读写分离 |
美国版/Food Labeling Management Platform/src/components/labels/LabelTemplateEditor/LabelCanvas.tsx
| @@ -1767,7 +1767,7 @@ function ElementContent({ | @@ -1767,7 +1767,7 @@ function ElementContent({ | ||
| 1767 | commonStyle={commonStyle} | 1767 | commonStyle={commonStyle} |
| 1768 | className="whitespace-nowrap" | 1768 | className="whitespace-nowrap" |
| 1769 | > | 1769 | > |
| 1770 | - {previewFmt || '—'} | 1770 | + {previewFmt || '—'} |
| 1771 | </AlignedTextBox>, | 1771 | </AlignedTextBox>, |
| 1772 | ); | 1772 | ); |
| 1773 | } | 1773 | } |
| @@ -1818,7 +1818,7 @@ function ElementContent({ | @@ -1818,7 +1818,7 @@ function ElementContent({ | ||
| 1818 | } | 1818 | } |
| 1819 | return wrapVertical( | 1819 | return wrapVertical( |
| 1820 | <AlignedTextBox cfg={cfg} commonStyle={commonStyle} className="whitespace-nowrap"> | 1820 | <AlignedTextBox cfg={cfg} commonStyle={commonStyle} className="whitespace-nowrap"> |
| 1821 | - {example} | 1821 | + {example} |
| 1822 | </AlignedTextBox>, | 1822 | </AlignedTextBox>, |
| 1823 | ); | 1823 | ); |
| 1824 | } | 1824 | } |
| @@ -1833,7 +1833,7 @@ function ElementContent({ | @@ -1833,7 +1833,7 @@ function ElementContent({ | ||
| 1833 | commonStyle={commonStyle} | 1833 | commonStyle={commonStyle} |
| 1834 | className="whitespace-nowrap" | 1834 | className="whitespace-nowrap" |
| 1835 | > | 1835 | > |
| 1836 | - {previewTime.trim() || '—'} | 1836 | + {previewTime.trim() || '—'} |
| 1837 | </AlignedTextBox>, | 1837 | </AlignedTextBox>, |
| 1838 | ); | 1838 | ); |
| 1839 | } | 1839 | } |
| @@ -1843,7 +1843,7 @@ function ElementContent({ | @@ -1843,7 +1843,7 @@ function ElementContent({ | ||
| 1843 | const example = formatDateByPreset(timeFormat, d); | 1843 | const example = formatDateByPreset(timeFormat, d); |
| 1844 | return wrapVertical( | 1844 | return wrapVertical( |
| 1845 | <AlignedTextBox cfg={cfg} commonStyle={commonStyle} className="whitespace-nowrap"> | 1845 | <AlignedTextBox cfg={cfg} commonStyle={commonStyle} className="whitespace-nowrap"> |
| 1846 | - {example} | 1846 | + {example} |
| 1847 | </AlignedTextBox>, | 1847 | </AlignedTextBox>, |
| 1848 | ); | 1848 | ); |
| 1849 | } | 1849 | } |
| @@ -1857,7 +1857,7 @@ function ElementContent({ | @@ -1857,7 +1857,7 @@ function ElementContent({ | ||
| 1857 | commonStyle={commonStyle} | 1857 | commonStyle={commonStyle} |
| 1858 | className="whitespace-nowrap" | 1858 | className="whitespace-nowrap" |
| 1859 | > | 1859 | > |
| 1860 | - {previewDur.trim() || '—'} | 1860 | + {previewDur.trim() || '—'} |
| 1861 | </AlignedTextBox>, | 1861 | </AlignedTextBox>, |
| 1862 | ); | 1862 | ); |
| 1863 | } | 1863 | } |
| @@ -1873,7 +1873,7 @@ function ElementContent({ | @@ -1873,7 +1873,7 @@ function ElementContent({ | ||
| 1873 | const example = `${durationValue} ${unit}`; | 1873 | const example = `${durationValue} ${unit}`; |
| 1874 | return wrapVertical( | 1874 | return wrapVertical( |
| 1875 | <AlignedTextBox cfg={cfg} commonStyle={commonStyle} className="whitespace-nowrap"> | 1875 | <AlignedTextBox cfg={cfg} commonStyle={commonStyle} className="whitespace-nowrap"> |
| 1876 | - {example} | 1876 | + {example} |
| 1877 | </AlignedTextBox>, | 1877 | </AlignedTextBox>, |
| 1878 | ); | 1878 | ); |
| 1879 | } | 1879 | } |
| @@ -2249,8 +2249,8 @@ export function LabelCanvas({ | @@ -2249,8 +2249,8 @@ export function LabelCanvas({ | ||
| 2249 | const dly = local.y - startLocalY; | 2249 | const dly = local.y - startLocalY; |
| 2250 | if (Math.hypot(dlx, dly) < ELEMENT_DRAG_THRESHOLD_PX) return; | 2250 | if (Math.hypot(dlx, dly) < ELEMENT_DRAG_THRESHOLD_PX) return; |
| 2251 | dragRef.current = { ...session, active: true }; | 2251 | dragRef.current = { ...session, active: true }; |
| 2252 | - const domEl = document.getElementById(`element-${id}`); | ||
| 2253 | - if (domEl) { | 2252 | + const domEl = document.getElementById(`element-${id}`); |
| 2253 | + if (domEl) { | ||
| 2254 | domEl.classList.add( | 2254 | domEl.classList.add( |
| 2255 | 'z-50', | 2255 | 'z-50', |
| 2256 | 'opacity-90', | 2256 | 'opacity-90', |
| @@ -2259,7 +2259,7 @@ export function LabelCanvas({ | @@ -2259,7 +2259,7 @@ export function LabelCanvas({ | ||
| 2259 | 'ring-blue-400', | 2259 | 'ring-blue-400', |
| 2260 | 'ring-offset-2', | 2260 | 'ring-offset-2', |
| 2261 | ); | 2261 | ); |
| 2262 | - domEl.style.cursor = 'grabbing'; | 2262 | + domEl.style.cursor = 'grabbing'; |
| 2263 | } | 2263 | } |
| 2264 | } | 2264 | } |
| 2265 | 2265 | ||
| @@ -3457,14 +3457,14 @@ export function LabelCanvas({ | @@ -3457,14 +3457,14 @@ export function LabelCanvas({ | ||
| 3457 | } | 3457 | } |
| 3458 | /> | 3458 | /> |
| 3459 | ) : null} | 3459 | ) : null} |
| 3460 | + </div> | ||
| 3460 | </div> | 3461 | </div> |
| 3461 | - </div> | ||
| 3462 | - </div> | 3462 | + </div> |
| 3463 | </div> | 3463 | </div> |
| 3464 | </div> | 3464 | </div> |
| 3465 | </div> | 3465 | </div> |
| 3466 | </div> | 3466 | </div> |
| 3467 | - </div> | 3467 | + </div> |
| 3468 | </div> | 3468 | </div> |
| 3469 | ); | 3469 | ); |
| 3470 | } | 3470 | } |
| @@ -3543,8 +3543,8 @@ export function LabelPreviewOnly({ | @@ -3543,8 +3543,8 @@ export function LabelPreviewOnly({ | ||
| 3543 | style={{ | 3543 | style={{ |
| 3544 | width: paperViewW, | 3544 | width: paperViewW, |
| 3545 | height: paperViewH, | 3545 | height: paperViewH, |
| 3546 | - }} | ||
| 3547 | - > | 3546 | + }} |
| 3547 | + > | ||
| 3548 | {template.elements.map((el) => { | 3548 | {template.elements.map((el) => { |
| 3549 | const isPrintField = isPrintInputElement(el); | 3549 | const isPrintField = isPrintInputElement(el); |
| 3550 | const isHighlighted = highlightElementId === el.id; | 3550 | const isHighlighted = highlightElementId === el.id; |
美国版/scripts/.deploy-us-test.pub
0 → 100644
| 1 | +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDUdJucD71nTpfb0aGe4zOM4el8tiLB2bLi6x9UqGZvm flus-ustest-deploy |
美国版/scripts/_deploy-us-ssh.ps1
0 → 100644
| 1 | +function Get-DeployPassword { | ||
| 2 | + if ($env:FLUS_DEPLOY_SSH_PASSWORD) { | ||
| 3 | + return $env:FLUS_DEPLOY_SSH_PASSWORD.Trim() | ||
| 4 | + } | ||
| 5 | + $passwordFile = Join-Path $ScriptDir ".deploy-us-password" | ||
| 6 | + if (Test-Path $passwordFile) { | ||
| 7 | + return (Get-Content $passwordFile -Raw -Encoding UTF8).Trim() | ||
| 8 | + } | ||
| 9 | + $sec = Read-Host "SSH root password" -AsSecureString | ||
| 10 | + $bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($sec) | ||
| 11 | + try { | ||
| 12 | + return [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr) | ||
| 13 | + } finally { | ||
| 14 | + [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) | ||
| 15 | + } | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +function Initialize-DeploySsh { | ||
| 19 | + $pass = Get-DeployPassword | ||
| 20 | + if ([string]::IsNullOrWhiteSpace($pass)) { | ||
| 21 | + throw "Missing SSH password. Put it in .deploy-us-password" | ||
| 22 | + } | ||
| 23 | + $env:FLUS_DEPLOY_SSH_PASSWORD = $pass | ||
| 24 | + $askPass = Join-Path $env:TEMP "flus-deploy-askpass.cmd" | ||
| 25 | + $askBody = "@echo off" + [char]13 + [char]10 + "echo %FLUS_DEPLOY_SSH_PASSWORD%" | ||
| 26 | + Set-Content -Path $askPass -Value $askBody -Encoding ASCII | ||
| 27 | + $env:SSH_ASKPASS = $askPass | ||
| 28 | + $env:SSH_ASKPASS_REQUIRE = "force" | ||
| 29 | + $env:DISPLAY = "dummy:0" | ||
| 30 | + $global:SshOpts = @( | ||
| 31 | + "-o", "PreferredAuthentications=password", | ||
| 32 | + "-o", "PubkeyAuthentication=no", | ||
| 33 | + "-o", "KbdInteractiveAuthentication=no", | ||
| 34 | + "-o", "NumberOfPasswordPrompts=1", | ||
| 35 | + "-o", "StrictHostKeyChecking=accept-new" | ||
| 36 | + ) | ||
| 37 | + Write-Host "== SSH password login check ==" -ForegroundColor Cyan | ||
| 38 | + & ssh @global:SshOpts "${UserName}@${HostName}" "echo SSH_OK" | ||
| 39 | + if ($LASTEXITCODE -ne 0) { | ||
| 40 | + throw "SSH password login failed. Update .deploy-us-password" | ||
| 41 | + } | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +function Invoke-Remote { | ||
| 45 | + param( | ||
| 46 | + [string]$Command, | ||
| 47 | + [switch]$AllowFail | ||
| 48 | + ) | ||
| 49 | + $Command = $Command -replace "`r", "" | ||
| 50 | + $b64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Command)) | ||
| 51 | + & ssh @global:SshOpts "${UserName}@${HostName}" "echo $b64 | base64 -d > /tmp/flus-deploy-run.sh && bash /tmp/flus-deploy-run.sh" | ||
| 52 | + if (-not $AllowFail -and $LASTEXITCODE -ne 0) { | ||
| 53 | + throw "Remote command failed" | ||
| 54 | + } | ||
| 55 | +} |
美国版/scripts/bt-register-net-project.py
0 → 100644
| 1 | +#!/usr/bin/env python3 | ||
| 2 | +# -*- coding: utf-8 -*- | ||
| 3 | +"""把 .NET 站点登记到宝塔 Net 项目,并写入域名 / Nginx 配置文件。""" | ||
| 4 | +import json | ||
| 5 | +import os | ||
| 6 | +import sqlite3 | ||
| 7 | +import subprocess | ||
| 8 | +import sys | ||
| 9 | +import time | ||
| 10 | + | ||
| 11 | +DB_CANDIDATES = [ | ||
| 12 | + "/www/server/panel/data/db/site.db", | ||
| 13 | + "/www/server/panel/data/default.db", | ||
| 14 | + "/www/server/panel/data/db.db", | ||
| 15 | +] | ||
| 16 | +VHOST_NGINX = "/www/server/panel/vhost/nginx" | ||
| 17 | +VHOST_REWRITE = "/www/server/panel/vhost/rewrite" | ||
| 18 | +VHOST_CERT = "/www/server/panel/vhost/cert" | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +def parse_args(argv): | ||
| 22 | + data = {} | ||
| 23 | + for item in argv: | ||
| 24 | + if "=" not in item: | ||
| 25 | + continue | ||
| 26 | + k, v = item.split("=", 1) | ||
| 27 | + data[k] = v | ||
| 28 | + required = ("name", "path", "port", "cmd") | ||
| 29 | + missing = [k for k in required if not data.get(k)] | ||
| 30 | + if missing: | ||
| 31 | + raise SystemExit("缺少参数: " + ",".join(missing)) | ||
| 32 | + data.setdefault("ps", data["name"]) | ||
| 33 | + data.setdefault("run_user", "root") | ||
| 34 | + data.setdefault("dotnet_version", "8.0.100") | ||
| 35 | + data.setdefault("domain", "") | ||
| 36 | + return data | ||
| 37 | + | ||
| 38 | + | ||
| 39 | +def find_db(): | ||
| 40 | + for path in DB_CANDIDATES: | ||
| 41 | + if os.path.isfile(path): | ||
| 42 | + return path | ||
| 43 | + raise SystemExit("找不到宝塔 site 数据库") | ||
| 44 | + | ||
| 45 | + | ||
| 46 | +def table_columns(conn, table): | ||
| 47 | + return {row[1] for row in conn.execute("PRAGMA table_info(%s)" % table).fetchall()} | ||
| 48 | + | ||
| 49 | + | ||
| 50 | +def ensure_start_script(cfg): | ||
| 51 | + scripts_dir = "/www/server/net_project/scripts" | ||
| 52 | + pid_dir = "/var/tmp/net_project" | ||
| 53 | + log_dir = "/www/wwwlogs/net" | ||
| 54 | + os.makedirs(scripts_dir, exist_ok=True) | ||
| 55 | + os.makedirs(pid_dir, exist_ok=True) | ||
| 56 | + os.makedirs(log_dir, exist_ok=True) | ||
| 57 | + os.chmod(pid_dir, 0o777) | ||
| 58 | + script = os.path.join(scripts_dir, "%s.sh" % cfg["name"]) | ||
| 59 | + log_file = os.path.join(log_dir, "%s.log" % cfg["name"]) | ||
| 60 | + pid_file = os.path.join(pid_dir, "%s.pid" % cfg["name"]) | ||
| 61 | + body = """#!/bin/bash | ||
| 62 | +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin | ||
| 63 | +export PATH | ||
| 64 | +cd {path} | ||
| 65 | +nohup {cmd} &>> {log_file} & | ||
| 66 | +echo $! > {pid_file} | ||
| 67 | +""".format(path=cfg["path"], cmd=cfg["cmd"], log_file=log_file, pid_file=pid_file) | ||
| 68 | + with open(script, "w", encoding="utf-8") as fh: | ||
| 69 | + fh.write(body) | ||
| 70 | + os.chmod(script, 0o755) | ||
| 71 | + return script | ||
| 72 | + | ||
| 73 | + | ||
| 74 | +def insert_site(conn, cfg): | ||
| 75 | + cols = table_columns(conn, "sites") | ||
| 76 | + exists = conn.execute("SELECT id,name,path FROM sites WHERE name=?", (cfg["name"],)).fetchone() | ||
| 77 | + domain = (cfg.get("domain") or "").strip() | ||
| 78 | + domains = ["%s:80" % domain] if domain else [] | ||
| 79 | + project_config = json.dumps( | ||
| 80 | + { | ||
| 81 | + "ssl_path": "/www/wwwroot/net_node_ssl", | ||
| 82 | + "project_name": cfg["name"], | ||
| 83 | + "bind_extranet": 1 if domain else 0, | ||
| 84 | + "domains": domains, | ||
| 85 | + "project_path": cfg["path"], | ||
| 86 | + "project_cmd": cfg["cmd"], | ||
| 87 | + "is_power_on": 1, | ||
| 88 | + "run_user": cfg["run_user"], | ||
| 89 | + "port": int(cfg["port"]), | ||
| 90 | + "log_path": "/www/wwwlogs/net", | ||
| 91 | + "dotnet_version": cfg["dotnet_version"], | ||
| 92 | + }, | ||
| 93 | + ensure_ascii=False, | ||
| 94 | + ) | ||
| 95 | + now = time.strftime("%Y-%m-%d %H:%M:%S") | ||
| 96 | + values = { | ||
| 97 | + "name": cfg["name"], | ||
| 98 | + "path": cfg["path"], | ||
| 99 | + "ps": cfg["ps"], | ||
| 100 | + "status": 1, | ||
| 101 | + "type_id": 0, | ||
| 102 | + "project_type": "net", | ||
| 103 | + "project_config": project_config, | ||
| 104 | + "addtime": now, | ||
| 105 | + "edate": "0000-00-00", | ||
| 106 | + } | ||
| 107 | + values = {k: v for k, v in values.items() if k in cols} | ||
| 108 | + if exists: | ||
| 109 | + sets = ", ".join("%s=?" % k for k in values if k != "name") | ||
| 110 | + params = [values[k] for k in values if k != "name"] + [cfg["name"]] | ||
| 111 | + conn.execute("UPDATE sites SET %s WHERE name=?" % sets, params) | ||
| 112 | + conn.commit() | ||
| 113 | + print("UPDATED id=%s name=%s" % (exists[0], cfg["name"])) | ||
| 114 | + return exists[0] | ||
| 115 | + keys = list(values.keys()) | ||
| 116 | + sql = "INSERT INTO sites (%s) VALUES (%s)" % (",".join(keys), ",".join("?" * len(keys))) | ||
| 117 | + cur = conn.execute(sql, [values[k] for k in keys]) | ||
| 118 | + conn.commit() | ||
| 119 | + print("INSERTED id=%s name=%s" % (cur.lastrowid, cfg["name"])) | ||
| 120 | + return cur.lastrowid | ||
| 121 | + | ||
| 122 | + | ||
| 123 | +def insert_domain(conn, site_id, cfg): | ||
| 124 | + domain = (cfg.get("domain") or "").strip() | ||
| 125 | + if not domain: | ||
| 126 | + return | ||
| 127 | + tables = [r[0] for r in conn.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()] | ||
| 128 | + if "domain" not in tables: | ||
| 129 | + print("SKIP domain table missing") | ||
| 130 | + return | ||
| 131 | + cols = table_columns(conn, "domain") | ||
| 132 | + conn.execute("DELETE FROM domain WHERE pid=?", (site_id,)) | ||
| 133 | + now = time.strftime("%Y-%m-%d %H:%M:%S") | ||
| 134 | + row = {"name": domain, "pid": site_id, "port": 80, "addtime": now} | ||
| 135 | + row = {k: v for k, v in row.items() if k in cols} | ||
| 136 | + keys = list(row.keys()) | ||
| 137 | + conn.execute( | ||
| 138 | + "INSERT INTO domain (%s) VALUES (%s)" % (",".join(keys), ",".join("?" * len(keys))), | ||
| 139 | + [row[k] for k in keys], | ||
| 140 | + ) | ||
| 141 | + conn.commit() | ||
| 142 | + print("DOMAIN %s pid=%s" % (domain, site_id)) | ||
| 143 | + | ||
| 144 | + | ||
| 145 | +def write_nginx_conf(cfg): | ||
| 146 | + domain = (cfg.get("domain") or "").strip() | ||
| 147 | + if not domain: | ||
| 148 | + return | ||
| 149 | + os.makedirs(VHOST_NGINX, exist_ok=True) | ||
| 150 | + os.makedirs(VHOST_REWRITE, exist_ok=True) | ||
| 151 | + name = cfg["name"] | ||
| 152 | + port = cfg["port"] | ||
| 153 | + conf_path = os.path.join(VHOST_NGINX, "net_%s.conf" % name) | ||
| 154 | + rewrite_path = os.path.join(VHOST_REWRITE, "net_%s.conf" % name) | ||
| 155 | + live = "/etc/letsencrypt/live/%s" % domain | ||
| 156 | + cert_dir = os.path.join(VHOST_CERT, name) | ||
| 157 | + os.makedirs(cert_dir, exist_ok=True) | ||
| 158 | + if os.path.isfile(os.path.join(live, "fullchain.pem")): | ||
| 159 | + for fname in ("fullchain.pem", "privkey.pem"): | ||
| 160 | + src = os.path.join(live, fname) | ||
| 161 | + dst = os.path.join(cert_dir, fname) | ||
| 162 | + if os.path.islink(dst) or os.path.exists(dst): | ||
| 163 | + try: | ||
| 164 | + os.remove(dst) | ||
| 165 | + except OSError: | ||
| 166 | + pass | ||
| 167 | + os.symlink(src, dst) | ||
| 168 | + ssl_cert = os.path.join(live, "fullchain.pem") | ||
| 169 | + ssl_key = os.path.join(live, "privkey.pem") | ||
| 170 | + ssl_include = "" | ||
| 171 | + if os.path.isfile("/etc/letsencrypt/options-ssl-nginx.conf"): | ||
| 172 | + ssl_include = " include /etc/letsencrypt/options-ssl-nginx.conf;\n" | ||
| 173 | + if os.path.isfile("/etc/letsencrypt/ssl-dhparams.pem"): | ||
| 174 | + ssl_include += " ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;\n" | ||
| 175 | + ssl_server = """ | ||
| 176 | +server {{ | ||
| 177 | + listen 443 ssl; | ||
| 178 | + listen [::]:443 ssl; | ||
| 179 | + server_name {domain}; | ||
| 180 | + ssl_certificate {ssl_cert}; | ||
| 181 | + ssl_certificate_key {ssl_key}; | ||
| 182 | +{ssl_include} access_log /www/wwwlogs/{domain}.access.log; | ||
| 183 | + error_log /www/wwwlogs/{domain}.error.log; | ||
| 184 | + client_max_body_size 50m; | ||
| 185 | + include {rewrite}; | ||
| 186 | + location / {{ | ||
| 187 | + proxy_pass http://127.0.0.1:{port}; | ||
| 188 | + proxy_http_version 1.1; | ||
| 189 | + proxy_set_header Host $host; | ||
| 190 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 191 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 192 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 193 | + proxy_set_header Upgrade $http_upgrade; | ||
| 194 | + proxy_set_header Connection $connection_upgrade; | ||
| 195 | + proxy_read_timeout 300s; | ||
| 196 | + proxy_send_timeout 300s; | ||
| 197 | + }} | ||
| 198 | +}} | ||
| 199 | +""".format(domain=domain, ssl_cert=ssl_cert, ssl_key=ssl_key, ssl_include=ssl_include, | ||
| 200 | + rewrite=rewrite_path, port=port) | ||
| 201 | + http_extra = """ client_max_body_size 50m; | ||
| 202 | + location / { | ||
| 203 | + proxy_pass http://127.0.0.1:%s; | ||
| 204 | + proxy_http_version 1.1; | ||
| 205 | + proxy_set_header Host $host; | ||
| 206 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 207 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 208 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 209 | + proxy_set_header Upgrade $http_upgrade; | ||
| 210 | + proxy_set_header Connection $connection_upgrade; | ||
| 211 | + proxy_read_timeout 300s; | ||
| 212 | + proxy_send_timeout 300s; | ||
| 213 | + } | ||
| 214 | +""" % port | ||
| 215 | + else: | ||
| 216 | + ssl_server = "" | ||
| 217 | + http_extra = """ location / { | ||
| 218 | + proxy_pass http://127.0.0.1:%s; | ||
| 219 | + proxy_http_version 1.1; | ||
| 220 | + proxy_set_header Host $host; | ||
| 221 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 222 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 223 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 224 | + proxy_read_timeout 300s; | ||
| 225 | + proxy_send_timeout 300s; | ||
| 226 | + } | ||
| 227 | +""" % port | ||
| 228 | + | ||
| 229 | + body = """server {{ | ||
| 230 | + listen 80; | ||
| 231 | + listen [::]:80; | ||
| 232 | + server_name {domain}; | ||
| 233 | + location /.well-known/acme-challenge/ {{ | ||
| 234 | + root /www/wwwroot/letsencrypt; | ||
| 235 | + allow all; | ||
| 236 | + }} | ||
| 237 | +{http_extra}}} | ||
| 238 | +{ssl_server} | ||
| 239 | +""".format(domain=domain, http_extra=http_extra, ssl_server=ssl_server) | ||
| 240 | + | ||
| 241 | + with open(conf_path, "w", encoding="utf-8") as fh: | ||
| 242 | + fh.write(body) | ||
| 243 | + if not os.path.isfile(rewrite_path): | ||
| 244 | + with open(rewrite_path, "w", encoding="utf-8") as fh: | ||
| 245 | + fh.write("# 请将伪静态规则或自定义NGINX配置填写到此处\n") | ||
| 246 | + old = os.path.join(VHOST_NGINX, "%s.conf" % domain) | ||
| 247 | + if os.path.isfile(old) and os.path.abspath(old) != os.path.abspath(conf_path): | ||
| 248 | + os.rename(old, old + ".bak") | ||
| 249 | + print("MOVED %s -> .bak" % old) | ||
| 250 | + print("NGINX %s" % conf_path) | ||
| 251 | + | ||
| 252 | + | ||
| 253 | +def reload_nginx(): | ||
| 254 | + nginx = "/www/server/nginx/sbin/nginx" | ||
| 255 | + conf = "/www/server/nginx/conf/nginx.conf" | ||
| 256 | + if not os.path.isfile(nginx): | ||
| 257 | + return | ||
| 258 | + test = subprocess.run([nginx, "-t", "-c", conf], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
| 259 | + out = test.stdout.decode("utf-8", "ignore") | ||
| 260 | + print(out) | ||
| 261 | + if test.returncode != 0: | ||
| 262 | + print("NGINX_TEST_FAIL skip reload") | ||
| 263 | + return | ||
| 264 | + subprocess.run([nginx, "-s", "reload"], check=False) | ||
| 265 | + print("NGINX_RELOADED") | ||
| 266 | + | ||
| 267 | + | ||
| 268 | +def main(): | ||
| 269 | + cfg = parse_args(sys.argv[1:]) | ||
| 270 | + ensure_start_script(cfg) | ||
| 271 | + db = find_db() | ||
| 272 | + conn = sqlite3.connect(db) | ||
| 273 | + try: | ||
| 274 | + site_id = insert_site(conn, cfg) | ||
| 275 | + insert_domain(conn, site_id, cfg) | ||
| 276 | + finally: | ||
| 277 | + conn.close() | ||
| 278 | + write_nginx_conf(cfg) | ||
| 279 | + reload_nginx() | ||
| 280 | + print("BT_REGISTER_OK %s %s domain=%s" % (cfg["name"], cfg["path"], cfg.get("domain") or "")) | ||
| 281 | + | ||
| 282 | + | ||
| 283 | +if __name__ == "__main__": | ||
| 284 | + main() |
美国版/scripts/fix-cors-on-server.sh
0 → 100644
| 1 | +#!/bin/bash | ||
| 2 | +# 在宝塔「终端」粘贴执行:补 CORS + HTTP 反代(不要 301 OPTIONS) | ||
| 3 | +set -e | ||
| 4 | +python3 - <<'PY' | ||
| 5 | +import re, pathlib | ||
| 6 | + | ||
| 7 | +cors_test = ( | ||
| 8 | + "http://0.0.0.0:19003;http://localhost:19003;" | ||
| 9 | + "https://flusapi-ustest.3flabeling.com;http://flusapi-ustest.3flabeling.com;" | ||
| 10 | + "http://flus-test.3flabeling.com;https://flus-test.3flabeling.com;" | ||
| 11 | + "http://flus-test.3ffoodsafety.com;https://flus-test.3ffoodsafety.com;" | ||
| 12 | + "http://localhost:18000;http://localhost:5666;http://localhost:5174;http://localhost:5173;http://localhost:3000" | ||
| 13 | +) | ||
| 14 | +cors_prod = ( | ||
| 15 | + "http://0.0.0.0:19001;http://localhost:19001;" | ||
| 16 | + "https://flusapi-us.3flabeling.com;http://flusapi-us.3flabeling.com;" | ||
| 17 | + "http://flus.3flabeling.com;https://flus.3flabeling.com;" | ||
| 18 | + "http://flus.3ffoodsafety.com;https://flus.3ffoodsafety.com;" | ||
| 19 | + "http://localhost:18000;http://localhost:5666;http://localhost:5174;http://localhost:5173;http://localhost:3000" | ||
| 20 | +) | ||
| 21 | +pairs = { | ||
| 22 | + "/www/wwwroot/FoodLabelingManagementUsTest/appsettings.json": cors_test, | ||
| 23 | + "/www/wwwroot/FoodLabelingManagementUs/appsettings.json": cors_prod, | ||
| 24 | +} | ||
| 25 | +for path, cors in pairs.items(): | ||
| 26 | + p = pathlib.Path(path) | ||
| 27 | + if not p.is_file(): | ||
| 28 | + print("skip missing", path) | ||
| 29 | + continue | ||
| 30 | + text = p.read_text(encoding="utf-8") | ||
| 31 | + text2, n = re.subn(r'"CorsOrigins"\s*:\s*"[^"]*"', '"CorsOrigins": "' + cors + '"', text, count=1) | ||
| 32 | + p.write_text(text2, encoding="utf-8") | ||
| 33 | + print("cors", path, n) | ||
| 34 | + | ||
| 35 | +proxy = r''' location / { | ||
| 36 | + proxy_pass http://127.0.0.1:PORTNUM; | ||
| 37 | + proxy_http_version 1.1; | ||
| 38 | + proxy_set_header Host $host; | ||
| 39 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 40 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 41 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 42 | + proxy_set_header Upgrade $http_upgrade; | ||
| 43 | + proxy_set_header Connection $connection_upgrade; | ||
| 44 | + proxy_read_timeout 300s; | ||
| 45 | + proxy_send_timeout 300s; | ||
| 46 | + } | ||
| 47 | +''' | ||
| 48 | +import glob | ||
| 49 | +for conf in glob.glob("/www/server/panel/vhost/nginx/*.conf"): | ||
| 50 | + t = pathlib.Path(conf).read_text(encoding="utf-8", errors="ignore") | ||
| 51 | + if "flusapi-ustest.3flabeling.com" in t: | ||
| 52 | + t2 = t.replace("return 301 https://$host$request_uri;", proxy.replace("PORTNUM", "19003")) | ||
| 53 | + pathlib.Path(conf).write_text(t2, encoding="utf-8") | ||
| 54 | + print("nginx http proxy", conf) | ||
| 55 | + elif "flusapi-us.3flabeling.com" in t: | ||
| 56 | + t2 = t.replace("return 301 https://$host$request_uri;", proxy.replace("PORTNUM", "19001")) | ||
| 57 | + pathlib.Path(conf).write_text(t2, encoding="utf-8") | ||
| 58 | + print("nginx http proxy", conf) | ||
| 59 | +PY | ||
| 60 | +/www/server/nginx/sbin/nginx -t -c /www/server/nginx/conf/nginx.conf | ||
| 61 | +/www/server/nginx/sbin/nginx -s reload | ||
| 62 | +pkill -f /www/wwwroot/FoodLabelingManagementUsTest/Yi.Abp.Web.dll || true | ||
| 63 | +pkill -f /www/wwwroot/FoodLabelingManagementUs/Yi.Abp.Web.dll || true | ||
| 64 | +sleep 1 | ||
| 65 | +mkdir -p /www/wwwlogs/net /var/tmp/net_project | ||
| 66 | +nohup /www/server/dotnet/8.0.100/dotnet /www/wwwroot/FoodLabelingManagementUsTest/Yi.Abp.Web.dll --urls=http://0.0.0.0:19003 >> /www/wwwlogs/net/食品标签美国测试版.log 2>&1 & | ||
| 67 | +echo $! > /var/tmp/net_project/食品标签美国测试版.pid | ||
| 68 | +nohup /www/server/dotnet/8.0.100/dotnet /www/wwwroot/FoodLabelingManagementUs/Yi.Abp.Web.dll --urls=http://0.0.0.0:19001 >> /www/wwwlogs/net/食品标签美国正式版.log 2>&1 & | ||
| 69 | +echo $! > /var/tmp/net_project/食品标签美国正式版.pid | ||
| 70 | +sleep 4 | ||
| 71 | +echo DONE |
美国版/scripts/nginx.flusapi-tetest.3flabeling.com.conf
0 → 100644
| 1 | +# 食品标签泰鄂测试版 API 反代(宝塔 nginx vhost) | ||
| 2 | +# HTTP 也反代,避免前端走 http:// API 时 OPTIONS 预检被 301 导致 CORS 失败。 | ||
| 3 | +server { | ||
| 4 | + listen 80; | ||
| 5 | + listen [::]:80; | ||
| 6 | + server_name flusapi-tetest.3flabeling.com; | ||
| 7 | + location /.well-known/acme-challenge/ { | ||
| 8 | + root /www/wwwroot/letsencrypt; | ||
| 9 | + allow all; | ||
| 10 | + } | ||
| 11 | + client_max_body_size 50m; | ||
| 12 | + location / { | ||
| 13 | + proxy_pass http://127.0.0.1:19002; | ||
| 14 | + proxy_http_version 1.1; | ||
| 15 | + proxy_set_header Host $host; | ||
| 16 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 17 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 18 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 19 | + proxy_set_header Upgrade $http_upgrade; | ||
| 20 | + proxy_set_header Connection $connection_upgrade; | ||
| 21 | + proxy_read_timeout 300s; | ||
| 22 | + proxy_send_timeout 300s; | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +server { | ||
| 27 | + listen 443 ssl; | ||
| 28 | + listen [::]:443 ssl; | ||
| 29 | + server_name flusapi-tetest.3flabeling.com; | ||
| 30 | + ssl_certificate /etc/letsencrypt/live/flusapi-tetest.3flabeling.com/fullchain.pem; | ||
| 31 | + ssl_certificate_key /etc/letsencrypt/live/flusapi-tetest.3flabeling.com/privkey.pem; | ||
| 32 | + include /etc/letsencrypt/options-ssl-nginx.conf; | ||
| 33 | + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; | ||
| 34 | + access_log /www/wwwlogs/flusapi-tetest.3flabeling.com.access.log; | ||
| 35 | + error_log /www/wwwlogs/flusapi-tetest.3flabeling.com.error.log; | ||
| 36 | + client_max_body_size 50m; | ||
| 37 | + location / { | ||
| 38 | + proxy_pass http://127.0.0.1:19002; | ||
| 39 | + proxy_http_version 1.1; | ||
| 40 | + proxy_set_header Host $host; | ||
| 41 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 42 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 43 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 44 | + proxy_set_header Upgrade $http_upgrade; | ||
| 45 | + proxy_set_header Connection $connection_upgrade; | ||
| 46 | + proxy_read_timeout 300s; | ||
| 47 | + proxy_send_timeout 300s; | ||
| 48 | + } | ||
| 49 | +} |
美国版/scripts/nginx.flusapi-teustest.3flabeling.com.conf
0 → 100644
| 1 | +# 食品标签泰鄂美国测试版 API 反代(宝塔 nginx vhost) | ||
| 2 | +# HTTP 也反代,避免前端走 http:// API 时 OPTIONS 预检被 301 导致 CORS 失败。 | ||
| 3 | +server { | ||
| 4 | + listen 80; | ||
| 5 | + listen [::]:80; | ||
| 6 | + server_name flusapi-teustest.3flabeling.com; | ||
| 7 | + location /.well-known/acme-challenge/ { | ||
| 8 | + root /www/wwwroot/letsencrypt; | ||
| 9 | + allow all; | ||
| 10 | + } | ||
| 11 | + client_max_body_size 50m; | ||
| 12 | + location / { | ||
| 13 | + proxy_pass http://127.0.0.1:19004; | ||
| 14 | + proxy_http_version 1.1; | ||
| 15 | + proxy_set_header Host $host; | ||
| 16 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 17 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 18 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 19 | + proxy_set_header Upgrade $http_upgrade; | ||
| 20 | + proxy_set_header Connection $connection_upgrade; | ||
| 21 | + proxy_read_timeout 300s; | ||
| 22 | + proxy_send_timeout 300s; | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +server { | ||
| 27 | + listen 443 ssl; | ||
| 28 | + listen [::]:443 ssl; | ||
| 29 | + server_name flusapi-teustest.3flabeling.com; | ||
| 30 | + ssl_certificate /etc/letsencrypt/live/flusapi-teustest.3flabeling.com/fullchain.pem; | ||
| 31 | + ssl_certificate_key /etc/letsencrypt/live/flusapi-teustest.3flabeling.com/privkey.pem; | ||
| 32 | + include /etc/letsencrypt/options-ssl-nginx.conf; | ||
| 33 | + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; | ||
| 34 | + access_log /www/wwwlogs/flusapi-teustest.access.log; | ||
| 35 | + error_log /www/wwwlogs/flusapi-teustest.error.log; | ||
| 36 | + client_max_body_size 50m; | ||
| 37 | + location / { | ||
| 38 | + proxy_pass http://127.0.0.1:19004; | ||
| 39 | + proxy_http_version 1.1; | ||
| 40 | + proxy_set_header Host $host; | ||
| 41 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 42 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 43 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 44 | + proxy_set_header Upgrade $http_upgrade; | ||
| 45 | + proxy_set_header Connection $connection_upgrade; | ||
| 46 | + proxy_read_timeout 300s; | ||
| 47 | + proxy_send_timeout 300s; | ||
| 48 | + } | ||
| 49 | +} |
美国版/scripts/nginx.flusapi-us.3flabeling.com.conf
0 → 100644
| 1 | +# 美国版正式环境 API 反代(宝塔 nginx vhost) | ||
| 2 | +# HTTP 也反代,避免前端走 http:// API 时 OPTIONS 预检被 301 导致 CORS 失败。 | ||
| 3 | +server { | ||
| 4 | + listen 80; | ||
| 5 | + listen [::]:80; | ||
| 6 | + server_name flusapi-us.3flabeling.com; | ||
| 7 | + location /.well-known/acme-challenge/ { | ||
| 8 | + root /www/wwwroot/letsencrypt; | ||
| 9 | + allow all; | ||
| 10 | + } | ||
| 11 | + client_max_body_size 50m; | ||
| 12 | + location / { | ||
| 13 | + proxy_pass http://127.0.0.1:19001; | ||
| 14 | + proxy_http_version 1.1; | ||
| 15 | + proxy_set_header Host $host; | ||
| 16 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 17 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 18 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 19 | + proxy_set_header Upgrade $http_upgrade; | ||
| 20 | + proxy_set_header Connection $connection_upgrade; | ||
| 21 | + proxy_read_timeout 300s; | ||
| 22 | + proxy_send_timeout 300s; | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +server { | ||
| 27 | + listen 443 ssl; | ||
| 28 | + listen [::]:443 ssl; | ||
| 29 | + server_name flusapi-us.3flabeling.com; | ||
| 30 | + ssl_certificate /etc/letsencrypt/live/flusapi-us.3flabeling.com/fullchain.pem; | ||
| 31 | + ssl_certificate_key /etc/letsencrypt/live/flusapi-us.3flabeling.com/privkey.pem; | ||
| 32 | + include /etc/letsencrypt/options-ssl-nginx.conf; | ||
| 33 | + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; | ||
| 34 | + access_log /www/wwwlogs/flusapi-us.access.log; | ||
| 35 | + error_log /www/wwwlogs/flusapi-us.error.log; | ||
| 36 | + client_max_body_size 50m; | ||
| 37 | + location / { | ||
| 38 | + proxy_pass http://127.0.0.1:19001; | ||
| 39 | + proxy_http_version 1.1; | ||
| 40 | + proxy_set_header Host $host; | ||
| 41 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 42 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 43 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 44 | + proxy_set_header Upgrade $http_upgrade; | ||
| 45 | + proxy_set_header Connection $connection_upgrade; | ||
| 46 | + proxy_read_timeout 300s; | ||
| 47 | + proxy_send_timeout 300s; | ||
| 48 | + } | ||
| 49 | +} |
美国版/scripts/nginx.flusapi-ustest.3flabeling.com.conf
0 → 100644
| 1 | +# 美国版测试环境 API 反代(宝塔 nginx vhost) | ||
| 2 | +# HTTP 也反代,避免前端走 http:// API 时 OPTIONS 预检被 301 导致 CORS 失败。 | ||
| 3 | +server { | ||
| 4 | + listen 80; | ||
| 5 | + listen [::]:80; | ||
| 6 | + server_name flusapi-ustest.3flabeling.com; | ||
| 7 | + location /.well-known/acme-challenge/ { | ||
| 8 | + root /www/wwwroot/letsencrypt; | ||
| 9 | + allow all; | ||
| 10 | + } | ||
| 11 | + client_max_body_size 50m; | ||
| 12 | + location / { | ||
| 13 | + proxy_pass http://127.0.0.1:19003; | ||
| 14 | + proxy_http_version 1.1; | ||
| 15 | + proxy_set_header Host $host; | ||
| 16 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 17 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 18 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 19 | + proxy_set_header Upgrade $http_upgrade; | ||
| 20 | + proxy_set_header Connection $connection_upgrade; | ||
| 21 | + proxy_read_timeout 300s; | ||
| 22 | + proxy_send_timeout 300s; | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +server { | ||
| 27 | + listen 443 ssl; | ||
| 28 | + listen [::]:443 ssl; | ||
| 29 | + server_name flusapi-ustest.3flabeling.com; | ||
| 30 | + ssl_certificate /etc/letsencrypt/live/flusapi-ustest.3flabeling.com/fullchain.pem; | ||
| 31 | + ssl_certificate_key /etc/letsencrypt/live/flusapi-ustest.3flabeling.com/privkey.pem; | ||
| 32 | + include /etc/letsencrypt/options-ssl-nginx.conf; | ||
| 33 | + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; | ||
| 34 | + access_log /www/wwwlogs/flusapi-ustest.access.log; | ||
| 35 | + error_log /www/wwwlogs/flusapi-ustest.error.log; | ||
| 36 | + client_max_body_size 50m; | ||
| 37 | + location / { | ||
| 38 | + proxy_pass http://127.0.0.1:19003; | ||
| 39 | + proxy_http_version 1.1; | ||
| 40 | + proxy_set_header Host $host; | ||
| 41 | + proxy_set_header X-Real-IP $remote_addr; | ||
| 42 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| 43 | + proxy_set_header X-Forwarded-Proto $scheme; | ||
| 44 | + proxy_set_header Upgrade $http_upgrade; | ||
| 45 | + proxy_set_header Connection $connection_upgrade; | ||
| 46 | + proxy_read_timeout 300s; | ||
| 47 | + proxy_send_timeout 300s; | ||
| 48 | + } | ||
| 49 | +} |
美国版/scripts/泰鄂测试版部署.cmd
0 → 100644
美国版/scripts/泰鄂测试版部署.ps1
0 → 100644
| 1 | +#Requires -Version 5.1 | ||
| 2 | +<# | ||
| 3 | +.SYNOPSIS | ||
| 4 | + 食品标签泰鄂测试版 API 一键部署 | ||
| 5 | +.DESCRIPTION | ||
| 6 | + 发布泰鄂版 Yi.Abp.Web,上传到 47.253.11.59,重启 Kestrel 19002,健康检查 https://flusapi-tetest.3flabeling.com | ||
| 7 | +#> | ||
| 8 | +param( | ||
| 9 | + [switch]$SkipBuild | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +$ErrorActionPreference = "Stop" | ||
| 13 | +$HostName = "47.253.11.59" | ||
| 14 | +$UserName = "root" | ||
| 15 | +$RemoteDir = "/www/wwwroot/FoodLabelingManagementTeTest" | ||
| 16 | +$Dotnet = "/www/server/dotnet/8.0.100/dotnet" | ||
| 17 | +$AppDll = "$RemoteDir/Yi.Abp.Web.dll" | ||
| 18 | +$HealthUrl = "https://flusapi-tetest.3flabeling.com/swagger/index.html" | ||
| 19 | +$ListenUrl = "http://0.0.0.0:19002" | ||
| 20 | +$Cors = "http://0.0.0.0:19002;http://localhost:19002;http://127.0.0.1:19002;https://flusapi-tetest.3flabeling.com;http://flusapi-tetest.3flabeling.com;http://flus-tetest.3flabeling.com;https://flus-tetest.3flabeling.com;http://localhost:18000;http://localhost:5666;http://localhost:5174;http://localhost:5173;http://localhost:3000" | ||
| 21 | +$DbHost = "rm-0xi95hpp522z6c62w.mysql.rds-aliyun-america.rds.aliyuncs.com" | ||
| 22 | +$ChinaDbHost = "rm-bp19ohrgc6111ynzh1o.mysql.rds.aliyuncs.com" | ||
| 23 | +$DbUser = "root" | ||
| 24 | +$DbPassword = 'Te2026@antis!' | ||
| 25 | +$TestDbName = "antis-foodlabeling-test-host" | ||
| 26 | +$BtName = "食品标签泰鄂测试版" | ||
| 27 | +$BtDomain = "flusapi-tetest.3flabeling.com" | ||
| 28 | +$BtCmd = "{0} {1} --urls={2}" -f $Dotnet, $AppDll, $ListenUrl | ||
| 29 | + | ||
| 30 | +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
| 31 | +$RepoRoot = Resolve-Path (Join-Path $ScriptDir "..\..") | ||
| 32 | +$WebCsproj = Join-Path $RepoRoot "泰额版\Food Labeling Management Code\Yi.Abp.Net8\src\Yi.Abp.Web\Yi.Abp.Web.csproj" | ||
| 33 | +$PublishDir = Join-Path $RepoRoot "泰额版\Food Labeling Management Code\Yi.Abp.Net8\_publish-tetest" | ||
| 34 | +. (Join-Path $ScriptDir "_deploy-us-ssh.ps1") | ||
| 35 | +Initialize-DeploySsh | ||
| 36 | +$SshOpts = $global:SshOpts | ||
| 37 | + | ||
| 38 | +Write-Host "== 食品标签泰鄂测试版部署 ==" -ForegroundColor Cyan | ||
| 39 | +Write-Host "目标: $HostName $RemoteDir" | ||
| 40 | +Write-Host "域名: $HealthUrl" | ||
| 41 | +Write-Host "数据库: $TestDbName @ $DbHost" | ||
| 42 | + | ||
| 43 | +if (-not $SkipBuild) { | ||
| 44 | + if (-not (Test-Path $WebCsproj)) { throw "找不到工程: $WebCsproj" } | ||
| 45 | + Write-Host "== 发布泰鄂版 Yi.Abp.Web ==" -ForegroundColor Cyan | ||
| 46 | + if (Test-Path $PublishDir) { Remove-Item $PublishDir -Recurse -Force } | ||
| 47 | + & dotnet publish $WebCsproj -c Release -o $PublishDir --nologo | ||
| 48 | + if ($LASTEXITCODE -ne 0) { throw "dotnet publish 失败" } | ||
| 49 | + | ||
| 50 | + $appsettings = Join-Path $PublishDir "appsettings.json" | ||
| 51 | + if (Test-Path $appsettings) { | ||
| 52 | + $json = Get-Content $appsettings -Raw -Encoding UTF8 | ||
| 53 | + $json = [regex]::Replace($json, '"SelfUrl"\s*:\s*"[^"]*"', '"SelfUrl": "' + $ListenUrl + '"') | ||
| 54 | + $json = [regex]::Replace($json, '"CorsOrigins"\s*:\s*"[^"]*"', '"CorsOrigins": "' + $Cors + '"') | ||
| 55 | + $json = $json.Replace($ChinaDbHost, $DbHost) | ||
| 56 | + $json = [regex]::Replace($json, 'server=[^;]+', "server=$DbHost") | ||
| 57 | + $json = [regex]::Replace($json, '"Server"\s*:\s*"rm-[^"]*"', '"Server": "' + $DbHost + '"') | ||
| 58 | + $json = [regex]::Replace($json, 'database=antis-foodlabeling-[^;]+', "database=$TestDbName") | ||
| 59 | + $json = [regex]::Replace($json, '"DatabaseName"\s*:\s*"antis-foodlabeling-host"', '"DatabaseName": "' + $TestDbName + '"') | ||
| 60 | + $json = [regex]::Replace($json, 'uid=netteam', "uid=$DbUser") | ||
| 61 | + $json = [regex]::Replace($json, 'pwd=netteam', "pwd=$DbPassword") | ||
| 62 | + $json = [regex]::Replace($json, 'uid=javateam', "uid=$DbUser") | ||
| 63 | + $json = [regex]::Replace($json, 'pwd=javateam2026', "pwd=$DbPassword") | ||
| 64 | + $json = [regex]::Replace($json, '"UserId"\s*:\s*"netteam"', '"UserId": "' + $DbUser + '"') | ||
| 65 | + $json = [regex]::Replace($json, '"Password"\s*:\s*"netteam"', '"Password": "' + $DbPassword + '"') | ||
| 66 | + $json = [regex]::Replace($json, '"TemplateDirectory"\s*:\s*"[^"]*"', '"TemplateDirectory": "' + $RemoteDir + '/batchImportOfFiles"') | ||
| 67 | + Set-Content -Path $appsettings -Value $json -Encoding UTF8 | ||
| 68 | + } | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +if (-not (Test-Path (Join-Path $PublishDir "Yi.Abp.Web.dll"))) { | ||
| 72 | + throw "发布目录缺少 Yi.Abp.Web.dll: $PublishDir" | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +Write-Host "== 停止远程进程 ==" -ForegroundColor Cyan | ||
| 76 | +Invoke-Remote @' | ||
| 77 | +set -e | ||
| 78 | +if [ -f "/var/tmp/net_project/食品标签泰鄂测试版.pid" ]; then | ||
| 79 | + pid=$(cat "/var/tmp/net_project/食品标签泰鄂测试版.pid" || true) | ||
| 80 | + if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi | ||
| 81 | +fi | ||
| 82 | +pkill -f "/www/wwwroot/FoodLabelingManagementTeTest/Yi.Abp.Web.dll" 2>/dev/null || true | ||
| 83 | +sleep 1 | ||
| 84 | +echo stopped | ||
| 85 | +'@ | ||
| 86 | + | ||
| 87 | +Write-Host "== 上传发布包 ==" -ForegroundColor Cyan | ||
| 88 | +$tar = Join-Path $env:TEMP "flus-tetest-publish.tgz" | ||
| 89 | +if (Test-Path $tar) { Remove-Item $tar -Force } | ||
| 90 | +Push-Location $PublishDir | ||
| 91 | +try { | ||
| 92 | + & tar -czf $tar --exclude=logs --exclude=startup.log * | ||
| 93 | + if ($LASTEXITCODE -ne 0) { throw "打包失败" } | ||
| 94 | +} finally { | ||
| 95 | + Pop-Location | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +& scp @SshOpts $tar "${UserName}@${HostName}:/tmp/flus-tetest-publish.tgz" | ||
| 99 | +if ($LASTEXITCODE -ne 0) { throw "scp 失败" } | ||
| 100 | + | ||
| 101 | +Invoke-Remote @" | ||
| 102 | +set -e | ||
| 103 | +mkdir -p '$RemoteDir' | ||
| 104 | +cd '$RemoteDir' | ||
| 105 | +for x in *; do | ||
| 106 | + case "`$x" in | ||
| 107 | + logs|*.log) ;; | ||
| 108 | + *) rm -rf "`$x" ;; | ||
| 109 | + esac | ||
| 110 | +done | ||
| 111 | +tar --overwrite -xzf /tmp/flus-tetest-publish.tgz -C '$RemoteDir' | ||
| 112 | +rm -f /tmp/flus-tetest-publish.tgz | ||
| 113 | +chmod -R a+rX '$RemoteDir' | ||
| 114 | +ls -l '$RemoteDir/Yi.Abp.Web.dll' | ||
| 115 | +echo uploaded_to=$RemoteDir | ||
| 116 | +"@ | ||
| 117 | + | ||
| 118 | +Write-Host "== 登记宝塔 Net 项目 ==" -ForegroundColor Cyan | ||
| 119 | +$btPyLocal = Join-Path $ScriptDir "bt-register-net-project.py" | ||
| 120 | +& scp @SshOpts $btPyLocal "${UserName}@${HostName}:/tmp/bt-register-net-project.py" | ||
| 121 | +if ($LASTEXITCODE -ne 0) { throw "上传宝塔登记脚本失败" } | ||
| 122 | +Invoke-Remote @" | ||
| 123 | +set -e | ||
| 124 | +sed -i 's/\r`$//' /tmp/bt-register-net-project.py | ||
| 125 | +python3 /tmp/bt-register-net-project.py name='$BtName' path='$RemoteDir' port='19002' ps='$BtName' domain='$BtDomain' cmd='$BtCmd' run_user='root' dotnet_version='8.0.100' | ||
| 126 | +"@ | ||
| 127 | + | ||
| 128 | +Write-Host "== 启动 API ==" -ForegroundColor Cyan | ||
| 129 | +Invoke-Remote -AllowFail @" | ||
| 130 | +mkdir -p /www/wwwlogs/net /var/tmp/net_project | ||
| 131 | +if [ ! -f /swapfile ]; then | ||
| 132 | + fallocate -l 2G /swapfile || dd if=/dev/zero of=/swapfile bs=1M count=2048 | ||
| 133 | + chmod 600 /swapfile | ||
| 134 | + mkswap /swapfile | ||
| 135 | + swapon /swapfile | ||
| 136 | + grep -q '^/swapfile ' /etc/fstab || echo '/swapfile none swap sw 0 0' >> /etc/fstab | ||
| 137 | +fi | ||
| 138 | +swapon -a || true | ||
| 139 | +cd '$RemoteDir' | ||
| 140 | +setsid nohup $Dotnet '$AppDll' --urls=$ListenUrl >> /www/wwwlogs/net/食品标签泰鄂测试版.log 2>&1 < /dev/null & | ||
| 141 | +echo `$! > /var/tmp/net_project/食品标签泰鄂测试版.pid | ||
| 142 | +sleep 15 | ||
| 143 | +ss -lntp | grep 19002 || true | ||
| 144 | +curl -s -o /dev/null -w 'local=%{http_code}\n' --max-time 15 http://127.0.0.1:19002/swagger/index.html || true | ||
| 145 | +tail -n 30 /www/wwwlogs/net/食品标签泰鄂测试版.log || true | ||
| 146 | +"@ | ||
| 147 | + | ||
| 148 | +Write-Host "== 健康检查 ==" -ForegroundColor Cyan | ||
| 149 | +$ok = $false | ||
| 150 | +for ($i = 1; $i -le 10; $i++) { | ||
| 151 | + try { | ||
| 152 | + $resp = Invoke-WebRequest -Uri $HealthUrl -UseBasicParsing -TimeoutSec 15 | ||
| 153 | + if ($resp.StatusCode -eq 200) { | ||
| 154 | + Write-Host "访问成功: $HealthUrl HTTP $($resp.StatusCode)" -ForegroundColor Green | ||
| 155 | + $ok = $true | ||
| 156 | + break | ||
| 157 | + } | ||
| 158 | + } catch { | ||
| 159 | + Write-Host "等待服务就绪 ($i/10)..." | ||
| 160 | + Start-Sleep -Seconds 3 | ||
| 161 | + } | ||
| 162 | +} | ||
| 163 | + | ||
| 164 | +if (-not $ok) { throw "部署后健康检查失败: $HealthUrl" } | ||
| 165 | +Write-Host "完成。API: https://flusapi-tetest.3flabeling.com" -ForegroundColor Green | ||
| 166 | +Write-Host "Swagger: $HealthUrl" | ||
| 167 | +Write-Host "登录: POST https://flusapi-tetest.3flabeling.com/api/app/th-web-auth/login" |
美国版/scripts/泰鄂美国测试版部署.cmd
0 → 100644
美国版/scripts/泰鄂美国测试版部署.ps1
0 → 100644
| 1 | +#Requires -Version 5.1 | ||
| 2 | +<# | ||
| 3 | +.SYNOPSIS | ||
| 4 | + 泰鄂美国测试版 API 一键部署 | ||
| 5 | +.DESCRIPTION | ||
| 6 | + 发布 Yi.Abp.Web,上传到 47.253.11.59,重启 Kestrel 19004,健康检查 https://flusapi-teustest.3flabeling.com | ||
| 7 | +#> | ||
| 8 | +param( | ||
| 9 | + [switch]$SkipBuild | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +$ErrorActionPreference = "Stop" | ||
| 13 | +$HostName = "47.253.11.59" | ||
| 14 | +$UserName = "root" | ||
| 15 | +$RemoteDir = "/www/wwwroot/FoodLabelingManagementTeUsTest" | ||
| 16 | +$Dotnet = "/www/server/dotnet/8.0.100/dotnet" | ||
| 17 | +$AppDll = "$RemoteDir/Yi.Abp.Web.dll" | ||
| 18 | +$HealthUrl = "https://flusapi-teustest.3flabeling.com/swagger/index.html" | ||
| 19 | +$ListenUrl = "http://0.0.0.0:19004" | ||
| 20 | +$Cors = "http://0.0.0.0:19004;http://localhost:19004;https://flusapi-teustest.3flabeling.com;http://flusapi-teustest.3flabeling.com;http://flus-teustest.3flabeling.com;https://flus-teustest.3flabeling.com;http://localhost:18000;http://localhost:5666;http://localhost:5174;http://localhost:5173;http://localhost:3000" | ||
| 21 | +$DbHost = "rm-0xi95hpp522z6c62w.mysql.rds-aliyun-america.rds.aliyuncs.com" | ||
| 22 | +$DbUser = "root" | ||
| 23 | +$DbPassword = 'Te2026@antis!' | ||
| 24 | +$TestDbName = "antis-foodlabeling-teus" | ||
| 25 | +$BtName = "食品标签泰鄂美国测试版" | ||
| 26 | +$BtDomain = "flusapi-teustest.3flabeling.com" | ||
| 27 | +$BtCmd = "{0} {1} --urls={2}" -f $Dotnet, $AppDll, $ListenUrl | ||
| 28 | + | ||
| 29 | +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
| 30 | +$RepoRoot = Resolve-Path (Join-Path $ScriptDir "..\..") | ||
| 31 | +$WebCsproj = Join-Path $RepoRoot "美国版\Food Labeling Management Code\Yi.Abp.Net8\src\Yi.Abp.Web\Yi.Abp.Web.csproj" | ||
| 32 | +$PublishDir = Join-Path $RepoRoot "美国版\Food Labeling Management Code\Yi.Abp.Net8\_publish-teustest" | ||
| 33 | +. (Join-Path $ScriptDir "_deploy-us-ssh.ps1") | ||
| 34 | +Initialize-DeploySsh | ||
| 35 | +$SshOpts = $global:SshOpts | ||
| 36 | + | ||
| 37 | +Write-Host "== 泰鄂美国测试版部署 ==" -ForegroundColor Cyan | ||
| 38 | +Write-Host "目标: $HostName $RemoteDir" | ||
| 39 | +Write-Host "域名: $HealthUrl" | ||
| 40 | +Write-Host "数据库: $TestDbName @ $DbHost" | ||
| 41 | + | ||
| 42 | +if (-not $SkipBuild) { | ||
| 43 | + if (-not (Test-Path $WebCsproj)) { throw "找不到工程: $WebCsproj" } | ||
| 44 | + Write-Host "== 发布 Yi.Abp.Web ==" -ForegroundColor Cyan | ||
| 45 | + if (Test-Path $PublishDir) { Remove-Item $PublishDir -Recurse -Force } | ||
| 46 | + & dotnet publish $WebCsproj -c Release -o $PublishDir --nologo | ||
| 47 | + if ($LASTEXITCODE -ne 0) { throw "dotnet publish 失败" } | ||
| 48 | + | ||
| 49 | + $appsettings = Join-Path $PublishDir "appsettings.json" | ||
| 50 | + if (Test-Path $appsettings) { | ||
| 51 | + $json = Get-Content $appsettings -Raw -Encoding UTF8 | ||
| 52 | + $json = [regex]::Replace($json, '"SelfUrl"\s*:\s*"[^"]*"', '"SelfUrl": "' + $ListenUrl + '"') | ||
| 53 | + $json = [regex]::Replace($json, '"CorsOrigins"\s*:\s*"[^"]*"', '"CorsOrigins": "' + $Cors + '"') | ||
| 54 | + $json = [regex]::Replace($json, 'server=[^;]+', "server=$DbHost") | ||
| 55 | + $json = [regex]::Replace($json, 'uid=[^;]+', "uid=$DbUser") | ||
| 56 | + $json = [regex]::Replace($json, 'pwd=[^;]+', "pwd=$DbPassword") | ||
| 57 | + $json = [regex]::Replace($json, 'database=antis-foodlabeling-[^;]+', "database=$TestDbName") | ||
| 58 | + Set-Content -Path $appsettings -Value $json -Encoding UTF8 | ||
| 59 | + } | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +if (-not (Test-Path (Join-Path $PublishDir "Yi.Abp.Web.dll"))) { | ||
| 63 | + throw "发布目录缺少 Yi.Abp.Web.dll: $PublishDir" | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +Write-Host "== 停止远程进程 ==" -ForegroundColor Cyan | ||
| 67 | +Invoke-Remote @' | ||
| 68 | +set -e | ||
| 69 | +if [ -f "/var/tmp/net_project/食品标签泰鄂美国测试版.pid" ]; then | ||
| 70 | + pid=$(cat "/var/tmp/net_project/食品标签泰鄂美国测试版.pid" || true) | ||
| 71 | + if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi | ||
| 72 | +fi | ||
| 73 | +pkill -f "/www/wwwroot/FoodLabelingManagementTeUsTest/Yi.Abp.Web.dll" 2>/dev/null || true | ||
| 74 | +sleep 1 | ||
| 75 | +echo stopped | ||
| 76 | +'@ | ||
| 77 | + | ||
| 78 | +Write-Host "== 上传发布包 ==" -ForegroundColor Cyan | ||
| 79 | +$tar = Join-Path $env:TEMP "flus-teustest-publish.tgz" | ||
| 80 | +if (Test-Path $tar) { Remove-Item $tar -Force } | ||
| 81 | +Push-Location $PublishDir | ||
| 82 | +try { | ||
| 83 | + & tar -czf $tar --exclude=logs --exclude=startup.log * | ||
| 84 | + if ($LASTEXITCODE -ne 0) { throw "打包失败" } | ||
| 85 | +} finally { | ||
| 86 | + Pop-Location | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +& scp @SshOpts $tar "${UserName}@${HostName}:/tmp/flus-teustest-publish.tgz" | ||
| 90 | +if ($LASTEXITCODE -ne 0) { throw "scp 失败" } | ||
| 91 | + | ||
| 92 | +Invoke-Remote @" | ||
| 93 | +set -e | ||
| 94 | +mkdir -p '$RemoteDir' | ||
| 95 | +cd '$RemoteDir' | ||
| 96 | +for x in *; do | ||
| 97 | + case "`$x" in | ||
| 98 | + logs|*.log) ;; | ||
| 99 | + *) rm -rf "`$x" ;; | ||
| 100 | + esac | ||
| 101 | +done | ||
| 102 | +tar --overwrite -xzf /tmp/flus-teustest-publish.tgz -C '$RemoteDir' | ||
| 103 | +rm -f /tmp/flus-teustest-publish.tgz | ||
| 104 | +chmod -R a+rX '$RemoteDir' | ||
| 105 | +ls -l '$RemoteDir/Yi.Abp.Web.dll' | ||
| 106 | +echo uploaded_to=$RemoteDir | ||
| 107 | +"@ | ||
| 108 | + | ||
| 109 | +Write-Host "== 登记宝塔 Net 项目 ==" -ForegroundColor Cyan | ||
| 110 | +$btPyLocal = Join-Path $ScriptDir "bt-register-net-project.py" | ||
| 111 | +& scp @SshOpts $btPyLocal "${UserName}@${HostName}:/tmp/bt-register-net-project.py" | ||
| 112 | +if ($LASTEXITCODE -ne 0) { throw "上传宝塔登记脚本失败" } | ||
| 113 | +Invoke-Remote @" | ||
| 114 | +set -e | ||
| 115 | +sed -i 's/\r`$//' /tmp/bt-register-net-project.py | ||
| 116 | +python3 /tmp/bt-register-net-project.py name='$BtName' path='$RemoteDir' port='19004' ps='$BtName' domain='$BtDomain' cmd='$BtCmd' run_user='root' dotnet_version='8.0.100' | ||
| 117 | +"@ | ||
| 118 | + | ||
| 119 | +Write-Host "== 启动 API ==" -ForegroundColor Cyan | ||
| 120 | +Invoke-Remote -AllowFail @" | ||
| 121 | +mkdir -p /www/wwwlogs/net /var/tmp/net_project | ||
| 122 | +cd '$RemoteDir' | ||
| 123 | +nohup $Dotnet '$AppDll' --urls=$ListenUrl >> /www/wwwlogs/net/食品标签泰鄂美国测试版.log 2>&1 & | ||
| 124 | +echo `$! > /var/tmp/net_project/食品标签泰鄂美国测试版.pid | ||
| 125 | +sleep 8 | ||
| 126 | +ss -lntp | grep 19004 || true | ||
| 127 | +curl -s -o /dev/null -w 'local=%{http_code}\n' --max-time 15 http://127.0.0.1:19004/swagger/index.html || true | ||
| 128 | +tail -n 20 /www/wwwlogs/net/食品标签泰鄂美国测试版.log || true | ||
| 129 | +"@ | ||
| 130 | + | ||
| 131 | +Write-Host "== 健康检查 ==" -ForegroundColor Cyan | ||
| 132 | +$ok = $false | ||
| 133 | +for ($i = 1; $i -le 8; $i++) { | ||
| 134 | + try { | ||
| 135 | + $resp = Invoke-WebRequest -Uri $HealthUrl -UseBasicParsing -TimeoutSec 15 | ||
| 136 | + if ($resp.StatusCode -eq 200) { | ||
| 137 | + Write-Host "访问成功: $HealthUrl HTTP $($resp.StatusCode)" -ForegroundColor Green | ||
| 138 | + $ok = $true | ||
| 139 | + break | ||
| 140 | + } | ||
| 141 | + } catch { | ||
| 142 | + Write-Host "等待服务就绪 ($i/8)..." | ||
| 143 | + Start-Sleep -Seconds 3 | ||
| 144 | + } | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +if (-not $ok) { throw "部署后健康检查失败: $HealthUrl" } | ||
| 148 | +Write-Host "完成。API: https://flusapi-teustest.3flabeling.com" -ForegroundColor Green | ||
| 149 | +Write-Host "Swagger: $HealthUrl" | ||
| 150 | +Write-Host "登录: POST https://flusapi-teustest.3flabeling.com/api/app/account/login" |
美国版/scripts/美国版本正式环境部署.cmd
0 → 100644
美国版/scripts/美国版本正式环境部署.ps1
0 → 100644
| 1 | +#Requires -Version 5.1 | ||
| 2 | +<# | ||
| 3 | +.SYNOPSIS | ||
| 4 | + 美国版本正式环境 API 一键部署 | ||
| 5 | +.DESCRIPTION | ||
| 6 | + 发布 Yi.Abp.Web,上传到 47.253.11.59,重启 Kestrel 19001,健康检查 https://flusapi-us.3flabeling.com | ||
| 7 | +#> | ||
| 8 | +param( | ||
| 9 | + [switch]$SkipBuild | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +$ErrorActionPreference = "Stop" | ||
| 13 | +$HostName = "47.253.11.59" | ||
| 14 | +$UserName = "root" | ||
| 15 | +$RemoteDir = "/www/wwwroot/FoodLabelingManagementUs" | ||
| 16 | +$Dotnet = "/www/server/dotnet/8.0.100/dotnet" | ||
| 17 | +$AppDll = "$RemoteDir/Yi.Abp.Web.dll" | ||
| 18 | +$HealthUrl = "https://flusapi-us.3flabeling.com/swagger/index.html" | ||
| 19 | +$ListenUrl = "http://0.0.0.0:19001" | ||
| 20 | +$Cors = "http://0.0.0.0:19001;http://localhost:19001;https://flusapi-us.3flabeling.com;http://flusapi-us.3flabeling.com;http://flus.3flabeling.com;https://flus.3flabeling.com;http://flus.3ffoodsafety.com;https://flus.3ffoodsafety.com;http://localhost:18000;http://localhost:5666;http://localhost:5174;http://localhost:5173;http://localhost:3000" | ||
| 21 | +$DbHost = "rm-0xi95hpp522z6c62w.mysql.rds-aliyun-america.rds.aliyuncs.com" | ||
| 22 | +$DbUser = "root" | ||
| 23 | +$DbPassword = "Te2026@antis!" | ||
| 24 | +$ProdDbName = "antis-foodlabeling-us" | ||
| 25 | +$BtName = "食品标签美国正式版" | ||
| 26 | +$BtDomain = "flusapi-us.3flabeling.com" | ||
| 27 | +$BtCmd = "{0} {1} --urls={2}" -f $Dotnet, $AppDll, $ListenUrl | ||
| 28 | + | ||
| 29 | +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
| 30 | +$RepoRoot = Resolve-Path (Join-Path $ScriptDir "..\..") | ||
| 31 | +$WebCsproj = Join-Path $RepoRoot "美国版\Food Labeling Management Code\Yi.Abp.Net8\src\Yi.Abp.Web\Yi.Abp.Web.csproj" | ||
| 32 | +$PublishDir = Join-Path $RepoRoot "美国版\Food Labeling Management Code\Yi.Abp.Net8\_publish-usprod" | ||
| 33 | +. (Join-Path $ScriptDir "_deploy-us-ssh.ps1") | ||
| 34 | +Initialize-DeploySsh | ||
| 35 | +$SshOpts = $global:SshOpts | ||
| 36 | + | ||
| 37 | +Write-Host "== 美国版本正式环境部署 ==" -ForegroundColor Cyan | ||
| 38 | +Write-Host "目标: $HostName $RemoteDir" | ||
| 39 | +Write-Host "域名: $HealthUrl" | ||
| 40 | +Write-Host "数据库: $ProdDbName @ $DbHost" | ||
| 41 | + | ||
| 42 | +if (-not $SkipBuild) { | ||
| 43 | + if (-not (Test-Path $WebCsproj)) { throw "找不到工程: $WebCsproj" } | ||
| 44 | + Write-Host "== 发布 Yi.Abp.Web ==" -ForegroundColor Cyan | ||
| 45 | + if (Test-Path $PublishDir) { Remove-Item $PublishDir -Recurse -Force } | ||
| 46 | + & dotnet publish $WebCsproj -c Release -o $PublishDir --nologo | ||
| 47 | + if ($LASTEXITCODE -ne 0) { throw "dotnet publish 失败" } | ||
| 48 | + | ||
| 49 | + $appsettings = Join-Path $PublishDir "appsettings.json" | ||
| 50 | + if (Test-Path $appsettings) { | ||
| 51 | + $json = Get-Content $appsettings -Raw -Encoding UTF8 | ||
| 52 | + $json = [regex]::Replace($json, '"SelfUrl"\s*:\s*"[^"]*"', '"SelfUrl": "' + $ListenUrl + '"') | ||
| 53 | + $json = [regex]::Replace($json, '"CorsOrigins"\s*:\s*"[^"]*"', '"CorsOrigins": "' + $Cors + '"') | ||
| 54 | + $json = [regex]::Replace($json, 'server=[^;]+', "server=$DbHost") | ||
| 55 | + $json = [regex]::Replace($json, 'uid=[^;]+', "uid=$DbUser") | ||
| 56 | + $json = [regex]::Replace($json, 'pwd=[^;]+', "pwd=$DbPassword") | ||
| 57 | + $json = [regex]::Replace($json, 'database=antis-foodlabeling-[^;]+', "database=$ProdDbName") | ||
| 58 | + Set-Content -Path $appsettings -Value $json -Encoding UTF8 | ||
| 59 | + } | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +if (-not (Test-Path (Join-Path $PublishDir "Yi.Abp.Web.dll"))) { | ||
| 63 | + throw "发布目录缺少 Yi.Abp.Web.dll: $PublishDir" | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +Write-Host "== 停止远程正式环境进程 ==" -ForegroundColor Cyan | ||
| 67 | +Invoke-Remote @' | ||
| 68 | +set -e | ||
| 69 | +if [ -f "/var/tmp/net_project/食品标签美国正式版.pid" ]; then | ||
| 70 | + pid=$(cat "/var/tmp/net_project/食品标签美国正式版.pid" || true) | ||
| 71 | + if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi | ||
| 72 | +fi | ||
| 73 | +pkill -f "/www/wwwroot/FoodLabelingManagementUs/Yi.Abp.Web.dll" 2>/dev/null || true | ||
| 74 | +sleep 1 | ||
| 75 | +echo stopped | ||
| 76 | +'@ | ||
| 77 | + | ||
| 78 | +Write-Host "== 上传发布包 ==" -ForegroundColor Cyan | ||
| 79 | +$tar = Join-Path $env:TEMP "flus-usprod-publish.tgz" | ||
| 80 | +if (Test-Path $tar) { Remove-Item $tar -Force } | ||
| 81 | +Push-Location $PublishDir | ||
| 82 | +try { | ||
| 83 | + & tar -czf $tar --exclude=logs --exclude=startup.log * | ||
| 84 | + if ($LASTEXITCODE -ne 0) { throw "打包失败" } | ||
| 85 | +} finally { | ||
| 86 | + Pop-Location | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +& scp @SshOpts $tar "${UserName}@${HostName}:/tmp/flus-usprod-publish.tgz" | ||
| 90 | +if ($LASTEXITCODE -ne 0) { throw "scp 失败" } | ||
| 91 | + | ||
| 92 | +Invoke-Remote @" | ||
| 93 | +set -e | ||
| 94 | +mkdir -p '$RemoteDir' | ||
| 95 | +cd '$RemoteDir' | ||
| 96 | +for x in *; do | ||
| 97 | + case "`$x" in | ||
| 98 | + logs|*.log) ;; | ||
| 99 | + *) rm -rf "`$x" ;; | ||
| 100 | + esac | ||
| 101 | +done | ||
| 102 | +tar --overwrite -xzf /tmp/flus-usprod-publish.tgz -C '$RemoteDir' | ||
| 103 | +rm -f /tmp/flus-usprod-publish.tgz | ||
| 104 | +chmod -R a+rX '$RemoteDir' | ||
| 105 | +ls -l '$RemoteDir/Yi.Abp.Web.dll' | ||
| 106 | +echo uploaded_to=$RemoteDir | ||
| 107 | +"@ | ||
| 108 | + | ||
| 109 | +Write-Host "== 登记宝塔 Net 项目 ==" -ForegroundColor Cyan | ||
| 110 | +$btPyLocal = Join-Path $ScriptDir "bt-register-net-project.py" | ||
| 111 | +& scp @SshOpts $btPyLocal "${UserName}@${HostName}:/tmp/bt-register-net-project.py" | ||
| 112 | +if ($LASTEXITCODE -ne 0) { throw "上传宝塔登记脚本失败" } | ||
| 113 | +Invoke-Remote @" | ||
| 114 | +set -e | ||
| 115 | +sed -i 's/\r`$//' /tmp/bt-register-net-project.py | ||
| 116 | +python3 /tmp/bt-register-net-project.py name='$BtName' path='$RemoteDir' port='19001' ps='$BtName' domain='$BtDomain' cmd='$BtCmd' run_user='root' dotnet_version='8.0.100' | ||
| 117 | +"@ | ||
| 118 | + | ||
| 119 | +Write-Host "== 启动 API ==" -ForegroundColor Cyan | ||
| 120 | +Invoke-Remote -AllowFail @" | ||
| 121 | +mkdir -p /www/wwwlogs/net /var/tmp/net_project | ||
| 122 | +cd '$RemoteDir' | ||
| 123 | +nohup $Dotnet '$AppDll' --urls=$ListenUrl >> /www/wwwlogs/net/食品标签美国正式版.log 2>&1 & | ||
| 124 | +echo `$! > /var/tmp/net_project/食品标签美国正式版.pid | ||
| 125 | +sleep 8 | ||
| 126 | +ss -lntp | grep 19001 || true | ||
| 127 | +curl -s -o /dev/null -w 'local=%{http_code}\n' --max-time 15 http://127.0.0.1:19001/swagger/index.html || true | ||
| 128 | +tail -n 20 /www/wwwlogs/net/食品标签美国正式版.log || true | ||
| 129 | +"@ | ||
| 130 | + | ||
| 131 | +Write-Host "== 健康检查 ==" -ForegroundColor Cyan | ||
| 132 | +$ok = $false | ||
| 133 | +for ($i = 1; $i -le 8; $i++) { | ||
| 134 | + try { | ||
| 135 | + $resp = Invoke-WebRequest -Uri $HealthUrl -UseBasicParsing -TimeoutSec 15 | ||
| 136 | + if ($resp.StatusCode -eq 200) { | ||
| 137 | + Write-Host "访问成功: $HealthUrl HTTP $($resp.StatusCode)" -ForegroundColor Green | ||
| 138 | + $ok = $true | ||
| 139 | + break | ||
| 140 | + } | ||
| 141 | + } catch { | ||
| 142 | + Write-Host "等待服务就绪 ($i/8)..." | ||
| 143 | + Start-Sleep -Seconds 3 | ||
| 144 | + } | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +if (-not $ok) { throw "部署后健康检查失败: $HealthUrl" } | ||
| 148 | +Write-Host "完成。API: https://flusapi-us.3flabeling.com" -ForegroundColor Green | ||
| 149 | +Write-Host "Swagger: $HealthUrl" | ||
| 150 | +Write-Host "登录: POST https://flusapi-us.3flabeling.com/api/app/account/login" |
美国版/scripts/美国版本测试环境部署.cmd
0 → 100644
美国版/scripts/美国版本测试环境部署.ps1
0 → 100644
| 1 | +#Requires -Version 5.1 | ||
| 2 | +<# | ||
| 3 | +.SYNOPSIS | ||
| 4 | + 美国版本测试环境 API 一键部署 | ||
| 5 | +.DESCRIPTION | ||
| 6 | + 发布 Yi.Abp.Web,上传到 47.253.11.59,重启 Kestrel,健康检查 https://flusapi-ustest.3flabeling.com | ||
| 7 | +#> | ||
| 8 | +param( | ||
| 9 | + [switch]$SkipBuild | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +$ErrorActionPreference = "Stop" | ||
| 13 | +$HostName = "47.253.11.59" | ||
| 14 | +$UserName = "root" | ||
| 15 | +$RemoteDir = "/www/wwwroot/FoodLabelingManagementUsTest" | ||
| 16 | +$Dotnet = "/www/server/dotnet/8.0.100/dotnet" | ||
| 17 | +$AppDll = "$RemoteDir/Yi.Abp.Web.dll" | ||
| 18 | +$HealthUrl = "https://flusapi-ustest.3flabeling.com/swagger/index.html" | ||
| 19 | +$ListenUrl = "http://0.0.0.0:19003" | ||
| 20 | +$Cors = "http://0.0.0.0:19003;http://localhost:19003;https://flusapi-ustest.3flabeling.com;http://flusapi-ustest.3flabeling.com;http://flus-test.3flabeling.com;https://flus-test.3flabeling.com;http://flus-test.3ffoodsafety.com;https://flus-test.3ffoodsafety.com;http://localhost:18000;http://localhost:5666;http://localhost:5174;http://localhost:5173;http://localhost:3000" | ||
| 21 | +$DbHost = "rm-0xi95hpp522z6c62w.mysql.rds-aliyun-america.rds.aliyuncs.com" | ||
| 22 | +$DbUser = "root" | ||
| 23 | +$DbPassword = "Te2026@antis!" | ||
| 24 | +$TestDbName = "antis-foodlabeling-test-us" | ||
| 25 | +$BtName = "食品标签美国测试版" | ||
| 26 | +$BtDomain = "flusapi-ustest.3flabeling.com" | ||
| 27 | +$BtCmd = "{0} {1} --urls={2}" -f $Dotnet, $AppDll, $ListenUrl | ||
| 28 | + | ||
| 29 | +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
| 30 | +$RepoRoot = Resolve-Path (Join-Path $ScriptDir "..\..") | ||
| 31 | +$WebCsproj = Join-Path $RepoRoot "美国版\Food Labeling Management Code\Yi.Abp.Net8\src\Yi.Abp.Web\Yi.Abp.Web.csproj" | ||
| 32 | +$PublishDir = Join-Path $RepoRoot "美国版\Food Labeling Management Code\Yi.Abp.Net8\_publish-ustest" | ||
| 33 | +. (Join-Path $ScriptDir "_deploy-us-ssh.ps1") | ||
| 34 | +Initialize-DeploySsh | ||
| 35 | +$SshOpts = $global:SshOpts | ||
| 36 | + | ||
| 37 | +Write-Host "== 美国版本测试环境部署 ==" -ForegroundColor Cyan | ||
| 38 | +Write-Host "目标: $HostName $RemoteDir" | ||
| 39 | +Write-Host "域名: $HealthUrl" | ||
| 40 | +Write-Host "数据库: $TestDbName @ $DbHost" | ||
| 41 | + | ||
| 42 | +if (-not $SkipBuild) { | ||
| 43 | + if (-not (Test-Path $WebCsproj)) { throw "找不到工程: $WebCsproj" } | ||
| 44 | + Write-Host "== 发布 Yi.Abp.Web ==" -ForegroundColor Cyan | ||
| 45 | + if (Test-Path $PublishDir) { Remove-Item $PublishDir -Recurse -Force } | ||
| 46 | + & dotnet publish $WebCsproj -c Release -o $PublishDir --nologo | ||
| 47 | + if ($LASTEXITCODE -ne 0) { throw "dotnet publish 失败" } | ||
| 48 | + | ||
| 49 | + $appsettings = Join-Path $PublishDir "appsettings.json" | ||
| 50 | + if (Test-Path $appsettings) { | ||
| 51 | + $json = Get-Content $appsettings -Raw -Encoding UTF8 | ||
| 52 | + $json = [regex]::Replace($json, '"SelfUrl"\s*:\s*"[^"]*"', '"SelfUrl": "' + $ListenUrl + '"') | ||
| 53 | + $json = [regex]::Replace($json, '"CorsOrigins"\s*:\s*"[^"]*"', '"CorsOrigins": "' + $Cors + '"') | ||
| 54 | + $json = [regex]::Replace($json, 'server=[^;]+', "server=$DbHost") | ||
| 55 | + $json = [regex]::Replace($json, 'uid=[^;]+', "uid=$DbUser") | ||
| 56 | + $json = [regex]::Replace($json, 'pwd=[^;]+', "pwd=$DbPassword") | ||
| 57 | + $json = [regex]::Replace($json, 'database=antis-foodlabeling-[^;]+', "database=$TestDbName") | ||
| 58 | + Set-Content -Path $appsettings -Value $json -Encoding UTF8 | ||
| 59 | + } | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +if (-not (Test-Path (Join-Path $PublishDir "Yi.Abp.Web.dll"))) { | ||
| 63 | + throw "发布目录缺少 Yi.Abp.Web.dll: $PublishDir" | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +Write-Host "== 停止远程进程 ==" -ForegroundColor Cyan | ||
| 67 | +Invoke-Remote @' | ||
| 68 | +set -e | ||
| 69 | +if [ -f "/var/tmp/net_project/食品标签美国测试版.pid" ]; then | ||
| 70 | + pid=$(cat "/var/tmp/net_project/食品标签美国测试版.pid" || true) | ||
| 71 | + if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi | ||
| 72 | +fi | ||
| 73 | +pkill -f "/www/wwwroot/FoodLabelingManagementUsTest/Yi.Abp.Web.dll" 2>/dev/null || true | ||
| 74 | +sleep 1 | ||
| 75 | +echo stopped | ||
| 76 | +'@ | ||
| 77 | + | ||
| 78 | +Write-Host "== 上传发布包 ==" -ForegroundColor Cyan | ||
| 79 | +$tar = Join-Path $env:TEMP "flus-ustest-publish.tgz" | ||
| 80 | +if (Test-Path $tar) { Remove-Item $tar -Force } | ||
| 81 | +Push-Location $PublishDir | ||
| 82 | +try { | ||
| 83 | + & tar -czf $tar --exclude=logs --exclude=startup.log * | ||
| 84 | + if ($LASTEXITCODE -ne 0) { throw "打包失败" } | ||
| 85 | +} finally { | ||
| 86 | + Pop-Location | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +& scp @SshOpts $tar "${UserName}@${HostName}:/tmp/flus-ustest-publish.tgz" | ||
| 90 | +if ($LASTEXITCODE -ne 0) { throw "scp 失败" } | ||
| 91 | + | ||
| 92 | +Invoke-Remote @" | ||
| 93 | +set -e | ||
| 94 | +mkdir -p '$RemoteDir' | ||
| 95 | +cd '$RemoteDir' | ||
| 96 | +for x in *; do | ||
| 97 | + case "`$x" in | ||
| 98 | + logs|*.log) ;; | ||
| 99 | + *) rm -rf "`$x" ;; | ||
| 100 | + esac | ||
| 101 | +done | ||
| 102 | +tar --overwrite -xzf /tmp/flus-ustest-publish.tgz -C '$RemoteDir' | ||
| 103 | +rm -f /tmp/flus-ustest-publish.tgz | ||
| 104 | +chmod -R a+rX '$RemoteDir' | ||
| 105 | +ls -l '$RemoteDir/Yi.Abp.Web.dll' | ||
| 106 | +echo uploaded_to=$RemoteDir | ||
| 107 | +"@ | ||
| 108 | + | ||
| 109 | +Write-Host "== 登记宝塔 Net 项目 ==" -ForegroundColor Cyan | ||
| 110 | +$btPyLocal = Join-Path $ScriptDir "bt-register-net-project.py" | ||
| 111 | +& scp @SshOpts $btPyLocal "${UserName}@${HostName}:/tmp/bt-register-net-project.py" | ||
| 112 | +if ($LASTEXITCODE -ne 0) { throw "上传宝塔登记脚本失败" } | ||
| 113 | +Invoke-Remote @" | ||
| 114 | +set -e | ||
| 115 | +sed -i 's/\r`$//' /tmp/bt-register-net-project.py | ||
| 116 | +python3 /tmp/bt-register-net-project.py name='$BtName' path='$RemoteDir' port='19003' ps='$BtName' domain='$BtDomain' cmd='$BtCmd' run_user='root' dotnet_version='8.0.100' | ||
| 117 | +"@ | ||
| 118 | + | ||
| 119 | +Write-Host "== 启动 API ==" -ForegroundColor Cyan | ||
| 120 | +Invoke-Remote -AllowFail @" | ||
| 121 | +mkdir -p /www/wwwlogs/net /var/tmp/net_project | ||
| 122 | +cd '$RemoteDir' | ||
| 123 | +nohup $Dotnet '$AppDll' --urls=$ListenUrl >> /www/wwwlogs/net/食品标签美国测试版.log 2>&1 & | ||
| 124 | +echo `$! > /var/tmp/net_project/食品标签美国测试版.pid | ||
| 125 | +sleep 8 | ||
| 126 | +ss -lntp | grep 19003 || true | ||
| 127 | +curl -s -o /dev/null -w 'local=%{http_code}\n' --max-time 15 http://127.0.0.1:19003/swagger/index.html || true | ||
| 128 | +tail -n 20 /www/wwwlogs/net/食品标签美国测试版.log || true | ||
| 129 | +"@ | ||
| 130 | + | ||
| 131 | +Write-Host "== 健康检查 ==" -ForegroundColor Cyan | ||
| 132 | +$ok = $false | ||
| 133 | +for ($i = 1; $i -le 8; $i++) { | ||
| 134 | + try { | ||
| 135 | + $resp = Invoke-WebRequest -Uri $HealthUrl -UseBasicParsing -TimeoutSec 15 | ||
| 136 | + if ($resp.StatusCode -eq 200) { | ||
| 137 | + Write-Host "访问成功: $HealthUrl HTTP $($resp.StatusCode)" -ForegroundColor Green | ||
| 138 | + $ok = $true | ||
| 139 | + break | ||
| 140 | + } | ||
| 141 | + } catch { | ||
| 142 | + Write-Host "等待服务就绪 ($i/8)..." | ||
| 143 | + Start-Sleep -Seconds 3 | ||
| 144 | + } | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +if (-not $ok) { throw "部署后健康检查失败: $HealthUrl" } | ||
| 148 | +Write-Host "完成。API: https://flusapi-ustest.3flabeling.com" -ForegroundColor Green | ||
| 149 | +Write-Host "Swagger: $HealthUrl" | ||
| 150 | +Write-Host "登录: POST https://flusapi-ustest.3flabeling.com/api/app/account/login" |