create-dp-koa 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +50 -0
  2. package/index.mjs +97 -0
  3. package/package.json +33 -0
  4. package/template/.env.development +9 -0
  5. package/template/.env.production +12 -0
  6. package/template/.github/workflows/ci-cd.yml +182 -0
  7. package/template/.trae/documents/controller_development_plan.md +386 -0
  8. package/template/.trae/skills/00-backend-core.skill.md +50 -0
  9. package/template/.trae/skills/01-backend-skill-router.skill.md +55 -0
  10. package/template/.trae/skills/10-backend-api.skill.md +54 -0
  11. package/template/.trae/skills/11-backend-controller-recipes.skill.md +107 -0
  12. package/template/.trae/skills/20-backend-repository.skill.md +25 -0
  13. package/template/.trae/skills/21-backend-service.skill.md +135 -0
  14. package/template/.trae/skills/25-backend-comments-and-doc.skill.md +97 -0
  15. package/template/.trae/skills/30-backend-validation.skill.md +320 -0
  16. package/template/.trae/skills/40-backend-error-logging.skill.md +21 -0
  17. package/template/.trae/skills/50-backend-bootstrap-lifecycle.skill.md +90 -0
  18. package/template/.trae/skills/60-backend-router-registration.skill.md +71 -0
  19. package/template/.trae/skills/70-backend-middleware.skill.md +98 -0
  20. package/template/.trae/skills/80-backend-utils-and-libs.skill.md +90 -0
  21. package/template/.trae/skills/85-backend-plugins.rule.md +64 -0
  22. package/template/.trae/skills/90-backend-testing.skill.md +29 -0
  23. package/template/.trae/skills/README.md +49 -0
  24. package/template/.vscode/launch.json +38 -0
  25. package/template/.vscode/settings.json +1 -0
  26. package/template/Dockerfile +36 -0
  27. package/template/README.md +229 -0
  28. package/template/docker-compose.yml +135 -0
  29. package/template/docs/API_DOCUMENTATION.md +837 -0
  30. package/template/docs/ARCHITECTURE_REFACTOR.md +109 -0
  31. package/template/docs/CACHE_MIGRATION_GUIDE.md +142 -0
  32. package/template/docs/DEPLOYMENT_GUIDE.md +1062 -0
  33. package/template/docs/DEVELOPMENT_GUIDE.md +1097 -0
  34. package/template/docs/DOCUMENTATION_CLEANUP_REPORT.md +166 -0
  35. package/template/docs/DOCUMENTATION_COMPLETION_REPORT.md +223 -0
  36. package/template/docs/DOCUMENTATION_INDEX.md +294 -0
  37. package/template/docs/DOCUMENTATION_STRUCTURE.md +221 -0
  38. package/template/docs/ENTERPRISE_ANNOTATION_SYSTEM_GUIDE.md +2069 -0
  39. package/template/docs/ENTERPRISE_DATABASE_ARCHITECTURE.md +318 -0
  40. package/template/docs/ENTERPRISE_DEPLOYMENT_GUIDE.md +547 -0
  41. package/template/docs/ENTERPRISE_ERROR_HANDLING_GUIDE.md +357 -0
  42. package/template/docs/ENTERPRISE_LOGGING_SYSTEM_GUIDE.md +494 -0
  43. package/template/docs/ENVIRONMENT_CONFIG_EXAMPLE.md +69 -0
  44. package/template/docs/FINAL_IMPLEMENTATION_SUMMARY.md +206 -0
  45. package/template/docs/HEALTH_CHECK_ROUTE_FIX.md +134 -0
  46. package/template/docs/IMPLEMENTATION_CHECKLIST.md +204 -0
  47. package/template/docs/INSTALLATION_GUIDE.md +611 -0
  48. package/template/docs/INTERCEPTOR_TESTING_REPORT.md +226 -0
  49. package/template/docs/INTERCEPTOR_TESTING_SCRIPTS.md +143 -0
  50. package/template/docs/LOGGING_OPTIMIZATION_GUIDE.md +126 -0
  51. package/template/docs/MEMORY_DATABASE_GUIDE.md +212 -0
  52. package/template/docs/NEW_ROUTER_INTEGRATION_GUIDE.md +345 -0
  53. package/template/docs/NEW_ROUTER_INTEGRATION_SUMMARY.md +259 -0
  54. package/template/docs/NEW_ROUTER_USAGE_GUIDE.md +364 -0
  55. package/template/docs/QUICK_START.md +268 -0
  56. package/template/docs/ROUTE_SLASH_COMPATIBILITY_FIX.md +191 -0
  57. package/template/docs/SERVICE_INTERCEPTOR_GUIDE.md +243 -0
  58. package/template/docs/SERVICE_LAYER_INDEX.md +205 -0
  59. package/template/docs/SERVICE_PATTERN_GUIDE.md +270 -0
  60. package/template/docs/SERVICE_RETURN_VALUE_SPECIFICATION.md +466 -0
  61. package/template/docs/SWAGGER_DEBUG_MODE_GUIDE.md +80 -0
  62. package/template/docs/SWAGGER_INTEGRATION_GUIDE.md +416 -0
  63. package/template/docs/TRANSACTION_MANAGER_USAGE.md +360 -0
  64. package/template/docs/TROUBLESHOOTING.md +869 -0
  65. package/template/env.production.example +62 -0
  66. package/template/jest.config.js +34 -0
  67. package/template/package-lock.json +13240 -0
  68. package/template/package.json +119 -0
  69. package/template/patches/typeorm+0.3.25.patch +22 -0
  70. package/template/scripts/sync-template.mjs +84 -0
  71. package/template/scripts/test-annotation-system.sh +48 -0
  72. package/template/scripts/test-core-functionality.sh +28 -0
  73. package/template/src/annotations/decorators/ConfigManagement.ts +9 -0
  74. package/template/src/annotations/decorators/DistributedTracing.ts +9 -0
  75. package/template/src/annotations/decorators/EnterprisePerformance.ts +9 -0
  76. package/template/src/annotations/decorators/PerformanceMonitor.ts +32 -0
  77. package/template/src/annotations/decorators/SecurityAudit.ts +9 -0
  78. package/template/src/annotations/index.ts +50 -0
  79. package/template/src/annotations/processors/ConfigManagementProcessor.ts +369 -0
  80. package/template/src/annotations/processors/DistributedTracingProcessor.ts +288 -0
  81. package/template/src/annotations/processors/EnterprisePerformanceProcessor.ts +189 -0
  82. package/template/src/annotations/processors/PerformanceMonitorProcessor.ts +101 -0
  83. package/template/src/annotations/processors/SecurityAuditProcessor.ts +345 -0
  84. package/template/src/annotations/processors/SwaggerProcessor.ts +612 -0
  85. package/template/src/annotations/processors/index.ts +10 -0
  86. package/template/src/app.ts +123 -0
  87. package/template/src/controllers/base.controller.ts +41 -0
  88. package/template/src/controllers/cacheManagement.controller.ts +131 -0
  89. package/template/src/controllers/captcha.controller.ts +57 -0
  90. package/template/src/controllers/demo/AnnotationDemoController.ts +118 -0
  91. package/template/src/controllers/example/EnterpriseExampleController.ts +297 -0
  92. package/template/src/controllers/example/ExampleController.ts +110 -0
  93. package/template/src/controllers/example/NewAnnotationExampleController.ts +159 -0
  94. package/template/src/controllers/example/SwaggerExampleController.ts +205 -0
  95. package/template/src/controllers/example/TransactionExample.controller.ts +336 -0
  96. package/template/src/controllers/health.controller.ts +235 -0
  97. package/template/src/controllers/home/register.controller.ts +58 -0
  98. package/template/src/controllers/home/ytGoods.controller.ts +92 -0
  99. package/template/src/controllers/home/ytShop.controller.ts +135 -0
  100. package/template/src/controllers/home/ytUser.controller.ts +89 -0
  101. package/template/src/controllers/logManagement.controller.ts +396 -0
  102. package/template/src/controllers/public/emailSend.controller.ts +65 -0
  103. package/template/src/controllers/public/ytUserAuth.controller.ts +174 -0
  104. package/template/src/controllers/testData.controller.ts +253 -0
  105. package/template/src/dto/controller/example/NewAnnotationExampleController.dto.ts +73 -0
  106. package/template/src/dto/controller/home/emailSend.controller.dto.ts +40 -0
  107. package/template/src/dto/controller/home/register.controller.dto.ts +45 -0
  108. package/template/src/dto/controller/home/ytGoods.controller.dto.ts +55 -0
  109. package/template/src/dto/controller/home/ytShop.controller.dto.ts +69 -0
  110. package/template/src/dto/controller/home/ytUser.controller.dto.ts +44 -0
  111. package/template/src/dto/controller/public/ytUserAuth.controller.dto.ts +63 -0
  112. package/template/src/dto/goods.dto.ts +212 -0
  113. package/template/src/dto/service/ytService.dto.ts +13 -0
  114. package/template/src/dto/user.dto.ts +177 -0
  115. package/template/src/entity/base.entity.ts +13 -0
  116. package/template/src/entity/columnTypes.ts +13 -0
  117. package/template/src/entity/goodsImagesUnlockKey.entity.ts +33 -0
  118. package/template/src/entity/goodsUnlocker.entity.ts +34 -0
  119. package/template/src/entity/index.ts +15 -0
  120. package/template/src/entity/shop.entity.ts +52 -0
  121. package/template/src/entity/shopUser.entity.ts +41 -0
  122. package/template/src/entity/ytGoods.entity.ts +94 -0
  123. package/template/src/entity/ytUser.entity.ts +96 -0
  124. package/template/src/examples/InterceptorExampleRunner.ts +284 -0
  125. package/template/src/examples/ServiceInterceptorExample.ts +214 -0
  126. package/template/src/examples/SwaggerProcessorExample.ts +169 -0
  127. package/template/src/examples/TransactionManagerDemo.ts +377 -0
  128. package/template/src/examples/cacheExamples.ts +155 -0
  129. package/template/src/framework/decorator/controller.ts +311 -0
  130. package/template/src/framework/decorator/processor/AnnotationDecorators.ts +100 -0
  131. package/template/src/framework/decorator/processor/AnnotationProcessor.ts +156 -0
  132. package/template/src/framework/decorator/processor/AnnotationProcessorConfig.ts +45 -0
  133. package/template/src/framework/decorator/processor/AnnotationRegistry.ts +117 -0
  134. package/template/src/framework/decorator/processor/AnnotationSystemInitializer.ts +95 -0
  135. package/template/src/framework/decorator/processor/ProcessorManager.ts +76 -0
  136. package/template/src/framework/decorator/processor/processors/CustomProcessors.ts +126 -0
  137. package/template/src/framework/decorator/processor/processors/DefaultProcessors.ts +207 -0
  138. package/template/src/framework/decorator/refactored/DecoratorFactory.ts +99 -0
  139. package/template/src/framework/decorator/refactored/DecoratorMetadataManager.ts +125 -0
  140. package/template/src/framework/decorator/refactored/DecoratorValidator.ts +128 -0
  141. package/template/src/framework/decorator/refactored/TypeSafeDecorators.ts +139 -0
  142. package/template/src/framework/decorator/refactored/index.ts +98 -0
  143. package/template/src/framework/decorator/swagger.ts +150 -0
  144. package/template/src/framework/interceptors/AdvancedServiceCallInterceptor.ts +375 -0
  145. package/template/src/framework/interceptors/ServiceCallInterceptor.ts +348 -0
  146. package/template/src/framework/interceptors/index.ts +19 -0
  147. package/template/src/framework/plugins/registry.ts +63 -0
  148. package/template/src/framework/plugins/types.ts +15 -0
  149. package/template/src/framework/types/ServiceResult.ts +151 -0
  150. package/template/src/framework/types/index.ts +16 -0
  151. package/template/src/framework/utils/CacheManager.ts +430 -0
  152. package/template/src/framework/utils/CacheService.ts +248 -0
  153. package/template/src/framework/utils/DtoValidator.ts +164 -0
  154. package/template/src/framework/utils/MigrationHelper.ts +179 -0
  155. package/template/src/framework/utils/MigrationManager.ts +256 -0
  156. package/template/src/framework/utils/NewRouter.ts +207 -0
  157. package/template/src/framework/utils/TransactionManager.ts +172 -0
  158. package/template/src/framework/utils/bootstrap.ts +445 -0
  159. package/template/src/framework/utils/cache.ts +269 -0
  160. package/template/src/framework/utils/databaseConfig.ts +148 -0
  161. package/template/src/framework/utils/db.ts +39 -0
  162. package/template/src/framework/utils/dbMonitor.ts +106 -0
  163. package/template/src/framework/utils/dynamicSwagger.ts +410 -0
  164. package/template/src/framework/utils/function.ts +61 -0
  165. package/template/src/framework/utils/gracefulShutdown.ts +131 -0
  166. package/template/src/framework/utils/logger.ts +388 -0
  167. package/template/src/framework/utils/metrics.ts +182 -0
  168. package/template/src/framework/utils/router.ts +417 -0
  169. package/template/src/framework/utils/swagger.ts +184 -0
  170. package/template/src/framework/utils/testDb.ts +19 -0
  171. package/template/src/framework/utils/token.ts +23 -0
  172. package/template/src/framework/utils/transform.ts +17 -0
  173. package/template/src/libs/aokEmailSender.ts +42 -0
  174. package/template/src/libs/captcha.ts +37 -0
  175. package/template/src/libs/cos.ts +45 -0
  176. package/template/src/libs/mCache.ts +7 -0
  177. package/template/src/libs/serviceValidate.ts +3 -0
  178. package/template/src/libs/tecentSms.ts +51 -0
  179. package/template/src/middlewares/a.middleware.ts +6 -0
  180. package/template/src/middlewares/error.middleware.ts +14 -0
  181. package/template/src/middlewares/logging.middleware.ts +187 -0
  182. package/template/src/middlewares/static.middleware.ts +79 -0
  183. package/template/src/middlewares/swagger.middleware.ts +70 -0
  184. package/template/src/middlewares/token.middleware.ts +32 -0
  185. package/template/src/migrations/1700000000000-InitialDatabaseStructure.ts +172 -0
  186. package/template/src/migrations/index.ts +6 -0
  187. package/template/src/plugins/weboffice/core/context.ts +47 -0
  188. package/template/src/plugins/weboffice/core/errors.ts +51 -0
  189. package/template/src/plugins/weboffice/core/types.ts +63 -0
  190. package/template/src/plugins/weboffice/core/utils.ts +7 -0
  191. package/template/src/plugins/weboffice/entities/index.ts +3 -0
  192. package/template/src/plugins/weboffice/entities/webofficeFile.entity.ts +28 -0
  193. package/template/src/plugins/weboffice/entities/webofficeFileVersion.entity.ts +29 -0
  194. package/template/src/plugins/weboffice/http/routes.ts +179 -0
  195. package/template/src/plugins/weboffice/index.ts +23 -0
  196. package/template/src/plugins/weboffice/services/webofficeCallback.service.ts +274 -0
  197. package/template/src/repository/UserRepository.ts +122 -0
  198. package/template/src/repository/base/BaseRepository.ts +124 -0
  199. package/template/src/repository/interfaces/IBaseRepository.ts +67 -0
  200. package/template/src/routers/index.ts +49 -0
  201. package/template/src/service/base.service.ts +116 -0
  202. package/template/src/service/paramValidateTest.service.ts +139 -0
  203. package/template/src/service/ytGoods.service.ts +42 -0
  204. package/template/src/service/ytShop.service.ts +90 -0
  205. package/template/src/service/ytUser.service.ts +451 -0
  206. package/template/src/test/swaggerParameterTest.ts +90 -0
  207. package/template/src/utils/testDataInitializer.ts +296 -0
  208. package/template/static/output.json +15203 -0
  209. package/template/test/controllers/controllers.test.ts +173 -0
  210. package/template/test/controllers/example/ExampleController.test.ts +222 -0
  211. package/template/test/controllers/example/NewAnnotationExampleController.test.ts +200 -0
  212. package/template/test/framework/TransactionManagerDemo.test.ts +363 -0
  213. package/template/test/framework/annotation/AnnotationDecorators.test.ts +222 -0
  214. package/template/test/framework/annotation/AnnotationExecutor.test.ts +246 -0
  215. package/template/test/framework/annotation/AnnotationProcessor.test.ts +179 -0
  216. package/template/test/framework/annotation/CustomProcessors.test.ts +313 -0
  217. package/template/test/framework/annotation/DefaultProcessors.test.ts +371 -0
  218. package/template/test/framework/annotation/NewRouter.test.ts +272 -0
  219. package/template/test/framework/annotation/ProcessorManager.test.ts +248 -0
  220. package/template/test/framework/annotation/setup.ts +26 -0
  221. package/template/test/framework/cache.test.ts +101 -0
  222. package/template/test/framework/databaseConfig.test.ts +142 -0
  223. package/template/test/integration/integration.test.ts +153 -0
  224. package/template/test/plugins/weboffice/http.routes.int.test.ts +61 -0
  225. package/template/test/service/business.test.ts +87 -0
  226. package/template/test/service/paramValidateTest.service.test.ts +184 -0
  227. package/template/test/service/ytUser.service.test.ts +566 -0
  228. package/template/test/setup.ts +20 -0
  229. package/template/test/setupAfterEnv.ts +14 -0
  230. package/template/test/utils/testHelpers.ts +220 -0
  231. package/template/test_output.txt +0 -0
  232. package/template/tsconfig.build.json +17 -0
  233. package/template/tsconfig.json +31 -0
  234. package/template/webpack.config.js +71 -0
  235. package/template/yarn.lock +7354 -0
