mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-03-27 11:33:45 +08:00
Merge pull request #118 from MuSan-Li/feature_20250610_add_prompt_template
Feature 20250610 add prompt template
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package org.ruoyi.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 提示词模板对象 prompt_template
|
||||
*
|
||||
* @author evo
|
||||
* @date 2025-06-12
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("prompt_template")
|
||||
public class PromptTemplate extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 提示词模板名称
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 提示词模板内容
|
||||
*/
|
||||
private String templateContent;
|
||||
|
||||
/**
|
||||
* 提示词分类,knowledge 知识库类型,chat 对话类型,draw绘画类型 ...
|
||||
*/
|
||||
private String category;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.ruoyi.domain.bo;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
import org.ruoyi.domain.PromptTemplate;
|
||||
|
||||
/**
|
||||
* 提示词模板业务对象 prompt_template
|
||||
*
|
||||
* @author evo
|
||||
* @date 2025-06-12
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = PromptTemplate.class, reverseConvertGenerate = false)
|
||||
public class PromptTemplateBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "主键不能为空", groups = {EditGroup.class})
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 提示词模板名称
|
||||
*/
|
||||
@NotBlank(message = "提示词模板名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 提示词模板内容
|
||||
*/
|
||||
@NotBlank(message = "提示词模板内容不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String templateContent;
|
||||
|
||||
/**
|
||||
* 提示词分类,knowledge 知识库类型,chat 对话类型,draw绘画类型 ...
|
||||
*/
|
||||
@NotBlank(message = "提示词分类", groups = {AddGroup.class, EditGroup.class})
|
||||
private String category;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@NotBlank(message = "备注不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.ruoyi.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import org.ruoyi.domain.PromptTemplate;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* 提示词模板视图对象 prompt_template
|
||||
*
|
||||
* @author evo
|
||||
* @date 2025-06-12
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@AutoMapper(target = PromptTemplate.class)
|
||||
public class PromptTemplateVo implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ExcelProperty(value = "主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 提示词模板名称
|
||||
*/
|
||||
@ExcelProperty(value = "提示词模板名称")
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 提示词模板内容
|
||||
*/
|
||||
@ExcelProperty(value = "提示词模板内容")
|
||||
private String templateContent;
|
||||
|
||||
/**
|
||||
* 提示词分类,knowledge 知识库类型,chat 对话类型,draw绘画类型 ...
|
||||
*/
|
||||
@ExcelProperty(value = "提示词分类")
|
||||
private String category;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelProperty(value = "备注")
|
||||
private String remark;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.ruoyi.mapper;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.ruoyi.core.mapper.BaseMapperPlus;
|
||||
import org.ruoyi.domain.PromptTemplate;
|
||||
import org.ruoyi.domain.vo.PromptTemplateVo;
|
||||
|
||||
/**
|
||||
* 提示词模板Mapper接口
|
||||
*
|
||||
* @author evo
|
||||
* @date 2025-06-12
|
||||
*/
|
||||
public interface PromptTemplateMapper extends BaseMapperPlus<PromptTemplate, PromptTemplateVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.ruoyi.service;
|
||||
|
||||
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.domain.bo.PromptTemplateBo;
|
||||
import org.ruoyi.domain.vo.PromptTemplateVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 提示词模板Service接口
|
||||
*
|
||||
* @author evo
|
||||
* @date 2025-06-12
|
||||
*/
|
||||
public interface IPromptTemplateService {
|
||||
|
||||
/**
|
||||
* 查询提示词模板
|
||||
*/
|
||||
PromptTemplateVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询提示词模板列表
|
||||
*/
|
||||
TableDataInfo<PromptTemplateVo> queryPageList(PromptTemplateBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询提示词模板列表
|
||||
*/
|
||||
List<PromptTemplateVo> queryList(PromptTemplateBo bo);
|
||||
|
||||
/**
|
||||
* 新增提示词模板
|
||||
*/
|
||||
Boolean insertByBo(PromptTemplateBo bo);
|
||||
|
||||
/**
|
||||
* 修改提示词模板
|
||||
*/
|
||||
Boolean updateByBo(PromptTemplateBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除提示词模板信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.ruoyi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||
import org.ruoyi.common.core.utils.StringUtils;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.domain.PromptTemplate;
|
||||
import org.ruoyi.domain.bo.PromptTemplateBo;
|
||||
import org.ruoyi.domain.vo.PromptTemplateVo;
|
||||
import org.ruoyi.mapper.PromptTemplateMapper;
|
||||
import org.ruoyi.service.IPromptTemplateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 提示词模板Service业务层处理
|
||||
*
|
||||
* @author evo
|
||||
* @date 2025-06-12
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PromptTemplateServiceImpl implements IPromptTemplateService {
|
||||
|
||||
private final PromptTemplateMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询提示词模板
|
||||
*/
|
||||
@Override
|
||||
public PromptTemplateVo queryById(Long id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询提示词模板列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<PromptTemplateVo> queryPageList(PromptTemplateBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<PromptTemplate> lqw = buildQueryWrapper(bo);
|
||||
Page<PromptTemplateVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询提示词模板列表
|
||||
*/
|
||||
@Override
|
||||
public List<PromptTemplateVo> queryList(PromptTemplateBo bo) {
|
||||
LambdaQueryWrapper<PromptTemplate> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<PromptTemplate> buildQueryWrapper(PromptTemplateBo bo) {
|
||||
LambdaQueryWrapper<PromptTemplate> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getTemplateName()),
|
||||
PromptTemplate::getTemplateName, bo.getTemplateName());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getTemplateContent()),
|
||||
PromptTemplate::getTemplateContent, bo.getTemplateContent());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getCategory()),
|
||||
PromptTemplate::getCategory, bo.getCategory());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增提示词模板
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(PromptTemplateBo bo) {
|
||||
PromptTemplate add = MapstructUtils.convert(bo, PromptTemplate.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改提示词模板
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(PromptTemplateBo bo) {
|
||||
PromptTemplate update = MapstructUtils.convert(bo, PromptTemplate.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(PromptTemplate entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除提示词模板
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user