feat: 게시판 관리 mpower 적용

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

@ -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<BoardDto> 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<BoardDto> 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<MinCivBoard680> findById(Long ciCode) {
return Optional.empty();
public Optional<BoardDto> 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<MinCivBoard680> 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);
}
}

@ -40,24 +40,10 @@ public class PublicBoardDao extends BaseMpowerDaoSupport {
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) {
// null 값 set 불가
String sql = QueryGenerator.createNamedQuery("pboard", "insertPublicBoard")
@ -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())

@ -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<MinCivBoard680> 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);
}
}

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings namespace="board">
<native-query id="selectBoardList">
/* board-mapper|selectBoardList|julim */
SELECT ci_code,
@ -60,6 +61,27 @@
</where>
</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">
/* 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 @@
</native-query>
<native-query id="updateBoard">
/* 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}
</native-query>
<native-query id="selectCntByCiRef">
/* board-mapper|selectCntByCiRef|julim */
SELECT COUNT(ci_code) AS cnt
FROM min_civ_board680
WHERE ci_ref = #{ciRef}
</native-query>
<native-query id="deleteBoard">
/* board-mapper|deleteBoard|julim */
DELETE
FROM min_civ_board680
WHERE ci_code = #{ciCode}
</native-query>
</entity-mappings>

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

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

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