# 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<Void> add(@Validated @RequestBody {实体类名}Bo bo) {
        return toAjax(service.insertByBo(bo));
    }

    /**
     * 修改{业务名称}
     */
    @Operation(summary = "修改{业务名称}")
    @SaCheckPermission("{模块}:{功能}:edit")
    @PutMapping()
    public R<Void> edit(@Validated @RequestBody {实体类名}Bo bo) {
        return toAjax(service.updateByBo(bo));
    }

    /**
     * 删除{业务名称}
     */
    @Operation(summary = "删除{业务名称}")
    @SaCheckPermission("{模块}:{功能}:remove")
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(service.deleteByIds(ids));
    }
}
```

## 注意事项

1. 所有占位符 `{xxx}` 需要替换为实际值
2. 权限字符串格式: `模块:功能:操作` (如 `inspection:task:add`)
3. 实体类字段需要添加合适的验证注解
4. VO 和 BO 类需要单独创建
5. 复杂查询逻辑在 `buildQueryWrapper` 方法中实现
