From cdfa528f0174f566239ff44d8f50e9233fb17a57 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Wed, 15 Jun 2022 14:46:51 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20dashboard=20=ED=98=84=ED=99=A9=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=8C=80=EC=83=81=20=EC=8B=AC=EC=9D=98?= =?UTF-8?q?=EC=A0=84=EC=9C=BC=EB=A1=9C=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 8 +- .../ctgy/v2/controller/BoardController.java | 57 ++++--- .../biz/ctgy/v2/service/IBoardService.java | 18 +-- .../ctgy/v2/service/impl/BoardService.java | 147 +++++++++++------- .../com/xit/core/util/mpower/MpowerUtil.java | 45 ++++-- 5 files changed, 167 insertions(+), 108 deletions(-) diff --git a/build.gradle b/build.gradle index f732450..55cdb43 100644 --- a/build.gradle +++ b/build.gradle @@ -72,6 +72,12 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-jdbc' + + // mybatis + implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' + //implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter' + + // config 암호화 사용 implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.3' // spring-boot 2.3 까지는 사용 불가 - spring-boot-starter-web에 포함되어 있다 @@ -103,7 +109,7 @@ dependencies { // Mybatis //-----------------------------------------------------------------------------------// implementation 'org.mybatis:mybatis:3.5.9' - implementation 'org.mybatis:mybatis-typehandlers-jsr310:1.0.2' + //implementation 'org.mybatis:mybatis-typehandlers-jsr310:1.0.2' implementation 'org.mybatis:mybatis-spring:2.0.6' //-----------------------------------------------------------------------------------// diff --git a/src/main/java/com/xit/biz/ctgy/v2/controller/BoardController.java b/src/main/java/com/xit/biz/ctgy/v2/controller/BoardController.java index b1a52f8..50b38e0 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/controller/BoardController.java +++ b/src/main/java/com/xit/biz/ctgy/v2/controller/BoardController.java @@ -48,35 +48,34 @@ public class BoardController { final BoardDto dto, @Parameter(hidden = true) final Pageable pageable) { - //return RestResponse.of(service.findAll(dto, pageable)); - return RestResponse.of(service.findAllTest(dto)); + return RestResponse.of(service.findAll(dto, pageable)); } - @Secured(policy = SecurityPolicy.TOKEN) - @Operation(summary = "게시글 조회수 증가" , description = "게시글 조회수 증가") - @Parameters({ - @Parameter(in = ParameterIn.PATH, name = "ciCode", description = "게시글번호", required = true, example = "18"), - }) - @PutMapping(value = "/hit/{ciCode}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity modifyByCiCode(@PathVariable final Long ciCode) { - return RestResponse.of(service.modifyByCiCode(ciCode)); - } - - @Secured(policy = SecurityPolicy.TOKEN) - @Operation(summary = "게시글 등록" , description = "게시글 등록") - @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity saveBoard(BoardDto dto) { - service.saveBoard(dto); - return RestResponse.of(HttpStatus.OK); - } - - @Secured(policy = SecurityPolicy.TOKEN) - @Operation(summary = "게시글 삭제", description = "게시글 삭제") - @PostMapping(value = "/{ciCode}") - public ResponseEntity removeBoard(@PathVariable @Nonnull final Long ciCode) { - AssertUtils.isTrue(!Checks.isEmpty(ciCode), "게시글이 선택되지 않았습니다."); - service.removeBoard(ciCode); - - return RestResponse.of(HttpStatus.OK); - } +// @Secured(policy = SecurityPolicy.TOKEN) +// @Operation(summary = "게시글 조회수 증가" , description = "게시글 조회수 증가") +// @Parameters({ +// @Parameter(in = ParameterIn.PATH, name = "ciCode", description = "게시글번호", required = true, example = "18"), +// }) +// @PutMapping(value = "/hit/{ciCode}", produces = MediaType.APPLICATION_JSON_VALUE) +// public ResponseEntity modifyByCiCode(@PathVariable final Long ciCode) { +// return RestResponse.of(service.modifyByCiCode(ciCode)); +// } +// +// @Secured(policy = SecurityPolicy.TOKEN) +// @Operation(summary = "게시글 등록" , description = "게시글 등록") +// @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) +// public ResponseEntity saveBoard(BoardDto dto) { +// service.saveBoard(dto); +// return RestResponse.of(HttpStatus.OK); +// } +// +// @Secured(policy = SecurityPolicy.TOKEN) +// @Operation(summary = "게시글 삭제", description = "게시글 삭제") +// @PostMapping(value = "/{ciCode}") +// public ResponseEntity removeBoard(@PathVariable @Nonnull final Long ciCode) { +// AssertUtils.isTrue(!Checks.isEmpty(ciCode), "게시글이 선택되지 않았습니다."); +// service.removeBoard(ciCode); +// +// return RestResponse.of(HttpStatus.OK); +// } } diff --git a/src/main/java/com/xit/biz/ctgy/v2/service/IBoardService.java b/src/main/java/com/xit/biz/ctgy/v2/service/IBoardService.java index 3d209a3..7170dbe 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/service/IBoardService.java +++ b/src/main/java/com/xit/biz/ctgy/v2/service/IBoardService.java @@ -6,17 +6,17 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import java.util.Map; +import java.util.List; public interface IBoardService { - Page findAll(final BoardDto dto, Pageable pageable); + List> findAll(final BoardDto dto, Pageable pageable); - Map findAllTest(final BoardDto dto); - Page findAll2(final MinCivBoard680 entity, Pageable pageable); - - int modifyByCiCode(Long ciCode); - - void saveBoard(BoardDto dto); - - void removeBoard(Long ciCode); +// Page findAll2(final MinCivBoard680 entity, Pageable pageable); +// +// int modifyByCiCode(Long ciCode); +// +// void saveBoard(BoardDto dto); +// +// void removeBoard(Long ciCode); } 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 7d19cc0..4ddc027 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 @@ -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 findAll(final BoardDto dto, Pageable pageable) { - pageable = JpaUtil.getPagingInfo(pageable); - return repository.findAll(dto, pageable); - } - @Transactional(readOnly = true) - public Map findAllTest(final BoardDto dto){ + public List> 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 eMap = sendXml.selectCustomQuery(); - return eMap; - } - @Transactional(readOnly = true) - public Page findAll2(final MinCivBoard680 entity, Pageable pageable) { - pageable = JpaUtil.getPagingInfo(pageable); - ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll() - .withMatcher("ciTitle", contains()) - .withMatcher("ciName", contains()); - Example 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 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 findAll2(final MinCivBoard680 entity, Pageable pageable) { +// pageable = JpaUtil.getPagingInfo(pageable); +// ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll() +// .withMatcher("ciTitle", contains()) +// .withMatcher("ciName", contains()); +// Example 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 list = repository.findByCiRef(ciCode); +// if(list.size() > 1) throw new CustomBaseException("삭제 할 수 없는 게시글 입니다[댓글 존재]"); +// repository.deleteById(ciCode); +// } } diff --git a/src/main/java/com/xit/core/util/mpower/MpowerUtil.java b/src/main/java/com/xit/core/util/mpower/MpowerUtil.java index e8c4eac..d2ea85b 100644 --- a/src/main/java/com/xit/core/util/mpower/MpowerUtil.java +++ b/src/main/java/com/xit/core/util/mpower/MpowerUtil.java @@ -10,13 +10,10 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.*; -//import org.apache.log4j.Logger; - -//import com.gpki.util.Base64; import com.plf.client.Client; +import lombok.extern.slf4j.Slf4j; -//import egovframework.rte.psl.dataaccess.util.EgovMap; - +@Slf4j public class MpowerUtil { //DBName Properties // static String DbName2 = PropertiesUtil.getValue("Globals.DBName"); @@ -210,6 +207,8 @@ public class MpowerUtil { mpower.setInput("SQLXML", query); mpower.Request(); String result = mpower.getString("result", 0, 0); + System.out.println("#######$$$$$$$$$$$$$$$$$$"+result); + int row; if (result.equals("true")){ row = mpower.getMaxRow("list1"); @@ -634,7 +633,7 @@ public class MpowerUtil { * @ 페이징 처리 SELECT 호출 * @return */ - public Map selectCustomQuery() { + public List> selectCustomQuery() { //EgovMap mListMap = new EgovMap(); Map mListMap = new HashMap<>(); //배열로 넘어온 필드를 String 오브젝트로 변형 @@ -652,7 +651,7 @@ public class MpowerUtil { System.out.println("======"+query); //List mList = new ArrayList(); - List mList = new ArrayList<>(); + List> mList = new ArrayList<>(); int mListCount = 0; try { mpower = new Client(hostip,port); @@ -660,6 +659,33 @@ public class MpowerUtil { mpower.setInput("SQLXML", query); mpower.Request(); String result = mpower.getString("result", 0, 0); + + System.out.println("#######message = "+mpower.getMessage()); + + String s = mpower.getMessage(); + +// System.out.println(new String(s.getBytes("unicode"), "unicode")); +// System.out.println(new String(s.getBytes("utf-8"), "utf-8")); +// System.out.println(new String(s.getBytes("utf-16"), "utf-16")); +// System.out.println(new String(s.getBytes("euc-kr"), "euc-kr")); +// System.out.println(new String(s.getBytes("ksc5601"), "ksc5601")); +// System.out.println(new String(s.getBytes("ms949"), "ms949")); +// System.out.println(new String(s.getBytes("iso-8859-1"), "iso-8859-1")); + + System.out.println(new String(s.getBytes("unicode"), "unicode")); + System.out.println(new String(s.getBytes("utf-8"), "utf-8")); + System.out.println(new String(s.getBytes("utf-16"), "utf-16")); + System.out.println(new String(s.getBytes("euc-kr"), "euc-kr")); + System.out.println(new String(s.getBytes("ksc5601"), "ksc5601")); + System.out.println(new String(s.getBytes("ms949"), "ms949")); + System.out.println(new String(s.getBytes("iso-8859-1"), "iso-8859-1")); + + + System.out.println("#######data:::result = "+mpower.getData("result")); + System.out.println("#######data:::result = "+mpower.getData("list1")); + System.out.println("#######$$$$$$$$$$$$$$$$$$"+result); + log.debug("#######$$$$$$$$$$$$$$$$$$====>>>>>>"+result); + int row; if (result.equals("true")){ row = mpower.getMaxRow("list1"); @@ -676,7 +702,8 @@ public class MpowerUtil { } mList.add(m); } - mListMap.put("resultList", mList); + //mListMap.put("resultList", mList); + //mList; } } mpower.disconnect(); @@ -688,7 +715,7 @@ public class MpowerUtil { } String s = String.valueOf(mList); byte[] b = s.getBytes(StandardCharsets.UTF_8); - return mListMap; + return mList; }