Merge branch 'khj' into main
This commit is contained in:
commit
8351e7a0d7
@ -19,7 +19,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import io.company.localhost.common.dto.MapDto;
|
import io.company.localhost.common.dto.MapDto;
|
||||||
import io.company.localhost.mapper.commoncodMapper;
|
import io.company.localhost.mapper.commoncodMapper;
|
||||||
@ -36,38 +38,87 @@ public class worddictyService {
|
|||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
|
|
||||||
public List<MapDto> selectWordList(MapDto map) {
|
public List<MapDto> selectWordList(MapDto map) {
|
||||||
List<MapDto> wordList = worddictymapper.selectWordList(map);
|
List<MapDto> wordList = worddictymapper.selectWordList(map);
|
||||||
for (MapDto word : wordList) {
|
String keyword = map.getString("searchKeyword");
|
||||||
Object content = word.get("WRDDICCON");
|
|
||||||
// BlobUtil.procBlobToString으로 content 변환
|
|
||||||
String contentString = BlobUtil.procBlobToString(content);
|
|
||||||
word.put("WRDDICCON", contentString);
|
|
||||||
}
|
|
||||||
List<MapDto> processedList = new ArrayList<>();
|
|
||||||
|
|
||||||
// 데이터 가공
|
List<MapDto> processedList = new ArrayList<>();
|
||||||
for (MapDto dto : wordList) {
|
|
||||||
MapDto author = new MapDto();
|
|
||||||
author.put("profileImage", dto.remove("REGPRF"));
|
|
||||||
author.put("name", dto.remove("REGNAME"));
|
|
||||||
author.put("color", dto.remove("REGCOLOR"));
|
|
||||||
author.put("createdAt", dto.remove("REGRDT"));
|
|
||||||
|
|
||||||
MapDto lastEditor = new MapDto();
|
// 데이터 가공
|
||||||
lastEditor.put("profileImage", dto.remove("UPDPRF"));
|
for (MapDto dto : wordList) {
|
||||||
lastEditor.put("name", dto.remove("UPDNAME"));
|
MapDto author = new MapDto();
|
||||||
lastEditor.put("color", dto.remove("UPDCOLOR"));
|
author.put("profileImage", dto.remove("REGPRF"));
|
||||||
lastEditor.put("updatedAt", dto.remove("UPDUDT"));
|
author.put("name", dto.remove("REGNAME"));
|
||||||
|
author.put("color", dto.remove("REGCOLOR"));
|
||||||
|
author.put("createdAt", dto.remove("REGRDT"));
|
||||||
|
|
||||||
dto.put("author", author);
|
MapDto lastEditor = new MapDto();
|
||||||
dto.put("lastEditor", lastEditor);
|
lastEditor.put("profileImage", dto.remove("UPDPRF"));
|
||||||
|
lastEditor.put("name", dto.remove("UPDNAME"));
|
||||||
|
lastEditor.put("color", dto.remove("UPDCOLOR"));
|
||||||
|
lastEditor.put("updatedAt", dto.remove("UPDUDT"));
|
||||||
|
|
||||||
MapDto processedDto = new MapDto();
|
dto.put("author", author);
|
||||||
processedDto.putAll(dto);
|
dto.put("lastEditor", lastEditor);
|
||||||
processedList.add(processedDto);
|
|
||||||
}
|
MapDto processedDto = new MapDto();
|
||||||
return processedList;
|
processedDto.putAll(dto);
|
||||||
|
processedList.add(processedDto);
|
||||||
|
}
|
||||||
|
return filterPostsByKeyword(processedList,keyword);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 검색어로 순수 텍스트 기준 게시글 필터링
|
||||||
|
*/
|
||||||
|
private List<MapDto> filterPostsByKeyword(List<MapDto> posts, String keyword) {
|
||||||
|
|
||||||
|
keyword = keyword.trim();
|
||||||
|
List<MapDto> filtered = new ArrayList<>();
|
||||||
|
|
||||||
|
for (MapDto post : posts) {
|
||||||
|
String title = post.getString("WRDDICTTL");
|
||||||
|
Object content = post.get("WRDDICCON");
|
||||||
|
// BlobUtil.procBlobToString으로 content 변환
|
||||||
|
String contentString = BlobUtil.procBlobToString(content);
|
||||||
|
if(keyword != null || !keyword.trim().isEmpty()) {
|
||||||
|
String plainText = extractPlainText(contentString);
|
||||||
|
|
||||||
|
if ((title != null && title.contains(keyword)) ||plainText.contains(keyword)) {
|
||||||
|
post.put("WRDDICCON", contentString); // content는 원래대로 복원
|
||||||
|
filtered.add(post);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String extractPlainText(String deltaJson) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
try {
|
||||||
|
JsonNode root = mapper.readTree(deltaJson);
|
||||||
|
|
||||||
|
if (root != null && root.isArray()) {
|
||||||
|
for (JsonNode op : root) {
|
||||||
|
JsonNode insertNode = op.get("insert");
|
||||||
|
|
||||||
|
// insert가 문자열일 경우만 추출
|
||||||
|
if (insertNode != null && insertNode.isTextual()) {
|
||||||
|
String text = insertNode.asText();
|
||||||
|
if (!"\n".equals(text.trim())) { // 줄바꿈 제외
|
||||||
|
sb.append(text).append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// insert가 객체면 image일 가능성 → 제외
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace(); // 실제 운영에서는 로깅 처리
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
public Long insertWord(MapDto map) {
|
public Long insertWord(MapDto map) {
|
||||||
Long result = 1L;
|
Long result = 1L;
|
||||||
|
|||||||
@ -5,8 +5,8 @@
|
|||||||
<!-- 검색어 조건 -->
|
<!-- 검색어 조건 -->
|
||||||
<if test="searchKeyword != null and searchKeyword != ''">
|
<if test="searchKeyword != null and searchKeyword != ''">
|
||||||
and (
|
and (
|
||||||
REGEXP_REPLACE(w.WRDDICTTL, '\\[\\{.*?"insert":"', '') LIKE CONCAT('%', #{searchKeyword}, '%')
|
w.WRDDICTTL LIKE CONCAT('%', #{searchKeyword}, '%')
|
||||||
OR REGEXP_REPLACE(w.WRDDICCON, '\\[\\{.*?"insert":"', '') LIKE CONCAT('%', #{searchKeyword}, '%')
|
OR w.WRDDICCON LIKE CONCAT('%', #{searchKeyword}, '%')
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
<!-- 색인표 조건 -->
|
<!-- 색인표 조건 -->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user