|
|
|
@ -14,6 +14,7 @@ import com.xit.core.util.Checks;
|
|
|
|
|
import com.xit.core.util.CommUtil;
|
|
|
|
|
import com.xit.core.util.mpower.MpowerUtil;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.mapstruct.factory.Mappers;
|
|
|
|
|
import org.springframework.data.domain.Example;
|
|
|
|
|
import org.springframework.data.domain.ExampleMatcher;
|
|
|
|
@ -30,19 +31,13 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class BoardService implements IBoardService {
|
|
|
|
|
|
|
|
|
|
private final IBoardRepository repository;
|
|
|
|
|
private final PasswordEncoder passwordEncoder;
|
|
|
|
|
private final MinCivBoard680Mapstruct mapstruct = Mappers.getMapper(MinCivBoard680Mapstruct.class);
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
|
|
public Page<BoardDto> findAll(final BoardDto dto, Pageable pageable) {
|
|
|
|
|
pageable = JpaUtil.getPagingInfo(pageable);
|
|
|
|
|
return repository.findAll(dto, pageable);
|
|
|
|
|
}
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
|
|
public Map<String, Object> findAllTest(final BoardDto dto){
|
|
|
|
|
public List<Map<String, Object>> findAll(final BoardDto dto, Pageable pageable) {
|
|
|
|
|
MpowerUtil sendXml = new MpowerUtil();
|
|
|
|
|
String query = "SELECT ci_code ciCode,\n" +
|
|
|
|
|
" name ciName,\n" +
|
|
|
|
@ -80,63 +75,95 @@ public class BoardService implements IBoardService {
|
|
|
|
|
" 2)";
|
|
|
|
|
sendXml.setFeilds("ciCode, ciName, ciContentno, ciTitle, ciContents, ciNalja, ciStep, ciRevel, ciRef, ciHit, ciPass, ciId");
|
|
|
|
|
sendXml.setQuery(query);
|
|
|
|
|
Map<String,Object> eMap = sendXml.selectCustomQuery();
|
|
|
|
|
return eMap;
|
|
|
|
|
}
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
|
|
public Page<MinCivBoard680> findAll2(final MinCivBoard680 entity, Pageable pageable) {
|
|
|
|
|
pageable = JpaUtil.getPagingInfo(pageable);
|
|
|
|
|
ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll()
|
|
|
|
|
.withMatcher("ciTitle", contains())
|
|
|
|
|
.withMatcher("ciName", contains());
|
|
|
|
|
Example<MinCivBoard680> example = Example.of(entity, exampleMatcher);
|
|
|
|
|
return repository.findAll(example, pageable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public int modifyByCiCode(Long ciCode) {
|
|
|
|
|
return repository.updateInHitForMinCivBoard680(ciCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void saveBoard(BoardDto dto) {
|
|
|
|
|
MinCivBoard680 entity = null;
|
|
|
|
|
|
|
|
|
|
// update 인 경우
|
|
|
|
|
if(Checks.isNotEmpty(dto.getCiCode())) {
|
|
|
|
|
entity = repository.findById(dto.getCiCode()).orElseThrow(() -> new CustomBaseException(ErrorCode.DATA_NOT_FOUND));
|
|
|
|
|
if(!entity.getCiPass().equals(passwordEncoder.encode(dto.getCiPass()))){
|
|
|
|
|
throw new CustomBaseException(ErrorCode.MISMATCH_PASSWORD);
|
|
|
|
|
}
|
|
|
|
|
entity.setCiTitle(dto.getCiTitle());
|
|
|
|
|
entity.setCiContents(dto.getCiContents());
|
|
|
|
|
}else {
|
|
|
|
|
dto.setCiCode(repository.getCiCode());
|
|
|
|
|
dto.setCiContentno(dto.getCiCode());
|
|
|
|
|
if (Checks.isEmpty(dto.getCiRef()) || dto.getCiRef() == 0L) {
|
|
|
|
|
dto.setCiRef(dto.getCiCode());
|
|
|
|
|
dto.setCiStep(0L);
|
|
|
|
|
dto.setCiRevel(0L);
|
|
|
|
|
}
|
|
|
|
|
dto.setCiPass(passwordEncoder.encode(dto.getCiPass()));
|
|
|
|
|
dto.setCiIp(CommUtil.getDeviceInfo().getIp());
|
|
|
|
|
entity = mapstruct.toEntity(dto);
|
|
|
|
|
}
|
|
|
|
|
repository.save(entity);
|
|
|
|
|
}
|
|
|
|
|
// SqlMapClientImpl sqlMapClientImpl;
|
|
|
|
|
// MappedStatement mappedStatement;
|
|
|
|
|
// StatementScope statementScope;
|
|
|
|
|
// SessionScope sessionScope;
|
|
|
|
|
// Sql sql ;
|
|
|
|
|
//
|
|
|
|
|
// //ibatis에서 sqlMapClient인터페이스 구현체는 sqlMapClientImpl 밖에 없습니다. doc 참조
|
|
|
|
|
// //다운캐스팅 합니다.
|
|
|
|
|
// sqlMapClientImpl = (SqlMapClientImpl)this.sqlMapClientTemplate.getSqlMapClient();
|
|
|
|
|
// //sqlmap statement 객체를 구합니다.
|
|
|
|
|
// mappedStatement = sqlMapClientImpl.getMappedStatement("selectMember");
|
|
|
|
|
//
|
|
|
|
|
// //iBatis에서는 ThreadLocal를 통해서 세션을 정의합니다.
|
|
|
|
|
// sessionScope = new SessionScope();
|
|
|
|
|
// statementScope = new StatementScope(sessionScope);
|
|
|
|
|
// //이부분 매우 중요합니다. 이부분을 생략 하면 다이나믹 쿼리가 적용되지 않습니다.
|
|
|
|
|
// mappedStatement.initRequest(statementScope);
|
|
|
|
|
// //sql을 추출 합니다.
|
|
|
|
|
// sql = mappedStatement.getSql();
|
|
|
|
|
//
|
|
|
|
|
// if(logger.isDebugEnabled()){
|
|
|
|
|
// logger.debug("======================="+
|
|
|
|
|
// sql.getSql(statementScope,parameterMap);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void removeBoard(Long ciCode) {
|
|
|
|
|
|
|
|
|
|
MinCivBoard680 savedEntity = repository.findById(ciCode).orElseThrow(() -> new CustomBaseException(ErrorCode.NOT_FOUND));
|
|
|
|
|
if(!Objects.equal(HeaderUtil.getUserId(), savedEntity.getCiId())) throw new CustomBaseException("삭제 권한(게시글 소유자)이 없는 사용자 입니다");
|
|
|
|
|
|
|
|
|
|
// 댓글 존재 여부 조회
|
|
|
|
|
List<MinCivBoard680> list = repository.findByCiRef(ciCode);
|
|
|
|
|
if(list.size() > 1) throw new CustomBaseException("삭제 할 수 없는 게시글 입니다[댓글 존재]");
|
|
|
|
|
repository.deleteById(ciCode);
|
|
|
|
|
return sendXml.selectCustomQuery();
|
|
|
|
|
//log.debug("{}", map);
|
|
|
|
|
//return map.get("resultList");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Transactional(readOnly = true)
|
|
|
|
|
// public Page<MinCivBoard680> findAll2(final MinCivBoard680 entity, Pageable pageable) {
|
|
|
|
|
// pageable = JpaUtil.getPagingInfo(pageable);
|
|
|
|
|
// ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll()
|
|
|
|
|
// .withMatcher("ciTitle", contains())
|
|
|
|
|
// .withMatcher("ciName", contains());
|
|
|
|
|
// Example<MinCivBoard680> example = Example.of(entity, exampleMatcher);
|
|
|
|
|
// return repository.findAll(example, pageable);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// @Transactional
|
|
|
|
|
// public int modifyByCiCode(Long ciCode) {
|
|
|
|
|
// return repository.updateInHitForMinCivBoard680(ciCode);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// @Transactional
|
|
|
|
|
// public void saveBoard(BoardDto dto) {
|
|
|
|
|
// MinCivBoard680 entity = null;
|
|
|
|
|
//
|
|
|
|
|
// // update 인 경우
|
|
|
|
|
// if(Checks.isNotEmpty(dto.getCiCode())) {
|
|
|
|
|
// entity = repository.findById(dto.getCiCode()).orElseThrow(() -> new CustomBaseException(ErrorCode.DATA_NOT_FOUND));
|
|
|
|
|
// if(!entity.getCiPass().equals(passwordEncoder.encode(dto.getCiPass()))){
|
|
|
|
|
// throw new CustomBaseException(ErrorCode.MISMATCH_PASSWORD);
|
|
|
|
|
// }
|
|
|
|
|
// entity.setCiTitle(dto.getCiTitle());
|
|
|
|
|
// entity.setCiContents(dto.getCiContents());
|
|
|
|
|
// }else {
|
|
|
|
|
// dto.setCiCode(repository.getCiCode());
|
|
|
|
|
// dto.setCiContentno(dto.getCiCode());
|
|
|
|
|
// if (Checks.isEmpty(dto.getCiRef()) || dto.getCiRef() == 0L) {
|
|
|
|
|
// dto.setCiRef(dto.getCiCode());
|
|
|
|
|
// dto.setCiStep(0L);
|
|
|
|
|
// dto.setCiRevel(0L);
|
|
|
|
|
// }
|
|
|
|
|
// dto.setCiPass(passwordEncoder.encode(dto.getCiPass()));
|
|
|
|
|
// dto.setCiIp(CommUtil.getDeviceInfo().getIp());
|
|
|
|
|
// entity = mapstruct.toEntity(dto);
|
|
|
|
|
// }
|
|
|
|
|
// repository.save(entity);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// @Transactional
|
|
|
|
|
// public void removeBoard(Long ciCode) {
|
|
|
|
|
//
|
|
|
|
|
// MinCivBoard680 savedEntity = repository.findById(ciCode).orElseThrow(() -> new CustomBaseException(ErrorCode.NOT_FOUND));
|
|
|
|
|
// if(!Objects.equal(HeaderUtil.getUserId(), savedEntity.getCiId())) throw new CustomBaseException("삭제 권한(게시글 소유자)이 없는 사용자 입니다");
|
|
|
|
|
//
|
|
|
|
|
// // 댓글 존재 여부 조회
|
|
|
|
|
// List<MinCivBoard680> list = repository.findByCiRef(ciCode);
|
|
|
|
|
// if(list.size() > 1) throw new CustomBaseException("삭제 할 수 없는 게시글 입니다[댓글 존재]");
|
|
|
|
|
// repository.deleteById(ciCode);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|