feat: 게시판 관리 mpower 적용

dev
Jonguk. Lim 2 years ago
parent ca2a5643de
commit 4cc51ca322

@ -1,7 +1,6 @@
package com.xit.biz.ctgy.v2.repository; package com.xit.biz.ctgy.v2.repository;
import com.xit.biz.ctgy.dto.BoardDto; 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.config.database.BaseMpowerDaoSupport;
import com.xit.core.support.sql.parser.QueryGenerator; import com.xit.core.support.sql.parser.QueryGenerator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -15,15 +14,15 @@ import java.util.*;
@Slf4j @Slf4j
public class BoardDao extends BaseMpowerDaoSupport { public class BoardDao extends BaseMpowerDaoSupport {
public Page<BoardDto> findAll(final BoardDto dto, Pageable pageable) { public Page<BoardDto> findAll(final BoardDto dto, final Pageable pageable) {
String cntSql = getSql("selectBoardListCnt", dto, pageable); final String cntSql = getSql("selectBoardListCnt", dto, pageable);
String listSql = getSql("selectBoardList", dto, pageable); final String listSql = getSql("selectBoardList", dto, pageable);
String fieldStrs = "ciCode, ciName, ciContentno, ciTitle, ciContents, ciNalja, ciStep, ciRevel, ciRef, ciHit, ciPass, ciId"; final String fieldStrs = "ciCode, ciName, ciContentno, ciTitle, ciContents, ciNalja, ciStep, ciRevel, ciRef, ciHit, ciPass, ciId";
return selectList(BoardDto.class, listSql, cntSql, fieldStrs, pageable); 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) return QueryGenerator.createNamedQuery("board", sqlId)
.setParameter("ciTitle", dto.getCiTitle()) .setParameter("ciTitle", dto.getCiTitle())
.setParameter("ciName", dto.getCiName()) .setParameter("ciName", dto.getCiName())
@ -33,30 +32,61 @@ public class BoardDao extends BaseMpowerDaoSupport {
.getQueryString(); .getQueryString();
} }
public void updateInHitForMinCivBoard680(final Long ciCode) {
//@Query("UPDATE MinCivBoard680 m SET m.ciHit = m.ciHit + 1 WHERE m.ciCode = :ciCode") final String sql = QueryGenerator.createNamedQuery("board", "updateCiHit")
public void updateInHitForMinCivBoard680(Long ciCode) {
String sql = QueryGenerator.createNamedQuery("board", "updateCiHit")
.setParameter("ciCode", ciCode).getQueryString(); .setParameter("ciCode", ciCode).getQueryString();
update(sql); update(sql);
} }
public Optional<MinCivBoard680> findById(Long ciCode) { public Optional<BoardDto> findById(final Long ciCode) {
return Optional.empty(); 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 void insertBoard(final BoardDto dto) {
public Long getCiCode() { final String sql = QueryGenerator.createNamedQuery("board", "insertBoard")
return null; .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<MinCivBoard680> findByCiRef(Long ciCode) { public int findByCiRefCnt(final Long ciCode) {
return null; 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);
} }
} }

@ -40,23 +40,9 @@ public class PublicBoardDao extends BaseMpowerDaoSupport {
update(sql); update(sql);
} }
//public Optional<Object> findById(Long inCode) { // public Long getInCodeByInBgubun() {
//} // return 1L;
// }
//@Query(value = "SELECT e.msMaincode FROM #{#entityName} e WHERE e.msChasu = :msChasu AND e.msSdate = :msSdate AND e.msEdate = :msEdate")
public List<Long> 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 void insertPublicBoard(MinInfoBoard680Dto dto) { public void insertPublicBoard(MinInfoBoard680Dto dto) {
// null 값 set 불가 // null 값 set 불가
@ -66,8 +52,6 @@ public class PublicBoardDao extends BaseMpowerDaoSupport {
.setParameter("inDept", dto.getInDept()) .setParameter("inDept", dto.getInDept())
.setParameter("inEtc", dto.getInEtc()) .setParameter("inEtc", dto.getInEtc())
.setParameter("inFilename", dto.getInFilename()) .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("inFilesize", dto.getInFilesize())
.setParameter("inFileurl", dto.getInFileurl()) .setParameter("inFileurl", dto.getInFileurl())
.setParameter("inHit", dto.getInHit()) .setParameter("inHit", dto.getInHit())

@ -17,10 +17,6 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service @Service
@AllArgsConstructor @AllArgsConstructor
@Slf4j @Slf4j
@ -46,15 +42,15 @@ public class BoardService implements IBoardService {
// update 인 경우 // update 인 경우
if(Checks.isNotEmpty(dto.getCiCode())) { if(Checks.isNotEmpty(dto.getCiCode())) {
entity = boardDao.findById(dto.getCiCode()).orElseThrow(() -> new CustomBaseException(ErrorCode.DATA_NOT_FOUND)); BoardDto savedDto = boardDao.findById(dto.getCiCode()).orElseThrow(() -> new CustomBaseException(ErrorCode.DATA_NOT_FOUND));
if(!entity.getCiPass().equals(passwordEncoder.encode(dto.getCiPass()))){ if(!savedDto.getCiPass().equals(passwordEncoder.encode(dto.getCiPass()))){
throw new CustomBaseException(ErrorCode.MISMATCH_PASSWORD); throw new CustomBaseException(ErrorCode.MISMATCH_PASSWORD);
} }
entity.setCiTitle(dto.getCiTitle()); savedDto.setCiTitle(dto.getCiTitle());
entity.setCiContents(dto.getCiContents()); savedDto.setCiContents(dto.getCiContents());
boardDao.updateBoard(savedDto);
}else { }else {
dto.setCiCode(boardDao.getCiCode()); dto.setSaveInit();
dto.setCiContentno(dto.getCiCode());
if (Checks.isEmpty(dto.getCiRef()) || dto.getCiRef() == 0L) { if (Checks.isEmpty(dto.getCiRef()) || dto.getCiRef() == 0L) {
dto.setCiRef(dto.getCiCode()); dto.setCiRef(dto.getCiCode());
dto.setCiStep(0L); dto.setCiStep(0L);
@ -62,20 +58,20 @@ public class BoardService implements IBoardService {
} }
dto.setCiPass(passwordEncoder.encode(dto.getCiPass())); dto.setCiPass(passwordEncoder.encode(dto.getCiPass()));
dto.setCiIp(CommUtil.getDeviceInfo().getIp()); dto.setCiIp(CommUtil.getDeviceInfo().getIp());
boardDao.insertBoard(dto);
} }
boardDao.save(entity);
} }
@Override @Override
@Transactional @Transactional
public void removeBoard(Long ciCode) { public void removeBoard(final Long ciCode) {
MinCivBoard680 savedEntity = boardDao.findById(ciCode).orElseThrow(() -> new CustomBaseException(ErrorCode.NOT_FOUND)); BoardDto savedDto = boardDao.findById(ciCode).orElseThrow(() -> new CustomBaseException(ErrorCode.NOT_FOUND));
if(!Objects.equal(HeaderUtil.getUserId(), savedEntity.getCiId())) throw new CustomBaseException("삭제 권한(게시글 소유자)이 없는 사용자 입니다"); if(!Objects.equal(HeaderUtil.getUserId(), savedDto.getCiId())) throw new CustomBaseException("삭제 권한(게시글 소유자)이 없는 사용자 입니다");
// 댓글 존재 여부 조회 // 댓글 존재 여부 조회
List<MinCivBoard680> list = boardDao.findByCiRef(ciCode); int cnt = boardDao.findByCiRefCnt(ciCode);
if(list.size() > 1) throw new CustomBaseException("삭제 할 수 없는 게시글 입니다[댓글 존재]"); if(cnt > 1) throw new CustomBaseException("삭제 할 수 없는 게시글 입니다[댓글 존재]");
boardDao.deleteById(ciCode); boardDao.deleteById(ciCode);
} }
} }

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<entity-mappings namespace="board"> <entity-mappings namespace="board">
<native-query id="selectBoardList"> <native-query id="selectBoardList">
/* board-mapper|selectBoardList|julim */ /* board-mapper|selectBoardList|julim */
SELECT ci_code, SELECT ci_code,
@ -60,6 +61,27 @@
</where> </where>
</native-query> </native-query>
<native-query id="selectBoard">
/* 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}
</native-query>
<native-query id="updateCiHit"> <native-query id="updateCiHit">
/* board-mapper|updateCiHit|julim */ /* board-mapper|updateCiHit|julim */
@ -89,8 +111,8 @@
ci_contents, ci_contents,
ci_ip ci_ip
) VALUES ( ) 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),
(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),
#{ciTitle}, #{ciTitle},
#{ciId}, #{ciId},
#{ciPwd}, #{ciPwd},
@ -109,14 +131,25 @@
</native-query> </native-query>
<native-query id="updateBoard"> <native-query id="updateBoard">
/* pboard-mapper|updateBoard|julim */ /* board-mapper|updateBoard|julim */
UPDATE min_civ_board680 UPDATE min_civ_board680
SET ci_title = #{ciTitle} SET ci_title = #{ciTitle}
, ci_dept = #{ciDept} , ci_contents = #{ciContents}
, ci_contents = #{ciContents} WHERE ci_code = #{ciCode}
, ci_filename = #{ciFilename} </native-query>
, ci_filesize = #{ciFilesize}
, ci_fileurl = #{ciFileurl} <native-query id="selectCntByCiRef">
WHERE ci_code = #{ciCode} /* board-mapper|selectCntByCiRef|julim */
SELECT COUNT(ci_code) AS cnt
FROM min_civ_board680
WHERE ci_ref = #{ciRef}
</native-query> </native-query>
<native-query id="deleteBoard">
/* board-mapper|deleteBoard|julim */
DELETE
FROM min_civ_board680
WHERE ci_code = #{ciCode}
</native-query>
</entity-mappings> </entity-mappings>

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<entity-mappings namespace="user"> <entity-mappings namespace="user">
<native-query id="selectUserInfo"> <native-query id="selectUserInfo">
/* minuserinfo-mapper|selectUserInfo|julim */ /* minuserinfo-mapper|selectUserInfo|julim */
SELECT userid, SELECT userid,

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<entity-mappings namespace="pboard"> <entity-mappings namespace="pboard">
<native-query id="selectPublicBoardList"> <native-query id="selectPublicBoardList">
/* pboard-mapper|selectPublicBoardList|julim */ /* pboard-mapper|selectPublicBoardList|julim */
SELECT in_code, SELECT in_code,
@ -116,4 +117,5 @@
FROM min_info_board680 FROM min_info_board680
WHERE in_code = #{inCode} WHERE in_code = #{inCode}
</native-query> </native-query>
</entity-mappings> </entity-mappings>

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<entity-mappings namespace="refreshToken"> <entity-mappings namespace="refreshToken">
<native-query id="selectRefreshToken"> <native-query id="selectRefreshToken">
/* refreshToken-mapper|selectRefreshToken|julim */ /* refreshToken-mapper|selectRefreshToken|julim */
SELECT key, SELECT key,
@ -26,4 +27,5 @@
SET value = #{value} SET value = #{value}
WHERE key = #{key} WHERE key = #{key}
</native-query> </native-query>
</entity-mappings> </entity-mappings>
Loading…
Cancel
Save