diff --git a/projects/Platform/Data/PlatformDbContext.cs b/projects/Platform/Data/PlatformDbContext.cs index 7fd321b7..3408a872 100644 --- a/projects/Platform/Data/PlatformDbContext.cs +++ b/projects/Platform/Data/PlatformDbContext.cs @@ -128,6 +128,7 @@ namespace Platform.Data } }); db.SaveChanges(); + db.Set().Add(new DictionaryCategory { Key = "OrganType", @@ -142,6 +143,7 @@ namespace Platform.Data } }); db.SaveChanges(); + db.Set().Add(new DictionaryCategory { Key = "BuildingType", @@ -154,6 +156,7 @@ namespace Platform.Data } }); db.SaveChanges(); + db.Set().Add(new DictionaryCategory { Key = "DepartmentType", @@ -166,6 +169,7 @@ namespace Platform.Data } }); db.SaveChanges(); + db.Set().Add(new DictionaryCategory { Key = "DepartmentUserType", @@ -177,6 +181,7 @@ namespace Platform.Data } }); db.SaveChanges(); + db.Set().Add(new DictionaryCategory { Key = "OrganUserType", @@ -189,6 +194,7 @@ namespace Platform.Data } }); db.SaveChanges(); + var order = 0; var root = db.Set().Add(new IoTProductCategory { @@ -493,7 +499,8 @@ namespace Platform.Data var superRole = new Role { OrganId = platformOrganId, Number = "super", Name = "超级管理员", IsReadOnly = true }; var adminRole = new Role { OrganId = platformOrganId, Number = "admin", Name = "管理员" }; var organRole = new Role { OrganId = platformOrganId, Number = "organ", Name = "机构管理员" }; - + db.Set().AddRange(superRole, adminRole, organRole); + db.SaveChanges(); //初始化角色 var skips = new string[] { //"添加Api", "修改Api", "添加分类", "修改分类", "添加参数", "修改参数", "添加产品", "修改产品", "添加节点", "添加权限", "修改权限", "添加权限分类", "修改权限分类", "添加设备" @@ -501,18 +508,17 @@ namespace Platform.Data foreach (var item in db.Set()) { - superRole.RolePermissions.Add(new RolePermission { IsReadOnly = true, Permission = item }); + db.Set().Add(new RolePermission {IsReadOnly = true,RoleId = superRole.Id,PermissionId=item.Id }); if (!item.Name.Contains("删除") && !skips.Contains(item.Name)) { - adminRole.RolePermissions.Add(new RolePermission { Permission = item }); + db.Set().Add(new RolePermission { IsReadOnly = true, RoleId = adminRole.Id, PermissionId = item.Id }); if (item.Type == PermissionType.Organ) { - organRole.RolePermissions.Add(new RolePermission { Permission = item }); + db.Set().Add(new RolePermission { IsReadOnly = true, RoleId = organRole.Id, PermissionId = item.Id }); } } + db.SaveChanges(); } - db.Set().AddRange(superRole, adminRole, organRole); - db.SaveChanges(); var securityStam = "123456"; db.Set().Add(new User diff --git a/projects/Platform/Program.cs b/projects/Platform/Program.cs index b7bd0d3a..256d936e 100644 --- a/projects/Platform/Program.cs +++ b/projects/Platform/Program.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore; +using Infrastructure.Extensions; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -55,19 +56,27 @@ namespace Platform private static ILogger GetLogger(IConfigurationRoot config) { - return new LoggerConfiguration() - .ReadFrom.Configuration(config, ConfigurationAssemblySource.AlwaysScanDllFiles) - .WriteTo.Console() - .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(config.GetConnectionString("Log"))) + var loggerConfiguration = new LoggerConfiguration().ReadFrom.Configuration(config, ConfigurationAssemblySource.AlwaysScanDllFiles); + loggerConfiguration.WriteTo.Console(); + var logType = config.GetAppSetting("Log", "File"); + if (logType == "Elasticsearch") + { + loggerConfiguration.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(config.GetConnectionString("Log.Elasticsearch"))) { AutoRegisterTemplate = true, AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7, CustomFormatter = new ExceptionAsObjectJsonFormatter(renderMessage: true), FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate), - EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog |EmitEventFailureHandling.WriteToFailureSink | EmitEventFailureHandling.RaiseCallback, + EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog | EmitEventFailureHandling.WriteToFailureSink | EmitEventFailureHandling.RaiseCallback, FailureSink = new RollingFileSink("logs/log.json", new JsonFormatter(), 100 * 1024 * 1024, 1, Encoding.UTF8) - }) - .CreateLogger(); + }); + } + else + { + loggerConfiguration.WriteTo + .File("logs/log.txt", rollOnFileSizeLimit: true, fileSizeLimitBytes: 100 * 1024 * 1024, rollingInterval: RollingInterval.Infinite); + } + return loggerConfiguration.CreateLogger(); } } } \ No newline at end of file diff --git a/projects/Platform/appsettings.Docker.json b/projects/Platform/appsettings.Docker.json index 51756158..2db1d26e 100644 --- a/projects/Platform/appsettings.Docker.json +++ b/projects/Platform/appsettings.Docker.json @@ -1,8 +1,8 @@ { "ConnectionStrings": { "SQLite": "Data Source=iotcenter.db", - "MySQL": "Server=mysql;Port=3306;Database=iotcenter;Uid=root;Pwd=aA123456!;", - "Log": "http://elasticsearch:9200", + "MySQL": "Server=mysql;Port=3306;Database=iotcenter;Uid=root;Pwd=aA123456!;default command timeout=300;", + "Log.Elasticsearch": "http://elasticsearch:9200", "Job.MySQL": "Server=mysql;Port=3306;Database=jobserver;Uid=root;Pwd=aA123456!;Allow User Variables=True;", "PostgreSQL": "User ID=root;Host=localhost;Port=26257;Database=iotcenter;CommandTimeout=600;TrustServerCertificate=true;", "Redis": "redis:6379,password=aA123456!,allowAdmin=true", diff --git a/projects/Platform/appsettings.json b/projects/Platform/appsettings.json index b9641991..7d602c5b 100644 --- a/projects/Platform/appsettings.json +++ b/projects/Platform/appsettings.json @@ -13,6 +13,7 @@ "OpenApi": "name=v1;title=title;version=1.0", "BasePath": "/platform", "TablePrefix": "", + "Log": "Elasticsearch", "Database": "MySQL", "JobDatabase": "MySQL", "FileServer": "MinIO", @@ -22,8 +23,8 @@ }, "ConnectionStrings": { "SQLite": "Data Source=iotcenter.db", - "MySQL": "Server=localhost;Port=3306;Database=iotcenter;Uid=root;Pwd=aA123456!;", - "Log": "http://localhost:9200", + "MySQL": "Server=localhost;Port=3306;Database=iotcenter;Uid=root;Pwd=aA123456!;default command timeout=300;", + "Log.Elasticsearch": "http://localhost:9200", "Job.MySQL": "Server=localhost;Port=3306;Database=jobserver;Uid=root;Pwd=aA123456!;Allow User Variables=True;", "PostgreSQL": "User ID=root;Host=localhost;Port=26257;Database=iotcenter;CommandTimeout=600;TrustServerCertificate=true;", "Redis": "localhost:6379,password=aA123456!,allowAdmin=true", diff --git a/publish/src/linux-x64/publish/docker-compose.prod.yml b/publish/src/linux-x64/publish/docker-compose.prod.yml index 568f2ff3..8047af41 100644 --- a/publish/src/linux-x64/publish/docker-compose.prod.yml +++ b/publish/src/linux-x64/publish/docker-compose.prod.yml @@ -5,6 +5,11 @@ services: #monitor platform: image: mcr.microsoft.com/dotnet/aspnet:5.0 + deploy: + resources: + limits: + memory: 2g + cpus: '0.20' restart: always environment: - TZ=Asia/Shanghai diff --git a/publish/src/linux-x64/publish/docker-compose.yml b/publish/src/linux-x64/publish/docker-compose.yml index 7ecbc573..4fdcdf9a 100644 --- a/publish/src/linux-x64/publish/docker-compose.yml +++ b/publish/src/linux-x64/publish/docker-compose.yml @@ -1,7 +1,4 @@ version: "3.8" -networks: - default: - driver: bridge services: #netdata netdata: @@ -71,10 +68,6 @@ services: mysql: image: mysql:8.0 restart: always - deploy: - resources: - limits: - memory: 2g environment: - MYSQL_ROOT_PASSWORD=aA123456! command: --default-authentication-plugin=mysql_native_password @@ -125,13 +118,9 @@ services: elasticsearch: image: elasticsearch:7.12.0 restart: always - deploy: - resources: - limits: - memory: 2g environment: - discovery.type=single-node - - ES_JAVA_OPTS=-Xms1g -Xmx1g + - ES_JAVA_OPTS=-Xms512m -Xmx512m - http.cors.enabled=true - http.cors.allow-origin=* ports: @@ -144,4 +133,6 @@ services: image: kibana:7.12.0 restart: always ports: - - 5601:5601 \ No newline at end of file + - 5601:5601 + depends_on: + - elasticsearch \ No newline at end of file