diff --git a/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java b/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java index 629ca45..5c63b48 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java +++ b/src/main/java/com/dbnt/kcgfilemanager/controller/BoardController.java @@ -2,6 +2,7 @@ package com.dbnt.kcgfilemanager.controller; import com.dbnt.kcgfilemanager.config.LogStatus; import com.dbnt.kcgfilemanager.model.*; +import com.dbnt.kcgfilemanager.service.BoardCategoryService; import com.dbnt.kcgfilemanager.service.BoardService; import lombok.RequiredArgsConstructor; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -19,9 +20,6 @@ import java.net.URLEncoder; import java.security.Principal; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -32,6 +30,7 @@ import java.util.zip.ZipOutputStream; public class BoardController { private final BoardService boardService; + private final BoardCategoryService boardCategoryService; @GetMapping("/contentWrite") public ModelAndView contentWrite(@AuthenticationPrincipal UserInfo loginUser, Board content) { @@ -62,7 +61,7 @@ public class BoardController { @GetMapping("/contentList") public ModelAndView contentList(Board board){ ModelAndView mav = new ModelAndView("board/contentList"); - mav.addObject("pageTitle", boardService.getPageTitle(board.getCategorySeq())); + mav.addObject("pageTitle", boardCategoryService.getPageTitle(board.getCategorySeq())); board.setQueryInfo(); mav.addObject("contentList", boardService.selectContentList(board)); board.setContentCnt(boardService.selectContentListCnt(board)); @@ -71,12 +70,15 @@ public class BoardController { return mav; } - @GetMapping("/fullSearchBoardContent") - public ModelAndView fullSearchBoardContent(Board board, - @RequestParam(value = "categorySeq", required = false) List categorySeqList, - @RequestParam(value = "tagName", required = false) List tagNameList){ + @PostMapping("/fullSearchBoardContent") + @ResponseBody + public ModelAndView fullSearchBoardContent( + Board board, + @RequestParam(value = "searchCategorySeq", required = false) List categorySeqList, + @RequestParam(value = "tagName", required = false) List tagNameList + ){ ModelAndView mav = new ModelAndView("board/contentSearchResult"); - + mav.addObject("boardList", boardService.fullSearchBoardContent(categorySeqList, board, tagNameList)); return mav; } diff --git a/src/main/java/com/dbnt/kcgfilemanager/model/Board.java b/src/main/java/com/dbnt/kcgfilemanager/model/Board.java index d506182..6e78680 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/model/Board.java +++ b/src/main/java/com/dbnt/kcgfilemanager/model/Board.java @@ -39,6 +39,9 @@ public class Board extends BaseModel{ @Column(name = "CREATE_DATE") private LocalDateTime createDate; + @Transient + private String originalName; + @Transient private String createName; @Transient @@ -48,6 +51,8 @@ public class Board extends BaseModel{ private List childFileList; @Transient private List hashTagList; + @Transient + private List categoryList; @Transient private String hashTagStr; diff --git a/src/main/java/com/dbnt/kcgfilemanager/model/SearchResult.java b/src/main/java/com/dbnt/kcgfilemanager/model/SearchResult.java new file mode 100644 index 0000000..8483384 --- /dev/null +++ b/src/main/java/com/dbnt/kcgfilemanager/model/SearchResult.java @@ -0,0 +1,14 @@ +package com.dbnt.kcgfilemanager.model; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + + +@Data +@NoArgsConstructor +public class SearchResult { + private String searchCategoryName; + private List contentList; +} diff --git a/src/main/java/com/dbnt/kcgfilemanager/service/BoardCategoryService.java b/src/main/java/com/dbnt/kcgfilemanager/service/BoardCategoryService.java index 2f0f9a8..f2dc3ad 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/service/BoardCategoryService.java +++ b/src/main/java/com/dbnt/kcgfilemanager/service/BoardCategoryService.java @@ -60,4 +60,20 @@ public class BoardCategoryService { } boardCategoryRepository.deleteAll(childList); } + + public String getPageTitle(Integer categorySeq) { + BoardCategory category = boardCategoryRepository.findById(categorySeq).orElse(null); + if(category.getParentSeq()==null){ + return category.getCategoryName(); + } + return getPageTitle(category.getParentSeq())+" > "+category.getCategoryName(); + } + + public String makeFilePath(Integer categorySeq){ + BoardCategory category = boardCategoryRepository.findById(categorySeq).orElse(null); + if(category.getParentSeq()==null){ + return "D:\\kcgFileManager\\"+category.getCategoryName(); + } + return makeFilePath(category.getParentSeq())+"\\"+category.getCategoryName(); + } } diff --git a/src/main/java/com/dbnt/kcgfilemanager/service/BoardService.java b/src/main/java/com/dbnt/kcgfilemanager/service/BoardService.java index 313b0b7..b75b1dc 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/service/BoardService.java +++ b/src/main/java/com/dbnt/kcgfilemanager/service/BoardService.java @@ -20,15 +20,49 @@ import java.util.UUID; @RequiredArgsConstructor public class BoardService { + private final BoardMapper boardMapper; private final BoardRepository boardRepository; + + private final BoardCategoryRepository boardCategoryRepository; + private final BoardCategoryService boardCategoryService; + private final BoardLogRepository boardLogRepository; + private final FileInfoRepository fileInfoRepository; private final HashTagRepository hashTagRepository; private final HashTagLinkRepository hashTagLinkRepository; - private final FileInfoRepository fileInfoRepository; - private final BoardCategoryRepository boardCategoryRepository; - private final BoardMapper boardMapper; private final UserInfoRepository userInfoRepository; + + public List fullSearchBoardContent(List categorySeqList, Board board, List tagNameList) { + board.setRowCnt(Integer.MAX_VALUE); + + List tagList = new ArrayList<>(); + for(String tagName: tagNameList){ + HashTag tag = new HashTag(); + tag.setTagName(tagName); + tagList.add(tag); + } + board.setHashTagList(tagList); + + List results = new ArrayList<>(); + for(int categorySeq : categorySeqList){ + SearchResult searchResult = new SearchResult(); + BoardCategory category = boardCategoryRepository.findById(categorySeq).orElse(null); + searchResult.setSearchCategoryName(boardCategoryService.getPageTitle(categorySeq)); + if(category.getDepth() != 4){ + category.setChildCategoryList(boardCategoryService.selectBoardCategoryAll(categorySeq, category.getDepth()+1)); + board.setCategoryList(setboardCategoryToLastDepth(new ArrayList<>(), category)); + }else{ + board.setCategoryList(new ArrayList<>()); + board.getCategoryList().add(category); + } + + searchResult.setContentList(boardMapper.selectContentList(board)); + results.add(searchResult); + } + return results; + } + @Transactional public Integer saveContent(Board content){ Integer contentSeq = boardRepository.save(content).getContentSeq(); @@ -92,7 +126,7 @@ public class BoardService { int fileSeq = lastFileInfo==null?1:(lastFileInfo.getFileSeq()+1); for(MultipartFile file : content.getFileList()){ String saveName = UUID.randomUUID().toString(); - String path = makeFilePath(content.getCategorySeq()); + String path = boardCategoryService.makeFilePath(content.getCategorySeq()); File saveFile = new File(path+"\\"+saveName); if(file.getSize()!=0){ // 저장될 파일 확인 @@ -126,14 +160,6 @@ public class BoardService { } } - public String getPageTitle(Integer categorySeq) { - BoardCategory category = boardCategoryRepository.findById(categorySeq).orElse(null); - if(category.getParentSeq()==null){ - return category.getCategoryName(); - } - return getPageTitle(category.getParentSeq())+" > "+category.getCategoryName(); - } - public List selectContentList(Board board) { return boardMapper.selectContentList(board); } @@ -207,6 +233,16 @@ public class BoardService { return contentSeq; } + private List setboardCategoryToLastDepth(List categoryList, BoardCategory category){ + for(BoardCategory child: category.getChildCategoryList()){ + if(child.getDepth()==4){ + categoryList.add(child); + } + setboardCategoryToLastDepth(categoryList, child); + } + return categoryList; + } + private void deleteHashTagLink(int contentSeq){ List tagLinkList = hashTagLinkRepository.findByContentSeq(contentSeq); hashTagLinkRepository.deleteAll(tagLinkList); @@ -234,13 +270,6 @@ public class BoardService { File deleteFile = new File(savePath, conversionName); deleteFile.delete(); } - private String makeFilePath(Integer categorySeq){ - BoardCategory category = boardCategoryRepository.findById(categorySeq).orElse(null); - if(category.getParentSeq()==null){ - return "D:\\kcgFileManager\\"+category.getCategoryName(); - } - return makeFilePath(category.getParentSeq())+"\\"+category.getCategoryName(); - } private String calculationFileSize(Long fileSize){ String[] units = {"bytes", "KB", "MB"}; double unitSelector = Math.floor(Math.log(fileSize)/Math.log(1024)); diff --git a/src/main/resources/mybatisMapper/BoardMapper.xml b/src/main/resources/mybatisMapper/BoardMapper.xml index fc931bf..519b2f1 100644 --- a/src/main/resources/mybatisMapper/BoardMapper.xml +++ b/src/main/resources/mybatisMapper/BoardMapper.xml @@ -18,7 +18,48 @@ FROM FILE_INFO GROUP BY CONTENT_SEQ ) C ON A.CONTENT_SEQ = C.CONTENT_SEQ - WHERE A.CATEGORY_SEQ = #{categorySeq} + + + AND A.CATEGORY_SEQ = #{categorySeq} + + + AND A.TITLE LIKE CONCAT('%', #{title}, '%') + + + AND B.NAME LIKE CONCAT('%', #{createName}, '%') + + + AND A.CREATE_DATE >= CONCAT(#{startDate}, ' 00:00:00') + + + AND A.CREATE_DATE <= CONCAT(#{endDate}, ' 23:59:59') + + + AND A.CONTENT_SEQ IN ( + SELECT B.CONTENT_SEQ + FROM HASH_TAG A + INNER JOIN HASH_TAG_LINK B ON A.TAG_SEQ = B.TAG_SEQ + + + OR A.TAG_NAME LIKE CONCAT('%',#{hashTag.tagName},'%') + + + ) + + + AND A.CATEGORY_SEQ IN + + #{category.categorySeq} + + + + AND A.CONTENT_SEQ IN ( + SELECT DISTINCT CONTENT_SEQ + FROM FILE_INFO + WHERE ORIGINAL_NAME LIKE CONCAT('%', #{originalName}, '%') + ) + + ORDER BY A.CREATE_DATE DESC LIMIT #{rowCnt} OFFSET #{firstIndex} diff --git a/src/main/resources/static/js/board/contentSearch.js b/src/main/resources/static/js/board/contentSearch.js index 125890b..0c670e0 100644 --- a/src/main/resources/static/js/board/contentSearch.js +++ b/src/main/resources/static/js/board/contentSearch.js @@ -36,75 +36,62 @@ $(document).on('click', '#categoryUpBtn', function (){ $(document).on('click', '#categorySelectBtn', function (){ const selectedCategory = $(".selectedCategory"); - let boardCategory = ""; + let categorySeq = ""; let categoryNames = ""; selectedCategory.each(function (idx, el){ - boardCategory += $(el).attr("data-categoryseq")+","+$(el).attr("data-depth")+"|"; + categorySeq += $(el).attr("data-categoryseq")+","; categoryNames += $(el).attr("data-categoryName")+", "; }) - $("#boardCategoryAry").val(boardCategory.slice(0, -1)); + $("#searchCategorySeq").val(categorySeq.slice(0, -1)); $("#categoryName").val(categoryNames.slice(0, -2)); $("#categorySelectModal").find(".btn-close").click(); }) $(document).on('click', '#searchBtn', function (){ - const param = getSearchParam(); - $.ajax({ - url: '/board/fullSearchBoardContent', - data: param, - type: 'GET', - processData: false, - contentType: false, - dataType:"html", - success: function(html){ - $("#searchResultDiv").empty().append(html) - }, - error:function(){ + if(searchParamCheck()){ + const formData = new FormData($("#searchForm")[0]) + $.ajax({ + type: "POST", + url: '/board/fullSearchBoardContent', + data: formData, + processData: false, + contentType: false, + beforeSend: function (xhr){ + xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val()); + }, + success: function (html) { + $("#searchResultDiv").empty().append(html) + }, + error: function () { - } - }); + } + }); + } }) -function getSearchParam(){ - const param = {board: {}}; - let boardCategoryAry = $("#boardCategoryAry").val(); - if(boardCategoryAry){ - boardCategoryAry = boardCategoryAry.split('|'); - param.boardCategoryList = []; - boardCategoryAry.forEach((value) => { - const boardCategory = value.split(','); - param.boardCategoryList.push({categorySeq: boardCategory[0], depth: boardCategory[1]}); - }) +function searchParamCheck(){ + let emptyCnt = 0; + if(!$("#title").val()){ + emptyCnt++; } - const title = $("#title").val(); - if(title){ - param.board.title = title; + if(!$("#createName").val()){ + emptyCnt++; } - const createName = $("#createName").val(); - if(createName){ - param.board.createName = createName; + if(!$("#tagName").val()){ + emptyCnt++; } - let tagNameAry = $("#tagName").val(); - if(tagNameAry){ - tagNameAry = tagNameAry.split(',') - param.hasTagList = []; - tagNameAry.forEach((value => { - param.hasTagList.push({tagName: value}) - })) + if(!$("#startDate").val() || !$("#endDate").val()){ + emptyCnt++; } - const startDate = $("#startDate").val(); - if(startDate){ - param.board.startDate = startDate; + if(!$("#originalName").val()){ + emptyCnt++; } - const endDate = $("#endDate").val(); - if(endDate){ - param.board.endDate = endDate; + if(emptyCnt>3){ + alert("분류를 제외한 5가지 조건 중 2가지 이상 입력해주세요.") + return false; + }else{ + return true; } - const originalName = $("#originalName").val(); - if(originalName){ - param.board.searchFileName = originalName; - } - return param; } function parentCheck(categorySeq){ diff --git a/src/main/resources/templates/board/contentSearch.html b/src/main/resources/templates/board/contentSearch.html index e498e00..257b8cd 100644 --- a/src/main/resources/templates/board/contentSearch.html +++ b/src/main/resources/templates/board/contentSearch.html @@ -11,61 +11,65 @@
+ +

통합 검색

-
+
-
- -
- - -
-
- -
-
-
- -
- -
- -
- -
-
-
- -
- -
- -
-
- - +
+
+ +
+ + +
+
+
-
-
- -
- +
+ +
+ +
+ +
+ +
-
+
+ +
+ +
+ +
+
+ + +
+
+
+
+ +
+ +
+
+
-
+
diff --git a/src/main/resources/templates/board/contentSearchResult.html b/src/main/resources/templates/board/contentSearchResult.html new file mode 100644 index 0000000..1447909 --- /dev/null +++ b/src/main/resources/templates/board/contentSearchResult.html @@ -0,0 +1,44 @@ + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
제목파일 수작성자작성일조회수
검색 결과가 없습니다.
+ +
+
+
+ \ No newline at end of file