Quellcode durchsuchen

refactor(backend): 删除废弃的 entity 模块

何文松 vor 20 Stunden
Ursprung
Commit
3b89f21296

+ 0 - 58
backend/lingyue-project/src/main/java/com/lingyue/project/entity/controller/EntityController.java

@@ -1,58 +0,0 @@
-package com.lingyue.project.entity.controller;
-
-import com.lingyue.common.core.Result;
-import com.lingyue.project.entity.dto.EntityMergeDTO;
-import com.lingyue.project.entity.dto.EntityUpdateDTO;
-import com.lingyue.project.entity.dto.EntityVO;
-import com.lingyue.project.entity.service.EntityService;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.validation.Valid;
-import lombok.RequiredArgsConstructor;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.List;
-
-@Tag(name = "实体管理接口")
-@RestController
-@RequiredArgsConstructor
-public class EntityController {
-
-    private final EntityService entityService;
-
-    @Operation(summary = "获取附件实体列表")
-    @GetMapping("/api/v1/attachments/{attachmentId}/entities")
-    public Result<List<EntityVO>> listByAttachment(
-            @PathVariable Long attachmentId,
-            @RequestParam(required = false) String entityType,
-            @RequestParam(required = false) String keyword) {
-        return Result.ok(entityService.listByAttachment(attachmentId, entityType, keyword));
-    }
-
-    @Operation(summary = "获取项目所有实体")
-    @GetMapping("/api/v1/projects/{projectId}/entities")
-    public Result<List<EntityVO>> listByProject(
-            @PathVariable Long projectId,
-            @RequestParam(required = false) String entityType,
-            @RequestParam(required = false) String keyword) {
-        return Result.ok(entityService.listByProject(projectId, entityType, keyword));
-    }
-
-    @Operation(summary = "获取实体详情")
-    @GetMapping("/api/v1/entities/{id}")
-    public Result<EntityVO> detail(@PathVariable Long id) {
-        return Result.ok(entityService.getEntity(id));
-    }
-
-    @Operation(summary = "更新实体")
-    @PutMapping("/api/v1/entities/{id}")
-    public Result<EntityVO> update(@PathVariable Long id, @Valid @RequestBody EntityUpdateDTO dto) {
-        return Result.ok(entityService.updateEntity(id, dto));
-    }
-
-    @Operation(summary = "合并实体")
-    @PostMapping("/api/v1/entities/merge")
-    public Result<EntityVO> merge(@Valid @RequestBody EntityMergeDTO dto) {
-        return Result.ok(entityService.mergeEntities(dto));
-    }
-}

+ 0 - 17
backend/lingyue-project/src/main/java/com/lingyue/project/entity/dto/EntityMergeDTO.java

@@ -1,17 +0,0 @@
-package com.lingyue.project.entity.dto;
-
-import jakarta.validation.constraints.NotEmpty;
-import jakarta.validation.constraints.NotNull;
-import lombok.Data;
-
-import java.util.List;
-
-@Data
-public class EntityMergeDTO {
-
-    @NotNull(message = "目标实体ID不能为空")
-    private Long targetEntityId;
-
-    @NotEmpty(message = "源实体ID列表不能为空")
-    private List<Long> sourceEntityIds;
-}

+ 0 - 14
backend/lingyue-project/src/main/java/com/lingyue/project/entity/dto/EntityUpdateDTO.java

@@ -1,14 +0,0 @@
-package com.lingyue.project.entity.dto;
-
-import lombok.Data;
-
-import java.math.BigDecimal;
-
-@Data
-public class EntityUpdateDTO {
-
-    private String entityText;
-    private String entityType;
-    private String businessLabel;
-    private BigDecimal confidence;
-}

+ 0 - 22
backend/lingyue-project/src/main/java/com/lingyue/project/entity/dto/EntityVO.java