@@ -0,0 +1,837 @@
1
+ # API 文档
2
+
3
+ DP-Koa Framework 提供完整的 RESTful API 接口,支持用户管理、商品管理、店铺管理等功能。
4
+
5
+ ## 📋 目录
6
+
7
+ - [API 概览](#api-概览)
8
+ - [认证授权](#认证授权)
9
+ - [用户管理 API](#用户管理-api)
10
+ - [商品管理 API](#商品管理-api)
11
+ - [店铺管理 API](#店铺管理-api)
12
+ - [系统管理 API](#系统管理-api)
13
+ - [健康检查 API](#健康检查-api)
14
+ - [错误处理](#错误处理)
15
+ - [响应格式](#响应格式)
16
+ - [示例代码](#示例代码)
17
+
18
+ ## 🌐 API 概览
19
+
20
+ ### 基础信息
21
+
22
+ - **Base URL**: `http://localhost:3000`
23
+ - **API 版本**: v1
24
+ - **协议**: HTTP/HTTPS
25
+ - **数据格式**: JSON
26
+ - **字符编码**: UTF-8
27
+
28
+ ### 接口分类
29
+
30
+ | 分类 | 路径前缀 | 描述 |
31
+ |------|----------|------|
32
+ | 用户管理 | `/home/user/yt_user` | 用户相关操作 |
33
+ | 商品管理 | `/home/goods/common` | 商品相关操作 |
34
+ | 店铺管理 | `/home/shop/common` | 店铺相关操作 |
35
+ | 认证授权 | `/public/auth/yt_user` | 用户认证 |
36
+ | 系统管理 | `/admin/*` | 管理员功能 |
37
+ | 健康检查 | `/health` | 系统状态检查 |
38
+
39
+ ### Swagger 文档
40
+
41
+ - **Swagger UI**: http://localhost:3000/swagger-ui
42
+ - **Swagger JSON**: http://localhost:3000/swagger.json
43
+
44
+ ## 🔐 认证授权
45
+
46
+ ### JWT Token 认证
47
+
48
+ 大部分 API 需要 JWT Token 认证,请在请求头中包含:
49
+
50
+ ```http
51
+ Authorization: Bearer <your-jwt-token>
52
+ ```
53
+
54
+ ### 获取 Token
55
+
56
+ ```http
57
+ POST /public/auth/yt_user/login
58
+ Content-Type: application/json
59
+
60
+ {
61
+ "email": "user@example.com",
62
+ "password": "password123"
63
+ }
64
+ ```
65
+
66
+ **响应示例**:
67
+ ```json
68
+ {
69
+ "code": 0,
70
+ "data": {
71
+ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
72
+ "user": {
73
+ "id": 1,
74
+ "email": "user@example.com",
75
+ "nickName": "用户昵称"
76
+ }
77
+ },
78
+ "message": "登录成功"
79
+ }
80
+ ```
81
+
82
+ ## 👤 用户管理 API
83
+
84
+ ### 获取用户信息
85
+
86
+ 获取当前登录用户的详细信息。
87
+
88
+ ```http
89
+ GET /home/user/yt_user
90
+ Authorization: Bearer <token>
91
+ ```
92
+
93
+ **响应示例**:
94
+ ```json
95
+ {
96
+ "code": 0,
97
+ "data": {
98
+ "id": 1,
99
+ "nickName": "用户昵称",
100
+ "status": "normal",
101
+ "email": "user@example.com",
102
+ "type": "CUSTOMER",
103
+ "avatar": "https://example.com/avatar.jpg",
104
+ "gender": 1,
105
+ "age": 25,
106
+ "constellation": "天秤座"
107
+ },
108
+ "message": ""
109
+ }
110
+ ```
111
+
112
+ **字段说明**:
113
+ - `id`: 用户ID
114
+ - `nickName`: 用户昵称
115
+ - `status`: 用户状态 (`normal` | `forbidden`)
116
+ - `email`: 邮箱地址
117
+ - `type`: 用户类型 (`CUSTOMER` | `SHOP`)
118
+ - `avatar`: 头像URL
119
+ - `gender`: 性别 (0: 未知, 1: 男, 2: 女)
120
+ - `age`: 年龄
121
+ - `constellation`: 星座
122
+
123
+ ### 检查用户店铺
124
+
125
+ 检查当前用户是否拥有店铺。
126
+
127
+ ```http
128
+ GET /home/user/yt_user/hasShop
129
+ Authorization: Bearer <token>
130
+ ```
131
+
132
+ **响应示例**:
133
+ ```json
134
+ {
135
+ "code": 0,
136
+ "data": 1,
137
+ "message": ""
138
+ }
139
+ ```
140
+
141
+ **字段说明**:
142
+ - `data`: 店铺ID,如果为 `null` 表示用户没有店铺
143
+
144
+ ## 🛍️ 商品管理 API
145
+
146
+ ### 获取商品信息
147
+
148
+ 根据商品ID获取商品详细信息。
149
+
150
+ ```http
151
+ GET /home/goods/common?id=1
152
+ Authorization: Bearer <token>
153
+ ```
154
+
155
+ **请求参数**:
156
+ - `id` (required): 商品ID
157
+
158
+ **响应示例**:
159
+ ```json
160
+ {
161
+ "code": 0,
162
+ "data": {
163
+ "id": 1,
164
+ "name": "商品名称",
165
+ "albums": ["https://example.com/image1.jpg", "https://example.com/image2.jpg"],
166
+ "tags": ["标签1", "标签2"],
167
+ "price": 99.99,
168
+ "description": "商品描述",
169
+ "content": "商品详细内容",
170
+ "imagesContent": "图片内容描述"
171
+ },
172
+ "message": ""
173
+ }
174
+ ```
175
+
176
+ **字段说明**:
177
+ - `id`: 商品ID
178
+ - `name`: 商品名称
179
+ - `albums`: 商品图片数组
180
+ - `tags`: 商品标签数组
181
+ - `price`: 商品价格
182
+ - `description`: 商品描述
183
+ - `content`: 商品详细内容
184
+ - `imagesContent`: 图片内容描述
185
+
186
+ ### 解锁商品图片
187
+
188
+ 使用密钥解锁商品图片。
189
+
190
+ ```http
191
+ POST /home/goods/common/unlockGoodsImage
192
+ Authorization: Bearer <token>
193
+ Content-Type: application/json
194
+
195
+ {
196
+ "goodsId": 1,
197
+ "key": "unlock_key_123"
198
+ }
199
+ ```
200
+
201
+ **请求参数**:
202
+ - `goodsId` (required): 商品ID
203
+ - `key` (required): 解锁密钥
204
+
205
+ **响应示例**:
206
+ ```json
207
+ {
208
+ "code": 0,
209
+ "data": true,
210
+ "message": ""
211
+ }
212
+ ```
213
+
214
+ ### 检查商品解锁状态
215
+
216
+ 检查用户是否已解锁指定商品。
217
+
218
+ ```http
219
+ GET /home/goods/common/getGoodsUnlockInfo?goodsId=1
220
+ Authorization: Bearer <token>
221
+ ```
222
+
223
+ **请求参数**:
224
+ - `goodsId` (required): 商品ID
225
+
226
+ **响应示例**:
227
+ ```json
228
+ {
229
+ "code": 0,
230
+ "data": true,
231
+ "message": ""
232
+ }
233
+ ```
234
+
235
+ **字段说明**:
236
+ - `data`: `true` 表示已解锁,`false` 表示未解锁
237
+
238
+ ## 🏪 店铺管理 API
239
+
240
+ ### 店铺相关接口
241
+
242
+ 店铺管理相关接口请参考具体的店铺控制器实现。
243
+
244
+ ## ⚙️ 系统管理 API
245
+
246
+ ### 缓存管理
247
+
248
+ #### 获取缓存统计信息
249
+
250
+ ```http
251
+ GET /admin/cache/stats
252
+ Authorization: Bearer <admin-token>
253
+ ```
254
+
255
+ **响应示例**:
256
+ ```json
257
+ {
258
+ "code": 0,
259
+ "data": {
260
+ "totalKeys": 150,
261
+ "hitRate": 0.85,
262
+ "memoryUsage": "2.5MB"
263
+ },
264
+ "message": ""
265
+ }
266
+ ```
267
+
268
+ #### 清理指定缓存
269
+
270
+ ```http
271
+ DELETE /admin/cache/clear?pattern=user_*
272
+ Authorization: Bearer <admin-token>
273
+ ```
274
+
275
+ **请求参数**:
276
+ - `pattern`: 缓存键模式,支持通配符
277
+
278
+ #### 清理所有缓存
279
+
280
+ ```http
281
+ DELETE /admin/cache/clearAll
282
+ Authorization: Bearer <admin-token>
283
+ ```
284
+
285
+ ### 日志管理
286
+
287
+ #### 获取日志列表
288
+
289
+ ```http
290
+ GET /admin/logs?level=error&limit=50
291
+ Authorization: Bearer <admin-token>
292
+ ```
293
+
294
+ **请求参数**:
295
+ - `level` (optional): 日志级别 (`error` | `warn` | `info` | `debug`)
296
+ - `limit` (optional): 返回条数限制,默认100
297
+
298
+ **响应示例**:
299
+ ```json
300
+ {
301
+ "code": 0,
302
+ "data": [
303
+ {
304
+ "timestamp": "2024-01-01T12:00:00.000Z",
305
+ "level": "error",
306
+ "message": "数据库连接失败",
307
+ "context": {
308
+ "userId": 1,
309
+ "action": "login"
310
+ }
311
+ }
312
+ ],
313
+ "message": ""
314
+ }
315
+ ```
316
+
317
+ #### 下载日志文件
318
+
319
+ ```http
320
+ GET /admin/logs/download?date=2024-01-01&type=error
321
+ Authorization: Bearer <admin-token>
322
+ ```
323
+
324
+ **请求参数**:
325
+ - `date`: 日志日期 (YYYY-MM-DD)
326
+ - `type`: 日志类型 (`error` | `access` | `performance`)
327
+
328
+ ## 🏥 健康检查 API
329
+
330
+ ### 基础健康检查
331
+
332
+ 检查应用整体健康状态。
333
+
334
+ ```http
335
+ GET /health
336
+ ```
337
+
338
+ **响应示例**:
339
+ ```json
340
+ {
341
+ "code": 0,
342
+ "data": {
343
+ "status": "ok",
344
+ "timestamp": "2024-01-01T12:00:00.000Z",
345
+ "database": {
346
+ "connected": true,
347
+ "pool": {
348
+ "active": 5,
349
+ "idle": 10,
350
+ "total": 15
351
+ }
352
+ },
353
+ "cache": {
354
+ "stats": {
355
+ "keys": 150,
356
+ "hitRate": 0.85
357
+ },
358
+ "memory": {
359
+ "used": "2.5MB",
360
+ "total": "10MB"
361
+ }
362
+ },
363
+ "uptime": 3600,
364
+ "memory": {
365
+ "used": 128,
366
+ "total": 256,
367
+ "rss": 200
368
+ }
369
+ },
370
+ "message": ""
371
+ }
372
+ ```
373
+
374
+ ### 数据库健康检查
375
+
376
+ 专门检查数据库连接状态。
377
+
378
+ ```http
379
+ GET /health/db
380
+ ```
381
+
382
+ **响应示例**:
383
+ ```json
384
+ {
385
+ "code": 0,
386
+ "data": {
387
+ "connected": true,
388
+ "pool": {
389
+ "active": 5,
390
+ "idle": 10,
391
+ "total": 15
392
+ }
393
+ },
394
+ "message": ""
395
+ }
396
+ ```
397
+
398
+ ### 缓存健康检查
399
+
400
+ 检查缓存系统状态。
401
+
402
+ ```http
403
+ GET /health/cache
404
+ ```
405
+
406
+ **响应示例**:
407
+ ```json
408
+ {
409
+ "code": 0,
410
+ "data": {
411
+ "stats": {
412
+ "keys": 150,
413
+ "hitRate": 0.85
414
+ },
415
+ "memory": {
416
+ "used": "2.5MB",
417
+ "total": "10MB"
418
+ },
419
+ "status": "healthy"
420
+ },
421
+ "message": ""
422
+ }
423
+ ```
424
+
425
+ ### 详细健康检查
426
+
427
+ 企业级详细健康检查,包含所有系统组件状态。
428
+
429
+ ```http
430
+ GET /health/detailed
431
+ ```
432
+
433
+ **响应示例**:
434
+ ```json
435
+ {
436
+ "code": 0,
437
+ "data": {
438
+ "status": "healthy",
439
+ "timestamp": "2024-01-01T12:00:00.000Z",
440
+ "uptime": 3600,
441
+ "pid": 12345,
442
+ "version": "1.0.0",
443
+ "environment": "production",
444
+ "checks": {
445
+ "database": {
446
+ "status": "healthy",
447
+ "message": "Database connection OK",
448
+ "type": "mysql"
449
+ },
450
+ "memory": {
451
+ "status": "healthy",
452
+ "message": "Memory usage OK",
453
+ "details": {
454
+ "heapUsed": 128000000,
455
+ "heapTotal": 256000000,
456
+ "rss": 200000000,
457
+ "external": 5000000
458
+ }
459
+ },
460
+ "cache": {
461
+ "status": "healthy",
462
+ "message": "Cache status OK",
463
+ "details": {
464
+ "stats": {
465
+ "keys": 150,
466
+ "hitRate": 0.85
467
+ },
468
+ "memory": {
469
+ "used": "2.5MB",
470
+ "total": "10MB"
471
+ }
472
+ }
473
+ }
474
+ }
475
+ },
476
+ "message": ""
477
+ }
478
+ ```
479
+
480
+ ### 就绪检查
481
+
482
+ Kubernetes 就绪探针。
483
+
484
+ ```http
485
+ GET /ready
486
+ ```
487
+
488
+ **响应示例**:
489
+ ```json
490
+ {
491
+ "code": 0,
492
+ "data": {
493
+ "status": "ready",
494
+ "timestamp": "2024-01-01T12:00:00.000Z",
495
+ "checks": {
496
+ "database": {
497
+ "status": "healthy"
498
+ }
499
+ }
500
+ },
501
+ "message": ""
502
+ }
503
+ ```
504
+
505
+ ### 存活检查
506
+
507
+ Kubernetes 存活探针。
508
+
509
+ ```http
510
+ GET /live
511
+ ```
512
+
513
+ **响应示例**:
514
+ ```json
515
+ {
516
+ "code": 0,
517
+ "data": {
518
+ "status": "alive",
519
+ "timestamp": "2024-01-01T12:00:00.000Z",
520
+ "pid": 12345,
521
+ "uptime": 3600
522
+ },
523
+ "message": ""
524
+ }
525
+ ```
526
+
527
+ ### 系统指标
528
+
529
+ 获取系统性能指标。
530
+
531
+ ```http
532
+ GET /metrics
533
+ ```
534
+
535
+ **响应示例**:
536
+ ```json
537
+ {
538
+ "code": 0,
539
+ "data": {
540
+ "prometheus": "# HELP http_requests_total Total number of HTTP requests\n# TYPE http_requests_total counter\nhttp_requests_total{method=\"GET\",status=\"200\"} 1000",
541
+ "json": {
542
+ "requests": {
543
+ "total": 1000,
544
+ "success": 950,
545
+ "error": 50
546
+ },
547
+ "responseTime": {
548
+ "avg": 150,
549
+ "p95": 300,
550
+ "p99": 500
551
+ }
552
+ }
553
+ },
554
+ "message": ""
555
+ }
556
+ ```
557
+
558
+ ## ❌ 错误处理
559
+
560
+ ### 错误响应格式
561
+
562
+ 所有 API 错误都遵循统一的响应格式:
563
+
564
+ ```json
565
+ {
566
+ "code": 400,
567
+ "data": null,
568
+ "message": "错误描述信息"
569
+ }
570
+ ```
571
+
572
+ ### 常见错误码
573
+
574
+ | 错误码 | 描述 | 说明 |
575
+ |--------|------|------|
576
+ | 0 | 成功 | 请求处理成功 |
577
+ | 400 | 请求错误 | 请求参数错误或格式不正确 |
578
+ | 401 | 未授权 | 缺少认证信息或Token无效 |
579
+ | 403 | 禁止访问 | 权限不足 |
580
+ | 404 | 资源不存在 | 请求的资源不存在 |
581
+ | 409 | 冲突 | 资源冲突(如邮箱已存在) |
582
+ | 429 | 请求过多 | 触发速率限制 |
583
+ | 500 | 服务器错误 | 服务器内部错误 |
584
+ | -1 | 业务错误 | 业务逻辑错误 |
585
+
586
+ ### 错误示例
587
+
588
+ #### 认证失败
589
+
590
+ ```json
591
+ {
592
+ "code": 401,
593
+ "data": null,
594
+ "message": "Token无效或已过期"
595
+ }
596
+ ```
597
+
598
+ #### 参数错误
599
+
600
+ ```json
601
+ {
602
+ "code": 400,
603
+ "data": null,
604
+ "message": "缺少必需参数: id"
605
+ }
606
+ ```
607
+
608
+ #### 资源不存在
609
+
610
+ ```json
611
+ {
612
+ "code": 404,
613
+ "data": null,
614
+ "message": "用户不存在"
615
+ }
616
+ ```
617
+
618
+ #### 业务错误
619
+
620
+ ```json
621
+ {
622
+ "code": -1,
623
+ "data": null,
624
+ "message": "解锁密钥错误"
625
+ }
626
+ ```
627
+
628
+ ## 📊 响应格式
629
+
630
+ ### 成功响应
631
+
632
+ 所有成功的 API 响应都遵循以下格式:
633
+
634
+ ```json
635
+ {
636
+ "code": 0,
637
+ "data": <响应数据>,
638
+ "message": "成功信息(可选)"
639
+ }
640
+ ```
641
+
642
+ ### 分页响应
643
+
644
+ 对于列表接口,支持分页响应:
645
+
646
+ ```json
647
+ {
648
+ "code": 0,
649
+ "data": {
650
+ "items": [...],
651
+ "pagination": {
652
+ "page": 1,
653
+ "size": 20,
654
+ "total": 100,
655
+ "totalPages": 5
656
+ }
657
+ },
658
+ "message": ""
659
+ }
660
+ ```
661
+
662
+ ### 缓存响应头
663
+
664
+ 支持缓存控制的响应头:
665
+
666
+ ```http
667
+ HTTP/1.1 200 OK
668
+ Content-Type: application/json
669
+ Cache-Control: public, max-age=300
670
+ ETag: "abc123"
671
+ Last-Modified: Wed, 01 Jan 2024 12:00:00 GMT
672
+ ```
673
+
674
+ ## 💻 示例代码
675
+
676
+ ### JavaScript/TypeScript
677
+
678
+ ```typescript
679
+ // 用户认证
680
+ async function login(email: string, password: string) {
681
+ const response = await fetch('/public/auth/yt_user/login', {
682
+ method: 'POST',
683
+ headers: {
684
+ 'Content-Type': 'application/json'
685
+ },
686
+ body: JSON.stringify({ email, password })
687
+ });
688
+
689
+ const result = await response.json();
690
+ if (result.code === 0) {
691
+ localStorage.setItem('token', result.data.token);
692
+ return result.data.user;
693
+ } else {
694
+ throw new Error(result.message);
695
+ }
696
+ }
697
+
698
+ // 获取用户信息
699
+ async function getUserInfo() {
700
+ const token = localStorage.getItem('token');
701
+ const response = await fetch('/home/user/yt_user', {
702
+ headers: {
703
+ 'Authorization': `Bearer ${token}`
704
+ }
705
+ });
706
+
707
+ const result = await response.json();
708
+ if (result.code === 0) {
709
+ return result.data;
710
+ } else {
711
+ throw new Error(result.message);
712
+ }
713
+ }
714
+
715
+ // 获取商品信息
716
+ async function getGoodsInfo(goodsId: number) {
717
+ const token = localStorage.getItem('token');
718
+ const response = await fetch(`/home/goods/common?id=${goodsId}`, {
719
+ headers: {
720
+ 'Authorization': `Bearer ${token}`
721
+ }
722
+ });
723
+
724
+ const result = await response.json();
725
+ if (result.code === 0) {
726
+ return result.data;
727
+ } else {
728
+ throw new Error(result.message);
729
+ }
730
+ }
731
+ ```
732
+
733
+ ### Python
734
+
735
+ ```python
736
+ import requests
737
+ import json
738
+
739
+ class DPKoaClient:
740
+ def __init__(self, base_url='http://localhost:3000'):
741
+ self.base_url = base_url
742
+ self.token = None
743
+
744
+ def login(self, email, password):
745
+ url = f"{self.base_url}/public/auth/yt_user/login"
746
+ data = {"email": email, "password": password}
747
+
748
+ response = requests.post(url, json=data)
749
+ result = response.json()
750
+
751
+ if result['code'] == 0:
752
+ self.token = result['data']['token']
753
+ return result['data']['user']
754
+ else:
755
+ raise Exception(result['message'])
756
+
757
+ def get_user_info(self):
758
+ if not self.token:
759
+ raise Exception("请先登录")
760
+
761
+ url = f"{self.base_url}/home/user/yt_user"
762
+ headers = {"Authorization": f"Bearer {self.token}"}
763
+
764
+ response = requests.get(url, headers=headers)
765
+ result = response.json()
766
+
767
+ if result['code'] == 0:
768
+ return result['data']
769
+ else:
770
+ raise Exception(result['message'])
771
+
772
+ def get_goods_info(self, goods_id):
773
+ if not self.token:
774
+ raise Exception("请先登录")
775
+
776
+ url = f"{self.base_url}/home/goods/common"
777
+ headers = {"Authorization": f"Bearer {self.token}"}
778
+ params = {"id": goods_id}
779
+
780
+ response = requests.get(url, headers=headers, params=params)
781
+ result = response.json()
782
+
783
+ if result['code'] == 0:
784
+ return result['data']
785
+ else:
786
+ raise Exception(result['message'])
787
+
788
+ # 使用示例
789
+ client = DPKoaClient()
790
+ user = client.login('user@example.com', 'password123')
791
+ print(f"登录成功: {user['nickName']}")
792
+
793
+ user_info = client.get_user_info()
794
+ print(f"用户信息: {user_info}")
795
+
796
+ goods_info = client.get_goods_info(1)
797
+ print(f"商品信息: {goods_info}")
798
+ ```
799
+
800
+ ### cURL
801
+
802
+ ```bash
803
+ # 用户登录
804
+ curl -X POST http://localhost:3000/public/auth/yt_user/login \
805
+ -H "Content-Type: application/json" \
806
+ -d '{"email":"user@example.com","password":"password123"}'
807
+
808
+ # 获取用户信息
809
+ curl -X GET http://localhost:3000/home/user/yt_user \
810
+ -H "Authorization: Bearer YOUR_JWT_TOKEN"
811
+
812
+ # 获取商品信息
813
+ curl -X GET "http://localhost:3000/home/goods/common?id=1" \
814
+ -H "Authorization: Bearer YOUR_JWT_TOKEN"
815
+
816
+ # 健康检查
817
+ curl -X GET http://localhost:3000/health
818
+
819
+ # 详细健康检查
820
+ curl -X GET http://localhost:3000/health/detailed
821
+ ```
822
+
823
+ ## 📚 相关文档
824
+
825
+ - [快速开始指南](QUICK_START.md) - 5分钟快速上手
826
+ - [开发指南](DEVELOPMENT_GUIDE.md) - 开发规范和最佳实践
827
+ - [Swagger 集成指南](SWAGGER_INTEGRATION_GUIDE.md) - Swagger 文档配置
828
+ - [故障排除指南](TROUBLESHOOTING.md) - 常见问题解决
829
+
830
+ ---
831
+
832
+ **相关链接**:
833
+ - [Swagger UI](http://localhost:3000/swagger-ui) - 在线 API 文档
834
+ - [健康检查](http://localhost:3000/health) - 系统状态检查
835
+ - [系统指标](http://localhost:3000/metrics) - 性能指标
836
+
837
+