From cdfa528f0174f566239ff44d8f50e9233fb17a57 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Wed, 15 Jun 2022 14:46:51 +0900 Subject: [PATCH 1/4] =?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; } From 24f640d21a5f937b25bffa198baa6cad561a23d3 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Wed, 22 Jun 2022 17:38:13 +0900 Subject: [PATCH 2/4] feat: mpower --- .../com/xit/core/util/mpower/MpowerUtils.java | 918 ++++++++++++++++++ 1 file changed, 918 insertions(+) create mode 100644 src/main/java/com/xit/core/util/mpower/MpowerUtils.java diff --git a/src/main/java/com/xit/core/util/mpower/MpowerUtils.java b/src/main/java/com/xit/core/util/mpower/MpowerUtils.java new file mode 100644 index 0000000..05bd5f6 --- /dev/null +++ b/src/main/java/com/xit/core/util/mpower/MpowerUtils.java @@ -0,0 +1,918 @@ +package com.xit.core.util.mpower; + +import com.plf.client.Client; +import com.xit.core.util.CommUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.binary.StringUtils; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.ParameterMapping; +import org.apache.ibatis.session.SqlSession; + +import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.sql.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +public class MpowerUtils { + //DBName Properties +// static String DbName2 = PropertiesUtil.getValue("Globals.DBName"); + static String DbName2 = "gn"; + + + Client mpower = null; + static Client mpower2 = null; + //static String hostip = "115.21.123.19"; + static String hostip = "127.0.0.1"; + static int port = 9999; + static String query = ""; + String wholeQuery = ""; + //protected static Logger logger = Logger.getLogger(MpowerUtil.class.getName()); + static ArrayList feilds = new ArrayList(); + static String feild = ""; + static String tmpFeilds = ""; + static Boolean RowNum = false; + static String tableNm = ""; + static String WhereStr = ""; + static String Orderby = ""; + static int pageIndex = 0; + static int firstIndex = 0; + static int lastIndex = 10; + static int recordCountPerPage = 10; + static String beforeXml = ""; + static String afterXmlsp = "]]>"; + static Boolean pagingYn = false; + + + //Ps변수 + static String Params = ""; + static String finalParams = ""; + static String threeXml = ""; + static String threeXmlEnd = ""; + static String forXmlEnd = ""; + static int psParamCount = 0; + static String psFinalFarams =""; + static String QueryXml = ""; + + //static String vioPhoto = PropertiesUtil.getValue("Globals.vioPhoto"); //주정차사진경로 + static String vioPhoto = ""; + //static String vioPhotoBus = PropertiesUtil.getValue("Globals.vioPhotoBus"); //버스사진경로 + static String vioPhotoBus = ""; + //static String tunullingFile = PropertiesUtil.getValue("Globals.tunullingFile"); //터널링서버에 복사되는 첨부파일 위치 + static String tunullingFile = ""; + + public void setQuery(String query){ + MpowerUtils.query = query; + } + + public void setRowNum(boolean truefalse){ + RowNum = truefalse; + } + + public void setPageIndex(int pi){ + pageIndex = pi; + } + + public void setRecordCountPerPage(int rcpp){ + recordCountPerPage = rcpp; + } + + public int getRecordCountPerPage(){ + return recordCountPerPage; + } + + public String getWholeQuery() { + return wholeQuery; + } + + public void setWholeQuery(String wholeQuery) { + this.wholeQuery = wholeQuery; + } + + public void setFeild(String feildNm){ + feilds.add(feildNm); + } + + public void setFeild2(String feildNm){ + feild = feildNm; + } + + public void setTableNm(String tNm){ + tableNm = tNm; + } + public void setWhereStr(String whr){ + WhereStr += whr; + } + public void setOrderby(String ob){ + Orderby += ob; + } + + public int getFirstIndex() { + return (pageIndex - 1) * recordCountPerPage +1; + } + + public int getLastIndex() { + return lastIndex = pageIndex * recordCountPerPage; + } + + public void setPagingYn(Boolean yn){ + pagingYn = yn; + } + + public void AddParam(String inputType,String Val){ + psParamCount ++; + Params += ""; + } + + //kkj추가 + public void AddParam2(String inputType,long Val){ + psParamCount ++; + Params += ""; + } + + public void setParamsBody(){ + Params = "" + Params + ""; + + afterXmlsp = "]]>"; + forXmlEnd = ""; + } + + public void setSPQuerysBody(){ + QueryXml = beforeXmlsp + tableNm + "(" +psFinalFarams + ")" + afterXmlsp + Params + forXmlEnd; + } + + public void AddFinalParam(int count){ + for(int i=0;i PsQuery() throws Exception{ + //EgovMap resultEgov = new EgovMap(); + Map resultEgov = new HashMap<>(); + try{ + AddFinalParam(psParamCount); + setParamsBody(); + setSPQuerysBody(); + resultEgov = connreturnMpwoer(QueryXml); + }catch(Exception e) + { + e.printStackTrace(); + }finally{ + clearValidation(); + } + return resultEgov; + } + + public Map connreturnMpwoer(String psQuery) throws Exception{ + mpower = new Client(hostip,port); + mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); + mpower.setInput("SQLXML", psQuery); + mpower.Request(); + //EgovMap eMap = new EgovMap(); + Map eMap = new HashMap<>(); + eMap.put("result",mpower.getString("result", 0, 0)); + + int cnt = 1; + for( int i = 0 ; i < mpower.getMaxCol("list1"); i++){ + eMap.put("list"+cnt,mpower.getString("list1", 0, i)); + cnt ++; + } + return eMap; + } + + public List> selectQuery() { + String fileList = ""; + for(int cnt = 0;cnt mList = new ArrayList(); + List> mList= new ArrayList>(); + + try { + mpower = new Client(hostip,port); + mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); + 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"); + if(row>0){ + for(int i=0;i m = new HashMap<>(); + for(int j=0;j(); + tableNm = ""; + WhereStr = ""; + Orderby = ""; + } + + return mList; + } + + private void clearValidation() { + query = ""; + feilds = new ArrayList(); + tableNm = ""; + WhereStr = ""; + Orderby=""; + psParamCount = 0; + QueryXml = ""; + Params = ""; + psFinalFarams = ""; + recordCountPerPage = 10; + feild = ""; + } + + + /** + * @ 페이징 처리 SELECT 호출 + * @return + */ + public Map selectListQuery() { + //EgovMap mListMap = new EgovMap(); + Map mListMap = new HashMap<>(); + //배열로 넘어온 필드를 String 오브젝트로 변형 + String fileList = ""; + for(int cnt = 0;cnt(); + this.setFeilds("RN, "+tmpFeilds); + } + + //List mList = new ArrayList(); + List> mList = new ArrayList<>(); + System.out.println("mlistmlist"); + System.out.println(mList); + System.out.println("mlistmlist"); + int mListCount = 0; + try { + mpower = new Client(hostip,port); + mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); + mpower.setInput("SQLXML", query); + mpower.Request(); + String result = mpower.getString("result", 0, 0); + int row = 0; + if (result.equals("true")){ + row = mpower.getMaxRow("list1"); + if(row>0){ + for(int i=0;i m = new HashMap<>(); + for(int j=0;j0){ + mpower = new Client(hostip,port); + mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); + mpower.setInput("SQLXML", Cquery); + mpower.Request(); + + String strList1 = mpower.getString("list1", 0, 0); + + if( !strList1.equals("") && strList1 != null){ + mListCount = Integer.parseInt(strList1); + } + mpower.disconnect(); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally{ + clearValidation(); + } + System.out.println("엠리스트트트트트"); + System.out.println(mListCount); + System.out.println(mListMap); + System.out.println(mList); + System.out.println("엠리스트트트트트"); + mListMap.put("mListCount", mListCount); + return mListMap; + } + + // + + /** + * @ 페이징 처리 SELECT 호출 + * @return + * @throws SQLException + */ + public Map selectListQueryNew() throws SQLException { + //EgovMap mListMap = new EgovMap(); + Map mListMap = new HashMap<>(); + //배열로 넘어온 필드를 String 오브젝트로 변형 + String fileList = ""; + for(int cnt = 0;cnt(); + this.setFeilds("RN, "+tmpFeilds); + } + + //List mList = new ArrayList(); + List> mList = new ArrayList>(); + int mListCount = 0; + + Connection con; + Statement stmt; //단순 쿼리 실행 + PreparedStatement pstmt = null; //컴파일시 디비에 먼저 파싱하므로 Statement 보다 빠름 + CallableStatement cstmt; //프로시져를 호출하므로 속도가 PreparedStatement 보다 빠름 + ResultSet rs = null; + String dbURL = "jdbc:oracle:thin:@115.21.123.114:1521:ora10g"; + String driver = "oracle.jdbc.OracleDriver"; + + try { + Class.forName(driver); + } catch (ClassNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + con = DriverManager.getConnection(dbURL, "TRAFFIC", "xhdgkq0"); + + //3.1 Statement 객체로 구문객체 생성 및 실행 + int size = 0; + try{ + System.out.println("Query :" + finalQuery); + pstmt = con.prepareStatement(finalQuery); + rs = pstmt.executeQuery(); // 이거 왜 실행안??? + System.out.println("rs:" + rs); + boolean chpoint = false; + while(rs.next()) + { + size = rs.getInt(1); + //EgovMap m = new EgovMap(); + Map m = new HashMap<>(); + if(!chpoint) + { + for(int j=0;j selectListQuery2() { + //EgovMap mListMap = new EgovMap(); + Map mListMap = new HashMap<>(); + //배열로 넘어온 필드를 String 오브젝트로 변형 + String fileList = ""; + for(int cnt = 0;cnt(); + this.setFeilds("RN, "+tmpFeilds); + } + + //List mList = new ArrayList(); + List> mList = new ArrayList<>(); + int mListCount = 0; + try { + mpower = new Client(hostip,port); + mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); + mpower.setInput("SQLXML", query); + mpower.Request(); + String result = mpower.getString("result", 0, 0); + int row = 0; + if (result.equals("true")){ + row = mpower.getMaxRow("list1"); + if(row>0){ + for(int i=0;i m = new HashMap<>(); + for(int j=0;j0){ + mpower = new Client(hostip,port); + mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); + mpower.setInput("SQLXML", Cquery); + mpower.Request(); + + String strList1 = mpower.getString("list1", 0, 0); + + if( !strList1.equals("") && strList1 != null){ + mListCount = Integer.parseInt(strList1); + } + mpower.disconnect(); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally{ + clearValidation(); + } + mListMap.put("mListCount", mListCount); + return mListMap; + } + + public Map selectListQuery_pay() { + //EgovMap mListMap = new EgovMap(); + Map mListMap = new HashMap<>(); + //배열로 넘어온 필드를 String 오브젝트로 변형 + String fileList = ""; + for(int cnt = 0;cnt(); + this.setFeilds("RN, "+tmpFeilds); + } + + //List mList = new ArrayList(); + List> mList = new ArrayList>(); + int mListCount = 0; + try { + mpower2 = new Client(hostip,port); + mpower2.getConnection("MPowerXmlToQuery.xmlQuery1"); + mpower2.setInput("SQLXML", query); + mpower2.Request(); + String result = mpower2.getString("result", 0, 0); + int row = 0; + if (result.equals("true")){ + row = mpower2.getMaxRow("list1"); + if(row>0){ + for(int i=0;i m = new HashMap<>(); + for(int j=0;j0){ + mpower2.getConnection("MPowerXmlToQuery.xmlQuery1"); + mpower2.setInput("SQLXML", Cquery); + mpower2.Request(); + mListCount = Integer.parseInt(mpower2.getString("list1", 0, 0)); + //System.out.println("mListCount:"+mListCount); + } + //logger.debug("END getString list1"); + mpower2.disconnect(); + //logger.debug(Cquery); + //logger.debug("==============================================================================================================="); + + } catch (Exception e) { + e.printStackTrace(); + } finally{ + clearValidation(); + } + mListMap.put("mListCount", mListCount); + return mListMap; + } + + /** + * @ 페이징 처리 SELECT 호출 + * @return + */ + public List> selectCustomQuery(String sql) { + //EgovMap mListMap = new EgovMap(); + Map mListMap = new HashMap<>(); + //배열로 넘어온 필드를 String 오브젝트로 변형 + String fileList = ""; + for(int cnt = 0;cnt mList = new ArrayList(); + List> mList = new ArrayList<>(); + int mListCount = 0; + try { + mpower = new Client(hostip,port); + mpower.setCryptEnable(false); + mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); + mpower.setInput("SQLXML", query); + mpower.Request(); + String result = mpower.getString("result", 0, 0); + + + + System.out.println("#######message = "+mpower.getFile("list1")); + + String s = "답변드립니다"; + //System.out.println(CommUtil.detectCharset(s.getBytes())); + + System.out.println(URLEncoder.encode(s, "euc-kr")); + System.out.println(URLDecoder.decode(s, "euc-kr")); + String ss = new String("답변드립니다".getBytes("euc-kr"), "euc-kr"); + System.out.println(CommUtil.detectCharset(ss.getBytes())); + + System.out.println((new String("답변드립니다".getBytes("utf-8"), "euc-kr"))); + System.out.println((new String("답변드립니다".getBytes("euc-kr"), "euc-kr"))); + + +// 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")); + + //String originalStr = URLDecoder.decode(mpower.getMessage(), "utf-8"); + System.out.println(URLDecoder.decode(mpower.getMessage(), "utf-8")); + System.out.println(URLDecoder.decode(mpower.getMessage(), "euc-kr")); + System.out.println(StringUtils.newStringUtf16Le(mpower.getMessage().getBytes())); + System.out.println(StringUtils.newStringUtf16(mpower.getMessage().getBytes())); + System.out.println(StringUtils.newStringUtf16Be(mpower.getMessage().getBytes())); + System.out.println(StringUtils.newStringIso8859_1(mpower.getMessage().getBytes())); + + String originalStr = mpower.getMessage(); + String [] charSet = {"utf-8","euc-kr","ksc5601","iso-8859-1","x-windows-949", "ms949"}; + + for (int i=0; i0){ + for(int i=0;i m = new HashMap<>(); + if(!"".equals(feild) && feild != null){ + m.put("cbContent", mpower.getString("list1", i, 4)); + //m.put("cbContent", new String(mpower.getString("list1", i, 4).getBytes("utf-8"), "utf-8")); + }else{ + for(int j=0;j Date: Wed, 22 Jun 2022 17:38:36 +0900 Subject: [PATCH 3/4] feat: mpower --- build.gradle | 4 ++ .../ctgy/v2/service/impl/BoardService.java | 30 +++++++++ .../xit/core/config/EncodingFilterConfig.java | 26 ++++++-- .../database/BaseMybatisDaoSupport.java | 48 ++++++++++++++ .../config/support/EucKrEncodingFilter.java | 11 ++++ src/main/java/com/xit/core/util/CommUtil.java | 56 ++++++++++++++++ .../com/xit/core/util/mpower/MpowerUtil.java | 64 +++++++++++++++---- src/main/resources/config/application-dev.yml | 3 + 8 files changed, 224 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/xit/core/config/database/BaseMybatisDaoSupport.java create mode 100644 src/main/java/com/xit/core/config/support/EucKrEncodingFilter.java diff --git a/build.gradle b/build.gradle index 55cdb43..b80b5d3 100644 --- a/build.gradle +++ b/build.gradle @@ -229,6 +229,10 @@ dependencies { //implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.5' //-----------------------------------------------------------------------------------// + // https://mvnrepository.com/artifact/com.googlecode.juniversalchardet/juniversalchardet + implementation group: 'com.googlecode.juniversalchardet', name: 'juniversalchardet', version: '1.0.3' + + //-----------------------------------------------------------------------------------// // Test //-----------------------------------------------------------------------------------// 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 4ddc027..ee20105 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 @@ -2,10 +2,12 @@ package com.xit.biz.ctgy.v2.service.impl; import com.google.common.base.Objects; import com.xit.biz.ctgy.dto.BoardDto; +import com.xit.biz.ctgy.dto.JudgeListDto; import com.xit.biz.ctgy.dto.struct.MinCivBoard680Mapstruct; import com.xit.biz.ctgy.entity.MinCivBoard680; import com.xit.biz.ctgy.repository.IBoardRepository; import com.xit.biz.ctgy.v2.service.IBoardService; +import com.xit.core.config.database.BaseMybatisDaoSupport; import com.xit.core.constant.ErrorCode; import com.xit.core.exception.CustomBaseException; import com.xit.core.oauth2.utils.HeaderUtil; @@ -13,9 +15,16 @@ import com.xit.core.support.jpa.JpaUtil; import com.xit.core.util.Checks; import com.xit.core.util.CommUtil; import com.xit.core.util.mpower.MpowerUtil; +import com.xit.core.util.mpower.MpowerUtils; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.session.Configuration; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; import org.mapstruct.factory.Mappers; +import org.mybatis.spring.SqlSessionTemplate; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.domain.Page; @@ -24,6 +33,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.nio.charset.Charset; import java.util.List; import java.util.Map; @@ -35,9 +45,29 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc public class BoardService implements IBoardService { private final PasswordEncoder passwordEncoder; + private final SqlSessionTemplate sqlSessionTemplate; @Transactional(readOnly = true) public List> findAll(final BoardDto dto, Pageable pageable) { + //MappedStatement ms = sqlSessionFactory.getConfiguration().getMappedStatement("com.xit.biz.ctgy.mapper.IParkingMapper.selectTotParkingJudgeResultGroupByTeamAndChasu"); + + + //SqlSession session = sqlSessionTemplate.getConfiguration().get; + //SqlSession session = sqlSessionTemplate.getConfiguration().getMappedStatement("com.xit.biz.ctgy.mapper.IParkingMapper.selectTotParkingJudgeResultGroupByTeamAndChasu"); + + JudgeListDto param = new JudgeListDto(); + param.setMsChasu(99L); + //param.get + + + String sql = CommUtil.getMybatisSql(sqlSessionTemplate, "com.xit.biz.ctgy.mapper.IParkingMapper.selectTotParkingJudgeResultGroupByTeamAndChasu", param); + System.out.println(sql); + System.out.println(Charset.defaultCharset().displayName()); + + + //SqlSession sqlSession = SqlMapClient.getSqlSession(); + + MpowerUtil sendXml = new MpowerUtil(); String query = "SELECT ci_code ciCode,\n" + " name ciName,\n" + diff --git a/src/main/java/com/xit/core/config/EncodingFilterConfig.java b/src/main/java/com/xit/core/config/EncodingFilterConfig.java index 8311be3..d561502 100644 --- a/src/main/java/com/xit/core/config/EncodingFilterConfig.java +++ b/src/main/java/com/xit/core/config/EncodingFilterConfig.java @@ -1,10 +1,14 @@ package com.xit.core.config; +import com.xit.core.config.support.EucKrEncodingFilter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.web.filter.CharacterEncodingFilter; +import java.nio.charset.StandardCharsets; + /** * 기본 UTF-8인데, encoding이 EUC-KR로 들어오는 경우가 있는 경우(외부에서 들어오는 - 결재 등 -) 사용 * spring.http.encoding.force = false 추가 @@ -13,14 +17,28 @@ import org.springframework.web.filter.CharacterEncodingFilter; //TODO :: 기본 UTF-8인데, encoding이 EUC-KR로 들어오는 경우가 있는 경우(외부에서 들어오는 - 결재 등 -) 사용 public class EncodingFilterConfig { + @Bean - public FilterRegistrationBean encodingFilterBean() { - FilterRegistrationBean registrationBean = new FilterRegistrationBean(); + public FilterRegistrationBean encodingFilterBean() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter(); filter.setForceEncoding(true); - filter.setEncoding("MS949"); + filter.setEncoding("utf-8"); registrationBean.setFilter(filter); - registrationBean.addUrlPatterns("/ms949filterUrl/*"); + registrationBean.addUrlPatterns("/api/v2/*"); return registrationBean; } + +/* + @Bean + public FilterRegistrationBean encodingFilterBean() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); + //CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter(); + //filter.setForceEncoding(true); + //filter.setEncoding("EUC-KR"); + registrationBean.setFilter(new EucKrEncodingFilter()); + registrationBean.addUrlPatterns("/api/v2/*"); + return registrationBean; + } + */ } \ No newline at end of file diff --git a/src/main/java/com/xit/core/config/database/BaseMybatisDaoSupport.java b/src/main/java/com/xit/core/config/database/BaseMybatisDaoSupport.java new file mode 100644 index 0000000..d3fee6f --- /dev/null +++ b/src/main/java/com/xit/core/config/database/BaseMybatisDaoSupport.java @@ -0,0 +1,48 @@ +package com.xit.core.config.database; + +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionTemplate; +import org.springframework.dao.support.DaoSupport; +import org.springframework.util.Assert; + + +public abstract class BaseMybatisDaoSupport extends DaoSupport +{ + + private SqlSession sqlSession; + private SqlSessionFactory sqlSessionFactory; + private boolean extenalSqlSession = false; + + public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { + this.sqlSession = sqlSessionTemplate; + this.extenalSqlSession = true; + } + + public final SqlSession getSqlSession() { + return sqlSession; + } + + public final void setSqlSession(SqlSession sqlSession) { + this.sqlSession = sqlSession; + } + + public final SqlSessionFactory getSqlSessionFactory() { + return sqlSessionFactory; + } + + public final void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { + this.sqlSessionFactory = sqlSessionFactory; + if(!this.extenalSqlSession) { + this.sqlSession = new SqlSessionTemplate(sqlSessionFactory); + } + } + + @Override + protected void checkDaoConfig() throws IllegalArgumentException { + Assert.notNull(this.sqlSession, "Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"); + } + + + +} diff --git a/src/main/java/com/xit/core/config/support/EucKrEncodingFilter.java b/src/main/java/com/xit/core/config/support/EucKrEncodingFilter.java new file mode 100644 index 0000000..addea40 --- /dev/null +++ b/src/main/java/com/xit/core/config/support/EucKrEncodingFilter.java @@ -0,0 +1,11 @@ +package com.xit.core.config.support; + +import org.springframework.web.filter.CharacterEncodingFilter; + +public class EucKrEncodingFilter extends CharacterEncodingFilter { + + public EucKrEncodingFilter() { + setEncoding("EUC-KR"); + setForceEncoding(true); + } +} \ No newline at end of file diff --git a/src/main/java/com/xit/core/util/CommUtil.java b/src/main/java/com/xit/core/util/CommUtil.java index 9226261..17101b7 100644 --- a/src/main/java/com/xit/core/util/CommUtil.java +++ b/src/main/java/com/xit/core/util/CommUtil.java @@ -4,6 +4,9 @@ import com.rits.cloning.Cloner; import eu.bitwalker.useragentutils.UserAgent; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.ParameterMapping; +import org.apache.ibatis.session.SqlSession; import org.mozilla.universalchardet.UniversalDetector; import org.springframework.http.ResponseCookie; import org.springframework.mobile.device.Device; @@ -18,9 +21,11 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import java.io.StringReader; import java.io.StringWriter; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLEncoder; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.*; @@ -645,6 +650,57 @@ public class CommUtil { System.out.println(getRanStrKey(16)); } } + + public static String detectCharset(byte[] bytes) { + UniversalDetector detector = new UniversalDetector(null); + detector.handleData(bytes, 0, bytes.length); + detector.dataEnd(); + String detectedCharset = detector.getDetectedCharset(); + if (detectedCharset != null && detector.isDone() && Charset.isSupported(detectedCharset)) { + return detectedCharset; + } + return detectedCharset; + } + + public static String getMybatisSql(SqlSession sqlSession, String id, Object param) { + BoundSql boundSql = sqlSession.getConfiguration().getMappedStatement(id).getBoundSql(param); + + List parameterMappings = new ArrayList<>(boundSql.getParameterMappings()); + Map parameters = new HashMap<>(); + if (param instanceof Map) { + parameters.putAll((Map) param); + } else { + for (ParameterMapping parameterMapping : parameterMappings) { + try { + String field = parameterMapping.getProperty(); + //try { + String methodNm = "get"+field.substring(0,1).toUpperCase()+field.substring(1); + Method method = param.getClass().getMethod(methodNm); + + parameters.put(field, method.invoke(param)); + //parameters.put(field, param.getClass().getMethod("get"+field.substring(0,1).toUpperCase()+field.substring(1)).invoke(param)); + + } catch (NoSuchMethodException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } catch (InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + String sql = boundSql.getSql(); + + for (ParameterMapping par : parameterMappings) { + Object parameter = parameters.get(par.getProperty()); + + if (parameter == null) + sql = sql.replaceFirst("\\?", "NULL"); + else + sql = sql.replaceFirst("\\?", "'" + parameter.toString() + "'"); + } + return sql; + } } 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 d2ea85b..a4fbce9 100644 --- a/src/main/java/com/xit/core/util/mpower/MpowerUtil.java +++ b/src/main/java/com/xit/core/util/mpower/MpowerUtil.java @@ -1,5 +1,8 @@ package com.xit.core.util.mpower; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.sql.CallableStatement; import java.sql.Connection; @@ -11,7 +14,9 @@ import java.sql.Statement; import java.util.*; import com.plf.client.Client; +import com.xit.core.util.CommUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.binary.StringUtils; @Slf4j public class MpowerUtil { @@ -39,7 +44,7 @@ public class MpowerUtil { static int firstIndex = 0; static int lastIndex = 10; static int recordCountPerPage = 10; - static String beforeXml = ""; static String afterXmlsp = "]]>"; @@ -655,14 +660,27 @@ public class MpowerUtil { int mListCount = 0; try { mpower = new Client(hostip,port); + mpower.setCryptEnable(false); mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); 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("#######message = "+mpower.getFile("list1")); + + String s = "답변드립니다"; + //System.out.println(CommUtil.detectCharset(s.getBytes())); + + System.out.println(URLEncoder.encode(s, "euc-kr")); + System.out.println(URLDecoder.decode(s, "euc-kr")); + String ss = new String("답변드립니다".getBytes("euc-kr"), "euc-kr"); + System.out.println(CommUtil.detectCharset(ss.getBytes())); + + System.out.println((new String("답변드립니다".getBytes("utf-8"), "euc-kr"))); + System.out.println((new String("답변드립니다".getBytes("euc-kr"), "euc-kr"))); + // System.out.println(new String(s.getBytes("unicode"), "unicode")); // System.out.println(new String(s.getBytes("utf-8"), "utf-8")); @@ -672,19 +690,35 @@ public class MpowerUtil { // 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")); + //String originalStr = URLDecoder.decode(mpower.getMessage(), "utf-8"); + System.out.println(URLDecoder.decode(mpower.getMessage(), "utf-8")); + System.out.println(URLDecoder.decode(mpower.getMessage(), "euc-kr")); + System.out.println(StringUtils.newStringUtf16Le(mpower.getMessage().getBytes())); + System.out.println(StringUtils.newStringUtf16(mpower.getMessage().getBytes())); + System.out.println(StringUtils.newStringUtf16Be(mpower.getMessage().getBytes())); + System.out.println(StringUtils.newStringIso8859_1(mpower.getMessage().getBytes())); + + String originalStr = mpower.getMessage(); + String [] charSet = {"utf-8","euc-kr","ksc5601","iso-8859-1","x-windows-949", "ms949"}; + + for (int i=0; i>>>>>"+result); int row; if (result.equals("true")){ @@ -695,8 +729,10 @@ public class MpowerUtil { Map m = new HashMap<>(); if(!"".equals(feild) && feild != null){ m.put("cbContent", mpower.getString("list1", i, 4)); + //m.put("cbContent", new String(mpower.getString("list1", i, 4).getBytes("utf-8"), "utf-8")); }else{ for(int j=0;j Date: Wed, 22 Jun 2022 20:19:25 +0900 Subject: [PATCH 4/4] feat: mpower --- .../biz/ctgy/controller/BoardController.java | 1 + .../ctgy/v2/controller/BoardController.java | 1 + .../ctgy/v2/service/impl/BoardService.java | 87 +--- .../xit/core/config/EncodingFilterConfig.java | 2 +- .../com/xit/core/util/mpower/MpowerUtil.java | 164 +----- .../com/xit/core/util/mpower/MpowerUtils.java | 467 +----------------- .../mybatis-mapper/biz/ctgy/board-mapper.xml | 36 ++ 7 files changed, 51 insertions(+), 707 deletions(-) create mode 100644 src/main/resources/mybatis-mapper/biz/ctgy/board-mapper.xml diff --git a/src/main/java/com/xit/biz/ctgy/controller/BoardController.java b/src/main/java/com/xit/biz/ctgy/controller/BoardController.java index 4f89880..bbe5860 100644 --- a/src/main/java/com/xit/biz/ctgy/controller/BoardController.java +++ b/src/main/java/com/xit/biz/ctgy/controller/BoardController.java @@ -39,6 +39,7 @@ public class BoardController { @Parameters({ @Parameter(in = ParameterIn.QUERY, name = "ciTitle", description = "제목", required = false, example = " "), @Parameter(in = ParameterIn.QUERY, name = "ciName", description = "이름", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "ciContents", description = "내용", required = false, example = " "), @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") }) 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 50b38e0..6a198b8 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 @@ -39,6 +39,7 @@ public class BoardController { @Parameters({ @Parameter(in = ParameterIn.QUERY, name = "ciTitle", description = "제목", required = false, example = " "), @Parameter(in = ParameterIn.QUERY, name = "ciName", description = "이름", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "ciContents", description = "내용", required = false, example = " "), @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") }) 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 ee20105..dcb923c 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 @@ -49,95 +49,14 @@ public class BoardService implements IBoardService { @Transactional(readOnly = true) public List> findAll(final BoardDto dto, Pageable pageable) { - //MappedStatement ms = sqlSessionFactory.getConfiguration().getMappedStatement("com.xit.biz.ctgy.mapper.IParkingMapper.selectTotParkingJudgeResultGroupByTeamAndChasu"); + String sql = CommUtil.getMybatisSql(sqlSessionTemplate, "board.selectBoardList", dto); - //SqlSession session = sqlSessionTemplate.getConfiguration().get; - //SqlSession session = sqlSessionTemplate.getConfiguration().getMappedStatement("com.xit.biz.ctgy.mapper.IParkingMapper.selectTotParkingJudgeResultGroupByTeamAndChasu"); - - JudgeListDto param = new JudgeListDto(); - param.setMsChasu(99L); - //param.get - - - String sql = CommUtil.getMybatisSql(sqlSessionTemplate, "com.xit.biz.ctgy.mapper.IParkingMapper.selectTotParkingJudgeResultGroupByTeamAndChasu", param); - System.out.println(sql); - System.out.println(Charset.defaultCharset().displayName()); - - - //SqlSession sqlSession = SqlMapClient.getSqlSession(); - - - MpowerUtil sendXml = new MpowerUtil(); - String query = "SELECT ci_code ciCode,\n" + - " name ciName,\n" + - " ci_contentno ciContentno,\n" + - " ci_title ciTitle,\n" + - " ci_contents ciContents,\n" + - " ci_nalja ciNalja,\n" + - " ci_step ciStep,\n" + - " ci_revel ciRevel,\n" + - " ci_ref ciRef,\n" + - " ci_hit ciHit,\n" + - " ci_pass ciPass,\n" + - " ci_id ciId \n" + - " FROM min_civ_board680 LEFT OUTER JOIN min_userinfo ON (ci_id = userid)\n" + - " WHERE ci_code IN\n" + - " (20,\n" + - " 19,\n" + - " 18,\n" + - " 17,\n" + - " 16,\n" + - " 13,\n" + - " 15,\n" + - " 12,\n" + - " 14,\n" + - " 11,\n" + - " 9,\n" + - " 10,\n" + - " 7,\n" + - " 8,\n" + - " 6,\n" + - " 4,\n" + - " 3,\n" + - " 1,\n" + - " 5,\n" + - " 2)"; + MpowerUtils sendXml = new MpowerUtils(); sendXml.setFeilds("ciCode, ciName, ciContentno, ciTitle, ciContents, ciNalja, ciStep, ciRevel, ciRef, ciHit, ciPass, ciId"); - sendXml.setQuery(query); - - - -// 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); -// } - - + sendXml.setQuery(sql); return sendXml.selectCustomQuery(); - //log.debug("{}", map); - //return map.get("resultList"); } // @Transactional(readOnly = true) diff --git a/src/main/java/com/xit/core/config/EncodingFilterConfig.java b/src/main/java/com/xit/core/config/EncodingFilterConfig.java index d561502..657f50a 100644 --- a/src/main/java/com/xit/core/config/EncodingFilterConfig.java +++ b/src/main/java/com/xit/core/config/EncodingFilterConfig.java @@ -23,7 +23,7 @@ public class EncodingFilterConfig { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter(); filter.setForceEncoding(true); - filter.setEncoding("utf-8"); + filter.setEncoding("euc-kr"); registrationBean.setFilter(filter); registrationBean.addUrlPatterns("/api/v2/*"); return registrationBean; 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 a4fbce9..8da5ea5 100644 --- a/src/main/java/com/xit/core/util/mpower/MpowerUtil.java +++ b/src/main/java/com/xit/core/util/mpower/MpowerUtil.java @@ -666,59 +666,8 @@ public class MpowerUtil { mpower.Request(); String result = mpower.getString("result", 0, 0); - - - System.out.println("#######message = "+mpower.getFile("list1")); - - String s = "답변드립니다"; - //System.out.println(CommUtil.detectCharset(s.getBytes())); - - System.out.println(URLEncoder.encode(s, "euc-kr")); - System.out.println(URLDecoder.decode(s, "euc-kr")); - String ss = new String("답변드립니다".getBytes("euc-kr"), "euc-kr"); - System.out.println(CommUtil.detectCharset(ss.getBytes())); - - System.out.println((new String("답변드립니다".getBytes("utf-8"), "euc-kr"))); - System.out.println((new String("답변드립니다".getBytes("euc-kr"), "euc-kr"))); - - -// 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")); - - //String originalStr = URLDecoder.decode(mpower.getMessage(), "utf-8"); - System.out.println(URLDecoder.decode(mpower.getMessage(), "utf-8")); - System.out.println(URLDecoder.decode(mpower.getMessage(), "euc-kr")); - System.out.println(StringUtils.newStringUtf16Le(mpower.getMessage().getBytes())); - System.out.println(StringUtils.newStringUtf16(mpower.getMessage().getBytes())); - System.out.println(StringUtils.newStringUtf16Be(mpower.getMessage().getBytes())); - System.out.println(StringUtils.newStringIso8859_1(mpower.getMessage().getBytes())); - - String originalStr = mpower.getMessage(); - String [] charSet = {"utf-8","euc-kr","ksc5601","iso-8859-1","x-windows-949", "ms949"}; - - for (int i=0; i m = new HashMap<>(); if(!"".equals(feild) && feild != null){ m.put("cbContent", mpower.getString("list1", i, 4)); - //m.put("cbContent", new String(mpower.getString("list1", i, 4).getBytes("utf-8"), "utf-8")); }else{ for(int j=0;j feilds = new ArrayList(); static String feild = ""; static String tmpFeilds = ""; @@ -43,79 +39,32 @@ public class MpowerUtils { static String WhereStr = ""; static String Orderby = ""; static int pageIndex = 0; - static int firstIndex = 0; static int lastIndex = 10; static int recordCountPerPage = 10; - static String beforeXml = ""; - static String afterXmlsp = "]]>"; - static Boolean pagingYn = false; + //Ps변수 static String Params = ""; - static String finalParams = ""; - static String threeXml = ""; - static String threeXmlEnd = ""; - static String forXmlEnd = ""; + static int psParamCount = 0; static String psFinalFarams =""; static String QueryXml = ""; - //static String vioPhoto = PropertiesUtil.getValue("Globals.vioPhoto"); //주정차사진경로 static String vioPhoto = ""; - //static String vioPhotoBus = PropertiesUtil.getValue("Globals.vioPhotoBus"); //버스사진경로 static String vioPhotoBus = ""; - //static String tunullingFile = PropertiesUtil.getValue("Globals.tunullingFile"); //터널링서버에 복사되는 첨부파일 위치 static String tunullingFile = ""; public void setQuery(String query){ MpowerUtils.query = query; } - public void setRowNum(boolean truefalse){ - RowNum = truefalse; - } - - public void setPageIndex(int pi){ - pageIndex = pi; - } - - public void setRecordCountPerPage(int rcpp){ - recordCountPerPage = rcpp; - } - - public int getRecordCountPerPage(){ - return recordCountPerPage; - } - - public String getWholeQuery() { - return wholeQuery; - } - - public void setWholeQuery(String wholeQuery) { - this.wholeQuery = wholeQuery; - } - public void setFeild(String feildNm){ feilds.add(feildNm); } - public void setFeild2(String feildNm){ - feild = feildNm; - } - - public void setTableNm(String tNm){ - tableNm = tNm; - } - public void setWhereStr(String whr){ - WhereStr += whr; - } - public void setOrderby(String ob){ - Orderby += ob; - } - public int getFirstIndex() { return (pageIndex - 1) * recordCountPerPage +1; } @@ -124,72 +73,6 @@ public class MpowerUtils { return lastIndex = pageIndex * recordCountPerPage; } - public void setPagingYn(Boolean yn){ - pagingYn = yn; - } - - public void AddParam(String inputType,String Val){ - psParamCount ++; - Params += ""; - } - - //kkj추가 - public void AddParam2(String inputType,long Val){ - psParamCount ++; - Params += ""; - } - - public void setParamsBody(){ - Params = "" + Params + ""; - - afterXmlsp = "]]>"; - forXmlEnd = ""; - } - - public void setSPQuerysBody(){ - QueryXml = beforeXmlsp + tableNm + "(" +psFinalFarams + ")" + afterXmlsp + Params + forXmlEnd; - } - - public void AddFinalParam(int count){ - for(int i=0;i PsQuery() throws Exception{ - //EgovMap resultEgov = new EgovMap(); - Map resultEgov = new HashMap<>(); - try{ - AddFinalParam(psParamCount); - setParamsBody(); - setSPQuerysBody(); - resultEgov = connreturnMpwoer(QueryXml); - }catch(Exception e) - { - e.printStackTrace(); - }finally{ - clearValidation(); - } - return resultEgov; - } - - public Map connreturnMpwoer(String psQuery) throws Exception{ - mpower = new Client(hostip,port); - mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); - mpower.setInput("SQLXML", psQuery); - mpower.Request(); - //EgovMap eMap = new EgovMap(); - Map eMap = new HashMap<>(); - eMap.put("result",mpower.getString("result", 0, 0)); - - int cnt = 1; - for( int i = 0 ; i < mpower.getMaxCol("list1"); i++){ - eMap.put("list"+cnt,mpower.getString("list1", 0, i)); - cnt ++; - } - return eMap; - } - public List> selectQuery() { String fileList = ""; for(int cnt = 0;cnt selectListQuery2() { - //EgovMap mListMap = new EgovMap(); - Map mListMap = new HashMap<>(); - //배열로 넘어온 필드를 String 오브젝트로 변형 - String fileList = ""; - for(int cnt = 0;cnt(); - this.setFeilds("RN, "+tmpFeilds); - } - - //List mList = new ArrayList(); - List> mList = new ArrayList<>(); - int mListCount = 0; - try { - mpower = new Client(hostip,port); - mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); - mpower.setInput("SQLXML", query); - mpower.Request(); - String result = mpower.getString("result", 0, 0); - int row = 0; - if (result.equals("true")){ - row = mpower.getMaxRow("list1"); - if(row>0){ - for(int i=0;i m = new HashMap<>(); - for(int j=0;j0){ - mpower = new Client(hostip,port); - mpower.getConnection("MPowerXmlToQuery.xmlQuery1"); - mpower.setInput("SQLXML", Cquery); - mpower.Request(); - - String strList1 = mpower.getString("list1", 0, 0); - - if( !strList1.equals("") && strList1 != null){ - mListCount = Integer.parseInt(strList1); - } - mpower.disconnect(); - } - - } catch (Exception e) { - e.printStackTrace(); - } finally{ - clearValidation(); - } - mListMap.put("mListCount", mListCount); - return mListMap; - } - - public Map selectListQuery_pay() { - //EgovMap mListMap = new EgovMap(); - Map mListMap = new HashMap<>(); - //배열로 넘어온 필드를 String 오브젝트로 변형 - String fileList = ""; - for(int cnt = 0;cnt(); - this.setFeilds("RN, "+tmpFeilds); - } - - //List mList = new ArrayList(); - List> mList = new ArrayList>(); - int mListCount = 0; - try { - mpower2 = new Client(hostip,port); - mpower2.getConnection("MPowerXmlToQuery.xmlQuery1"); - mpower2.setInput("SQLXML", query); - mpower2.Request(); - String result = mpower2.getString("result", 0, 0); - int row = 0; - if (result.equals("true")){ - row = mpower2.getMaxRow("list1"); - if(row>0){ - for(int i=0;i m = new HashMap<>(); - for(int j=0;j0){ - mpower2.getConnection("MPowerXmlToQuery.xmlQuery1"); - mpower2.setInput("SQLXML", Cquery); - mpower2.Request(); - mListCount = Integer.parseInt(mpower2.getString("list1", 0, 0)); - //System.out.println("mListCount:"+mListCount); - } - //logger.debug("END getString list1"); - mpower2.disconnect(); - //logger.debug(Cquery); - //logger.debug("==============================================================================================================="); - - } catch (Exception e) { - e.printStackTrace(); - } finally{ - clearValidation(); - } - mListMap.put("mListCount", mListCount); - return mListMap; - } - - /** - * @ 페이징 처리 SELECT 호출 - * @return - */ - public List> selectCustomQuery(String sql) { + public List> selectCustomQuery() { //EgovMap mListMap = new EgovMap(); Map mListMap = new HashMap<>(); //배열로 넘어온 필드를 String 오브젝트로 변형 @@ -652,7 +357,7 @@ public class MpowerUtils { fileList += "," + feilds.get(cnt); } } - query = beforeXml+sql+afterXml; + query = beforeXml+query+afterXml; //logger.debug("=====================================================Select Query=================================================="); //logger.debug(query); @@ -668,60 +373,10 @@ public class MpowerUtils { mpower.Request(); String result = mpower.getString("result", 0, 0); + System.out.println("#######message = "+mpower.getMessage()); + System.out.println("#######message charset = "+CommUtil.detectCharset(mpower.getMessage().getBytes())); - System.out.println("#######message = "+mpower.getFile("list1")); - - String s = "답변드립니다"; - //System.out.println(CommUtil.detectCharset(s.getBytes())); - - System.out.println(URLEncoder.encode(s, "euc-kr")); - System.out.println(URLDecoder.decode(s, "euc-kr")); - String ss = new String("답변드립니다".getBytes("euc-kr"), "euc-kr"); - System.out.println(CommUtil.detectCharset(ss.getBytes())); - - System.out.println((new String("답변드립니다".getBytes("utf-8"), "euc-kr"))); - System.out.println((new String("답변드립니다".getBytes("euc-kr"), "euc-kr"))); - - -// 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")); - - //String originalStr = URLDecoder.decode(mpower.getMessage(), "utf-8"); - System.out.println(URLDecoder.decode(mpower.getMessage(), "utf-8")); - System.out.println(URLDecoder.decode(mpower.getMessage(), "euc-kr")); - System.out.println(StringUtils.newStringUtf16Le(mpower.getMessage().getBytes())); - System.out.println(StringUtils.newStringUtf16(mpower.getMessage().getBytes())); - System.out.println(StringUtils.newStringUtf16Be(mpower.getMessage().getBytes())); - System.out.println(StringUtils.newStringIso8859_1(mpower.getMessage().getBytes())); - - String originalStr = mpower.getMessage(); - String [] charSet = {"utf-8","euc-kr","ksc5601","iso-8859-1","x-windows-949", "ms949"}; - - for (int i=0; i m = new HashMap<>(); if(!"".equals(feild) && feild != null){ m.put("cbContent", mpower.getString("list1", i, 4)); - //m.put("cbContent", new String(mpower.getString("list1", i, 4).getBytes("utf-8"), "utf-8")); }else{ for(int j=0;j + + + + + + + \ No newline at end of file