一期项目框架搭建

This commit is contained in:
“hsc”
2026-08-27 17:10:56 +08:00
parent 9b852e5c95
commit 03d46fb473
97 changed files with 1222 additions and 14 deletions
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 设备台账
/// </summary>
[ApiController]
[Route("api/asset/equipment")]
public class EquipmentController : ControllerBase
{
// TODO: 实现 设备台账 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 二维码
/// </summary>
[ApiController]
[Route("api/asset/qrcode")]
public class QrCodeController : ControllerBase
{
// TODO: 实现 二维码 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 证书管理
/// </summary>
[ApiController]
[Route("api/config/certificate")]
public class CertificateController : ControllerBase
{
// TODO: 实现 证书管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 采集点位配置
/// </summary>
[ApiController]
[Route("api/config/collection-point")]
public class CollectionPointController : ControllerBase
{
// TODO: 实现 采集点位配置 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 采集策略管理
/// </summary>
[ApiController]
[Route("api/config/collection-strategy")]
public class CollectionStrategyController : ControllerBase
{
// TODO: 实现 采集策略管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 数据清洗与转换
/// </summary>
[ApiController]
[Route("api/config/data-cleaning")]
public class DataCleaningController : ControllerBase
{
// TODO: 实现 数据清洗与转换 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 设备网关
/// </summary>
[ApiController]
[Route("api/config/device-gateway")]
public class DeviceGatewayController : ControllerBase
{
// TODO: 实现 设备网关 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 网关管理
/// </summary>
[ApiController]
[Route("api/config/gateway")]
public class GatewayController : ControllerBase
{
// TODO: 实现 网关管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// IOT设备管理
/// </summary>
[ApiController]
[Route("api/config/device")]
public class IotDeviceController : ControllerBase
{
// TODO: 实现 IOT设备管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 网络组件与协议注册
/// </summary>
[ApiController]
[Route("api/config/network-component")]
public class NetworkComponentController : ControllerBase
{
// TODO: 实现 网络组件与协议注册 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 产品管理
/// </summary>
[ApiController]
[Route("api/config/product")]
public class ProductController : ControllerBase
{
// TODO: 实现 产品管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 协议管理
/// </summary>
[ApiController]
[Route("api/config/protocol")]
public class ProtocolController : ControllerBase
{
// TODO: 实现 协议管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 协议模板库
/// </summary>
[ApiController]
[Route("api/config/protocol-template")]
public class ProtocolTemplateController : ControllerBase
{
// TODO: 实现 协议模板库 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 时序数据存储
/// </summary>
[ApiController]
[Route("api/config/time-series")]
public class TimeSeriesStorageController : ControllerBase
{
// TODO: 实现 时序数据存储 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 消息告警
/// </summary>
[ApiController]
[Route("api/inspection/alert-message")]
public class AlertMessageController : ControllerBase
{
// TODO: 实现 消息告警 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 告警规则
/// </summary>
[ApiController]
[Route("api/inspection/alert-rule")]
public class AlertRuleController : ControllerBase
{
// TODO: 实现 告警规则 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 数据大屏
/// </summary>
[ApiController]
[Route("api/inspection/bigscreen")]
public class BigScreenController : ControllerBase
{
// TODO: 实现 数据大屏 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 设备看板
/// </summary>
[ApiController]
[Route("api/inspection/dashboard")]
public class DeviceDashboardController : ControllerBase
{
// TODO: 实现 设备看板 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 设备效率分析
/// </summary>
[ApiController]
[Route("api/inspection/efficiency")]
public class EfficiencyController : ControllerBase
{
// TODO: 实现 设备效率分析 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 巡检管理
/// </summary>
[ApiController]
[Route("api/inspection/patrol")]
public class PatrolController : ControllerBase
{
// TODO: 实现 巡检管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 统计报表
/// </summary>
[ApiController]
[Route("api/inspection/report")]
public class StatisticsReportController : ControllerBase
{
// TODO: 实现 统计报表 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 访问日志
/// </summary>
[ApiController]
[Route("api/system/access-log")]
public class AccessLogController : ControllerBase
{
// TODO: 实现 访问日志 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 操作审计日志
/// </summary>
[ApiController]
[Route("api/system/audit")]
public class AuditController : ControllerBase
{
// TODO: 实现 操作审计日志 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 数据字典管理
/// </summary>
[ApiController]
[Route("api/system/dict")]
public class DictController : ControllerBase
{
// TODO: 实现 数据字典管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 文件存储管理
/// </summary>
[ApiController]
[Route("api/system/file-storage")]
public class FileStorageController : ControllerBase
{
// TODO: 实现 文件存储管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 组织架构管理
/// </summary>
[ApiController]
[Route("api/system/organization")]
public class OrganizationController : ControllerBase
{
// TODO: 实现 组织架构管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 角色权限管理
/// </summary>
[ApiController]
[Route("api/system/role")]
public class RoleController : ControllerBase
{
// TODO: 实现 角色权限管理 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 系统日志
/// </summary>
[ApiController]
[Route("api/system/system-log")]
public class SystemLogController : ControllerBase
{
// TODO: 实现 系统日志 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 系统参数配置
/// </summary>
[ApiController]
[Route("api/system/param")]
public class SystemParamController : ControllerBase
{
// TODO: 实现 系统参数配置 相关接口
}
}
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
/// <summary>
/// 用户管理
/// </summary>
[ApiController]
[Route("api/system/user")]
public class UserController : ControllerBase
{
// TODO: 实现 用户管理 相关接口
}
}
+48
View File
@@ -0,0 +1,48 @@
using Service.Implement;
using System.Reflection;
namespace WebAPI
{
/// <summary>
/// 业务服务依赖注入扩展
/// 约定:Service.Interface 中的 IXxxService 对应 Service.Implement 中的 XxxService
/// </summary>
public static class DependencyInjection
{
/// <summary>
/// 自动注册所有业务服务(按命名约定:接口去掉前缀 I 即为实现类名)
/// 以后在 Service 项目里新增「接口 + 实现」时,无需改动这里,会自动注册
/// </summary>
public static IServiceCollection AddBusinessServices(this IServiceCollection services)
{
// Service 项目程序集(接口与实现都在同一个程序集里)
Assembly assembly = typeof(BaseService<>).Assembly;
// 所有具体实现类(非抽象、非泛型定义)
var implTypes = assembly.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract && !t.IsGenericTypeDefinition)
.ToList();
// 所有接口
var ifaceTypes = assembly.GetTypes()
.Where(t => t.IsInterface && !t.IsGenericTypeDefinition)
.ToList();
foreach (var iface in ifaceTypes)
{
// 接口名去掉前缀 I,得到期望的实现类名
string implName = iface.Name.StartsWith("I") ? iface.Name.Substring(1) : iface.Name;
var impl = implTypes.FirstOrDefault(t => t.Name == implName);
if (impl != null && iface.IsAssignableFrom(impl))
{
services.AddScoped(iface, impl);
}
}
// 泛型基础服务(IBaseService<> -> BaseService<>)单独注册
services.AddScoped(typeof(Service.Interface.IBaseService<>), typeof(Service.Implement.BaseService<>));
return services;
}
}
}
+20 -11
View File
@@ -1,4 +1,5 @@
using Common;
using ORM;
using System.Text.Json;
namespace WebAPI
@@ -7,30 +8,39 @@ namespace WebAPI
{
public static void Main(string[] args)
{
// ======= 崩溃转储:未处理异常时自动生成 MiniDump =======
//dump文件崩溃记录(不用或者使用后记得去编译路径删除,.dump文件体积很大)
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
//记录dump文件
Exception ex = e.ExceptionObject as Exception;
MiniDump.TryDump($"dumps\\Error_{DateTime.Now:yyyy-MM-dd HH-mm-ss-ms}.dmp", MiniDump.Option.WithFullMemory, ex);
string exeDir = AppContext.BaseDirectory;
string dumpDir = Path.Combine(exeDir, "Dump");
if (!Directory.Exists(dumpDir))
{
Directory.CreateDirectory(dumpDir);
}
string dumpFileName = $"Error_{DateTime.Now:yyyy-MM-dd HH-mm-ss-fff}.dmp";
string dumpFullPath = Path.Combine(dumpDir, dumpFileName);
MiniDump.TryDump(dumpFullPath, MiniDump.Option.WithFullMemory, ex);
};
// ======= 崩溃转储结束 =======
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// ======= 核心配置开始 =======
//注册postgre数据库
var db = builder.Configuration.GetSection("Database");
DatabaseConfig.InitPostgreSQL(db["Server"]!, int.Parse(db["Port"] ?? "5432"), db["Database"]!, db["User"]!, db["Password"]!);
if (int.TryParse(db["TenantId"], out var tenantId))
DatabaseConfig.SetTenant(tenantId);
DatabaseConfig.CreateDatabaseAndCheckConnection(createDatabase: true, checkConnection: true);
SqlSugarContext.InitDatabase();
builder.Services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
options.JsonSerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString;
// 3. 属性命名策略保持原样(不强制转为驼峰)
options.JsonSerializerOptions.PropertyNamingPolicy = null;
});
// ======= 核心配置结束 =======
// 自动注册业务服务(Service.Interface -> Service.Implement
builder.Services.AddBusinessServices();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
@@ -43,7 +53,6 @@ namespace WebAPI
app.UseSwaggerUI();
}
// 注意:如果上位机只支持 http 请求,现场部署时你可能需要根据实际情况注释掉下面这行 Https 重定向
app.UseHttpsRedirection();
app.UseAuthorization();
+10 -1
View File
@@ -5,5 +5,14 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Database": {
"Type": "PostgreSQL",
"Server": "127.0.0.1",
"Port": 5432,
"Database": "IOT_WEB",
"User": "postgres",
"Password": "kylt123",
"TenantId": 10001
}
}