From 8277cd4d8c596bee8031502ed3c73569abf6a96e Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Tue, 13 Aug 2024 21:02:09 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=82=AC=EC=A7=84=20=EB=8B=A4?= =?UTF-8?q?=EC=9A=B4=EB=A1=9C=EB=93=9C=20=EC=8B=9C,=20photos=5Fes=EC=97=90?= =?UTF-8?q?=20download=20=ED=83=9C=EA=B7=B8=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PhotoEsClientRepository.java | 36 +++++++++++++++++++ .../PhotoEsClientRepositoryTest.java | 20 ----------- 2 files changed, 36 insertions(+), 20 deletions(-) delete mode 100644 src/test/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepositoryTest.java diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java index 96534671..ffc8db77 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java @@ -7,6 +7,7 @@ import co.elastic.clients.elasticsearch.core.BulkResponse; import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.core.search.Hit; +import co.elastic.clients.json.JsonData; import com.umc.naoman.domain.photo.elasticsearch.document.PhotoEs; import com.umc.naoman.domain.photo.entity.Photo; import com.umc.naoman.global.error.BusinessException; @@ -21,7 +22,9 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Repository @@ -268,6 +271,39 @@ public List deletePhotoEsByShareGroupIdList(List shareGroupIdList) { return rdsIdList; } + //특정 사진에 특정 맴버 다운로드 태그 추가 + public void addDownloadTag(List photoEs, Long memberId){ + List fieldValueList = photoEs.stream() + .map(photo -> FieldValue.of(photo.getName())) + .toList(); + String routing = photoEs.get(0).getShareGroupId().toString(); + Map params = new HashMap<>(); + params.put("memberId", JsonData.of(memberId)); + try { + elasticsearchClient.updateByQuery(u -> u + .index("photos_es") + .routing(routing) + .query(q -> q + .terms(t -> t + .field("name") + .terms(te -> te.value(fieldValueList)) + ) + ) + .script(s -> s + .inline(i->i + .source("if (!ctx._source.downloadTag.contains(params.memberId)) { " + + "ctx._source.downloadTag.add(params.memberId); }") + .lang("painless") + .params(params) + ) + + ) + ); + } catch (IOException e) { + throw new BusinessException(ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION, e); + } + } + String esTimeFormat(LocalDateTime localDateTime) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); return localDateTime.format(dateTimeFormatter); diff --git a/src/test/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepositoryTest.java b/src/test/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepositoryTest.java deleted file mode 100644 index 9e80cae8..00000000 --- a/src/test/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepositoryTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.umc.naoman.domain.photo.elasticsearch.repository; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest -class PhotoEsClientRepositoryTest { - @Autowired - private PhotoEsClientRepository photoEsClientRepository; - @Test - public void test() { - List val = photoEsClientRepository.deletePhotoEsByFaceTag(1001L); - - } -} \ No newline at end of file