结构和功能的删除接口
This commit is contained in:
@@ -15,6 +15,7 @@ import jakarta.validation.constraints.Positive;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -94,6 +95,20 @@ public class CadAnnotationController {
|
||||
return ApiResponse.success(cadAnnotationService.getStructure(modelId, structureId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 CAD 结构。
|
||||
*
|
||||
* <p>按模型归属校验后逻辑删除结构,并清理结构下的关联关系。</p>
|
||||
*/
|
||||
@DeleteMapping("/structures/{structureId}")
|
||||
public ApiResponse<Void> deleteStructure(
|
||||
@PathVariable @Positive Long modelId,
|
||||
@PathVariable @Positive Long structureId
|
||||
) {
|
||||
cadAnnotationService.deleteStructure(modelId, structureId);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 CAD 功能。
|
||||
*
|
||||
@@ -143,4 +158,18 @@ public class CadAnnotationController {
|
||||
) {
|
||||
return ApiResponse.success(cadAnnotationService.getFunction(modelId, functionId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 CAD 功能。
|
||||
*
|
||||
* <p>按模型归属校验后逻辑删除功能,并清理功能下的结构关系。</p>
|
||||
*/
|
||||
@DeleteMapping("/functions/{functionId}")
|
||||
public ApiResponse<Void> deleteFunction(
|
||||
@PathVariable @Positive Long modelId,
|
||||
@PathVariable @Positive Long functionId
|
||||
) {
|
||||
cadAnnotationService.deleteFunction(modelId, functionId);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@ public interface CadAnnotationService {
|
||||
*/
|
||||
CadStructureResponse getStructure(Long modelId, Long structureId);
|
||||
|
||||
/**
|
||||
* 逻辑删除结构,并清理结构关联关系。
|
||||
*/
|
||||
void deleteStructure(Long modelId, Long structureId);
|
||||
|
||||
/**
|
||||
* 创建功能并建立功能与结构的关系。
|
||||
*/
|
||||
@@ -62,4 +67,9 @@ public interface CadAnnotationService {
|
||||
* 查询功能详情。
|
||||
*/
|
||||
CadFunctionResponse getFunction(Long modelId, Long functionId);
|
||||
|
||||
/**
|
||||
* 逻辑删除功能,并清理功能关联关系。
|
||||
*/
|
||||
void deleteFunction(Long modelId, Long functionId);
|
||||
}
|
||||
|
||||
@@ -199,6 +199,31 @@ public class CadAnnotationServiceImpl implements CadAnnotationService {
|
||||
return toStructureResponse(requireStructure(modelId, structureId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除结构,并清理结构关联的建模历史关系和功能引用关系。
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteStructure(Long modelId, Long structureId) {
|
||||
requireStructure(modelId, structureId);
|
||||
|
||||
int historyRelationCount = structureHistoryRelMapper.delete(Wrappers.lambdaQuery(CadStructureHistoryRel.class)
|
||||
.eq(CadStructureHistoryRel::getModelId, modelId)
|
||||
.eq(CadStructureHistoryRel::getStructureId, structureId));
|
||||
int functionRelationCount = functionStructureRelMapper.delete(Wrappers.lambdaQuery(CadFunctionStructureRel.class)
|
||||
.eq(CadFunctionStructureRel::getModelId, modelId)
|
||||
.eq(CadFunctionStructureRel::getStructureId, structureId));
|
||||
structureMapper.update(null, Wrappers.lambdaUpdate(CadStructure.class)
|
||||
.eq(CadStructure::getId, structureId)
|
||||
.eq(CadStructure::getModelId, modelId)
|
||||
.eq(CadStructure::getDeleted, 0)
|
||||
.set(CadStructure::getDeleted, 1)
|
||||
.set(CadStructure::getUpdatedAt, LocalDateTime.now()));
|
||||
|
||||
log.info("Deleted CAD structure. modelId={}, structureId={}, historyRelationCount={}, functionRelationCount={}",
|
||||
modelId, structureId, historyRelationCount, functionRelationCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建功能并绑定结构。
|
||||
*
|
||||
@@ -289,6 +314,28 @@ public class CadAnnotationServiceImpl implements CadAnnotationService {
|
||||
return toFunctionResponse(requireFunction(modelId, functionId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除功能,并清理功能关联的结构关系。
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteFunction(Long modelId, Long functionId) {
|
||||
requireFunction(modelId, functionId);
|
||||
|
||||
int structureRelationCount = functionStructureRelMapper.delete(Wrappers.lambdaQuery(CadFunctionStructureRel.class)
|
||||
.eq(CadFunctionStructureRel::getModelId, modelId)
|
||||
.eq(CadFunctionStructureRel::getFunctionId, functionId));
|
||||
functionMapper.update(null, Wrappers.lambdaUpdate(CadFunction.class)
|
||||
.eq(CadFunction::getId, functionId)
|
||||
.eq(CadFunction::getModelId, modelId)
|
||||
.eq(CadFunction::getDeleted, 0)
|
||||
.set(CadFunction::getDeleted, 1)
|
||||
.set(CadFunction::getUpdatedAt, LocalDateTime.now()));
|
||||
|
||||
log.info("Deleted CAD function. modelId={}, functionId={}, structureRelationCount={}",
|
||||
modelId, functionId, structureRelationCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验模型存在并返回模型记录。
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user