|
|
|
|
@ -1,12 +1,18 @@
|
|
|
|
|
package kr.re.etri.autoflow.service;
|
|
|
|
|
|
|
|
|
|
import io.minio.MinioClient;
|
|
|
|
|
import io.minio.RemoveObjectArgs;
|
|
|
|
|
import kr.re.etri.autoflow.entity.DataGroupEntity;
|
|
|
|
|
import kr.re.etri.autoflow.entity.MinioAttachmentEntity;
|
|
|
|
|
import kr.re.etri.autoflow.payload.request.ProjectBaseSearchRequest;
|
|
|
|
|
import kr.re.etri.autoflow.payload.request.ProjectRequest;
|
|
|
|
|
import kr.re.etri.autoflow.repository.DataGroupRepository;
|
|
|
|
|
import kr.re.etri.autoflow.repository.MinioAttachmentRepository;
|
|
|
|
|
import kr.re.etri.autoflow.specification.DataGroupSpecification;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
@ -24,10 +30,13 @@ import java.util.Optional;
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class DataGroupService {
|
|
|
|
|
|
|
|
|
|
private final DataGroupRepository dataGroupRepository;
|
|
|
|
|
|
|
|
|
|
private final MinioAttachmentRepository minioAttachmentRepository;
|
|
|
|
|
|
|
|
|
|
private final DataGroupSpecification dataGroupSpecification;
|
|
|
|
|
|
|
|
|
|
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
@ -40,6 +49,12 @@ public class DataGroupService {
|
|
|
|
|
return dataGroupRepository.findById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final MinioClient minioClient;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${minio.bucket}")
|
|
|
|
|
private String bucketName;
|
|
|
|
|
|
|
|
|
|
public Page<DataGroupEntity> search(ProjectBaseSearchRequest request) {
|
|
|
|
|
int pageIndex = request.getPage() > 0 ? request.getPage() - 1 : 0;
|
|
|
|
|
|
|
|
|
|
@ -93,11 +108,41 @@ public class DataGroupService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public boolean delete(Long id) {
|
|
|
|
|
if (!dataGroupRepository.existsById(id)) {
|
|
|
|
|
public boolean delete(Long dataGroupId) {
|
|
|
|
|
try {
|
|
|
|
|
// 1. 데이터그룹 존재 여부 확인
|
|
|
|
|
Optional<DataGroupEntity> dataGroupOpt = dataGroupRepository.findById(dataGroupId);
|
|
|
|
|
if (dataGroupOpt.isEmpty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
dataGroupRepository.deleteById(id);
|
|
|
|
|
|
|
|
|
|
// 2. refId 기준으로 MinIO 첨부파일 조회
|
|
|
|
|
List<MinioAttachmentEntity> attachments =
|
|
|
|
|
minioAttachmentRepository.findAllByRefId(dataGroupId);
|
|
|
|
|
|
|
|
|
|
// 3. MinIO에서 파일 삭제
|
|
|
|
|
for (MinioAttachmentEntity attachment : attachments) {
|
|
|
|
|
try {
|
|
|
|
|
minioClient.removeObject(
|
|
|
|
|
RemoveObjectArgs.builder()
|
|
|
|
|
.bucket(bucketName)
|
|
|
|
|
.object(attachment.getStoragePath())
|
|
|
|
|
.build()
|
|
|
|
|
);
|
|
|
|
|
// DB에서도 첨부파일 삭제
|
|
|
|
|
minioAttachmentRepository.delete(attachment);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("MinIO 파일 삭제 실패: {}", attachment.getStoragePath(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4. 데이터그룹 삭제
|
|
|
|
|
dataGroupRepository.delete(dataGroupOpt.get());
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("데이터그룹 삭제 중 오류 발생 (id={})", dataGroupId, e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|