|
|
|
@ -161,7 +161,9 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
boolean save;
|
|
|
|
|
if (StringUtils.isEmpty(prompt.getId())) {
|
|
|
|
|
// 新增的时候,校验是否已经存在相同的三元组关系,如果已经存在了相同的三元组关系,不允许添加
|
|
|
|
|
checkHasSameTriple(prompt.getStartEntityType(), prompt.getRelType(), prompt.getEndEntityType(), null);
|
|
|
|
|
if (checkHasSameTriple(prompt.getStartEntityType(), prompt.getRelType(), prompt.getEndEntityType(), null)) {
|
|
|
|
|
return R.fail("已存在相同的三元组关系,不允许添加");
|
|
|
|
|
}
|
|
|
|
|
save = notePromptService.save(prompt);
|
|
|
|
|
// 新增prompt绑定的分类信息
|
|
|
|
|
for (String typeId : typeList) {
|
|
|
|
@ -171,7 +173,9 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
notePromptTypeRelService.save(rel);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
checkHasSameTriple(prompt.getStartEntityType(), prompt.getRelType(), prompt.getEndEntityType(), prompt.getId());
|
|
|
|
|
if (checkHasSameTriple(prompt.getStartEntityType(), prompt.getRelType(), prompt.getEndEntityType(), prompt.getId())) {
|
|
|
|
|
return R.fail("已存在相同的三元组关系,不允许添加");
|
|
|
|
|
}
|
|
|
|
|
save = notePromptService.updateById(prompt);
|
|
|
|
|
// 更新prompt绑定的分类信息
|
|
|
|
|
// 首先查询已经有的,如果都存在,就不变,如果数据库有,前端没有,就删除,如果前端有,数据库没有,就新增
|
|
|
|
@ -255,21 +259,18 @@ public class ModelRecordTypeServiceImpl extends ServiceImpl<ModelRecordTypeMappe
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkHasSameTriple(String startEntityType, String relType, String endEntityType, String promptId) {
|
|
|
|
|
private boolean checkHasSameTriple(String startEntityType, String relType, String endEntityType, String promptId) {
|
|
|
|
|
List<NotePrompt> list = notePromptService.lambdaQuery().eq(NotePrompt::getStartEntityType, startEntityType)
|
|
|
|
|
.eq(NotePrompt::getRelType, relType).eq(NotePrompt::getEndEntityType, endEntityType).list();
|
|
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
if (StrUtil.isBlank(promptId)) {
|
|
|
|
|
throw new RuntimeException("该三元组关系已经存在,请勿重复添加");
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// 校验list查出来的是不是和promptId相等,如果不想等,也报错
|
|
|
|
|
if (!list.get(0).getId().equals(promptId)) {
|
|
|
|
|
throw new RuntimeException("该三元组关系已经存在,请勿重复添加");
|
|
|
|
|
}
|
|
|
|
|
return !list.get(0).getId().equals(promptId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|