package com.dbnt.kcgfilemanager.service; import com.dbnt.kcgfilemanager.model.Board; import com.dbnt.kcgfilemanager.model.BoardLog; import com.dbnt.kcgfilemanager.model.HashTag; import com.dbnt.kcgfilemanager.model.HashTagLink; import com.dbnt.kcgfilemanager.repository.BoardLogRepository; import com.dbnt.kcgfilemanager.repository.BoardRepository; import com.dbnt.kcgfilemanager.repository.HashTagLinkRepository; import com.dbnt.kcgfilemanager.repository.HashTagRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.util.List; @Service @RequiredArgsConstructor public class BoardService { private BoardRepository boardRepository; private BoardLogRepository boardLogRepository; private HashTagRepository hashTagRepository; private HashTagLinkRepository hashTagLinkRepository; @Transactional public Integer saveContent(Board content){ boardRepository.save(content); saveBoardLog(content.getContentSeq(), "I", null, content.getCreateId()); saveHashTagLink(content.getContentSeq(), content.getHashTagStr()); saveUploadFiles(content.getContentSeq(), content.getFileList()); return content.getContentSeq(); } public void saveBoardLog(Integer contentSeq, String status, String description, String createId){ BoardLog lastLog = boardLogRepository.findTopByContentSeqOrderByLogSeqDesc(contentSeq).orElse(null); BoardLog log = new BoardLog(); log.setContentSeq(contentSeq); log.setLogSeq(lastLog == null?1:(lastLog.getLogSeq()+1)); log.setLogStatus(status); log.setDescription(description); log.setCreateId(createId); boardLogRepository.save(log); } public HashTag saveHashTag(String tagName){ HashTag tag = new HashTag(); tag.setTagName(tagName); return hashTagRepository.save(tag); } public void saveHashTagLink(Integer contentSeq, String hashTagStr){ String[] hashTagAry = hashTagStr.trim().replaceAll(",", "").split("#"); for(String tagName : hashTagAry){ HashTag tag = hashTagRepository.findByTagName(tagName).orElse(null); if(tag==null){ tag = saveHashTag(tagName); } HashTagLink link = new HashTagLink(); link.setContentSeq(contentSeq); link.setTagSeq(tag.getTagSeq()); hashTagLinkRepository.save(link); } } public void saveUploadFiles(Integer contentSeq, List files){ } }