Files
wind_power_cal/.agents/skills/wind-backend-conventions/SKILL.md
T
cloud 3cb7684039 更新项目 skills 并完善设计功率曲线前端
- skills: 移除 edge_collector 专属技能(OTA/协议/边缘主机/collector 等),
  保留通用工程规范(analyze-questions/cpp-coding-style/git-commit/shell-scripting/
  frontend-debug/frontend-dialog/frontend-ui-conventions),新增 wind_power_cal
  项目技能(wind-project-overview/build-run/deploy/backend-conventions/
  frontend-conventions/third-party-libs)与元技能 skill-builder;
  .agents/skills 与 .claude/skills 保持同步
- 前端: HomePage/App.css 增加设计功率曲线录入与图表展示

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-14 17:50:23 +08:00

41 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: wind-backend-conventions
description: wind_power_cal 后端 Drogon 规范。用于新增/修改后端 Controller、接口、响应、配置时,遵循 HttpController 模式与统一响应信封。
---
# 后端 Drogon 规范
## 新增 Controller
1. `backend/src/controllers/XxxController.{h,cpp}`CMake `GLOB_RECURSE src/*.cpp` 自动纳入,无需改 CMakeLists
2. 头文件继承 `drogon::HttpController<XxxController>`,用 `METHOD_LIST_BEGIN / ADD_METHOD_TO / METHOD_LIST_END` 声明路由:
```cpp
METHOD_LIST_BEGIN
ADD_METHOD_TO(XxxController::GetXxx, "/api/xxx", Get);
METHOD_LIST_END
```
3. handler 签名:`void GetXxx(const HttpRequestPtr&, std::function<void(const HttpResponsePtr&)>&& callback)`
4. `main.cpp` 注册:`app().registerController(std::make_shared<XxxController>());`
## 响应信封(必须遵守)
统一 `{"status":0,"msg":"success","data":{...}}`,用 `backend/src/utils/ResponseUtil.h`header-only,自 edge_collector 复制):
```cpp
#include "utils/ResponseUtil.h"
json data; data["version"] = "0.1.0";
SendSuccess(callback, data); // 成功带数据
SendSuccess(callback); // 成功无数据
SendError(callback, 1, "参数错误"); // 业务错误
SendForbidden(callback); // 无权限(code 3, 403
```
## include / 命名空间
- `#include <nlohmann/json.hpp>`third_party/nlohmann 已在 include path
- `main.cpp` 必须 `using namespace drogon;`,否则 `app()` / `HttpResponse` / `CT_TEXT_HTML` 未声明
## 配置 / SPA
- `backend/config/server_config.json`listener(默认 :8848)、CORS、`document_root ./web`
- SPA 回退:`app().setCustom404Page(HttpResponse::newFileResponse("./web/index.html","",CT_TEXT_HTML), false)`
## 现有 Controller
- `SystemController``/api/system/health`、`/api/system/version`
- `WindPowerController`:风电功率计算业务接口