diff --git a/src/main/java/com/xit/biz/ctgy/v2/repository/BoardDao.java b/src/main/java/com/xit/biz/ctgy/v2/repository/BoardDao.java index 6edd4d9..d2f2d25 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/repository/BoardDao.java +++ b/src/main/java/com/xit/biz/ctgy/v2/repository/BoardDao.java @@ -1,7 +1,6 @@ package com.xit.biz.ctgy.v2.repository; import com.xit.biz.ctgy.dto.BoardDto; -import com.xit.biz.ctgy.entity.MinCivBoard680; import com.xit.core.config.database.BaseMpowerDaoSupport; import com.xit.core.support.sql.parser.QueryGenerator; import lombok.extern.slf4j.Slf4j; @@ -15,15 +14,15 @@ import java.util.*; @Slf4j public class BoardDao extends BaseMpowerDaoSupport { - public Page findAll(final BoardDto dto, Pageable pageable) { - String cntSql = getSql("selectBoardListCnt", dto, pageable); - String listSql = getSql("selectBoardList", dto, pageable); - String fieldStrs = "ciCode, ciName, ciContentno, ciTitle, ciContents, ciNalja, ciStep, ciRevel, ciRef, ciHit, ciPass, ciId"; + public Page findAll(final BoardDto dto, final Pageable pageable) { + final String cntSql = getSql("selectBoardListCnt", dto, pageable); + final String listSql = getSql("selectBoardList", dto, pageable); + final String fieldStrs = "ciCode, ciName, ciContentno, ciTitle, ciContents, ciNalja, ciStep, ciRevel, ciRef, ciHit, ciPass, ciId"; return selectList(BoardDto.class, listSql, cntSql, fieldStrs, pageable); } - private String getSql(String sqlId, BoardDto dto, Pageable pageable){ + private String getSql(final String sqlId, final BoardDto dto, final Pageable pageable){ return QueryGenerator.createNamedQuery("board", sqlId) .setParameter("ciTitle", dto.getCiTitle()) .setParameter("ciName", dto.getCiName()) @@ -33,30 +32,61 @@ public class BoardDao extends BaseMpowerDaoSupport { .getQueryString(); } - - //@Query("UPDATE MinCivBoard680 m SET m.ciHit = m.ciHit + 1 WHERE m.ciCode = :ciCode") - public void updateInHitForMinCivBoard680(Long ciCode) { - String sql = QueryGenerator.createNamedQuery("board", "updateCiHit") + public void updateInHitForMinCivBoard680(final Long ciCode) { + final String sql = QueryGenerator.createNamedQuery("board", "updateCiHit") .setParameter("ciCode", ciCode).getQueryString(); update(sql); } - public Optional findById(Long ciCode) { - return Optional.empty(); + public Optional findById(final Long ciCode) { + final String sql = QueryGenerator.createNamedQuery("board", "selectBoard") + .setParameter("ciCode", ciCode) + .getQueryString(); + final String fieldStrs = "ci_code, ci_contentno, ci_contents, ci_email, ci_hit, ci_id, ci_ip, ci_nalja, ci_name, ci_pass, ci_pwd, ci_ref, ci_revel, ci_step, ci_time, ci_title"; + + return Optional.ofNullable(selectOne(BoardDto.class, sql, fieldStrs)); } - //@Query(value = "SELECT max(e.ci_code) + 1 FROM min_civ_board680 e", nativeQuery = true) - public Long getCiCode() { - return null; + public void insertBoard(final BoardDto dto) { + final String sql = QueryGenerator.createNamedQuery("board", "insertBoard") + .setParameter("ciTitle", dto.getCiTitle()) + .setParameter("ciContents", dto.getCiContents()) + .setParameter("ciEmail", dto.getCiEmail()) + .setParameter("ciHit", dto.getCiHit()) + .setParameter("ciId", dto.getCiId()) + .setParameter("ciIp", dto.getCiIp()) + .setParameter("ciNalja", dto.getCiNalja()) + .setParameter("ciName", dto.getCiName()) + .setParameter("ciPass", dto.getCiPass()) + .setParameter("ciPwd", dto.getCiPwd()) + .setParameter("ciRef", dto.getCiRef()) + .setParameter("ciRevel", dto.getCiRevel()) + .setParameter("ciStep", dto.getCiStep()) + .setParameter("ciTime", dto.getCiTime()) + .getQueryString(); + insert(sql); } - public void save(MinCivBoard680 entity) { + public void updateBoard(final BoardDto dto){ + final String sql = QueryGenerator.createNamedQuery("board", "updateBoard") + .setParameter("ciCode", dto.getCiCode()) + .setParameter("ciTitle", dto.getCiTitle()) + .setParameter("ciContents", dto.getCiContents()) + .getQueryString(); + update(sql); } - public List findByCiRef(Long ciCode) { - return null; + public int findByCiRefCnt(final Long ciCode) { + final String sql = QueryGenerator.createNamedQuery("board", "selectCntByCiRef") + .setParameter("ciCode", ciCode) + .getQueryString(); + return Integer.parseInt(selectOneColumn(sql)); } - public void deleteById(Long ciCode) { + public void deleteById(final Long ciCode) { + final String sql = QueryGenerator.createNamedQuery("board", "deleteBoard") + .setParameter("ciCode", ciCode) + .getQueryString(); + delete(sql); } } diff --git a/src/main/java/com/xit/biz/ctgy/v2/repository/PublicBoardDao.java b/src/main/java/com/xit/biz/ctgy/v2/repository/PublicBoardDao.java index a7af068..dddd436 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/repository/PublicBoardDao.java +++ b/src/main/java/com/xit/biz/ctgy/v2/repository/PublicBoardDao.java @@ -40,23 +40,9 @@ public class PublicBoardDao extends BaseMpowerDaoSupport { update(sql); } - //public Optional findById(Long inCode) { - //} - - //@Query(value = "SELECT e.msMaincode FROM #{#entityName} e WHERE e.msChasu = :msChasu AND e.msSdate = :msSdate AND e.msEdate = :msEdate") - public List findAllMsMaincode(Long msChasu, LocalDate msSdate, LocalDate msEdate){ - return null; - }; - - //@Modifying - //@Query(value = "UPDATE #{#entityName} m SET m.msResult = :msResult WHERE m.msMaincode = :msMaincode AND m.msSeq = :msSeq") - public int updateMsResult(final Long msMaincode, final String msSeq, final String msResult){ - return 1; - }; - - public Long getInCodeByInBgubun() { - return 1L; - } +// public Long getInCodeByInBgubun() { +// return 1L; +// } public void insertPublicBoard(MinInfoBoard680Dto dto) { // null 값 set 불가 @@ -66,8 +52,6 @@ public class PublicBoardDao extends BaseMpowerDaoSupport { .setParameter("inDept", dto.getInDept()) .setParameter("inEtc", dto.getInEtc()) .setParameter("inFilename", dto.getInFilename()) - //.setParameter("inFilesize", Checks.isNull(dto.getInFilesize()) ? 0L : dto.getInFilesize()) - //.setParameter("inFileurl", Checks.isNull(dto.getInFileurl()) ? "" : dto.getInFileurl()) .setParameter("inFilesize", dto.getInFilesize()) .setParameter("inFileurl", dto.getInFileurl()) .setParameter("inHit", dto.getInHit()) diff --git a/src/main/java/com/xit/biz/ctgy/v2/service/impl/BoardService.java b/src/main/java/com/xit/biz/ctgy/v2/service/impl/BoardService.java index a631ba4..1822af4 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/service/impl/BoardService.java +++ b/src/main/java/com/xit/biz/ctgy/v2/service/impl/BoardService.java @@ -17,10 +17,6 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - @Service @AllArgsConstructor @Slf4j @@ -46,15 +42,15 @@ public class BoardService implements IBoardService { // update 인 경우 if(Checks.isNotEmpty(dto.getCiCode())) { - entity = boardDao.findById(dto.getCiCode()).orElseThrow(() -> new CustomBaseException(ErrorCode.DATA_NOT_FOUND)); - if(!entity.getCiPass().equals(passwordEncoder.encode(dto.getCiPass()))){ + BoardDto savedDto = boardDao.findById(dto.getCiCode()).orElseThrow(() -> new CustomBaseException(ErrorCode.DATA_NOT_FOUND)); + if(!savedDto.getCiPass().equals(passwordEncoder.encode(dto.getCiPass()))){ throw new CustomBaseException(ErrorCode.MISMATCH_PASSWORD); } - entity.setCiTitle(dto.getCiTitle()); - entity.setCiContents(dto.getCiContents()); + savedDto.setCiTitle(dto.getCiTitle()); + savedDto.setCiContents(dto.getCiContents()); + boardDao.updateBoard(savedDto); }else { - dto.setCiCode(boardDao.getCiCode()); - dto.setCiContentno(dto.getCiCode()); + dto.setSaveInit(); if (Checks.isEmpty(dto.getCiRef()) || dto.getCiRef() == 0L) { dto.setCiRef(dto.getCiCode()); dto.setCiStep(0L); @@ -62,20 +58,20 @@ public class BoardService implements IBoardService { } dto.setCiPass(passwordEncoder.encode(dto.getCiPass())); dto.setCiIp(CommUtil.getDeviceInfo().getIp()); + boardDao.insertBoard(dto); } - boardDao.save(entity); } @Override @Transactional - public void removeBoard(Long ciCode) { + public void removeBoard(final Long ciCode) { - MinCivBoard680 savedEntity = boardDao.findById(ciCode).orElseThrow(() -> new CustomBaseException(ErrorCode.NOT_FOUND)); - if(!Objects.equal(HeaderUtil.getUserId(), savedEntity.getCiId())) throw new CustomBaseException("삭제 권한(게시글 소유자)이 없는 사용자 입니다"); + BoardDto savedDto = boardDao.findById(ciCode).orElseThrow(() -> new CustomBaseException(ErrorCode.NOT_FOUND)); + if(!Objects.equal(HeaderUtil.getUserId(), savedDto.getCiId())) throw new CustomBaseException("삭제 권한(게시글 소유자)이 없는 사용자 입니다"); // 댓글 존재 여부 조회 - List list = boardDao.findByCiRef(ciCode); - if(list.size() > 1) throw new CustomBaseException("삭제 할 수 없는 게시글 입니다[댓글 존재]"); + int cnt = boardDao.findByCiRefCnt(ciCode); + if(cnt > 1) throw new CustomBaseException("삭제 할 수 없는 게시글 입니다[댓글 존재]"); boardDao.deleteById(ciCode); } } diff --git a/src/main/resources/sql/board-mapper.xml b/src/main/resources/sql/board-mapper.xml index 356cda3..7ca2709 100644 --- a/src/main/resources/sql/board-mapper.xml +++ b/src/main/resources/sql/board-mapper.xml @@ -1,5 +1,6 @@ + /* board-mapper|selectBoardList|julim */ SELECT ci_code, @@ -60,6 +61,27 @@ + + /* board-mapper|updateCiHit|julim */ + SELECT ci_code + ci_contentno, + ci_contents, + ci_email, + ci_hit, + ci_id, + ci_ip, + ci_nalja, + ci_name, + ci_pass, + ci_pwd, + ci_ref, + ci_revel, + ci_step, + ci_time, + ci_title + FROM min_civ_board680 + WHERE ci_code = #{ciCode} + /* board-mapper|updateCiHit|julim */ @@ -89,8 +111,8 @@ ci_contents, ci_ip ) VALUES ( - (SELECT MAX(c.ci_code) + 1 FROM min_civ_board680 c WHERE c.ci_bgubun = '1'), - (SELECT MAX(c.ci_code) + 1 FROM min_civ_board680 c WHERE c.ci_bgubun = '1'), + (SELECT MAX(c.ci_code) + 1 FROM min_civ_board680 c), + (SELECT MAX(c.ci_code) + 1 FROM min_civ_board680 c), #{ciTitle}, #{ciId}, #{ciPwd}, @@ -109,14 +131,25 @@ - /* pboard-mapper|updateBoard|julim */ + /* board-mapper|updateBoard|julim */ UPDATE min_civ_board680 - SET ci_title = #{ciTitle} - , ci_dept = #{ciDept} - , ci_contents = #{ciContents} - , ci_filename = #{ciFilename} - , ci_filesize = #{ciFilesize} - , ci_fileurl = #{ciFileurl} - WHERE ci_code = #{ciCode} + SET ci_title = #{ciTitle} + , ci_contents = #{ciContents} + WHERE ci_code = #{ciCode} + + + + /* board-mapper|selectCntByCiRef|julim */ + SELECT COUNT(ci_code) AS cnt + FROM min_civ_board680 + WHERE ci_ref = #{ciRef} + + + /* board-mapper|deleteBoard|julim */ + DELETE + FROM min_civ_board680 + WHERE ci_code = #{ciCode} + + \ No newline at end of file diff --git a/src/main/resources/sql/minuserinfo-mapper.xml b/src/main/resources/sql/minuserinfo-mapper.xml index c87a885..f06bc76 100644 --- a/src/main/resources/sql/minuserinfo-mapper.xml +++ b/src/main/resources/sql/minuserinfo-mapper.xml @@ -1,5 +1,6 @@ + /* minuserinfo-mapper|selectUserInfo|julim */ SELECT userid, diff --git a/src/main/resources/sql/pboard-mapper.xml b/src/main/resources/sql/pboard-mapper.xml index f89ba2e..5f9d20e 100644 --- a/src/main/resources/sql/pboard-mapper.xml +++ b/src/main/resources/sql/pboard-mapper.xml @@ -1,5 +1,6 @@ + /* pboard-mapper|selectPublicBoardList|julim */ SELECT in_code, @@ -116,4 +117,5 @@ FROM min_info_board680 WHERE in_code = #{inCode} + \ No newline at end of file diff --git a/src/main/resources/sql/refreshToken-mapper.xml b/src/main/resources/sql/refreshToken-mapper.xml index 5ba9070..6c09916 100644 --- a/src/main/resources/sql/refreshToken-mapper.xml +++ b/src/main/resources/sql/refreshToken-mapper.xml @@ -1,5 +1,6 @@ + /* refreshToken-mapper|selectRefreshToken|julim */ SELECT key, @@ -26,4 +27,5 @@ SET value = #{value} WHERE key = #{key} + \ No newline at end of file