@@ -1,22 +0,0 @@
-package com.lingyue.project.entity.dto;
-
-import lombok.Data;
-
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-
-@Data
-public class EntityVO {
-
-    private Long id;
-    private String entityText;
-    private String entityKey;
-    private String entityType;
-    private String businessLabel;
-    private BigDecimal confidence;
-    private Integer occurrenceCount;
-    private Long attachmentId;
-    private String attachmentName;
-    private LocalDateTime createdAt;
-    private LocalDateTime updatedAt;
-}

+ 0 - 133
backend/lingyue-project/src/main/java/com/lingyue/project/entity/service/EntityService.java

@@ -1,133 +0,0 @@
-package com.lingyue.project.entity.service;
-
-import com.lingyue.common.core.Constants;
-import com.lingyue.common.exception.BusinessException;
-import com.lingyue.graph.entity.Node;
-import com.lingyue.graph.service.NodeService;
-import com.lingyue.graph.service.PropertyService;
-import com.lingyue.project.attachment.viewmapper.AttachmentViewMapper;
-import com.lingyue.project.attachment.viewmapper.VAttachment;
-import com.lingyue.project.entity.dto.EntityMergeDTO;
-import com.lingyue.project.entity.dto.EntityUpdateDTO;
-import com.lingyue.project.entity.dto.EntityVO;
-import com.lingyue.project.entity.viewmapper.EntityViewMapper;
-import com.lingyue.project.entity.viewmapper.VEntity;
-import lombok.RequiredArgsConstructor;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.StringUtils;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.stream.Collectors;
-
-@Service
-@RequiredArgsConstructor
-public class EntityService {
-
-    private final NodeService nodeService;
-    private final PropertyService propertyService;
-    private final EntityViewMapper entityViewMapper;
-    private final AttachmentViewMapper attachmentViewMapper;
-
-    public List<EntityVO> listByAttachment(Long attachmentId, String entityType, String keyword) {
-        List<VEntity> entities = entityViewMapper.selectByAttachmentId(attachmentId);
-        return filterAndConvert(entities, entityType, keyword);
-    }
-
-    public List<EntityVO> listByProject(Long projectId, String entityType, String keyword) {
-        List<VEntity> entities = entityViewMapper.selectByProjectId(projectId);
-        return filterAndConvert(entities, entityType, keyword);
-    }
-
-    public EntityVO getEntity(Long entityId) {
-        VEntity ve = entityViewMapper.selectById(entityId);
-        if (ve == null) {
-            throw new BusinessException(404, "实体不存在");
-        }
-        return toEntityVO(ve);
-    }
-
-    @Transactional
-    public EntityVO updateEntity(Long entityId, EntityUpdateDTO dto) {
-        Node node = nodeService.getById(entityId);
-        if (node == null || !Constants.NODE_ENTITY.equals(node.getNodeType())) {
-            throw new BusinessException(404, "实体不存在");
-        }
-
-        if (StringUtils.hasText(dto.getEntityText())) {
-            nodeService.updateNodeName(entityId, dto.getEntityText());
-        }
-        if (StringUtils.hasText(dto.getEntityType())) {
-            propertyService.setNodeProperty(entityId, "entity_type", dto.getEntityType());
-        }
-        if (dto.getBusinessLabel() != null) {
-            propertyService.setNodeProperty(entityId, "business_label", dto.getBusinessLabel());
-        }
-        if (dto.getConfidence() != null) {
-            propertyService.setNodePropertyNumber(entityId, "confidence", dto.getConfidence());
-        }
-
-        VEntity ve = entityViewMapper.selectById(entityId);
-        return toEntityVO(ve);
-    }
-
-    @Transactional
-    public EntityVO mergeEntities(EntityMergeDTO dto) {
-        Node target = nodeService.getById(dto.getTargetEntityId());
-        if (target == null || !Constants.NODE_ENTITY.equals(target.getNodeType())) {
-            throw new BusinessException(404, "目标实体不存在");
-        }
-
-        BigDecimal currentCount = propertyService.getNodePropertyNumber(dto.getTargetEntityId(), "occurrence_count");
-        int totalCount = currentCount != null ? currentCount.intValue() : 1;
-
-        for (Long sourceId : dto.getSourceEntityIds()) {
-            if (sourceId.equals(dto.getTargetEntityId())) continue;
-
-            Node source = nodeService.getById(sourceId);
-            if (source == null || !Constants.NODE_ENTITY.equals(source.getNodeType())) continue;
-
-            BigDecimal srcCount = propertyService.getNodePropertyNumber(sourceId, "occurrence_count");
-            totalCount += (srcCount != null ? srcCount.intValue() : 1);
-
-            nodeService.deleteNodeCascade(sourceId);
-        }
-
-        propertyService.setNodePropertyNumber(dto.getTargetEntityId(), "occurrence_count",
-                BigDecimal.valueOf(totalCount));
-
-        VEntity ve = entityViewMapper.selectById(dto.getTargetEntityId());
-        return toEntityVO(ve);
-    }
-
-    private List<EntityVO> filterAndConvert(List<VEntity> entities, String entityType, String keyword) {
-        return entities.stream()
-                .filter(e -> !StringUtils.hasText(entityType) || entityType.equals(e.getEntityType()))
-                .filter(e -> !StringUtils.hasText(keyword) || (e.getEntityText() != null && e.getEntityText().contains(keyword)))
-                .map(this::toEntityVO)
-                .collect(Collectors.toList());
-    }
-
-    private EntityVO toEntityVO(VEntity ve) {
-        EntityVO vo = new EntityVO();
-        vo.setId(ve.getId());
-        vo.setEntityText(ve.getEntityText());
-        vo.setEntityKey(ve.getEntityKey());
-        vo.setEntityType(ve.getEntityType());
-        vo.setBusinessLabel(ve.getBusinessLabel());
-        vo.setConfidence(ve.getConfidence());
-        vo.setOccurrenceCount(ve.getOccurrenceCount());
-        vo.setAttachmentId(ve.getAttachmentId());
-        vo.setCreatedAt(ve.getCreatedAt());
-        vo.setUpdatedAt(ve.getUpdatedAt());
-
-        if (ve.getAttachmentId() != null) {
-            VAttachment va = attachmentViewMapper.selectById(ve.getAttachmentId());
-            if (va != null) {
-                vo.setAttachmentName(va.getDisplayName());
-            }
-        }
-        return vo;
-    }
-}

