下载Prompt模板时,显示关联标签的名称而不是Id。
This commit is contained in:
parent
438ac49fba
commit
6e80da1d1d
@ -8,25 +8,17 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.llm.controller.admin.prompttemplates.vo.*;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.prompttemplates.PromptTemplatesDO;
|
||||
import cn.iocoder.yudao.module.llm.service.prompttemplates.PromptTemplatesService;
|
||||
|
||||
@Tag(name = "管理后台 - Prompt模板")
|
||||
@ -34,7 +26,6 @@ import cn.iocoder.yudao.module.llm.service.prompttemplates.PromptTemplatesServic
|
||||
@RequestMapping("/llm/prompt-templates")
|
||||
@Validated
|
||||
public class PromptTemplatesController {
|
||||
|
||||
@Resource
|
||||
private PromptTemplatesService promptTemplatesService;
|
||||
|
||||
@ -82,18 +73,7 @@ public class PromptTemplatesController {
|
||||
@PreAuthorize("@ss.hasPermission('llm:prompt-templates:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportPromptTemplatesExcel(@Valid PromptTemplatesPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<PromptTemplatesRespVO> list = promptTemplatesService.getPromptTemplatesPage(pageReqVO).getList();
|
||||
List<PromptTemplatesExcelVO> excelList = BeanUtils.toBean(list, PromptTemplatesExcelVO.class);
|
||||
for(PromptTemplatesExcelVO excelVO : excelList){
|
||||
// TODO 从字典模块查询
|
||||
excelVO.setTemplateCategoryDisplay("");
|
||||
excelVO.setTag("");
|
||||
}
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "Prompt模板信息.xls", "数据",
|
||||
PromptTemplatesExcelVO.class, excelList);
|
||||
HttpServletResponse response) throws Exception {
|
||||
this.promptTemplatesService.exportPromptTemplatesExcel(pageReqVO, response);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@ import java.util.List;
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class PromptTemplatesExcelVO {
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("模板名称")
|
||||
private String name;
|
||||
|
||||
|
@ -1,55 +1,21 @@
|
||||
package cn.iocoder.yudao.module.llm.service.prompttemplates;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.llm.controller.admin.prompttemplates.vo.*;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.prompttemplates.PromptTemplatesDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* Prompt 模板表,用于记录每个模板的信息 Service 接口
|
||||
*
|
||||
* @author 华大大模型
|
||||
*/
|
||||
public interface PromptTemplatesService {
|
||||
|
||||
/**
|
||||
* 创建Prompt 模板表,用于记录每个模板的信息
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createPromptTemplates(@Valid PromptTemplatesSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新Prompt 模板表,用于记录每个模板的信息
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updatePromptTemplates(@Valid PromptTemplatesSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除Prompt 模板表,用于记录每个模板的信息
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deletePromptTemplates(Long id);
|
||||
|
||||
/**
|
||||
* 获得Prompt 模板表,用于记录每个模板的信息
|
||||
*
|
||||
* @param id 编号
|
||||
* @return Prompt 模板表,用于记录每个模板的信息
|
||||
*/
|
||||
PromptTemplatesRespVO getPromptTemplates(Long id);
|
||||
|
||||
/**
|
||||
* 获得Prompt 模板表,用于记录每个模板的信息分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return Prompt 模板表,用于记录每个模板的信息分页
|
||||
*/
|
||||
PageResult<PromptTemplatesRespVO> getPromptTemplatesPage(PromptTemplatesPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
void exportPromptTemplatesExcel(PromptTemplatesPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws Exception;
|
||||
}
|
@ -1,14 +1,19 @@
|
||||
package cn.iocoder.yudao.module.llm.service.prompttemplates;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.label.LabelDO;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.prompttemplatesapplications.PromptTemplatesApplicationsDO;
|
||||
import cn.iocoder.yudao.module.llm.dal.dataobject.prompttemplatestags.PromptTemplatesTagsDO;
|
||||
import cn.iocoder.yudao.module.llm.dal.mysql.prompttemplatesapplications.PromptTemplatesApplicationsMapper;
|
||||
import cn.iocoder.yudao.module.llm.dal.mysql.prompttemplatestags.PromptTemplatesTagsMapper;
|
||||
import cn.iocoder.yudao.module.llm.service.label.LabelService;
|
||||
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -24,26 +29,23 @@ import cn.iocoder.yudao.module.llm.dal.mysql.prompttemplates.PromptTemplatesMapp
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* Prompt 模板表,用于记录每个模板的信息 Service 实现类
|
||||
*
|
||||
* @author 华大大模型
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class PromptTemplatesServiceImpl implements PromptTemplatesService {
|
||||
|
||||
@Resource
|
||||
private PromptTemplatesMapper promptTemplatesMapper;
|
||||
@Resource
|
||||
private PromptTemplatesTagsMapper promptTemplatesTagsMapper;
|
||||
@Resource
|
||||
private PromptTemplatesApplicationsMapper promptTemplatesApplicationsMapper;
|
||||
@Resource
|
||||
private DictDataApi dictDataApi;
|
||||
@Resource
|
||||
private LabelService labelService;
|
||||
|
||||
@Override
|
||||
public Long createPromptTemplates(PromptTemplatesSaveReqVO createReqVO) {
|
||||
this.isNameDuplicate(createReqVO.getName());
|
||||
// 插入
|
||||
PromptTemplatesDO promptTemplates = BeanUtils.toBean(createReqVO, PromptTemplatesDO.class);
|
||||
promptTemplates.setTemplateType(2);
|
||||
promptTemplatesMapper.insert(promptTemplates);
|
||||
@ -67,15 +69,12 @@ public class PromptTemplatesServiceImpl implements PromptTemplatesService {
|
||||
.collect(Collectors.toList());
|
||||
this.promptTemplatesApplicationsMapper.insertBatch(applicationDOList, 1);
|
||||
}
|
||||
// 返回
|
||||
return promptTemplates.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePromptTemplates(PromptTemplatesSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validatePromptTemplatesExists(updateReqVO.getId());
|
||||
// 更新
|
||||
PromptTemplatesDO updateObj = BeanUtils.toBean(updateReqVO, PromptTemplatesDO.class);
|
||||
promptTemplatesMapper.updateById(updateObj);
|
||||
Map<String, Object> deleteCondition = new HashMap<>(1);
|
||||
@ -106,9 +105,7 @@ public class PromptTemplatesServiceImpl implements PromptTemplatesService {
|
||||
|
||||
@Override
|
||||
public void deletePromptTemplates(Long id) {
|
||||
// 校验存在
|
||||
validatePromptTemplatesExists(id);
|
||||
// 删除
|
||||
promptTemplatesMapper.deleteById(id);
|
||||
Map<String, Object> condition = new HashMap<>(1);
|
||||
condition.put("prompt_template_id", id);
|
||||
@ -124,7 +121,7 @@ public class PromptTemplatesServiceImpl implements PromptTemplatesService {
|
||||
|
||||
private void isNameDuplicate(String name) {
|
||||
List<PromptTemplatesDO> templateDOList = this.promptTemplatesMapper.selectList("name", name);
|
||||
if(templateDOList!=null && templateDOList.size()>0) {
|
||||
if(templateDOList!=null && !templateDOList.isEmpty()) {
|
||||
throw exception(PROMPT_TEMPLATES_EXISTS);
|
||||
}
|
||||
}
|
||||
@ -166,9 +163,39 @@ public class PromptTemplatesServiceImpl implements PromptTemplatesService {
|
||||
Long applicationCount = this.promptTemplatesApplicationsMapper.selectCount(
|
||||
new QueryWrapper<PromptTemplatesApplicationsDO>()
|
||||
.eq("prompt_template_id", respVO.getId()));
|
||||
respVO.setApplicationCount(Integer.valueOf(applicationCount.toString()));
|
||||
respVO.setApplicationCount(Integer.parseInt(applicationCount.toString()));
|
||||
}
|
||||
return pageRespList;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void exportPromptTemplatesExcel(PromptTemplatesPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws Exception {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<PromptTemplatesRespVO> list = this.getPromptTemplatesPage(pageReqVO).getList();
|
||||
List<PromptTemplatesExcelVO> excelList = BeanUtils.toBean(list, PromptTemplatesExcelVO.class);
|
||||
for(PromptTemplatesExcelVO excelVO : excelList){
|
||||
try {
|
||||
excelVO.setTemplateCategoryDisplay(this.dictDataApi
|
||||
.getDictDataLabel(Long.valueOf(excelVO.getTemplateCategory().toString())));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
List<PromptTemplatesTagsDO> tagDOList = this.promptTemplatesTagsMapper
|
||||
.selectList("prompt_template_id", excelVO.getId());
|
||||
if(tagDOList!=null && !tagDOList.isEmpty()) {
|
||||
excelVO.setTag(tagDOList.stream()
|
||||
.map(p->this.labelService.getLabel(p.getTagId()))
|
||||
.filter(Objects::nonNull)
|
||||
.map(LabelDO::getLabelName)
|
||||
.collect(Collectors.joining(";")));
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
ExcelUtils.write(response, "Prompt模板信息.xls", "数据",
|
||||
PromptTemplatesExcelVO.class, excelList);
|
||||
}
|
||||
}
|
@ -35,6 +35,14 @@ public interface DictDataApi {
|
||||
*/
|
||||
DictDataRespDTO getDictData(String type, String value);
|
||||
|
||||
/**
|
||||
* 获得指定的字典数据,从缓存中
|
||||
*
|
||||
* @param id
|
||||
* @return 字典数据
|
||||
*/
|
||||
DictDataRespDTO getDictData(Long id);
|
||||
|
||||
/**
|
||||
* 获得指定的字典标签,从缓存中
|
||||
*
|
||||
@ -50,6 +58,20 @@ public interface DictDataApi {
|
||||
return dictData.getLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得指定的字典标签,从缓存中
|
||||
*
|
||||
* @param id
|
||||
* @return 字典标签
|
||||
*/
|
||||
default String getDictDataLabel(Long id) {
|
||||
DictDataRespDTO dictData = getDictData(id);
|
||||
if (ObjUtil.isNull(dictData)) {
|
||||
return StrUtil.EMPTY;
|
||||
}
|
||||
return dictData.getLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析获得指定的字典数据,从缓存中
|
||||
*
|
||||
|
@ -32,6 +32,12 @@ public class DictDataApiImpl implements DictDataApi {
|
||||
return BeanUtils.toBean(dictData, DictDataRespDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DictDataRespDTO getDictData(Long id) {
|
||||
DictDataDO dictData = dictDataService.getDictData(id);
|
||||
return BeanUtils.toBean(dictData, DictDataRespDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DictDataRespDTO parseDictData(String dictType, String label) {
|
||||
DictDataDO dictData = dictDataService.parseDictData(dictType, label);
|
||||
|
Loading…
x
Reference in New Issue
Block a user