From f118cc1e9b8f12d8a4b64b0142aead71dd8cfce3 Mon Sep 17 00:00:00 2001 From: YANG JIANKUAN Date: Mon, 1 Dec 2025 23:57:09 +0800 Subject: [PATCH] feat: opt claude --- .../settings.local.json | 11 + .claude/commands/analyze.md | 29 + .claude/commands/build.md | 20 + .claude/commands/lint.md | 24 + .claude/commands/new-module.md | 39 ++ .claude/commands/start-backend.md | 22 + .claude/commands/start-frontend.md | 26 + .claude/prompts/backend-module-template.md | 248 ++++++++ .claude/prompts/frontend-page-template.md | 329 ++++++++++ .claude/settings.json | 60 ++ CLAUDE.md | 600 ++++++++++++++---- CLAUDE.md.backup-2025-12-01T13-57-32 | 273 ++++++++ 12 files changed, 1542 insertions(+), 139 deletions(-) create mode 100644 .claude.backup-2025-12-01T13-57-32/settings.local.json create mode 100644 .claude/commands/analyze.md create mode 100644 .claude/commands/build.md create mode 100644 .claude/commands/lint.md create mode 100644 .claude/commands/new-module.md create mode 100644 .claude/commands/start-backend.md create mode 100644 .claude/commands/start-frontend.md create mode 100644 .claude/prompts/backend-module-template.md create mode 100644 .claude/prompts/frontend-page-template.md create mode 100644 .claude/settings.json create mode 100644 CLAUDE.md.backup-2025-12-01T13-57-32 diff --git a/.claude.backup-2025-12-01T13-57-32/settings.local.json b/.claude.backup-2025-12-01T13-57-32/settings.local.json new file mode 100644 index 0000000..14ae886 --- /dev/null +++ b/.claude.backup-2025-12-01T13-57-32/settings.local.json @@ -0,0 +1,11 @@ +{ + "permissions": { + "allow": [ + "Bash(tree:*)", + "Bash(mvn clean package:*)", + "Bash(echo:*)" + ], + "deny": [], + "ask": [] + } +} diff --git a/.claude/commands/analyze.md b/.claude/commands/analyze.md new file mode 100644 index 0000000..c2df371 --- /dev/null +++ b/.claude/commands/analyze.md @@ -0,0 +1,29 @@ +--- +description: 分析项目结构并生成架构文档 +--- + +# 项目架构分析 + +执行以下操作: + +1. **分析项目结构**: + - 统计各模块的文件数量 + - 识别主要的业务模块 + - 分析依赖关系 + +2. **检查关键配置**: + - pom.xml 依赖版本 + - application.yml 配置项 + - 前端 package.json 依赖 + +3. **生成架构概览**: + - 模块依赖图 + - 技术栈清单 + - 开发环境要求 + +4. **识别潜在问题**: + - 过时的依赖 + - 配置不一致 + - 代码规范问题 + +输出格式化的架构分析报告。 diff --git a/.claude/commands/build.md b/.claude/commands/build.md new file mode 100644 index 0000000..c189413 --- /dev/null +++ b/.claude/commands/build.md @@ -0,0 +1,20 @@ +--- +description: 构建整个 Maven 项目并运行测试 +--- + +# Maven 项目构建和测试 + +执行以下操作: + +1. 清理之前的构建文件 +2. 编译整个项目(跳过测试) +3. 显示构建结果 +4. 检查是否有编译错误 + +使用 Maven 命令: +```bash +mvn clean install -DskipTests +``` + +如果构建成功,输出项目的模块结构和构建时间。 +如果有错误,分析错误信息并提供解决建议。 diff --git a/.claude/commands/lint.md b/.claude/commands/lint.md new file mode 100644 index 0000000..5a9cd20 --- /dev/null +++ b/.claude/commands/lint.md @@ -0,0 +1,24 @@ +--- +description: 运行前端代码检查和格式化 +--- + +# 前端代码质量检查 + +执行以下操作: + +1. 切换到 plus-ui 目录 +2. 运行 ESLint 检查并自动修复 +3. 运行 Prettier 格式化代码 +4. 显示检查结果 + +使用命令: +```bash +cd plus-ui +npm run lint:eslint:fix +npm run prettier +``` + +检查以下文件类型: +- *.vue (Vue 组件) +- *.ts (TypeScript 文件) +- *.tsx (TypeScript JSX) diff --git a/.claude/commands/new-module.md b/.claude/commands/new-module.md new file mode 100644 index 0000000..3e1355d --- /dev/null +++ b/.claude/commands/new-module.md @@ -0,0 +1,39 @@ +--- +description: 创建新的业务模块(Controller, Service, Mapper, Domain) +--- + +# 创建新的业务模块 + +根据提供的模块名称和功能描述,创建完整的业务模块结构: + +1. **确定模块位置**: ruoyi-modules/ 下的对应业务模块 +2. **创建实体类 (Domain)**: + - 位置: src/main/java/**/domain/ + - 使用 Lombok 注解 + - 继承 BaseEntity + - 添加字段注释和验证注解 + +3. **创建 Mapper 接口**: + - 位置: src/main/java/**/mapper/ + - 继承 BaseMapperPlus + - 添加自定义查询方法 + +4. **创建 Service 接口和实现**: + - 位置: src/main/java/**/service/ 和 service/impl/ + - 实现 CRUD 基础方法 + - 添加业务逻辑方法 + +5. **创建 Controller**: + - 位置: src/main/java/**/controller/ + - 使用 @RestController 和 @RequestMapping + - 实现 RESTful API + - 添加 Swagger 文档注解 + +6. **创建对应的 Mapper XML**: + - 位置: src/main/resources/mapper/**/ + +示例: +- 实体类使用 @Data, @EqualsAndHashCode(callSuper = true) +- Service 使用 @RequiredArgsConstructor +- Controller 返回 R<> 统一响应格式 +- 使用 @SaCheckPermission 进行权限控制 diff --git a/.claude/commands/start-backend.md b/.claude/commands/start-backend.md new file mode 100644 index 0000000..b243080 --- /dev/null +++ b/.claude/commands/start-backend.md @@ -0,0 +1,22 @@ +--- +description: 启动后端 Spring Boot 应用 +--- + +# 启动后端服务 + +执行以下操作: + +1. 检查后端服务是否已经在运行(端口 8080) +2. 如果没有运行,启动 Spring Boot 应用 +3. 监控启动日志,确认服务正常启动 +4. 显示可访问的地址和 API 文档地址 + +使用命令: +```bash +cd ruoyi-admin && mvn spring-boot:run -Dspring-boot.run.profiles=dev +``` + +启动后提示: +- 应用地址: http://localhost:8080 +- API文档: http://localhost:8080/doc.html +- 监控中心: http://localhost:9090/admin diff --git a/.claude/commands/start-frontend.md b/.claude/commands/start-frontend.md new file mode 100644 index 0000000..0355596 --- /dev/null +++ b/.claude/commands/start-frontend.md @@ -0,0 +1,26 @@ +--- +description: 启动前端 Vue3 开发服务器 +--- + +# 启动前端开发服务器 + +执行以下操作: + +1. 切换到前端目录 plus-ui +2. 检查 node_modules 是否存在,如果没有则先安装依赖 +3. 启动 Vite 开发服务器 +4. 显示访问地址 + +使用命令: +```bash +cd plus-ui +# 如果需要安装依赖 +npm install --registry=https://registry.npmmirror.com + +# 启动开发服务器 +npm run dev +``` + +启动后提示: +- 前端地址: http://localhost:80 +- 确保后端服务已启动: http://localhost:8080 diff --git a/.claude/prompts/backend-module-template.md b/.claude/prompts/backend-module-template.md new file mode 100644 index 0000000..74ebc1d --- /dev/null +++ b/.claude/prompts/backend-module-template.md @@ -0,0 +1,248 @@ +# Spring Boot + MyBatis-Plus 业务模块生成提示词 + +当需要创建新的业务模块时,按照以下模板生成代码: + +## 实体类模板 (Domain) + +```java +package com.ruoyi.{module}.domain; + +import com.baomidou.mybatisplus.annotation.*; +import com.ruoyi.common.core.domain.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * {业务名称}对象 {表名} + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("{表名}") +public class {实体类名} extends BaseEntity { + + /** 主键ID */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** 字段说明 */ + private String fieldName; + + // ... 其他字段 +} +``` + +## Mapper 接口模板 + +```java +package com.ruoyi.{module}.mapper; + +import com.ruoyi.common.core.mapper.BaseMapperPlus; +import com.ruoyi.{module}.domain.{实体类名}; +import com.ruoyi.{module}.domain.vo.{实体类名}Vo; + +/** + * {业务名称}Mapper接口 + */ +public interface {实体类名}Mapper extends BaseMapperPlus<{实体类名}Mapper, {实体类名}, {实体类名}Vo> { + +} +``` + +## Service 接口模板 + +```java +package com.ruoyi.{module}.service; + +import com.ruoyi.{module}.domain.vo.{实体类名}Vo; +import com.ruoyi.{module}.domain.bo.{实体类名}Bo; +import com.ruoyi.common.mybatis.core.page.TableDataInfo; +import com.ruoyi.common.mybatis.core.page.PageQuery; + +/** + * {业务名称}Service接口 + */ +public interface I{实体类名}Service { + + /** + * 查询{业务名称} + */ + {实体类名}Vo queryById(Long id); + + /** + * 查询{业务名称}列表 + */ + TableDataInfo<{实体类名}Vo> queryPageList({实体类名}Bo bo, PageQuery pageQuery); + + /** + * 新增{业务名称} + */ + Boolean insertByBo({实体类名}Bo bo); + + /** + * 修改{业务名称} + */ + Boolean updateByBo({实体类名}Bo bo); + + /** + * 删除{业务名称} + */ + Boolean deleteByIds(Long[] ids); +} +``` + +## Service 实现类模板 + +```java +package com.ruoyi.{module}.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import com.ruoyi.common.core.utils.MapstructUtils; +import com.ruoyi.common.mybatis.core.page.TableDataInfo; +import com.ruoyi.common.mybatis.core.page.PageQuery; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import com.ruoyi.{module}.domain.bo.{实体类名}Bo; +import com.ruoyi.{module}.domain.vo.{实体类名}Vo; +import com.ruoyi.{module}.domain.{实体类名}; +import com.ruoyi.{module}.mapper.{实体类名}Mapper; +import com.ruoyi.{module}.service.I{实体类名}Service; + +/** + * {业务名称}Service业务层处理 + */ +@RequiredArgsConstructor +@Service +public class {实体类名}ServiceImpl implements I{实体类名}Service { + + private final {实体类名}Mapper baseMapper; + + @Override + public {实体类名}Vo queryById(Long id) { + return baseMapper.selectVoById(id); + } + + @Override + public TableDataInfo<{实体类名}Vo> queryPageList({实体类名}Bo bo, PageQuery pageQuery) { + LambdaQueryWrapper<{实体类名}> lqw = buildQueryWrapper(bo); + Page<{实体类名}Vo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); + return TableDataInfo.build(result); + } + + private LambdaQueryWrapper<{实体类名}> buildQueryWrapper({实体类名}Bo bo) { + LambdaQueryWrapper<{实体类名}> lqw = Wrappers.lambdaQuery(); + // 添加查询条件 + return lqw; + } + + @Override + public Boolean insertByBo({实体类名}Bo bo) { + {实体类名} entity = MapstructUtils.convert(bo, {实体类名}.class); + return baseMapper.insert(entity) > 0; + } + + @Override + public Boolean updateByBo({实体类名}Bo bo) { + {实体类名} entity = MapstructUtils.convert(bo, {实体类名}.class); + return baseMapper.updateById(entity) > 0; + } + + @Override + public Boolean deleteByIds(Long[] ids) { + return baseMapper.deleteByIds(Arrays.asList(ids)) > 0; + } +} +``` + +## Controller 模板 + +```java +package com.ruoyi.{module}.controller; + +import cn.dev33.satoken.annotation.SaCheckPermission; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.mybatis.core.page.PageQuery; +import com.ruoyi.common.mybatis.core.page.TableDataInfo; +import com.ruoyi.common.web.core.BaseController; +import com.ruoyi.{module}.domain.bo.{实体类名}Bo; +import com.ruoyi.{module}.domain.vo.{实体类名}Vo; +import com.ruoyi.{module}.service.I{实体类名}Service; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; + +/** + * {业务名称}Controller + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/{module}/{路径}") +@Tag(name = "{业务名称}管理", description = "{业务名称}管理") +public class {实体类名}Controller extends BaseController { + + private final I{实体类名}Service service; + + /** + * 查询{业务名称}列表 + */ + @Operation(summary = "查询{业务名称}列表") + @SaCheckPermission("{模块}:{功能}:list") + @GetMapping("/list") + public TableDataInfo<{实体类名}Vo> list({实体类名}Bo bo, PageQuery pageQuery) { + return service.queryPageList(bo, pageQuery); + } + + /** + * 获取{业务名称}详细信息 + */ + @Operation(summary = "获取{业务名称}详细信息") + @SaCheckPermission("{模块}:{功能}:query") + @GetMapping("/{id}") + public R<{实体类名}Vo> getInfo(@PathVariable Long id) { + return R.ok(service.queryById(id)); + } + + /** + * 新增{业务名称} + */ + @Operation(summary = "新增{业务名称}") + @SaCheckPermission("{模块}:{功能}:add") + @PostMapping() + public R add(@Validated @RequestBody {实体类名}Bo bo) { + return toAjax(service.insertByBo(bo)); + } + + /** + * 修改{业务名称} + */ + @Operation(summary = "修改{业务名称}") + @SaCheckPermission("{模块}:{功能}:edit") + @PutMapping() + public R edit(@Validated @RequestBody {实体类名}Bo bo) { + return toAjax(service.updateByBo(bo)); + } + + /** + * 删除{业务名称} + */ + @Operation(summary = "删除{业务名称}") + @SaCheckPermission("{模块}:{功能}:remove") + @DeleteMapping("/{ids}") + public R remove(@PathVariable Long[] ids) { + return toAjax(service.deleteByIds(ids)); + } +} +``` + +## 注意事项 + +1. 所有占位符 `{xxx}` 需要替换为实际值 +2. 权限字符串格式: `模块:功能:操作` (如 `inspection:task:add`) +3. 实体类字段需要添加合适的验证注解 +4. VO 和 BO 类需要单独创建 +5. 复杂查询逻辑在 `buildQueryWrapper` 方法中实现 diff --git a/.claude/prompts/frontend-page-template.md b/.claude/prompts/frontend-page-template.md new file mode 100644 index 0000000..9f42055 --- /dev/null +++ b/.claude/prompts/frontend-page-template.md @@ -0,0 +1,329 @@ +# Vue3 + TypeScript + Element Plus 页面生成提示词 + +当需要创建新的前端页面时,按照以下模板生成代码: + +## API 接口定义模板 + +```typescript +// src/api/{module}/{name}.ts +import request from '@/utils/request' + +/** + * {业务名称} VO 接口 + */ +export interface {Name}VO { + id?: number | string + // ... 其他字段 +} + +/** + * {业务名称} Form 接口 + */ +export interface {Name}Form { + id?: number | string + // ... 其他字段 +} + +/** + * {业务名称} 查询参数 + */ +export interface {Name}Query { + pageNum: number + pageSize: number + // ... 其他查询字段 +} + +/** + * 查询{业务名称}列表 + */ +export const list{Name} = (params: {Name}Query) => { + return request({ + url: '/{module}/{path}/list', + method: 'get', + params + }) +} + +/** + * 查询{业务名称}详情 + */ +export const get{Name} = (id: number | string) => { + return request({ + url: `/{module}/{path}/${id}`, + method: 'get' + }) +} + +/** + * 新增{业务名称} + */ +export const add{Name} = (data: {Name}Form) => { + return request({ + url: '/{module}/{path}', + method: 'post', + data + }) +} + +/** + * 修改{业务名称} + */ +export const update{Name} = (data: {Name}Form) => { + return request({ + url: '/{module}/{path}', + method: 'put', + data + }) +} + +/** + * 删除{业务名称} + */ +export const del{Name} = (ids: (number | string)[]) => { + return request({ + url: `/{module}/{path}/${ids}`, + method: 'delete' + }) +} +``` + +## 列表页面模板 + +```vue + + + + +``` + +## 表单组件模板 + +```vue + + + + +``` + +## 注意事项 + +1. 所有占位符 `{xxx}` 需要替换为实际值 +2. 使用 Composition API 和 `