[update] Prompt模版详情返回值新增
This commit is contained in:
parent
cb495b69c0
commit
08d20b55f3
@ -19,6 +19,7 @@ import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
@ -194,26 +195,66 @@ public class PromptTemplatesServiceImpl implements PromptTemplatesService {
|
||||
@Override
|
||||
public PromptTemplatesRespVO getPromptTemplates(Long id) {
|
||||
PromptTemplatesDO templatesDO = this.promptTemplatesMapper.selectById(id);
|
||||
|
||||
if(templatesDO == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PromptTemplatesRespVO promptTemplates = BeanUtils.toBean(templatesDO, PromptTemplatesRespVO.class);
|
||||
|
||||
// 标签
|
||||
List<PromptTemplatesTagsDO> tagDOList = this.promptTemplatesTagsMapper
|
||||
.selectList("prompt_template_id", id);
|
||||
if(tagDOList!=null && !tagDOList.isEmpty()) {
|
||||
|
||||
List<LabelDO> labelList = labelService.getLabelList();
|
||||
if (CollectionUtils.isEmpty(labelList)){
|
||||
labelList=new ArrayList<>();
|
||||
}
|
||||
|
||||
Map<Long, String> labelMap = new HashMap<>();
|
||||
labelList.forEach(labelDO -> labelMap.put(labelDO.getId(), labelDO.getLabelName()));
|
||||
|
||||
|
||||
if (tagDOList!= null &&!tagDOList.isEmpty()) {
|
||||
List<String> tagIds = tagDOList.stream()
|
||||
.map(p->p.getTagId().toString())
|
||||
.map(p -> String.valueOf(p.getTagId()))
|
||||
.collect(Collectors.toList());
|
||||
promptTemplates.setTagIds(tagIds);
|
||||
|
||||
|
||||
List<String> labelNameList = tagIds.stream()
|
||||
.map(tagId -> labelMap.computeIfAbsent(Long.parseLong(tagId), k -> null))
|
||||
.collect(Collectors.toList());
|
||||
promptTemplates.setTagNames(labelNameList);
|
||||
}
|
||||
|
||||
// 应用
|
||||
List<PromptTemplatesApplicationsDO> applicationDOList = this.promptTemplatesApplicationsMapper
|
||||
.selectList("prompt_template_id", id);
|
||||
|
||||
List<ApplicationDO> appList = applicationService.getList();
|
||||
if (CollectionUtils.isEmpty(appList)){
|
||||
appList=new ArrayList<>();
|
||||
}
|
||||
|
||||
labelList.forEach(labelDO -> labelMap.put(labelDO.getId(), labelDO.getLabelName()));
|
||||
|
||||
HashMap<Long,String> appMap = new HashMap<>();
|
||||
appList.forEach(applicationDO -> appMap.put(applicationDO.getId(),applicationDO.getAppName()));
|
||||
|
||||
if(applicationDOList!=null && !applicationDOList.isEmpty()) {
|
||||
List<String> applicationIds = applicationDOList.stream()
|
||||
.map(p->p.getApplicationId().toString())
|
||||
.collect(Collectors.toList());
|
||||
promptTemplates.setApplicationIds(applicationIds);
|
||||
|
||||
|
||||
List<String> appNameList = applicationIds.stream()
|
||||
.map(appId -> appMap.computeIfAbsent(Long.parseLong(appId), k -> null))
|
||||
.collect(Collectors.toList());
|
||||
promptTemplates.setApplicationNames(appNameList);
|
||||
}
|
||||
|
||||
// String categoryName = this.dictDataApi.getDictDataLabel("llm_prompt_template_framework",Integer.valueOf(templatesDO.getTemplateFramework()));
|
||||
// switch (categoryName) {
|
||||
// case "简介框架":
|
||||
|
@ -23,6 +23,7 @@ import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -141,42 +142,78 @@ public class PromptTemplatesBackupServiceImpl implements PromptTemplatesBackupSe
|
||||
}
|
||||
|
||||
PromptTemplatesBackupRespVO promptTemplates = BeanUtils.toBean(templatesDO, PromptTemplatesBackupRespVO.class);
|
||||
// 标签
|
||||
List<PromptTemplatesTagsDO> tagDOList = this.promptTemplatesTagsMapper
|
||||
.selectList("prompt_template_id", templatesDO.getSrcId());
|
||||
if(tagDOList!=null && !tagDOList.isEmpty()) {
|
||||
|
||||
List<LabelDO> labelList = labelService.getLabelList();
|
||||
if (CollectionUtils.isEmpty(labelList)){
|
||||
labelList=new ArrayList<>();
|
||||
}
|
||||
|
||||
Map<Long, String> labelMap = new HashMap<>();
|
||||
labelList.forEach(labelDO -> labelMap.put(labelDO.getId(), labelDO.getLabelName()));
|
||||
|
||||
|
||||
if (tagDOList!= null &&!tagDOList.isEmpty()) {
|
||||
List<String> tagIds = tagDOList.stream()
|
||||
.map(p->p.getTagId().toString())
|
||||
.map(p -> String.valueOf(p.getTagId()))
|
||||
.collect(Collectors.toList());
|
||||
promptTemplates.setTagIds(tagIds);
|
||||
|
||||
|
||||
List<String> labelNameList = tagIds.stream()
|
||||
.map(tagId -> labelMap.computeIfAbsent(Long.parseLong(tagId), k -> null))
|
||||
.collect(Collectors.toList());
|
||||
promptTemplates.setTagNames(labelNameList);
|
||||
}
|
||||
|
||||
// 应用
|
||||
List<PromptTemplatesApplicationsDO> applicationDOList = this.promptTemplatesApplicationsMapper
|
||||
.selectList("prompt_template_id", templatesDO.getSrcId());
|
||||
|
||||
List<ApplicationDO> appList = applicationService.getList();
|
||||
if (CollectionUtils.isEmpty(appList)){
|
||||
appList=new ArrayList<>();
|
||||
}
|
||||
|
||||
labelList.forEach(labelDO -> labelMap.put(labelDO.getId(), labelDO.getLabelName()));
|
||||
|
||||
HashMap<Long,String> appMap = new HashMap<>();
|
||||
appList.forEach(applicationDO -> appMap.put(applicationDO.getId(),applicationDO.getAppName()));
|
||||
|
||||
if(applicationDOList!=null && !applicationDOList.isEmpty()) {
|
||||
List<String> applicationIds = applicationDOList.stream()
|
||||
.map(p->p.getApplicationId().toString())
|
||||
.collect(Collectors.toList());
|
||||
promptTemplates.setApplicationIds(applicationIds);
|
||||
|
||||
|
||||
List<String> appNameList = applicationIds.stream()
|
||||
.map(appId -> appMap.computeIfAbsent(Long.parseLong(appId), k -> null))
|
||||
.collect(Collectors.toList());
|
||||
promptTemplates.setApplicationNames(appNameList);
|
||||
}
|
||||
String categoryName = this.dictDataApi.getDictDataLabel("llm_prompt_template_framework",Integer.valueOf(templatesDO.getTemplateFramework()));
|
||||
switch (categoryName) {
|
||||
case "简介框架":
|
||||
promptTemplates.setBriefFramework(JSON.parseObject(promptTemplates
|
||||
.getTemplateText(), BriefFramework.class));
|
||||
promptTemplates.setTemplateText("");
|
||||
break;
|
||||
case "角色能力框架":
|
||||
promptTemplates.setAbilityFramework(JSON.parseObject(promptTemplates
|
||||
.getTemplateText(), AbilityFramework.class));
|
||||
promptTemplates.setTemplateText("");
|
||||
break;
|
||||
case "样例提示框架":
|
||||
promptTemplates.setSampleFramework(JSON.parseObject(promptTemplates
|
||||
.getTemplateText(), SampleFramework.class));
|
||||
promptTemplates.setTemplateText("");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// String categoryName = this.dictDataApi.getDictDataLabel("llm_prompt_template_framework",Integer.valueOf(templatesDO.getTemplateFramework()));
|
||||
// switch (categoryName) {
|
||||
// case "简介框架":
|
||||
// promptTemplates.setBriefFramework(JSON.parseObject(promptTemplates
|
||||
// .getTemplateText(), BriefFramework.class));
|
||||
// promptTemplates.setTemplateText("");
|
||||
// break;
|
||||
// case "角色能力框架":
|
||||
// promptTemplates.setAbilityFramework(JSON.parseObject(promptTemplates
|
||||
// .getTemplateText(), AbilityFramework.class));
|
||||
// promptTemplates.setTemplateText("");
|
||||
// break;
|
||||
// case "样例提示框架":
|
||||
// promptTemplates.setSampleFramework(JSON.parseObject(promptTemplates
|
||||
// .getTemplateText(), SampleFramework.class));
|
||||
// promptTemplates.setTemplateText("");
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
return promptTemplates;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user