+ 0 - 20
backend/lingyue-project/src/main/java/com/lingyue/project/entity/viewmapper/EntityViewMapper.java

@@ -1,20 +0,0 @@
-package com.lingyue.project.entity.viewmapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
-
-import java.util.List;
-
-@Mapper
-public interface EntityViewMapper extends BaseMapper<VEntity> {
-
-    @Select("SELECT * FROM v_entities WHERE attachment_id = #{attachmentId} ORDER BY created_at")
-    List<VEntity> selectByAttachmentId(@Param("attachmentId") Long attachmentId);
-
-    @Select("SELECT ve.* FROM v_entities ve " +
-            "JOIN v_attachments va ON va.id = ve.attachment_id " +
-            "WHERE va.project_id = #{projectId} ORDER BY ve.created_at")
-    List<VEntity> selectByProjectId(@Param("projectId") Long projectId);
-}

+ 0 - 24
backend/lingyue-project/src/main/java/com/lingyue/project/entity/viewmapper/VEntity.java

@@ -1,24 +0,0 @@
-package com.lingyue.project.entity.viewmapper;
-
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-
-@Data
-@TableName("v_entities")
-public class VEntity implements Serializable {
-
-    private Long id;
-    private String entityText;
-    private String entityKey;
-    private String entityType;
-    private String businessLabel;
-    private BigDecimal confidence;
-    private Integer occurrenceCount;
-    private Long attachmentId;
-    private LocalDateTime createdAt;
-    private LocalDateTime updatedAt;
-}