Compare commits
25 Commits
aa429e9b40
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5affbe8179 | |||
| 88c597205b | |||
| 088832d33c | |||
| dc5e8b4cc3 | |||
| 8a19c5dadb | |||
| 7ec3446da3 | |||
| fb79d4990e | |||
| 7ec12d91da | |||
| 9e2c73790c | |||
| a6c9cf508f | |||
| 27ff0ec1a7 | |||
| 33fff4a34e | |||
| 0a838d7ca9 | |||
| be866f9980 | |||
| b27ac93fef | |||
| 1015094a7c | |||
| 922b660ca6 | |||
| a96372fc4d | |||
| 34b18df044 | |||
| 0db2f2f15f | |||
| 66a663fb27 | |||
| 1f4bea92d1 | |||
| 57fe9a216f | |||
| e51130e6ba | |||
| a59e0b8ade |
@@ -1,177 +0,0 @@
|
|||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
---
|
|
||||||
name: frontend-design
|
|
||||||
description: Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
|
|
||||||
license: Complete terms in LICENSE.txt
|
|
||||||
---
|
|
||||||
|
|
||||||
# Frontend Design
|
|
||||||
|
|
||||||
Approach this as the design lead at a small studio known for giving every client a visual identity that could not be mistaken for anyone else's. This client has already rejected proposals that felt templated, and is paying for a distinctive point of view: make deliberate, opinionated choices about palette, typography, and layout that are specific to this brief, and take one real aesthetic risk you can justify.
|
|
||||||
|
|
||||||
## Ground it in the subject
|
|
||||||
|
|
||||||
If the brief does not pin down what the product or subject is, pin it yourself before designing: name one concrete subject, its audience, and the page's single job, and state your choice. If there's any information in your memory about the human's preferences, context about what they're building, or designs you've made before – use that as a hint. The subject's own world, its materials, instruments, artifacts, and vernacular, is where distinctive choices come from. Build with the brief's real content and subject matter throughout.
|
|
||||||
|
|
||||||
## Design principles
|
|
||||||
|
|
||||||
For web designs, the hero is a thesis. Open with the most characteristic thing in the subject's world, in whatever form makes sense for it: a headline, an image, an animation, a live demo, an interactive moment. Be deliberate with your choice: a big number with a small label, supporting stats, and a gradient accent is the template answer, only use if that's truly the best option.
|
|
||||||
|
|
||||||
Typography carries the personality of the page. Pair the display and body faces deliberately, not the same families you would reach for on any other project, and set a clear type scale with intentional weights, widths, and spacing. Make the type treatment itself a memorable part of the design, not a neutral delivery vehicle for the content.
|
|
||||||
|
|
||||||
Structure is information. Structural devices, numbering, eyebrows, dividers, labels, should encode something true about the content, not decorate it. Many generic designs use numbered markers (01 / 02 / 03), but that's only appropriate if the content actually is a sequence - like a real process or a typed timeline where order carries information the reader needs. Question if choices like numbered markers actually make sense before incorporating them.
|
|
||||||
|
|
||||||
Leverage motion deliberately. Think about where and if animation can serve the subject: a page-load sequence, a scroll-triggered reveal, hover micro-interactions, ambient atmosphere. An orchestrated moment usually lands harder than scattered effects; choose what the direction calls for. However, sometimes less is more, and extra animation contributes to the feeling that the design is AI-generated.
|
|
||||||
|
|
||||||
Match complexity to the vision. Maximalist directions need elaborate execution; minimal directions need precision in spacing, type, and detail. Elegance is executing the chosen vision well.
|
|
||||||
|
|
||||||
Consider written content carefully. Often a design brief may not contain real content, and it's up to you to come up with copy. Copy can make a design feel as templated as the design itself. See the below section on writing for more guidance.
|
|
||||||
|
|
||||||
## Process: brainstorm, explore, plan, critique, build, critique again
|
|
||||||
|
|
||||||
For calibration: AI-generated design right now clusters around three looks: (1) a warm cream background (near #F4F1EA) with a high-contrast serif display and a terracotta accent; (2) a near-black background with a single bright acid-green or vermilion accent; (3) a broadsheet-style layout with hairline rules, zero border-radius, and dense newspaper-like columns. All three are legitimate for some briefs, but they are defaults rather than choices, and they appear regardless of subject. Where the brief pins down a visual direction, follow it exactly — the brief's own words always win, including when it asks for one of these looks. Where it leaves an axis free, don't spend that freedom on one of these defaults. Just like a human designer who's hired, there's often a careful balance between doing what you're good at and taking each project as a chance to experiment and learn.
|
|
||||||
|
|
||||||
Work in two passes. First, brainstorm a short design plan based on the human's design brief: create a compact token system with color, type, layout, and signature. Color: describe the palette as 4–6 named hex values. Type: the typefaces for 2+ roles (a characterful display face that's used with restraint, a complementary body face, and a utility face for captions or data if needed). Layout: a layout concept, using one-sentence prose descriptions and ASCII wireframes to ideate and compare. Signature: the single unique element this page will be remembered by that embodies the brief in an appropriate way.
|
|
||||||
|
|
||||||
Then review that plan against the brief before building: if any part of it reads like the generic default you would produce for any similar page (work through a similar prompt to see if you arrive somewhere similar) rather than a choice made for this specific brief — revise that part, say what you changed and why. Only after you've confirmed the relative uniqueness of your design plan should you start to write the code, following the revised plan exactly and deriving every color and type decision from it.
|
|
||||||
|
|
||||||
When writing the code, be careful of structuring your CSS selector specificities. It's easy to generate CSS classes that cancel each other out (especially with a type-based selector like .section and a element-based selector like .cta). This can happen often with paddings/margins between sections.
|
|
||||||
|
|
||||||
Try to do a lot of this planning and iteration in your thinking, and only show ideas to the user when you have higher confidence it'll delight them.
|
|
||||||
|
|
||||||
## Restraint and self-critique
|
|
||||||
|
|
||||||
Spend your boldness in one place. Let the signature element be the one memorable thing, keep everything around it quiet and disciplined, and cut any decoration that does not serve the brief. Not taking a risk can be a risk itself! Build to a quality floor without announcing it: responsive down to mobile, visible keyboard focus, reduced motion respected. Critique your own work as you build, taking screenshots if your environment supports it – a picture is worth 1000 tokens. Consider Chanel's advice: before leaving the house, take a look in the mirror and remove one accessory. Human creators have memory and always try to do something new, so if you have a space to quickly jot down notes about what you've tried, it can help you in future passes.
|
|
||||||
|
|
||||||
## More on writing in design
|
|
||||||
|
|
||||||
Words appear in a design for one reason: to make it easier to understand, and therefore easier to use. They are design material, not decoration. Bring the same intentionality to copy that you would bring to spacing and color. Before writing anything, ask what the design needs to say, and how it can best be said to help the person navigate the experience.
|
|
||||||
|
|
||||||
Write from the end user's side of the screen. Name things by what people control and recognize, never by how the system is built. A person manages notifications, not webhook config. Describe what something does in plain terms rather than selling it. Being specific is always better than being clever.
|
|
||||||
|
|
||||||
Use active voice as default. A control should say exactly what happens when it's used: "Save changes," not "Submit." An action keeps the same name through the whole flow, so the button that says "Publish" produces a toast that says "Published." The vocabulary of an interface is the signposting for someone navigating the product. Cohesion and consistency are how people learn their way around.
|
|
||||||
|
|
||||||
Treat failure and emptiness as moments for direction, not mood. Explain what went wrong and how to fix it, in the interface's voice rather than a person's. Errors don't apologize, and they are never vague about what happened. An empty screen is an invitation to act.
|
|
||||||
|
|
||||||
Keep the register conversational and tuned: plain verbs, sentence case, no filler, with tone matched to the brand and the audience. Let each element do exactly one job. A label labels, an example demonstrates, and nothing quietly does double duty.
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
---
|
|
||||||
name: frontend-spec
|
|
||||||
version: 1.0.0
|
|
||||||
description: 企业级前端开发规范 Skill,包含命名、目录、CSS/JS/TS、Vue/React、Git、构建、性能、安全完整规范
|
|
||||||
trigger: 前端规范|代码规范|命名规范|目录规范|css规范|js规范|ts规范|vue规范|react规范|git规范|eslint规范|前端最佳实践
|
|
||||||
author: huhu
|
|
||||||
license: MIT-0
|
|
||||||
---
|
|
||||||
|
|
||||||
# 前端开发规范 Skill(企业级)
|
|
||||||
|
|
||||||
本 Skill 提供**完整、可落地、团队统一**的前端开发规范,适用于中后台、移动端、Web 应用。
|
|
||||||
|
|
||||||
## 覆盖范围
|
|
||||||
- 项目结构与目录规范
|
|
||||||
- 文件命名规范
|
|
||||||
- HTML 编写规范
|
|
||||||
- CSS / SCSS 规范
|
|
||||||
- JavaScript / TypeScript 规范
|
|
||||||
- Vue / React 编码规范
|
|
||||||
- Git 提交规范
|
|
||||||
- ESLint / Prettier 规范
|
|
||||||
- 构建与性能优化规范
|
|
||||||
- 安全规范
|
|
||||||
|
|
||||||
## 使用方式
|
|
||||||
你可以直接问:
|
|
||||||
- 前端项目目录怎么设计?
|
|
||||||
- JS 变量命名有什么规范?
|
|
||||||
- Vue 组件编写最佳实践
|
|
||||||
- Git commit 信息怎么写?
|
|
||||||
- 如何配置 ESLint 规范?
|
|
||||||
- 前端性能优化有哪些规则?
|
|
||||||
|
|
||||||
## 1. 项目目录规范(通用)
|
|
||||||
|
|
||||||
```text
|
|
||||||
src/
|
|
||||||
├── api/ # 接口请求
|
|
||||||
├── assets/ # 静态资源
|
|
||||||
├── components/ # 公共组件
|
|
||||||
├── composables/ # 组合式函数
|
|
||||||
├── constants/ # 常量
|
|
||||||
├── hooks/ # 业务 hooks
|
|
||||||
├── layouts/ # 布局
|
|
||||||
├── pages/ # 页面
|
|
||||||
├── router/ # 路由
|
|
||||||
├── store/ # 状态管理
|
|
||||||
├── styles/ # 全局样式
|
|
||||||
├── utils/ # 工具函数
|
|
||||||
└── App.vue/main.ts
|
|
||||||
```
|
|
||||||
|
|
||||||
## 2. 命名规范
|
|
||||||
|
|
||||||
### 文件命名
|
|
||||||
- 组件:大驼峰 `UserList.vue`
|
|
||||||
- 工具/页面:短横线 `user-info.ts`
|
|
||||||
- 样式:短横线 `index.scss`、`button.scss`
|
|
||||||
|
|
||||||
### 变量/函数
|
|
||||||
- 变量:小驼峰 `userList`
|
|
||||||
- 常量:全大写下划线 `MAX_COUNT`
|
|
||||||
- 布尔:is/has/should 开头 `isVisible`
|
|
||||||
- 函数:动词开头 `getUserInfo()`
|
|
||||||
|
|
||||||
## 3. HTML 规范
|
|
||||||
- 语义化标签:header/main/section/aside/footer
|
|
||||||
- 类名使用短横线:`class="user-card"`
|
|
||||||
- 禁止冗余标签、禁止行内样式
|
|
||||||
- 图片必须加 alt,懒加载使用 loading="lazy"
|
|
||||||
|
|
||||||
## 4. CSS / SCSS 规范
|
|
||||||
- 使用 BEM 或短横线命名
|
|
||||||
- 禁止嵌套超过 3 层
|
|
||||||
- 公共样式抽离到 variables/mixins
|
|
||||||
- z-index 统一管理
|
|
||||||
- 单位优先使用 rem / vh / %
|
|
||||||
- 颜色使用变量,禁止硬编码
|
|
||||||
|
|
||||||
## 5. JavaScript 规范
|
|
||||||
- 使用 const/let,禁止 var
|
|
||||||
- 优先使用箭头函数
|
|
||||||
- 异步优先 async/await
|
|
||||||
- 禁止嵌套过深(<3 层)
|
|
||||||
- 禁止魔法数字,抽为常量
|
|
||||||
- 数组优先使用 map/filter/reduce
|
|
||||||
|
|
||||||
## 6. TypeScript 规范
|
|
||||||
- 必须定义接口/类型
|
|
||||||
- 禁止 any,能用 unknown 替代
|
|
||||||
- 接口使用 I 前缀或后缀 Type
|
|
||||||
- 函数参数与返回值必须标注类型
|
|
||||||
- 类型复用优先使用 type / interface
|
|
||||||
|
|
||||||
## 7. Vue 规范
|
|
||||||
- 组件名多单词,避免与 HTML 重名
|
|
||||||
- props 必须定义类型、默认值、校验
|
|
||||||
- 指令缩写:: @ #
|
|
||||||
- 计算属性避免副作用
|
|
||||||
- watch 慎用,优先 computed
|
|
||||||
- 方法命名遵循动词+名词
|
|
||||||
|
|
||||||
## 8. React 规范
|
|
||||||
- 组件使用函数式 + Hooks
|
|
||||||
- 状态扁平化,避免嵌套
|
|
||||||
- 禁止在循环/条件中使用 Hooks
|
|
||||||
- 事件处理函数以 handle 开头
|
|
||||||
- 样式使用 CSS Modules / styled-components
|
|
||||||
|
|
||||||
## 9. Git 规范
|
|
||||||
提交格式:
|
|
||||||
type(scope): content
|
|
||||||
|
|
||||||
type:
|
|
||||||
- feat: 新功能
|
|
||||||
- fix: 修复
|
|
||||||
- docs: 文档
|
|
||||||
- style: 格式
|
|
||||||
- refactor: 重构
|
|
||||||
- perf: 性能
|
|
||||||
- test: 测试
|
|
||||||
- chore: 构建/工具
|
|
||||||
|
|
||||||
## 10. ESLint + Prettier 规范
|
|
||||||
- 2 空格缩进
|
|
||||||
- 单引号
|
|
||||||
- 语句末尾分号
|
|
||||||
- 文件末尾空行
|
|
||||||
- 禁止未使用变量
|
|
||||||
- 禁止 console(生产环境)
|
|
||||||
|
|
||||||
## 11. 性能规范
|
|
||||||
- 图片压缩、WebP
|
|
||||||
- 懒加载图片、组件
|
|
||||||
- 路由懒加载
|
|
||||||
- 防抖节流处理高频事件
|
|
||||||
- 大数据列表使用虚拟滚动
|
|
||||||
- 减少冗余渲染
|
|
||||||
|
|
||||||
## 12. 安全规范
|
|
||||||
- 防止 XSS:过滤用户输入
|
|
||||||
- 防止 CSRF:token 校验
|
|
||||||
- 敏感信息不放在 localStorage
|
|
||||||
- 接口必须做权限控制
|
|
||||||
- 禁止前端明文存储密钥/Token
|
|
||||||
|
|
||||||
@@ -1,482 +0,0 @@
|
|||||||
---
|
|
||||||
name: mis-agent-spec
|
|
||||||
description: 在mis-agent模块编写代码必备技能。
|
|
||||||
---
|
|
||||||
|
|
||||||
# Intro
|
|
||||||
|
|
||||||
请结合[目录结构](#目录结构)与[核心技术栈](#核心技术栈),并严格遵守[代码编写规范](#代码编写规范)生成代码,被要求编写HTTP接口文档时,请参考[HTTP接口文档示例](./examples/api-doc.md)。
|
|
||||||
|
|
||||||
## 核心技术栈
|
|
||||||
|
|
||||||
- Java:OpenJDK21
|
|
||||||
- spring-boot:
|
|
||||||
- 版本:3.2.9
|
|
||||||
- 文档:https://docs.spring.io/spring-boot/docs/3.2.9/reference/html
|
|
||||||
- 源码:https://github.com/spring-projects/spring-boot/tree/v3.2.9
|
|
||||||
- spring-framework:
|
|
||||||
- 版本:6.1.12
|
|
||||||
- 文档:https://docs.spring.io/spring-framework/reference/6.2/index.html
|
|
||||||
- 源码:https://github.com/spring-projects/spring-framework/tree/v6.1.12
|
|
||||||
- mybatis-plus:
|
|
||||||
- 版本:3.5.7
|
|
||||||
- 文档:https://github.com/baomidou/mybatis-plus-doc
|
|
||||||
- 源码:https://github.com/baomidou/mybatis-plus/tree/v3.5.7
|
|
||||||
- MySQL:
|
|
||||||
- 版本:8.0.25
|
|
||||||
- 文档:https://dev.mysql.com/doc/refman/8.0/en/
|
|
||||||
- 源码:https://github.com/mysql/mysql-server/tree/mysql-8.0.25
|
|
||||||
- Redis:8.0+
|
|
||||||
- redisson-spring-boot-starter:
|
|
||||||
- 版本:3.34.1
|
|
||||||
- 文档:https://redisson.pro/docs/integration-with-spring/#usage
|
|
||||||
- 源码:https://github.com/redisson/redisson/tree/redisson-3.34.1/redisson-spring-boot-starter/src/main
|
|
||||||
- RocketMQ:
|
|
||||||
- 文档:https://rocketmq.apache.org/zh/docs/4.x
|
|
||||||
- rocketmq-client:
|
|
||||||
- 版本:4.9.8
|
|
||||||
- 源码:https://github.com/apache/rocketmq/tree/rocketmq-all-4.9.8
|
|
||||||
- rocketmq-spring-boot-starter:
|
|
||||||
- 版本:2.2.3
|
|
||||||
- 源码:https://github.com/apache/rocketmq-spring/tree/rocketmq-spring-all-2.2.3
|
|
||||||
- agentscope-java:
|
|
||||||
- 版本:1.0.11
|
|
||||||
- 文档:https://java.agentscope.io/v1/zh/docs/task/agent-as-tool.html
|
|
||||||
- 源码:https://github.com/agentscope-ai/agentscope-java/tree/v1.0.11
|
|
||||||
- spring-ai:
|
|
||||||
- 版本:1.1.2
|
|
||||||
- 文档:https://docs.spring.io/spring-ai/reference/1.1/index.html
|
|
||||||
- 源码:https://github.com/spring-projects/spring-ai/tree/v1.1.2
|
|
||||||
- spring-ai-alibaba:
|
|
||||||
- 版本:1.1.2.2
|
|
||||||
- 文档:https://java2ai.com/docs/overview
|
|
||||||
- 源码:https://github.com/alibaba/spring-ai-alibaba/tree/v1.1.2.2
|
|
||||||
- hutool-core:
|
|
||||||
- 版本:5.8.42
|
|
||||||
- 文档:https://github.com/chinabugotech/hutool-site/tree/master/docs/core
|
|
||||||
- 源码:https://github.com/chinabugotech/hutool/tree/5.8.42/hutool-core
|
|
||||||
- hutool-json:
|
|
||||||
- 版本:5.8.42
|
|
||||||
- 文档:https://github.com/chinabugotech/hutool-site/tree/master/docs/json
|
|
||||||
- 源码:https://github.com/chinabugotech/hutool/tree/5.8.42/hutool-json
|
|
||||||
- spring-cloud-alibaba:
|
|
||||||
- 版本:2023.0.1.2
|
|
||||||
- 文档:https://sca.aliyun.com/docs/2023/overview/version-explain
|
|
||||||
- 源码:https://github.com/alibaba/spring-cloud-alibaba/tree/2023.0.1.2
|
|
||||||
|
|
||||||
## 目录结构
|
|
||||||
|
|
||||||
### 项目根目录
|
|
||||||
|
|
||||||
```text
|
|
||||||
<root>\
|
|
||||||
├── mis-api\ # 微服务之间暴露的dubbo接口
|
|
||||||
├── mis-auth\ # API网关鉴权服务
|
|
||||||
├── mis-common\ # 存放多个模块的公共依赖
|
|
||||||
├── mis-gateway\ # API网关
|
|
||||||
├── mis-modules\ # 业务模块代码根目录
|
|
||||||
├── mis-visual\ # 与业务无关的子模块
|
|
||||||
└── pom.xml # 在<profiles>中定义了Nacos地址及账号密码、NewAPI的地址和密钥
|
|
||||||
```
|
|
||||||
|
|
||||||
### 模块根目录
|
|
||||||
|
|
||||||
```text
|
|
||||||
mis-modules\mis-agent\src\main\
|
|
||||||
├── java
|
|
||||||
│ └── com\lcfc\agent\
|
|
||||||
│ ├── agents\ # 智能体核心
|
|
||||||
│ │ ├── a2a\ # A2A Agent
|
|
||||||
│ │ ├── config\ # Spring配置类
|
|
||||||
│ │ ├── constants\ # 常量类
|
|
||||||
│ │ ├── context\ # 自定义上下文载体类
|
|
||||||
│ │ ├── controller\ # SpringWeb控制器
|
|
||||||
│ │ ├── dubbo\ # Dubbo接口实现类
|
|
||||||
│ │ ├── enums\ # 枚举类
|
|
||||||
│ │ ├── events\ # Spring事件消息
|
|
||||||
│ │ ├── mapper\ # Mybatis Mapper接口
|
|
||||||
│ │ ├── multiagent\ # 多智能体
|
|
||||||
│ │ ├── saa\ # 单智能体
|
|
||||||
│ │ ├── service\ # Service接口
|
|
||||||
│ │ │ └── impl\ # Service接口实现类
|
|
||||||
│ │ ├── util\ # 工具类
|
|
||||||
│ │ ├── validator\ # 验证器
|
|
||||||
│ │ └── domain\ # 数据库实体类
|
|
||||||
│ │ ├── DTO\ # 数据传输对象
|
|
||||||
│ │ └── VO\ # 视图对象
|
|
||||||
│ ├── eventhub\ # 事件发布订阅(非SpringBean可用)
|
|
||||||
│ │ ├── MisAgentEventHub.java # 注册监听器,broadcast推送事件
|
|
||||||
│ │ └── MisAgentEventListener.java # 所有监听器须实现此接口
|
|
||||||
│ ├── memory\ # 长期记忆
|
|
||||||
│ │ ├── UserLongTermChannel.java # 记忆通道(如hindsight)
|
|
||||||
│ │ ├── UserLongTermMemoryClient.java # 用户级长期记忆客户端接口
|
|
||||||
│ │ ├── UserLongTermMemoryConfig.java # 用户级长期记忆配置
|
|
||||||
│ │ └── UserLongTermMemoryCtl.java # 用户级长期记忆控制类
|
|
||||||
│ ├── monitor\ # 智能体监控(收集tool/skill/workflow/知识库调用及token消耗)
|
|
||||||
│ │ ├── AgentChatMetricsCtx.java # 监控数据上下文
|
|
||||||
│ │ ├── AgentChatMetricsFinishEvent.java# 监控数据收集完成事件
|
|
||||||
│ │ ├── AgentChatMetricsFinishListener.java # 监控数据完成监听器
|
|
||||||
│ │ ├── IAgentChatMetricsConsumer.java # 消费监控数据接口
|
|
||||||
│ │ ├── MisAgentChatMetricsCtl.java # 监控上下文控制类
|
|
||||||
│ │ └── MisMcpToolMetadataCtl.java # MCP元数据控制类
|
|
||||||
│ ├── skills\ # 智能体Skill
|
|
||||||
│ │ ├── BaseSkillToolsExecutor.java # Skill脚本执行工具父类
|
|
||||||
│ │ ├── AgentScopeSkillTools.java # 基于agentscope-java执行Skill脚本
|
|
||||||
│ │ ├── SpringAiSkillTools.java # 基于spring-ai执行Skill脚本
|
|
||||||
│ │ ├── AgentSkillMetadataHandler.java # Skill元数据(磁盘记录数量)
|
|
||||||
│ │ ├── AgentSkillResourceHandler.java # Skill静态资源处理(下载/删除)
|
|
||||||
│ │ ├── AgentSkillRuntimeHandler.java # Skill运行时临时目录管理(创建/删除)
|
|
||||||
│ │ ├── AgentSkillRuntimeConfigHandler.java # Skill运行时自定义配置(读取/删除)
|
|
||||||
│ │ ├── AgentSkillSessionCache.java # Skill临时目录缓存(自动续期/删除)
|
|
||||||
│ │ ├── RemoveSkillConsumer.java # 智能体解绑Skill事件 / 服务端Skill删除事件
|
|
||||||
│ │ ├── SkillRemoveConsumer.java # (待确认用途)
|
|
||||||
│ │ ├── SkillResourceChangeConsumer.java # Skill静态资源更新事件处理
|
|
||||||
│ │ └── SkillStateChangeConsumer.java # Skill状态变更事件处理(禁用/启用)
|
|
||||||
│ ├── utils\ # 公共工具包
|
|
||||||
│ │ ├── AsyncTaskTemplate.java # 多线程异步任务模板
|
|
||||||
│ │ ├── RLockTemplate.java # 基于Redis的分布式锁
|
|
||||||
│ │ └── TransactionTaskTemplate.java # 编程式Spring事务模板
|
|
||||||
│ └── stats\ # 项目数据统计
|
|
||||||
│ ├── api\ # Controller
|
|
||||||
│ ├── service\ # Service
|
|
||||||
│ ├── conf\ # 配置类
|
|
||||||
│ ├── domain\
|
|
||||||
│ │ ├── dto\ # DTO
|
|
||||||
│ │ ├── vo\ # VO
|
|
||||||
│ │ ├── enums\ # Enum
|
|
||||||
│ │ ├── entity\ # Entity
|
|
||||||
│ │ └── mapper\ # Mapper Java源文件
|
|
||||||
│ └── mq\
|
|
||||||
│ ├── event\ # 消息载体
|
|
||||||
│ └── consumer\ # 监听器
|
|
||||||
└── resources
|
|
||||||
├── mapper\ # Mybatis Mapper XML
|
|
||||||
└── application.yml # 配置文件
|
|
||||||
```
|
|
||||||
|
|
||||||
## 代码编写规范
|
|
||||||
|
|
||||||
| 类目 | 使用原则 | 描述 |
|
|
||||||
|:--- | :--- | :--- |
|
|
||||||
| JDK11~21的新特性 | 积极使用 | 局部变量类型推断、Switch表达式、模式匹配、文本块、记录类、密封类、虚拟线程,虚拟线程应当用于IO密集型的任务,而不是CPU密集型任务。|
|
|
||||||
| 设计模式 | 非常看重 | 为了降低代码耦合度,提高可维护性,请积极的采用工厂、模板、策略、发布订阅等常用的设计模式。一个Java源文件的代码行数不得超过300行,超出则拆成多个文件,一个方法体内的行数不得超过20行,超出则拆成多个方法。对于发布订阅模式,请根据以下情况判断:跨服务通信、集群实例广播消息,优先使用RocketMQ消息队列。进程内通信则使用ApplicationEventPublisher和@EventListener即可。|
|
|
||||||
| Lombok注解 | 积极使用 | 无需担心编译速度被拖慢。|
|
|
||||||
| Null值处理 | 适当应用 | 优先考虑`Optional.ofNullable(obj)`而不是`if (obj == null)` |
|
|
||||||
| Stream | 积极使用 | 优先使用Stream而不是循环,若map代码块超过5行就单独写一个方法,如果需要中间对象则优先使用记录类,记录类和DTO存放在一个目录。|
|
|
||||||
| 工具类 | 积极使用 | 优先采纳hutool,除非hutool没有提供才新建一个工具类。|
|
|
||||||
| 构建对象 | 非常看重 | 构建JavaBean对象,优先使用构造函数而不是单独写工具类或方法,只有3个以内的属性,应提供一个全部参数的构造函数。|
|
|
||||||
| List | 适当应用 | 在非多线程场景,默认用ArrayList就够了。只有需要按照插入顺序遍历元素的场景,才考虑使用LinkedList。需考虑线程安全用CopyOnWriteArrayList。|
|
|
||||||
| Set | 适当应用 | 在非多线程场景,默认用HashSet。对排序要求考虑用LinkedHashSet或TreeSet。需考虑线程安全用`cn.hutool.core.collection.ConcurrentHashSet`、ConcurrentSkipListSet、CopyOnWriteArraySet等。|
|
|
||||||
| Map | 适当应用 | 在非线程场景,默认使用HashMap就够了。对排序要求考虑用LinkedHashMap或TreeMap。如果存在并发场景,需考虑线程安全用ConcurrentHashMap或ConcurrentSkipListMap等JUC工具包。|
|
|
||||||
| Queue | 适当应用 | 要控制内存,用ArrayBlockingQueue。经典生产者消费者,用LinkedBlockingQueue。要窃取任务,用LinkedBlockingDeque。追求极致吞吐且不怕队列暴涨,用ConcurrentLinkedQueue。必须双端且高吞吐,用ConcurrentLinkedDeque。|
|
|
||||||
| Lock | 适当应用 | 分布式锁使用Redisson相关API,单机使用ReentrantLock、StampedLock、ReentrantReadWriteLock即可。|
|
|
||||||
|
|
||||||
## 实体类与MySQL字段类型映射规则
|
|
||||||
|
|
||||||
|实体类字段类型|MySQL字段类型|
|
|
||||||
| --- | --- |
|
|
||||||
| String | VARCHAT(255) |
|
|
||||||
| Long | BIGINT |
|
|
||||||
| Integer | INT |
|
|
||||||
| LocalDate | DATE |
|
|
||||||
| LocalDateTime | DATETIME |
|
|
||||||
| BigDecimal | DECIMAL(14, 2) |
|
|
||||||
|
|
||||||
- 数据库表结构字段名称、实体类字段名称,采用驼峰与下划线映射的方式。
|
|
||||||
- `@TableField`注解中`typeHandler`等于`JacksonTypeHandler.class`时,表结构字段默认JSON类型。
|
|
||||||
- 实体类字段包含`@NotNull`注解,需要结合`@Schema`注解中的`defaultValue`属性判断是否需要设置默认值。
|
|
||||||
- 主键列是否采用MySQL自增序列,取决于实体类被`@TableId`注解修饰的字段,要看其`type`属性,如果是`IdType.AUTO`则使用自增,否则不需要。
|
|
||||||
- 如果`@Schema`注解指定了`maxLength`属性,按如下原则设置字段类型:
|
|
||||||
- 数值小于或等于2000,使用VARCHAR
|
|
||||||
- 数值大于2000且小于10000,使用TEXT
|
|
||||||
- 数值大于10000,使用LONGTEXT
|
|
||||||
|
|
||||||
## MySQL表结构示例
|
|
||||||
|
|
||||||
```sql
|
|
||||||
CREATE TABLE `example_table` (
|
|
||||||
`id` BIGINT NOT NULL COMMENT 'ID',
|
|
||||||
`str_field` VARCHAR(32) NOT NULL COMMENT '字符串`,
|
|
||||||
`int_field` INT DEFAULT NULL COMMENT '整数`,
|
|
||||||
`long_field` BIGINT DEFAULT NULL COMMENT '长整数`,
|
|
||||||
`decimal_field` DECIMAL(14, 2) DEFAULT NULL COMMENT '高精度浮点数`,
|
|
||||||
`date_field` DATE NOT NULL COMMENT '日期类型`,
|
|
||||||
`time_field` DATETIME NOT NULL COMMENT '日期类型`,
|
|
||||||
`state` VARCHAR(32) NOT NULL COMMENT '状态:only_read、read_write',
|
|
||||||
`json_field` JSON DATETIME NULL COMMENT 'JSON类型'
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='示例表';
|
|
||||||
```
|
|
||||||
|
|
||||||
## 实体类示例
|
|
||||||
|
|
||||||
```java
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
import java.io.Serial;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@TableName(value = "example_table", autoResultMap = true)
|
|
||||||
@Schema(title = "示例表")
|
|
||||||
public class ExampleEntity implements Serializable {
|
|
||||||
|
|
||||||
@Serial
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Schema(description = "ID")
|
|
||||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
|
||||||
@TableField(value = "id")
|
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Schema(description = "字符串")
|
|
||||||
@TableField(value = "str_field")
|
|
||||||
private String strField;
|
|
||||||
|
|
||||||
@Schema(description = "整数", defaultValue = "0")
|
|
||||||
@TableField(value = "int_field")
|
|
||||||
private Integer intField;
|
|
||||||
|
|
||||||
@Schema(description = "长整数")
|
|
||||||
@TableField(value = "long_field")
|
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
|
||||||
private Long longField;
|
|
||||||
|
|
||||||
@Schema(description = "高精度浮点数")
|
|
||||||
@TableField(value = "decimal_field")
|
|
||||||
private BigDecimal decimalField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "日期类型", pattern = "yyyy-MM-dd")
|
|
||||||
@TableField(value = "date_field")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
|
||||||
private LocalDate dateField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "时间类型", pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@TableField(value = "time_field")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
|
||||||
private LocalDateTime timeField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(
|
|
||||||
title = "状态",
|
|
||||||
description = "参考示例值",
|
|
||||||
example = StateEnum.DESC
|
|
||||||
)
|
|
||||||
@TableField(value = "state")
|
|
||||||
private StateEnum state;
|
|
||||||
|
|
||||||
@Schema(description = "JSON类型")
|
|
||||||
@TableField(value = "json_field", typeHandler = JacksonTypeHandler.class)
|
|
||||||
private JsonField jsonField;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class JsonField implements Serializable {
|
|
||||||
|
|
||||||
@Serial
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Schema(description = "示例字段1")
|
|
||||||
private String field1;
|
|
||||||
|
|
||||||
@Schema(description = "示例字段2")
|
|
||||||
private Integer field2;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 枚举类示例
|
|
||||||
|
|
||||||
```java
|
|
||||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Schema(description = "某某状态")
|
|
||||||
public enum StateEnum {
|
|
||||||
|
|
||||||
ONLY_READ("only_read"),
|
|
||||||
|
|
||||||
READ_WRITE("read_write");
|
|
||||||
|
|
||||||
public static final String DESC = "only_read=只读、read_write=读写";
|
|
||||||
|
|
||||||
@JsonValue
|
|
||||||
@EnumValue
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public static StateEnum deserialize(String input) {
|
|
||||||
return Arrays.stream(values()).filter(e -> e.getValue().equals(input)).findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## DTO示例
|
|
||||||
|
|
||||||
```java
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
import java.io.Serial;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Schema(title = "DTO示例")
|
|
||||||
public class ExampleDTO implements Serializable {
|
|
||||||
|
|
||||||
@Serial
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Schema(description = "字符串")
|
|
||||||
private String strField;
|
|
||||||
|
|
||||||
@Schema(description = "长整数")
|
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
|
||||||
private Long longField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "日期类型", pattern = "yyyy-MM-dd")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
|
||||||
private LocalDate dateField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "时间类型", pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
|
||||||
private LocalDateTime timeField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(
|
|
||||||
title = "状态",
|
|
||||||
description = "参考示例值",
|
|
||||||
example = StateEnum.DESC
|
|
||||||
)
|
|
||||||
private StateEnum state;
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## FAQ
|
|
||||||
|
|
||||||
### 怎么确认用哪个profile?
|
|
||||||
|
|
||||||
若当前Git分支出于dev则使用dev,否则使用qas。
|
|
||||||
|
|
||||||
### 怎么读profile的配置?
|
|
||||||
|
|
||||||
从[项目根目录](#项目根目录)的`pom.xml`文件中获取不同`profiles.active`的配置,示例:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<profile>
|
|
||||||
<id>dev</id>
|
|
||||||
<properties>
|
|
||||||
<!-- 环境标识,可用的数值有:dev、qas -->
|
|
||||||
<profiles.active>dev</profiles.active>
|
|
||||||
<!-- 当前环境的Nacos服务地址 -->
|
|
||||||
<nacos.server>127.0.0.1:8868</nacos.server>
|
|
||||||
<!-- 当前环境的Nacos注册中心分组名称 -->
|
|
||||||
<nacos.discovery.group>DEFAULT_GROUP</nacos.discovery.group>
|
|
||||||
<!-- 当前环境的Nacos配置中心分组名称 -->
|
|
||||||
<nacos.config.group>DEFAULT_GROUP</nacos.config.group>
|
|
||||||
<!-- 当前环境的Nacos登录账号 -->
|
|
||||||
<nacos.username>nacos</nacos.username>
|
|
||||||
<!-- 当前环境的Nacos登录密码 -->
|
|
||||||
<nacos.password>1234567890</nacos.password>
|
|
||||||
<!-- 当前环境的NewAPI服务地址 -->
|
|
||||||
<newAPI.url>http://127.0.0.1:3000</newAPI.url>
|
|
||||||
<!-- 当前环境的NewAPI模型ApiKey -->
|
|
||||||
<newAPI.key>sk-xxx</newAPI.key>
|
|
||||||
</properties>
|
|
||||||
</profile>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 怎么打包?
|
|
||||||
|
|
||||||
系统已安装`mvnd`用来替换`mvn`命令,先确认该用哪个profile,获取`profiles.active`后在[项目根目录](#项目根目录)执行命令`mvnd clean package -DskipTests -P{profiles.active}`,**耗时约80秒**。
|
|
||||||
|
|
||||||
### 怎么读取nacos配置文件?
|
|
||||||
|
|
||||||
按步骤一步步执行:
|
|
||||||
|
|
||||||
1. 先确认该用哪个profile,从**项目根目录**的`pom.xml`获取以下几个属性:
|
|
||||||
|
|
||||||
- `profiles.active`
|
|
||||||
- `nacos.server`
|
|
||||||
- `nacos.config.group`
|
|
||||||
- `nacos.username`
|
|
||||||
- `nacos.password`
|
|
||||||
|
|
||||||
2. 获取accessToken。
|
|
||||||
|
|
||||||
请求示例:
|
|
||||||
```bash
|
|
||||||
curl -X POST 'http://{nacos.server}/nacos/v1/auth/login' -d 'username={nacos.username}&password={nacos.password}'
|
|
||||||
```
|
|
||||||
|
|
||||||
输出示例:
|
|
||||||
```json
|
|
||||||
{"accessToken":"xxx"}
|
|
||||||
```
|
|
||||||
|
|
||||||
如果输出不包含accessToken字段视为失败,**最多重试2次,仍然失败则直接中断整个流程。**
|
|
||||||
|
|
||||||
3. 获取配置文件信息。
|
|
||||||
|
|
||||||
- `dataId`:如果要请求MySQL执行SQL使用`datasource.yml`,否则使用`mis-agent.yml`。
|
|
||||||
- `accessToken`:上一步得到的`accessToken`。
|
|
||||||
|
|
||||||
请求示例:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X GET "http://{nacos.server}/nacos/v3/console/cs/config?dataId={dataId}&groupName={groupName}&namespaceId={profiles.active}" -H "Authorization: Bearer {accessToken}"
|
|
||||||
```
|
|
||||||
|
|
||||||
输出示例:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"code": 0,
|
|
||||||
"message": "success",
|
|
||||||
"data": {"content": "..."}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`data.content`就是配置内容,通常是yaml格式。
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
---
|
|
||||||
name: mis-database-ops
|
|
||||||
description: 生成SQL的参考文档。
|
|
||||||
---
|
|
||||||
|
|
||||||
# 能力索引
|
|
||||||
|
|
||||||
| 能力名称 | 触发条件 |
|
|
||||||
| --- | --- |
|
|
||||||
| [查询智能体对话日志](./references/query-agent-chat-log.md) | 明确要求查智能体的对话日志 |
|
|
||||||
| [查询智能体信息](./references/query-agent-info.md) | 明确要求查智能体信息 |
|
|
||||||
| [查询智能体使用数据](./references/query-agent-usage.md) | 明确要求查智能体使用数据 |
|
|
||||||
| [查询项目统计数据](./references/query-project-stats.md) | 明确要求查项目统计数据 |
|
|
||||||
| [新增devco账号](./references/add-devco-accout.md) | 当用户提到新增devco账号的时候 |
|
|
||||||
| [查询paw-agent信息](./references/query-user-paw-agent.md) | 当用户提到查询paw-agent信息 |
|
|
||||||
|
|
||||||
## 工作流程
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
flowchart LR
|
|
||||||
A[开始] --> B[意图识别]
|
|
||||||
B --> C{请求是否被能力索引覆盖?}
|
|
||||||
C -->|是| D[参考文档执行相关操作]
|
|
||||||
C -->|否| E[利用相关工具想办法解决]
|
|
||||||
D --> F[结束]
|
|
||||||
E --> F
|
|
||||||
```
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# 能力说明
|
|
||||||
|
|
||||||
在`mis-dev`资源下的`mis-cloud-paw`库中执行批量插入sql,用户的输入格式如下。
|
|
||||||
|
|
||||||
```text
|
|
||||||
devco
|
|
||||||
username1
|
|
||||||
username2
|
|
||||||
username3
|
|
||||||
```
|
|
||||||
在用户的输入中,`devco`是触发d当前技能的关键词。从第二行开始,去掉空白行以后,每一个都是用户名。如果用户提供的用户名存在重复,请忽略大小写保留1个即可。`client_id`和`state`字段是固定值,用户名对应的是`account`字段,生成一条下面这样的sql执行即可。
|
|
||||||
|
|
||||||
```sql
|
|
||||||
INSERT INTO external_login_client_account (client_id, account, state) VALUES
|
|
||||||
('226c18408b5705449f37b621a432a6d3', 'username1', 1),
|
|
||||||
('226c18408b5705449f37b621a432a6d3', 'username2', 1),
|
|
||||||
('226c18408b5705449f37b621a432a6d3', 'username3', 1);
|
|
||||||
```
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
# 输入要求
|
|
||||||
|
|
||||||
必须要求用户提供**会话ID**。
|
|
||||||
|
|
||||||
## 工作流程
|
|
||||||
|
|
||||||
1. 查询所有切片号,假设查询出来的`part`是[1,2]
|
|
||||||
|
|
||||||
```sql
|
|
||||||
select part from log_agent_chat where del_flag = '0';
|
|
||||||
```
|
|
||||||
|
|
||||||
2. 根据切片号查询并合并各个切片表的数据
|
|
||||||
|
|
||||||
```sql
|
|
||||||
select * from log_agent_chat_1 where chat_window_id = <会话ID>
|
|
||||||
UNION ALL
|
|
||||||
select * from log_agent_chat_2 where chat_window_id = <会话ID>
|
|
||||||
```
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
# 输入要求
|
|
||||||
|
|
||||||
必须提供**智能体ID**,在不明确用户查询的是单智能体还是多智能体时,友好的询问要查询哪种智能体。
|
|
||||||
|
|
||||||
## 查询单智能体信息
|
|
||||||
|
|
||||||
```sql
|
|
||||||
with agent_info AS (
|
|
||||||
select
|
|
||||||
agent_id,
|
|
||||||
agent_name,
|
|
||||||
system_prompt,
|
|
||||||
`description`,
|
|
||||||
max_messages,
|
|
||||||
max_tokens,
|
|
||||||
kb_uuids,
|
|
||||||
kb_configs,
|
|
||||||
kb_similarity_threshold,
|
|
||||||
kb_top_k,
|
|
||||||
kb_max_recall_toekn,
|
|
||||||
llm_name,
|
|
||||||
long_term_memory,
|
|
||||||
case kb_mode when '1' then '直接检索' when '2' then 'tool检索' else '' end AS kb_mode,
|
|
||||||
case kb_search_type when '0' then '向量检索' when '1' then '混合检索' when '2' then '智能检索' else '' end AS kb_search_type
|
|
||||||
from mis-agent.agent
|
|
||||||
where agent_id = <智能体ID>
|
|
||||||
),
|
|
||||||
agent_skill AS (
|
|
||||||
select
|
|
||||||
<智能体ID> AS agent_id,
|
|
||||||
GROUP_CONCAT(skill_name) AS skill_names
|
|
||||||
from mis-mcp.skill
|
|
||||||
where skill_id in (
|
|
||||||
select skill_id from mis-agent.agent_skill_mapping
|
|
||||||
where agent_id = <智能体ID>
|
|
||||||
)
|
|
||||||
),
|
|
||||||
agent_mcp_tool AS (
|
|
||||||
select
|
|
||||||
<智能体ID> AS agent_id,
|
|
||||||
GROUP_CONCAT(tool_name) AS tool_names
|
|
||||||
from mis-mcp.map_tools
|
|
||||||
where mcp_server_uuid in (
|
|
||||||
select mcp_server_uuid from mis-agent.agent_tool_mapping
|
|
||||||
where relate_agent_id = <智能体ID>
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
select * from agent_info AS a
|
|
||||||
left join agent_skill AS b on a.agent_id = b.agent_id
|
|
||||||
left join agent_mcp_tool AS c on a.agent_id = c.agent_id
|
|
||||||
```
|
|
||||||
|
|
||||||
## 查询多智能体信息
|
|
||||||
|
|
||||||
```sql
|
|
||||||
select * from mis-agent.agent_release_info where release_id in (
|
|
||||||
select
|
|
||||||
release_id
|
|
||||||
from mis-agent.multi_agent_sub
|
|
||||||
where main_agent_id = <智能体ID>
|
|
||||||
)
|
|
||||||
```
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# 输入要求
|
|
||||||
|
|
||||||
必须提供**智能体ID**。
|
|
||||||
|
|
||||||
## 执行查询
|
|
||||||
|
|
||||||
```sql
|
|
||||||
select * from mis-agent.agent_usage_stats_daily where agent_id = <智能体ID> order by daily desc
|
|
||||||
```
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
# 输入要求
|
|
||||||
|
|
||||||
必须提供**项目名称**。
|
|
||||||
|
|
||||||
## 工作流程
|
|
||||||
|
|
||||||
1. 查询项目注册表,判断是否包含该项目。用户提供的项目名称大概率是模糊的,比如"认证"、"ebiz",要根据语义判断究竟是哪一个,如果猜不准就询问一下用户是哪个。重要:`project_stats_registry`里的`id`字段,称为项目ID,或者叫project_id,后面的步骤需要用到。
|
|
||||||
|
|
||||||
```sql
|
|
||||||
select * from mis-agent.project_stats_registry
|
|
||||||
```
|
|
||||||
|
|
||||||
2. 查询项目统计数据
|
|
||||||
|
|
||||||
```sql
|
|
||||||
select * from mis-agent.project_data_stats_daily where project_id = <project_id>
|
|
||||||
```
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
# 能力说明
|
|
||||||
|
|
||||||
查看用户上传的`skill`审批详情数据。
|
|
||||||
|
|
||||||
# 工作流程
|
|
||||||
|
|
||||||
如果用户没有提供**流程单号**则先询问用户,然后在`mis-dev`资源下的`mis-workflow-claw`库中执行如下sql,把`{process_id}`替换成用户提供的流程单号。
|
|
||||||
|
|
||||||
```sql
|
|
||||||
SELECT
|
|
||||||
ht.ID_ AS task_id,
|
|
||||||
ht.NAME_ AS task_name,
|
|
||||||
ht.TASK_DEF_KEY_ AS task_definition_key,
|
|
||||||
ht.ASSIGNEE_ AS assignee,
|
|
||||||
ht.START_TIME_ AS start_time,
|
|
||||||
ht.END_TIME_ AS end_time,
|
|
||||||
c.TYPE_ AS comment_type,
|
|
||||||
c.MESSAGE_ AS comment_msg,
|
|
||||||
h.PROC_INST_ID_ AS process_instance_id,
|
|
||||||
h.BUSINESS_KEY_ AS business_key
|
|
||||||
FROM ACT_HI_TASKINST ht
|
|
||||||
INNER JOIN ACT_HI_PROCINST h ON h.PROC_INST_ID_ = ht.PROC_INST_ID_
|
|
||||||
LEFT JOIN ACT_HI_COMMENT c
|
|
||||||
ON c.TASK_ID_ = ht.ID_
|
|
||||||
AND c.TYPE_ IN ('pass', 'back')
|
|
||||||
WHERE h.BUSINESS_KEY_ = '{process_id}'
|
|
||||||
AND (ht.PARENT_TASK_ID_ IS NULL OR ht.PARENT_TASK_ID_ = '')
|
|
||||||
ORDER BY ht.START_TIME_ ASC, ht.ID_ ASC;
|
|
||||||
```
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
# 能力说明
|
|
||||||
|
|
||||||
在`mis-dev`资源下,根据用户名(username)查询paw-agent信息,如果用户没有提供username,友好的提问要查哪个用户的,一个可用的username示例:`Agnes2.wang`。
|
|
||||||
|
|
||||||
## 工作流程
|
|
||||||
|
|
||||||
1. 根据用户提供的`username`查询`user_id`,只会查出来1行数据,示例:
|
|
||||||
|
|
||||||
```sql
|
|
||||||
select user_id from `mis-cloud-claw`.`sys_user` where user_name = '{username}';
|
|
||||||
```
|
|
||||||
|
|
||||||
2. 根据`user_id`查询agent信息,可能返回多行数据,使用markdown表格的形式展示每一行的数据,示例:
|
|
||||||
|
|
||||||
```sql
|
|
||||||
select agent_id, agent_mode, publish_status, publish_scope, published_at, version_lane, key_scope_default from `mis-paw-claw`.`agent` where create_by = '1889506629046902786';
|
|
||||||
```
|
|
||||||
@@ -1,443 +0,0 @@
|
|||||||
---
|
|
||||||
name: mis-paw-spec
|
|
||||||
description: 在mis-paw模块编写代码必备技能。
|
|
||||||
---
|
|
||||||
|
|
||||||
# Intro
|
|
||||||
|
|
||||||
请结合[目录结构](#目录结构)与[核心技术栈](#核心技术栈),并严格遵守[代码编写规范](#代码编写规范)生成代码,被要求编写HTTP接口文档时,请参考[HTTP接口文档示例](./examples/api-doc.md)。
|
|
||||||
|
|
||||||
## 核心技术栈
|
|
||||||
|
|
||||||
- Java:OpenJDK21
|
|
||||||
- spring-boot:
|
|
||||||
- 版本:3.2.9
|
|
||||||
- 文档:https://docs.spring.io/spring-boot/docs/3.2.9/reference/html
|
|
||||||
- 源码:https://github.com/spring-projects/spring-boot/tree/v3.2.9
|
|
||||||
- spring-framework:
|
|
||||||
- 版本:6.1.12
|
|
||||||
- 文档:https://docs.spring.io/spring-framework/reference/6.2/index.html
|
|
||||||
- 源码:https://github.com/spring-projects/spring-framework/tree/v6.1.12
|
|
||||||
- mybatis-plus:
|
|
||||||
- 版本:3.5.7
|
|
||||||
- 文档:https://github.com/baomidou/mybatis-plus-doc
|
|
||||||
- 源码:https://github.com/baomidou/mybatis-plus/tree/v3.5.7
|
|
||||||
- MySQL:
|
|
||||||
- 版本:8.0.25
|
|
||||||
- 文档:https://dev.mysql.com/doc/refman/8.0/en/
|
|
||||||
- 源码:https://github.com/mysql/mysql-server/tree/mysql-8.0.25
|
|
||||||
- Redis:8.0+
|
|
||||||
- hutool-core:
|
|
||||||
- 版本:5.8.42
|
|
||||||
- 文档:https://github.com/chinabugotech/hutool-site/tree/master/docs/core
|
|
||||||
- 源码:https://github.com/chinabugotech/hutool/tree/5.8.42/hutool-core
|
|
||||||
- hutool-json:
|
|
||||||
- 版本:5.8.42
|
|
||||||
- 文档:https://github.com/chinabugotech/hutool-site/tree/master/docs/json
|
|
||||||
- 源码:https://github.com/chinabugotech/hutool/tree/5.8.42/hutool-json
|
|
||||||
- spring-cloud-alibaba:
|
|
||||||
- 版本:2023.0.1.2
|
|
||||||
- 文档:https://sca.aliyun.com/docs/2023/overview/version-explain
|
|
||||||
- 源码:https://github.com/alibaba/spring-cloud-alibaba/tree/2023.0.1.2
|
|
||||||
- RocketMQ:
|
|
||||||
- 文档:https://rocketmq.apache.org/zh/docs/4.x
|
|
||||||
- rocketmq-client:
|
|
||||||
- 版本:4.9.8
|
|
||||||
- 源码:https://github.com/apache/rocketmq/tree/rocketmq-all-4.9.8
|
|
||||||
- rocketmq-spring-boot-starter:
|
|
||||||
- 版本:2.2.3
|
|
||||||
- 源码:https://github.com/apache/rocketmq-spring/tree/rocketmq-spring-all-2.2.3
|
|
||||||
- elasticsearch:
|
|
||||||
- 版本:9.2.0
|
|
||||||
- 文档:https://github.com/elastic/elasticsearch/tree/v9.2.0/docs
|
|
||||||
- 源码:https://github.com/elastic/elasticsearch/tree/v9.2.0
|
|
||||||
|
|
||||||
## 目录结构
|
|
||||||
|
|
||||||
### 项目根目录
|
|
||||||
|
|
||||||
```text
|
|
||||||
<root>\
|
|
||||||
├── mis-api\ # 微服务之间暴露的dubbo接口
|
|
||||||
├── mis-auth\ # API网关鉴权服务
|
|
||||||
├── mis-common\ # 存放多个模块的公共依赖
|
|
||||||
├── mis-gateway\ # API网关
|
|
||||||
├── mis-modules\ # 业务模块代码根目录
|
|
||||||
├── mis-visual\ # 与业务无关的子模块
|
|
||||||
└── pom.xml # 在<profiles>中定义了Nacos地址及账号密码、NewAPI的地址和密钥
|
|
||||||
```
|
|
||||||
|
|
||||||
### 模块目录结构
|
|
||||||
|
|
||||||
```text
|
|
||||||
mis-modules\mis-paw\
|
|
||||||
├── src\main\
|
|
||||||
│ ├── java\com\lcfc\mispaw\
|
|
||||||
│ │ ├── cluster # 集群相关
|
|
||||||
│ │ ├── config # 配置类
|
|
||||||
│ │ ├── constant # 常量定义
|
|
||||||
│ │ ├── controller\ # 控制器层
|
|
||||||
│ │ │ ├── agents # 智能体
|
|
||||||
│ │ │ ├── approval # 审批
|
|
||||||
│ │ │ ├── chats # 聊天
|
|
||||||
│ │ │ ├── client # 客户端
|
|
||||||
│ │ │ ├── corn # 定时任务
|
|
||||||
│ │ │ ├── export # 导出
|
|
||||||
│ │ │ ├── files # 文件预览
|
|
||||||
│ │ │ ├── instance # 管理qwenpaw实例
|
|
||||||
│ │ │ ├── mcp # 管理qwenpaw实例的MCP
|
|
||||||
│ │ │ ├── models # 模型相关
|
|
||||||
│ │ │ ├── plan # 计划模式配置
|
|
||||||
│ │ │ ├── plugins # 管理qwenpaw实例的插件
|
|
||||||
│ │ │ ├── settings # 自定义qwenpaw实例设置
|
|
||||||
│ │ │ ├── skills # 管理qwenpaw实例的Skill
|
|
||||||
│ │ │ ├── token # 查看qwenpaw实例的token消耗
|
|
||||||
│ │ │ ├── toolguard # 管理qwenpaw实例的工具护栏
|
|
||||||
│ │ │ ├── tools # 管理qwenpaw实例的工具
|
|
||||||
│ │ │ └── workspace # 管理qwenpaw实例的工作区
|
|
||||||
│ │ ├── domain\ # 存放DTO、VO
|
|
||||||
│ │ ├── dubbo # Dubbo接口实现类
|
|
||||||
│ │ ├── enums # 枚举
|
|
||||||
│ │ ├── event # Spring的ApplicationEvent子类
|
|
||||||
│ │ ├── exception # 自定义异常类
|
|
||||||
│ │ ├── filter # 过滤器
|
|
||||||
│ │ ├── handler # 处理器
|
|
||||||
│ │ ├── mapper\ # MybatisMapper接口
|
|
||||||
│ │ ├── mq # 消息队列相关
|
|
||||||
│ │ ├── service\ # 业务服务层
|
|
||||||
│ │ ├── sessionfact\ # 会话服务
|
|
||||||
│ │ ├── task # 定时任务
|
|
||||||
│ │ ├── util # 工具类
|
|
||||||
│ │ └── workflow # 工作流
|
|
||||||
│ └── resources\
|
|
||||||
│ ├── mapper\ # MybatisMapperXML
|
|
||||||
│ ├── application.yml # 配置文件
|
|
||||||
│ └── logback-plus.xml # 日志配置
|
|
||||||
└── pom.xml # 当前Maven模块的依赖与构建配置
|
|
||||||
```
|
|
||||||
|
|
||||||
## 代码编写规范
|
|
||||||
|
|
||||||
| 类目 | 使用原则 | 描述 |
|
|
||||||
|:--- | :--- | :--- |
|
|
||||||
| JDK11~21的新特性 | 积极使用 | 局部变量类型推断、Switch表达式、模式匹配、文本块、记录类、密封类、虚拟线程,虚拟线程应当用于IO密集型的任务,而不是CPU密集型任务。|
|
|
||||||
| 设计模式 | 非常看重 | 为了降低代码耦合度,提高可维护性,请积极的采用工厂、模板、策略、发布订阅等常用的设计模式。一个Java源文件的代码行数不得超过300行,超出则拆成多个文件,一个方法体内的行数不得超过20行,超出则拆成多个方法。对于发布订阅模式,请根据以下情况判断:跨服务通信、集群实例广播消息,优先使用RocketMQ消息队列。进程内通信则使用ApplicationEventPublisher和@EventListener即可。|
|
|
||||||
| Lombok注解 | 积极使用 | 无需担心编译速度被拖慢。|
|
|
||||||
| Null值处理 | 适当应用 | 优先考虑`Optional.ofNullable(obj)`而不是`if (obj == null)` |
|
|
||||||
| Stream | 积极使用 | 优先使用Stream而不是循环,若map代码块超过5行就单独写一个方法,如果需要中间对象则优先使用记录类,记录类和DTO存放在一个目录。|
|
|
||||||
| 工具类 | 积极使用 | 优先采纳hutool,除非hutool没有提供才新建一个工具类。|
|
|
||||||
| 构建对象 | 非常看重 | 构建JavaBean对象,优先使用构造函数而不是单独写工具类或方法,只有3个以内的属性,应提供一个全部参数的构造函数。|
|
|
||||||
| List | 适当应用 | 在非多线程场景,默认用ArrayList就够了。只有需要按照插入顺序遍历元素的场景,才考虑使用LinkedList。需考虑线程安全用CopyOnWriteArrayList。|
|
|
||||||
| Set | 适当应用 | 在非多线程场景,默认用HashSet。对排序要求考虑用LinkedHashSet或TreeSet。需考虑线程安全用`cn.hutool.core.collection.ConcurrentHashSet`、ConcurrentSkipListSet、CopyOnWriteArraySet等。|
|
|
||||||
| Map | 适当应用 | 在非线程场景,默认使用HashMap就够了。对排序要求考虑用LinkedHashMap或TreeMap。如果存在并发场景,需考虑线程安全用ConcurrentHashMap或ConcurrentSkipListMap等JUC工具包。|
|
|
||||||
| Queue | 适当应用 | 要控制内存,用ArrayBlockingQueue。经典生产者消费者,用LinkedBlockingQueue。要窃取任务,用LinkedBlockingDeque。追求极致吞吐且不怕队列暴涨,用ConcurrentLinkedQueue。必须双端且高吞吐,用ConcurrentLinkedDeque。|
|
|
||||||
| Lock | 适当应用 | 分布式锁使用Redisson相关API,单机使用ReentrantLock、StampedLock、ReentrantReadWriteLock即可。|
|
|
||||||
|
|
||||||
## 实体类与MySQL字段类型映射规则
|
|
||||||
|
|
||||||
|实体类字段类型|MySQL字段类型|
|
|
||||||
| --- | --- |
|
|
||||||
| String | VARCHAT(255) |
|
|
||||||
| Long | BIGINT |
|
|
||||||
| Integer | INT |
|
|
||||||
| LocalDate | DATE |
|
|
||||||
| LocalDateTime | DATETIME |
|
|
||||||
| BigDecimal | DECIMAL(14, 2) |
|
|
||||||
|
|
||||||
- 数据库表结构字段名称、实体类字段名称,采用驼峰与下划线映射的方式。
|
|
||||||
- `@TableField`注解中`typeHandler`等于`JacksonTypeHandler.class`时,表结构字段默认JSON类型。
|
|
||||||
- 实体类字段包含`@NotNull`注解,需要结合`@Schema`注解中的`defaultValue`属性判断是否需要设置默认值。
|
|
||||||
- 主键列是否采用MySQL自增序列,取决于实体类被`@TableId`注解修饰的字段,要看其`type`属性,如果是`IdType.AUTO`则使用自增,否则不需要。
|
|
||||||
- 如果`@Schema`注解指定了`maxLength`属性,按如下原则设置字段类型:
|
|
||||||
- 数值小于或等于2000,使用VARCHAR
|
|
||||||
- 数值大于2000且小于10000,使用TEXT
|
|
||||||
- 数值大于10000,使用LONGTEXT
|
|
||||||
|
|
||||||
## MySQL表结构示例
|
|
||||||
|
|
||||||
```sql
|
|
||||||
CREATE TABLE `example_table` (
|
|
||||||
`id` BIGINT NOT NULL COMMENT 'ID',
|
|
||||||
`str_field` VARCHAR(32) NOT NULL COMMENT '字符串`,
|
|
||||||
`int_field` INT DEFAULT NULL COMMENT '整数`,
|
|
||||||
`long_field` BIGINT DEFAULT NULL COMMENT '长整数`,
|
|
||||||
`decimal_field` DECIMAL(14, 2) DEFAULT NULL COMMENT '高精度浮点数`,
|
|
||||||
`date_field` DATE NOT NULL COMMENT '日期类型`,
|
|
||||||
`time_field` DATETIME NOT NULL COMMENT '日期类型`,
|
|
||||||
`state` VARCHAR(32) NOT NULL COMMENT '状态:only_read、read_write',
|
|
||||||
`json_field` JSON DATETIME NULL COMMENT 'JSON类型'
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='示例表';
|
|
||||||
```
|
|
||||||
|
|
||||||
## 实体类示例
|
|
||||||
|
|
||||||
```java
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
import java.io.Serial;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@TableName(value = "example_table", autoResultMap = true)
|
|
||||||
@Schema(title = "示例表")
|
|
||||||
public class ExampleEntity implements Serializable {
|
|
||||||
|
|
||||||
@Serial
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Schema(description = "ID")
|
|
||||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
|
||||||
@TableField(value = "id")
|
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Schema(description = "字符串")
|
|
||||||
@TableField(value = "str_field")
|
|
||||||
private String strField;
|
|
||||||
|
|
||||||
@Schema(description = "整数", defaultValue = "0")
|
|
||||||
@TableField(value = "int_field")
|
|
||||||
private Integer intField;
|
|
||||||
|
|
||||||
@Schema(description = "长整数")
|
|
||||||
@TableField(value = "long_field")
|
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
|
||||||
private Long longField;
|
|
||||||
|
|
||||||
@Schema(description = "高精度浮点数")
|
|
||||||
@TableField(value = "decimal_field")
|
|
||||||
private BigDecimal decimalField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "日期类型", pattern = "yyyy-MM-dd")
|
|
||||||
@TableField(value = "date_field")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
|
||||||
private LocalDate dateField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "时间类型", pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@TableField(value = "time_field")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
|
||||||
private LocalDateTime timeField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(
|
|
||||||
title = "状态",
|
|
||||||
description = "参考示例值",
|
|
||||||
example = StateEnum.DESC
|
|
||||||
)
|
|
||||||
@TableField(value = "state")
|
|
||||||
private StateEnum state;
|
|
||||||
|
|
||||||
@Schema(description = "JSON类型")
|
|
||||||
@TableField(value = "json_field", typeHandler = JacksonTypeHandler.class)
|
|
||||||
private JsonField jsonField;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class JsonField implements Serializable {
|
|
||||||
|
|
||||||
@Serial
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Schema(description = "示例字段1")
|
|
||||||
private String field1;
|
|
||||||
|
|
||||||
@Schema(description = "示例字段2")
|
|
||||||
private Integer field2;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 枚举类示例
|
|
||||||
|
|
||||||
```java
|
|
||||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Schema(description = "某某状态")
|
|
||||||
public enum StateEnum {
|
|
||||||
|
|
||||||
ONLY_READ("only_read"),
|
|
||||||
|
|
||||||
READ_WRITE("read_write");
|
|
||||||
|
|
||||||
public static final String DESC = "only_read=只读、read_write=读写";
|
|
||||||
|
|
||||||
@JsonValue
|
|
||||||
@EnumValue
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public static StateEnum deserialize(String input) {
|
|
||||||
return Arrays.stream(values()).filter(e -> e.getValue().equals(input)).findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## DTO示例
|
|
||||||
|
|
||||||
```java
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
import java.io.Serial;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Schema(title = "DTO示例")
|
|
||||||
public class ExampleDTO implements Serializable {
|
|
||||||
|
|
||||||
@Serial
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Schema(description = "字符串")
|
|
||||||
private String strField;
|
|
||||||
|
|
||||||
@Schema(description = "长整数")
|
|
||||||
@JsonSerialize(using = ToStringSerializer.class)
|
|
||||||
private Long longField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "日期类型", pattern = "yyyy-MM-dd")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
|
||||||
private LocalDate dateField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "时间类型", pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
|
||||||
private LocalDateTime timeField;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(
|
|
||||||
title = "状态",
|
|
||||||
description = "参考示例值",
|
|
||||||
example = StateEnum.DESC
|
|
||||||
)
|
|
||||||
private StateEnum state;
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## FAQ
|
|
||||||
|
|
||||||
### 怎么确认用哪个profile?
|
|
||||||
|
|
||||||
固定使用dev的profile。
|
|
||||||
|
|
||||||
### 怎么读profile的配置?
|
|
||||||
|
|
||||||
从[项目根目录](#项目根目录)的`pom.xml`文件中获取**id=dev,profiles.active=lab**的profile,例如:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<profile>
|
|
||||||
<id>dev</id>
|
|
||||||
<properties>
|
|
||||||
<profiles.active>lab</profiles.active>
|
|
||||||
<!-- 当前环境的Nacos服务地址 -->
|
|
||||||
<nacos.server>127.0.0.1:8868</nacos.server>
|
|
||||||
<!-- 当前环境的Nacos注册中心分组名称 -->
|
|
||||||
<nacos.discovery.group>DEFAULT_GROUP</nacos.discovery.group>
|
|
||||||
<!-- 当前环境的Nacos配置中心分组名称 -->
|
|
||||||
<nacos.config.group>DEFAULT_GROUP</nacos.config.group>
|
|
||||||
<!-- 当前环境的Nacos登录账号 -->
|
|
||||||
<nacos.username>nacos</nacos.username>
|
|
||||||
<!-- 当前环境的Nacos登录密码 -->
|
|
||||||
<nacos.password>1234567890</nacos.password>
|
|
||||||
<!-- 当前环境的NewAPI服务地址 -->
|
|
||||||
<newAPI.url>http://127.0.0.1:3000</newAPI.url>
|
|
||||||
<!-- 当前环境的NewAPI模型ApiKey -->
|
|
||||||
<newAPI.key>sk-xxx</newAPI.key>
|
|
||||||
</properties>
|
|
||||||
</profile>
|
|
||||||
```
|
|
||||||
|
|
||||||
### 怎么打包?
|
|
||||||
|
|
||||||
系统已安装`mvnd`用来替换`mvn`命令,在[项目根目录](#项目根目录)执行命令:`mvnd clean package -DskipTests -Pdev`,**耗时约80秒**。
|
|
||||||
|
|
||||||
### 怎么读取nacos配置文件?
|
|
||||||
|
|
||||||
按步骤一步步执行:
|
|
||||||
|
|
||||||
1. 从**项目根目录**的`pom.xml`获取以下几个属性:
|
|
||||||
|
|
||||||
- `profiles.active`
|
|
||||||
- `nacos.server`
|
|
||||||
- `nacos.config.group`
|
|
||||||
- `nacos.username`
|
|
||||||
- `nacos.password`
|
|
||||||
|
|
||||||
2. 获取accessToken。
|
|
||||||
|
|
||||||
请求示例:
|
|
||||||
```bash
|
|
||||||
curl -X POST 'http://{nacos.server}/nacos/v1/auth/login' -d 'username={nacos.username}&password={nacos.password}'
|
|
||||||
```
|
|
||||||
|
|
||||||
输出示例:
|
|
||||||
```json
|
|
||||||
{"accessToken":"xxx"}
|
|
||||||
```
|
|
||||||
|
|
||||||
如果输出不包含accessToken字段视为失败,**最多重试2次,仍然失败则直接中断整个流程。**
|
|
||||||
|
|
||||||
3. 获取配置文件信息。
|
|
||||||
|
|
||||||
- `dataId`:如果要请求MySQL执行SQL使用`datasource.yml`,否则使用`mis-agent.yml`。
|
|
||||||
- `accessToken`:上一步得到的`accessToken`。
|
|
||||||
|
|
||||||
请求示例:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X GET "http://{nacos.server}/nacos/v3/console/cs/config?dataId={dataId}&groupName={groupName}&namespaceId={profiles.active}" -H "Authorization: Bearer {accessToken}"
|
|
||||||
```
|
|
||||||
|
|
||||||
输出示例:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"code": 0,
|
|
||||||
"message": "success",
|
|
||||||
"data": {"content": "..."}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`data.content`就是配置内容,通常是yaml格式。
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
# 智能体使用数据
|
|
||||||
|
|
||||||
以下是关于智能体使用数据的API文档。
|
|
||||||
|
|
||||||
## 累计使用数据卡片
|
|
||||||
|
|
||||||
- 请求地址:/agent/metrics/total
|
|
||||||
- 请求方式:GET
|
|
||||||
|
|
||||||
### 请求参数
|
|
||||||
|
|
||||||
| 参数名称 | 是否必传 | 类型 | 描述 |
|
|
||||||
|:-----|:-----|:-----|:-----|
|
|
||||||
| agentId | 是 | String | 智能体ID |
|
|
||||||
|
|
||||||
### 请求示例
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X GET {gateway}/agent/metrics/total?agentId={agentId}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 响应参数
|
|
||||||
|
|
||||||
| 参数名称 | 类型 | 描述 |
|
|
||||||
|:-----|:-----|:-----|
|
|
||||||
| code | Number | 返回码(200=成功) |
|
|
||||||
| msg | String | 提示信息 |
|
|
||||||
| data | Object | 返回数据 |
|
|
||||||
| data.agentId | String | 智能体 ID |
|
|
||||||
| data.agentName | String | 智能体名称 |
|
|
||||||
| data.inputToken | Number | 累计输入Token |
|
|
||||||
| data.outputToken | Number | 累计输出Token |
|
|
||||||
| data.userNum | Number | 累计用户数 |
|
|
||||||
| data.chatNum | Number | 累计对话数 |
|
|
||||||
|
|
||||||
### 成功示例
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"code": 200,
|
|
||||||
"msg": "操作成功",
|
|
||||||
"data": {
|
|
||||||
"agentId": "123456",
|
|
||||||
"agentName": "智能体名称",
|
|
||||||
"inputToken": "123243654645",
|
|
||||||
"outputToken": "345645765765",
|
|
||||||
"userNum": 5678,
|
|
||||||
"chatNum": 45678999
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 失败示例
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"code": 500,
|
|
||||||
"msg": "错误信息"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
name: mis-spec
|
||||||
|
description: 在mis编写代码的必备技能。
|
||||||
|
---
|
||||||
|
|
||||||
|
# mis-spec
|
||||||
|
|
||||||
|
请结合[核心技术栈](./references/core_arch.md)、[MVC通用目录结构](./references/mvc_dir.md),并严格遵守[代码编写规范](./references/coding_rules.md)生成代码,被要求编写HTTP接口文档时,请参考[api-doc.md](./examples//api-doc.md)文档生成。
|
||||||
|
|
||||||
|
## 示例代码
|
||||||
|
|
||||||
|
- [MySQL建表语句示例](./examples/example_table.sql)
|
||||||
|
- [Java实体类示例](./examples/ExampleEntity.java)
|
||||||
|
- [Java枚举类示例](./examples/StateEnum.java)
|
||||||
|
- [DTO或者VO示例](./examples/ExampleDTO.java)
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
|
||||||
|
| 问题 | 答案 |
|
||||||
|
|:---|:---|
|
||||||
|
|项目根目录在哪?|一般就位于当前工作目录!|
|
||||||
|
|该用哪个profile执行编译?|向用户询问,可用的数值有:dev、local、qas、prd。|
|
||||||
|
|怎么读profile的配置?| 阅读文档[read_profile.md](./references/read_profile.md)|
|
||||||
|
|怎么编译或打包?|系统已安装`mvnd`用来替换`mvn`命令,在**项目根目录**执行命令:`mvnd clean package -DskipTests -Plocal`,**耗时约200秒**。|
|
||||||
|
|怎么读取nacos配置文件?|阅读文档[read_nacos_config.md](./references/read_nacos_config.md)|
|
||||||
|
|如何发起重试?比如提高异步任务可靠性!|阅读文档[worksheet.md](./references/worksheet.md)|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(title = "DTO示例")
|
||||||
|
public class ExampleDTO implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Schema(description = "字符串")
|
||||||
|
private String strField;
|
||||||
|
|
||||||
|
@Schema(description = "长整数")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long longField;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "日期类型", pattern = "yyyy-MM-dd")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
|
private LocalDate dateField;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "时间类型", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime timeField;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(
|
||||||
|
title = "状态",
|
||||||
|
description = "参考示例值",
|
||||||
|
example = StateEnum.DESC
|
||||||
|
)
|
||||||
|
private StateEnum state;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName(value = "example_table", autoResultMap = true)
|
||||||
|
@Schema(title = "示例表")
|
||||||
|
public class ExampleEntity implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "ID")
|
||||||
|
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||||
|
@TableField(value = "id")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Schema(description = "字符串")
|
||||||
|
@TableField(value = "str_field")
|
||||||
|
private String strField;
|
||||||
|
|
||||||
|
@Schema(description = "整数", defaultValue = "0")
|
||||||
|
@TableField(value = "int_field")
|
||||||
|
private Integer intField;
|
||||||
|
|
||||||
|
@Schema(description = "长整数")
|
||||||
|
@TableField(value = "long_field")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long longField;
|
||||||
|
|
||||||
|
@Schema(description = "高精度浮点数")
|
||||||
|
@TableField(value = "decimal_field")
|
||||||
|
private BigDecimal decimalField;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "日期类型", pattern = "yyyy-MM-dd")
|
||||||
|
@TableField(value = "date_field")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
|
private LocalDate dateField;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "时间类型", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@TableField(value = "time_field")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime timeField;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(
|
||||||
|
title = "状态",
|
||||||
|
description = "参考示例值",
|
||||||
|
example = StateEnum.DESC
|
||||||
|
)
|
||||||
|
@TableField(value = "state")
|
||||||
|
private StateEnum state;
|
||||||
|
|
||||||
|
@Schema(description = "JSON类型")
|
||||||
|
@TableField(value = "json_field", typeHandler = JacksonTypeHandler.class)
|
||||||
|
private JsonField jsonField;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class JsonField implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Schema(description = "示例字段1")
|
||||||
|
private String field1;
|
||||||
|
|
||||||
|
@Schema(description = "示例字段2")
|
||||||
|
private Integer field2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Schema(description = "某某状态")
|
||||||
|
public enum StateEnum {
|
||||||
|
|
||||||
|
ONLY_READ("only_read"),
|
||||||
|
|
||||||
|
READ_WRITE("read_write");
|
||||||
|
|
||||||
|
public static final String DESC = "only_read=只读、read_write=读写";
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
@EnumValue
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public static StateEnum deserialize(String input) {
|
||||||
|
return Arrays.stream(values()).filter(e -> e.getValue().equals(input)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE `example_table` (
|
||||||
|
`id` BIGINT NOT NULL COMMENT 'ID',
|
||||||
|
`str_field` VARCHAR(32) NOT NULL COMMENT '字符串`,
|
||||||
|
`int_field` INT DEFAULT NULL COMMENT '整数`,
|
||||||
|
`long_field` BIGINT DEFAULT NULL COMMENT '长整数`,
|
||||||
|
`decimal_field` DECIMAL(14, 2) DEFAULT NULL COMMENT '高精度浮点数`,
|
||||||
|
`date_field` DATE NOT NULL COMMENT '日期类型`,
|
||||||
|
`time_field` DATETIME NOT NULL COMMENT '日期类型`,
|
||||||
|
`state` VARCHAR(32) NOT NULL COMMENT '状态:only_read、read_write',
|
||||||
|
`json_field` JSON DATETIME NULL COMMENT 'JSON类型'
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='示例表';
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# 代码编写规范
|
||||||
|
|
||||||
|
| 类目 | 使用原则 | 描述 |
|
||||||
|
|:--- | :--- | :--- |
|
||||||
|
| 异步任务工单 | 适当应用 | 阅读文档[worksheet.md](../references/worksheet.md),拿捏不准请询问用户是否要使用。 |
|
||||||
|
| JDK11~21的新特性 | 积极使用 | 局部变量类型推断、Switch表达式、模式匹配、文本块、记录类、虚拟线程。<br/>**虚拟线程应当用于IO密集型的任务,而不是CPU密集型任务。**|
|
||||||
|
| 设计模式 | 非常看重 | 为了降低代码耦合度,提高可维护性。<br/>请积极的采用工厂、模板、策略、发布订阅等常用的设计模式。<br/>一个Java源文件的代码行数不得超过**300**行,超出则拆成多个文件。<br/>一个方法体内的行数不得超过**20**行,超出则拆成多个方法。<br/>对于发布订阅模式,请根据以下情况判断:<br/>跨服务通信、集群实例广播消息,优先使用RocketMQ消息队列。<br/>进程内通信则使用`ApplicationEventPublisher`和`@EventListener`即可。|
|
||||||
|
| Lombok注解 | 积极使用 | 无需担心编译速度被拖慢。|
|
||||||
|
| Null值处理 | 适当应用 | 优先考虑`Optional.ofNullable(obj)`而不是`if (obj == null)` |
|
||||||
|
| Stream | 积极使用 | 优先使用Stream而不是循环,若map代码块超过5行就单独写一个方法。<br/>如果需要中间对象则优先使用记录类,记录类和DTO存放在一个目录。|
|
||||||
|
| 工具类 | 积极使用 | 优先采纳hutool,除非hutool没有提供才新建一个工具类。|
|
||||||
|
| 构建对象 | 非常看重 | 构建JavaBean对象,优先使用构造函数而不是单独写工具类或方法。<br/>只有3个以内的属性,应提供一个全部参数的构造函数。|
|
||||||
|
| List | 适当应用 | 在非多线程场景,默认用`ArrayList`。<br/>有需要按照插入顺序遍历元素的场景,使用`LinkedList`。<br/>需考虑线程安全用`CopyOnWriteArrayList`。|
|
||||||
|
| Set | 适当应用 | 在非多线程场景,默认用`HashSet`。<br/>按照插入顺序遍历元素的场景用`LinkedHashSet`。<br/>有排序的需求则使用`TreeSet`。<br/>需考虑线程安全用:<br/>`cn.hutool.core.collection.ConcurrentHashSet`<br/>`ConcurrentSkipListSet`<br/>`CopyOnWriteArraySet`|
|
||||||
|
| Map | 适当应用 | 在非线程场景,默认用`HashMap`。<br/>对排序要求考虑用LinkedHashMap或TreeMap。<br/>如果存在并发场景,用`ConcurrentHashMap`或`ConcurrentSkipListMap`。|
|
||||||
|
| Queue | 适当应用 | 要控制内存,用`ArrayBlockingQueue`。<br/>经典生产者消费者,用`LinkedBlockingQueue`。<br/>要窃取任务,用`LinkedBlockingDeque`。<br/>追求极致吞吐且不怕队列暴涨,用`ConcurrentLinkedQueue`。<br/>必须双端且高吞吐,用`ConcurrentLinkedDeque`。|
|
||||||
|
| Lock | 适当应用 | 分布式锁使用`Redisson`相关API<br/>单机使用`ReentrantLock`、`StampedLock`。|
|
||||||
|
|
||||||
|
## 实体类与MySQL字段类型映射规则
|
||||||
|
|
||||||
|
|实体类字段类型|MySQL字段类型|
|
||||||
|
| --- | --- |
|
||||||
|
| String | VARCHAT(255) |
|
||||||
|
| Long | BIGINT |
|
||||||
|
| Integer | INT |
|
||||||
|
| LocalDate | DATE |
|
||||||
|
| LocalDateTime | DATETIME |
|
||||||
|
| BigDecimal | DECIMAL(14, 2) |
|
||||||
|
|
||||||
|
- 数据库表结构字段名称、实体类字段名称,采用驼峰与下划线映射的方式。
|
||||||
|
- `@TableField`注解中`typeHandler`等于`JacksonTypeHandler.class`时,表结构字段默认JSON类型。
|
||||||
|
- 实体类字段包含`@NotNull`注解,需要结合`@Schema`注解中的`defaultValue`属性判断是否需要设置默认值。
|
||||||
|
- 主键列是否采用MySQL自增序列,取决于实体类被`@TableId`注解修饰的字段,要看其`type`属性,如果是`IdType.AUTO`则使用自增,否则不需要。
|
||||||
|
- 如果`@Schema`注解指定了`maxLength`属性,按如下原则设置字段类型:
|
||||||
|
- 数值小于或等于2000,使用VARCHAR
|
||||||
|
- 数值大于2000且小于10000,使用TEXT
|
||||||
|
- 数值大于10000,使用LONGTEXT
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
- Java:OpenJDK21
|
||||||
|
- spring-boot:
|
||||||
|
- 版本:3.2.9
|
||||||
|
- 文档:https://docs.spring.io/spring-boot/docs/3.2.9/reference/html
|
||||||
|
- 源码:https://github.com/spring-projects/spring-boot/tree/v3.2.9
|
||||||
|
- spring-framework:
|
||||||
|
- 版本:6.1.12
|
||||||
|
- 文档:https://docs.spring.io/spring-framework/reference/6.2/index.html
|
||||||
|
- 源码:https://github.com/spring-projects/spring-framework/tree/v6.1.12
|
||||||
|
- mybatis-plus:
|
||||||
|
- 版本:3.5.7
|
||||||
|
- 文档:https://github.com/baomidou/mybatis-plus-doc
|
||||||
|
- 源码:https://github.com/baomidou/mybatis-plus/tree/v3.5.7
|
||||||
|
- MySQL:
|
||||||
|
- 版本:8.0.25
|
||||||
|
- 文档:https://dev.mysql.com/doc/refman/8.0/en/
|
||||||
|
- 源码:https://github.com/mysql/mysql-server/tree/mysql-8.0.25
|
||||||
|
- Redis:8.0+
|
||||||
|
- hutool-core:
|
||||||
|
- 版本:5.8.42
|
||||||
|
- 文档:https://github.com/chinabugotech/hutool-site/tree/master/docs/core
|
||||||
|
- 源码:https://github.com/chinabugotech/hutool/tree/5.8.42/hutool-core
|
||||||
|
- hutool-json:
|
||||||
|
- 版本:5.8.42
|
||||||
|
- 文档:https://github.com/chinabugotech/hutool-site/tree/master/docs/json
|
||||||
|
- 源码:https://github.com/chinabugotech/hutool/tree/5.8.42/hutool-json
|
||||||
|
- spring-cloud-alibaba:
|
||||||
|
- 版本:2023.0.1.2
|
||||||
|
- 文档:https://sca.aliyun.com/docs/2023/overview/version-explain
|
||||||
|
- 源码:https://github.com/alibaba/spring-cloud-alibaba/tree/2023.0.1.2
|
||||||
|
- RocketMQ:
|
||||||
|
- 文档:https://rocketmq.apache.org/zh/docs/4.x
|
||||||
|
- rocketmq-client:
|
||||||
|
- 版本:4.9.8
|
||||||
|
- 源码:https://github.com/apache/rocketmq/tree/rocketmq-all-4.9.8
|
||||||
|
- rocketmq-spring-boot-starter:
|
||||||
|
- 版本:2.2.3
|
||||||
|
- 源码:https://github.com/apache/rocketmq-spring/tree/rocketmq-spring-all-2.2.3
|
||||||
|
- elasticsearch:
|
||||||
|
- 版本:9.2.0
|
||||||
|
- 文档:https://github.com/elastic/elasticsearch/tree/v9.2.0/docs
|
||||||
|
- 源码:https://github.com/elastic/elasticsearch/tree/v9.2.0
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
# 目录结构说明
|
||||||
|
|
||||||
|
一个标准的MVC三层目录结构示例:
|
||||||
|
|
||||||
|
```text
|
||||||
|
com/example/project/
|
||||||
|
│
|
||||||
|
├── controller/ # 控制器层(接收请求)
|
||||||
|
│ ├── UserController.java
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
├── service/ # 业务逻辑层
|
||||||
|
│ ├── UserService.java # 接口
|
||||||
|
│ ├── impl/ # 实现类
|
||||||
|
│ │ └── UserServiceImpl.java
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
├── mapper/ # 数据访问层(MyBatis Mapper)
|
||||||
|
│ ├── ProductMapper.java
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
├── domain/ # 领域层(聚合所有数据对象)
|
||||||
|
│ ├── entity/ # 实体类(与数据库表对应)
|
||||||
|
│ │ ├── Product.java
|
||||||
|
│ │ └── ...
|
||||||
|
│ │
|
||||||
|
│ ├── dto/ # 数据传输对象(输入参数)
|
||||||
|
│ │ ├── ProductQueryDTO.java
|
||||||
|
│ │ └── ...
|
||||||
|
│ │
|
||||||
|
│ └── vo/ # 视图对象(输出结果)
|
||||||
|
│ ├── UserVO.java
|
||||||
|
│ ├── ProductVO.java
|
||||||
|
│ ├── PageVO.java # 分页结果封装
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
├── config/ # 配置类
|
||||||
|
│ ├── DataSourceConfig.java
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
├── utils/ # 工具类
|
||||||
|
│ ├── DateUtil.java
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
├── constants/ # 常量类
|
||||||
|
│ ├── StatusCode.java
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
├── enums/ # 枚举类
|
||||||
|
│ ├── ResultCodeEnum.java
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
└── Application.java # 启动类
|
||||||
|
```
|
||||||
|
|
||||||
|
## MVC各层职责说明
|
||||||
|
|
||||||
|
| 包名 | 职责 | 关键注解 | 典型类名示例 |
|
||||||
|
|------|------|----------|-------------|
|
||||||
|
| **controller** | 接收HTTP请求,参数校验,调用Service层,返回VO给前端 | `@RestController`<br>`@RequestMapping`<br>`@Validated` | `UserController.java` |
|
||||||
|
| **service** | 业务逻辑处理,事务管理,调用Mapper层,组装数据 | `@Service`<br>`@Transactional` | `UserService.java`(接口)<br>`UserServiceImpl.java`(实现) |
|
||||||
|
| **mapper** | 数据库CRUD操作,SQL映射,与数据库交互 | `@Mapper`<br>`@Repository`| `UserMapper.java` |
|
||||||
|
| **domain/entity** | 数据库表映射实体,与表结构一一对应 | `@TableName`(MyBatis-Plus)| `User.java` |
|
||||||
|
| **domain/dto** | 接口输入参数对象,用于接收前端请求数据,可添加校验注解 | `@Data`<br>`@NotBlank`/`@NotNull`等校验注解 | `ProductQueryDTO.java` |
|
||||||
|
| **domain/vo** | 接口输出结果对象,用于返回前端展示数据,过滤敏感字段 | `@Data`<br>无业务注解 |`ProductVO.java` |
|
||||||
|
| **config** | 配置类 | `@Configuration`<br>`@Bean` | `DataSourceConfig.java`|
|
||||||
|
| **utils** | 通用工具类,提供各种辅助方法 | 无注解 | `DateUtil.java` |
|
||||||
|
| **constants** | 常量定义,统一管理常量值 | 无注解 | `Constants.java` |
|
||||||
|
| **enums** | 枚举类型定义,管理固定状态码、类型等 | `@Enum` |`ResultCodeEnum.java` |
|
||||||
|
| **Application** | 项目启动类,Spring Boot应用入口 | `@SpringBootApplication`<br>`@MapperScan` | `Application.java` |
|
||||||
|
|
||||||
|
## 各层调用关系图
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
subgraph 调用链
|
||||||
|
Controller -->|依赖调用| Service
|
||||||
|
Service -->|依赖调用| Mapper
|
||||||
|
Mapper -->|依赖调用| Database
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph 数据对象
|
||||||
|
DTO[DTO<br/>输入参数]
|
||||||
|
VO[VO<br/>输出结果]
|
||||||
|
Entity[Entity<br/>实体对象]
|
||||||
|
end
|
||||||
|
|
||||||
|
Controller -.->|接收| DTO
|
||||||
|
Controller -.->|返回| VO
|
||||||
|
Service -.->|转换| Entity
|
||||||
|
Mapper -.->|操作| Entity
|
||||||
|
```
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
按步骤一步步执行:
|
||||||
|
|
||||||
|
1. 从**项目根目录**的`pom.xml`获取以下几个属性:
|
||||||
|
|
||||||
|
- `profiles.active`
|
||||||
|
- `nacos.server`
|
||||||
|
- `nacos.config.group`
|
||||||
|
- `nacos.username`
|
||||||
|
- `nacos.password`
|
||||||
|
|
||||||
|
2. 获取accessToken。
|
||||||
|
|
||||||
|
请求示例:
|
||||||
|
```bash
|
||||||
|
curl -X POST 'http://{nacos.server}/nacos/v1/auth/login' -d 'username={nacos.username}&password={nacos.password}'
|
||||||
|
```
|
||||||
|
|
||||||
|
输出示例:
|
||||||
|
```json
|
||||||
|
{"accessToken":"xxx"}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果输出不包含accessToken字段视为失败,**最多重试2次,仍然失败则直接中断整个流程。**
|
||||||
|
|
||||||
|
3. 获取配置文件信息。
|
||||||
|
|
||||||
|
- `dataId`:如果要请求MySQL执行SQL使用`datasource.yml`,否则使用`mis-agent.yml`。
|
||||||
|
- `accessToken`:上一步得到的`accessToken`。
|
||||||
|
|
||||||
|
请求示例:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X GET "http://{nacos.server}/nacos/v3/console/cs/config?dataId={dataId}&groupName={groupName}&namespaceId={profiles.active}" -H "Authorization: Bearer {accessToken}"
|
||||||
|
```
|
||||||
|
|
||||||
|
输出示例:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"message": "success",
|
||||||
|
"data": {"content": "..."}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`data.content`就是配置内容,通常是yaml格式。
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
从**项目根目录**`pom.xml`文件中获取查看`profiles`标签内容,类似如下片段:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<profile>
|
||||||
|
<id>dev</id>
|
||||||
|
<properties>
|
||||||
|
<profiles.active>lab</profiles.active>
|
||||||
|
<!-- 当前环境的Nacos服务地址 -->
|
||||||
|
<nacos.server>127.0.0.1:8868</nacos.server>
|
||||||
|
<!-- 当前环境的Nacos注册中心分组名称 -->
|
||||||
|
<nacos.discovery.group>DEFAULT_GROUP</nacos.discovery.group>
|
||||||
|
<!-- 当前环境的Nacos配置中心分组名称 -->
|
||||||
|
<nacos.config.group>DEFAULT_GROUP</nacos.config.group>
|
||||||
|
<!-- 当前环境的Nacos登录账号 -->
|
||||||
|
<nacos.username>nacos</nacos.username>
|
||||||
|
<!-- 当前环境的Nacos登录密码 -->
|
||||||
|
<nacos.password>1234567890</nacos.password>
|
||||||
|
<!-- 当前环境的NewAPI服务地址 -->
|
||||||
|
<newAPI.url>http://127.0.0.1:3000</newAPI.url>
|
||||||
|
<!-- 当前环境的NewAPI模型ApiKey -->
|
||||||
|
<newAPI.key>sk-xxx</newAPI.key>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
```
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
# 使用场景
|
||||||
|
|
||||||
|
凡是**异步且对延迟时间不敏感的任务**一律使用工单,如果不确定则向用户询问是否要使用工单。
|
||||||
|
|
||||||
|
## 前置条件
|
||||||
|
|
||||||
|
请先在编写代码的模块,检查是否存在`WorkSheetHandler.java`或者`SimpleWorkSheet.java`类,若存在则直接使用工单,不存在则不使用工单。
|
||||||
|
|
||||||
|
## 使用案例
|
||||||
|
|
||||||
|
调用方使用`tryOrderCreate`方法,遇到异常将自动处理重试逻辑。
|
||||||
|
|
||||||
|
```java
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WorksheetExample implements SimpleWorkSheet {
|
||||||
|
|
||||||
|
private final WorkSheetHandler workSheetHandler;
|
||||||
|
|
||||||
|
public void tryOrderCreate(String taskId, ExampleDTO param) {
|
||||||
|
try {
|
||||||
|
createOrder(param);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("do_something_err", e);
|
||||||
|
workSheetHandler.putObjectParam(getWorkCode(), taskId, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createOrder(ExampleDTO param) {
|
||||||
|
// do something
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getWorkCode() {
|
||||||
|
return "ORDER_CREATE";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object execute(WorkSheetEntity workSheet) {
|
||||||
|
createOrder(workSheet.readBeanParam(ExampleDTO.class));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user