|
|
|
package com.supervision.pdfqaserver.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
import com.supervision.pdfqaserver.constant.DomainMetaGenerationEnum;
|
|
|
|
import com.supervision.pdfqaserver.domain.DomainMetadata;
|
|
|
|
import com.supervision.pdfqaserver.domain.ErAttribute;
|
|
|
|
import com.supervision.pdfqaserver.domain.IntentionDomainMetadata;
|
|
|
|
import com.supervision.pdfqaserver.dto.DomainMetadataDTO;
|
|
|
|
import com.supervision.pdfqaserver.dto.ERAttributeDTO;
|
|
|
|
import com.supervision.pdfqaserver.service.DomainMetadataService;
|
|
|
|
import com.supervision.pdfqaserver.mapper.DomainMetadataMapper;
|
|
|
|
import com.supervision.pdfqaserver.service.ErAttributeService;
|
|
|
|
import com.supervision.pdfqaserver.service.IntentionDomainMetadataService;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Administrator
|
|
|
|
* @description 针对表【domain_metadata(领域元数据)】的数据库操作Service实现
|
|
|
|
* @createDate 2025-04-27 11:45:24
|
|
|
|
*/
|
|
|
|
@Slf4j
|
|
|
|
@Service
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
public class DomainMetadataServiceImpl extends ServiceImpl<DomainMetadataMapper, DomainMetadata>
|
|
|
|
implements DomainMetadataService{
|
|
|
|
|
|
|
|
|
|
|
|
private final IntentionDomainMetadataService intentionDomainMetadataService;
|
|
|
|
|
|
|
|
private final ErAttributeService erAttributeService;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void saveIfNotExists(DomainMetadata metadata) {
|
|
|
|
|
|
|
|
boolean exists = this.lambdaQuery()
|
|
|
|
.eq(DomainMetadata::getSourceType, metadata.getSourceType())
|
|
|
|
.eq(DomainMetadata::getTargetType, metadata.getTargetType())
|
|
|
|
.eq(DomainMetadata::getRelation, metadata.getRelation()).exists();
|
|
|
|
if (!exists) {
|
|
|
|
this.save(metadata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void saveIfNotExists(DomainMetadata metadata, String domainCategoryId) {
|
|
|
|
DomainMetadata data = this.getByPrimaryKey(metadata.getSourceType(), metadata.getTargetType(), metadata.getRelation(), domainCategoryId);
|
|
|
|
if (null != data){
|
|
|
|
metadata.setId(data.getId());
|
|
|
|
}else {
|
|
|
|
metadata.setDomainCategoryId(domainCategoryId);
|
|
|
|
super.save(metadata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void batchSaveOrUpdateMetadata(List<DomainMetadataDTO> metadatas,String intentionId,String domainCategoryId) {
|
|
|
|
if (CollUtil.isEmpty(metadatas)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Assert.notEmpty(domainCategoryId, "行业分类ID不能为空");
|
|
|
|
Assert.notEmpty(intentionId, "意图ID不能为空");
|
|
|
|
|
|
|
|
for (DomainMetadataDTO metadata : metadatas) {
|
|
|
|
DomainMetadata data = this.getByPrimaryKey(metadata.getSourceType(), metadata.getTargetType(), metadata.getRelation(), domainCategoryId);
|
|
|
|
if (null != data){
|
|
|
|
metadata.setId(data.getId());
|
|
|
|
}else {
|
|
|
|
DomainMetadata domainMetadata = metadata.toDomainMetadata();
|
|
|
|
domainMetadata.setGenerationType(DomainMetaGenerationEnum.SYSTEM_AUTO_GENERATION.getCode());// 1:系统录入
|
|
|
|
this.saveIfNotExists(domainMetadata, domainCategoryId);
|
|
|
|
metadata.setId(domainMetadata.getId());
|
|
|
|
}
|
|
|
|
// 保存意图和领域元数据的关系
|
|
|
|
intentionDomainMetadataService.batchSaveIfAbsent(intentionId, List.of(metadata.getId()));
|
|
|
|
// 保存意图和领域元数据的关系属性
|
|
|
|
List<ERAttributeDTO> relationAttributes = metadata.getRelationAttributes();
|
|
|
|
if (CollUtil.isNotEmpty(relationAttributes)){
|
|
|
|
for (ERAttributeDTO relationAttribute : relationAttributes) {
|
|
|
|
relationAttribute.setDomainMetadataId(metadata.getId());
|
|
|
|
relationAttribute.setErType("2");
|
|
|
|
erAttributeService.saveIfAbsents(relationAttribute.toErAttribute(), metadata.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 保存意图和领域元数据的节点属性
|
|
|
|
List<ERAttributeDTO> nodeAttributes = metadata.getSourceAttributes();
|
|
|
|
nodeAttributes.addAll(metadata.getTargetAttributes());
|
|
|
|
if (CollUtil.isNotEmpty(nodeAttributes)){
|
|
|
|
for (ERAttributeDTO nodeAttribute : nodeAttributes) {
|
|
|
|
nodeAttribute.setDomainMetadataId(metadata.getId());
|
|
|
|
nodeAttribute.setErType("1");
|
|
|
|
erAttributeService.saveIfAbsents(nodeAttribute.toErAttribute(), metadata.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void completeSave(DomainMetadataDTO domainMetadataDTO) {
|
|
|
|
/* if (CollUtil.isEmpty(domainMetadataDTOS)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (DomainMetadataDTO domainMetadataDTO : domainMetadataDTOS) {
|
|
|
|
DomainMetadata domainMetadata = domainMetadataDTO.toDomainMetadata();
|
|
|
|
this.saveIfNotExists(domainMetadata);
|
|
|
|
// 保存属性信息
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DomainMetadata getByPrimaryKey(String sourceType, String targetType, String relation, String domainCategoryId) {
|
|
|
|
return this.lambdaQuery()
|
|
|
|
.eq(DomainMetadata::getSourceType, sourceType)
|
|
|
|
.eq(DomainMetadata::getTargetType, targetType)
|
|
|
|
.eq(DomainMetadata::getRelation, relation)
|
|
|
|
.eq(DomainMetadata::getDomainCategoryId, domainCategoryId)
|
|
|
|
.one();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<DomainMetadataDTO> listByIntentionIds(List<String> intentionIds) {
|
|
|
|
|
|
|
|
List<DomainMetadataDTO> domainMetadataDTOS = new ArrayList<>();
|
|
|
|
List<IntentionDomainMetadata> intentionDomainMetadataList = intentionDomainMetadataService.listByIntentionIds(intentionIds);
|
|
|
|
if (CollUtil.isEmpty(intentionDomainMetadataList)){
|
|
|
|
return domainMetadataDTOS;
|
|
|
|
}
|
|
|
|
List<String> domainMetadataIds = intentionDomainMetadataList.stream().map(IntentionDomainMetadata::getDomainMetadataId).distinct().toList();
|
|
|
|
List<ErAttribute> erAttributes = erAttributeService.listByDomainMetadataIds(domainMetadataIds);
|
|
|
|
for (IntentionDomainMetadata intentionDomainMetadata : intentionDomainMetadataList) {
|
|
|
|
DomainMetadata domainMetadata = this.getById(intentionDomainMetadata.getDomainMetadataId());
|
|
|
|
domainMetadataDTOS.add(new DomainMetadataDTO(domainMetadata, erAttributes));
|
|
|
|
}
|
|
|
|
return domainMetadataDTOS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|