투표 쿼리수정 필터링 추가
This commit is contained in:
parent
4fdc97fde5
commit
373a8c6a5e
@ -19,7 +19,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.mapper.commoncodMapper;
|
||||
@ -36,38 +38,87 @@ public class worddictyService {
|
||||
private final FileService fileService;
|
||||
|
||||
public List<MapDto> selectWordList(MapDto map) {
|
||||
List<MapDto> wordList = worddictymapper.selectWordList(map);
|
||||
for (MapDto word : wordList) {
|
||||
Object content = word.get("WRDDICCON");
|
||||
// BlobUtil.procBlobToString으로 content 변환
|
||||
String contentString = BlobUtil.procBlobToString(content);
|
||||
word.put("WRDDICCON", contentString);
|
||||
}
|
||||
List<MapDto> processedList = new ArrayList<>();
|
||||
List<MapDto> wordList = worddictymapper.selectWordList(map);
|
||||
String keyword = map.getString("searchKeyword");
|
||||
|
||||
// 데이터 가공
|
||||
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"));
|
||||
List<MapDto> processedList = new ArrayList<>();
|
||||
|
||||
MapDto lastEditor = new MapDto();
|
||||
lastEditor.put("profileImage", dto.remove("UPDPRF"));
|
||||
lastEditor.put("name", dto.remove("UPDNAME"));
|
||||
lastEditor.put("color", dto.remove("UPDCOLOR"));
|
||||
lastEditor.put("updatedAt", dto.remove("UPDUDT"));
|
||||
// 데이터 가공
|
||||
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"));
|
||||
|
||||
dto.put("author", author);
|
||||
dto.put("lastEditor", lastEditor);
|
||||
MapDto lastEditor = new MapDto();
|
||||
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();
|
||||
processedDto.putAll(dto);
|
||||
processedList.add(processedDto);
|
||||
}
|
||||
return processedList;
|
||||
dto.put("author", author);
|
||||
dto.put("lastEditor", lastEditor);
|
||||
|
||||
MapDto processedDto = new MapDto();
|
||||
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) {
|
||||
Long result = 1L;
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
<!-- 검색어 조건 -->
|
||||
<if test="searchKeyword != null and searchKeyword != ''">
|
||||
and (
|
||||
REGEXP_REPLACE(w.WRDDICTTL, '\\[\\{.*?"insert":"', '') LIKE CONCAT('%', #{searchKeyword}, '%')
|
||||
OR REGEXP_REPLACE(w.WRDDICCON, '\\[\\{.*?"insert":"', '') LIKE CONCAT('%', #{searchKeyword}, '%')
|
||||
w.WRDDICTTL LIKE CONCAT('%', #{searchKeyword}, '%')
|
||||
OR w.WRDDICCON LIKE CONCAT('%', #{searchKeyword}, '%')
|
||||
)
|
||||
</if>
|
||||
<!-- 색인표 조건 -->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user