이호영 이호영 2023-08-08
feat: API 치환 데이터가 lms / sms 와 같이 문자 발송이 다를때 그룹아이디도 따로 받을 수 있게 개선
@1ac01fa8bf9ecce1a7c5bd8f3f6ee1318f36a193
src/main/java/itn/let/fax/user/web/FaxRestController.java
--- src/main/java/itn/let/fax/user/web/FaxRestController.java
+++ src/main/java/itn/let/fax/user/web/FaxRestController.java
@@ -198,7 +198,7 @@
 		
 	}
 	
-	
+
 	
 	
 }
 
src/main/java/itn/let/mjo/test/service/TestVO.java (added)
+++ src/main/java/itn/let/mjo/test/service/TestVO.java
@@ -0,0 +1,18 @@
+package itn.let.mjo.test.service;
+
+public class TestVO {
+
+	private String fileNm;
+
+	public String getFileNm() {
+		return fileNm;
+	}
+
+	public void setFileNm(String fileNm) {
+		this.fileNm = fileNm;
+	}
+	
+	
+	
+	
+}
src/main/java/itn/let/mjo/test/web/TestController.java
--- src/main/java/itn/let/mjo/test/web/TestController.java
+++ src/main/java/itn/let/mjo/test/web/TestController.java
@@ -1,7 +1,16 @@
 package itn.let.mjo.test.web;
 
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
@@ -13,25 +22,42 @@
 import java.util.Map;
 
 import javax.annotation.Resource;
+import javax.imageio.ImageIO;
+import javax.mail.internet.ContentDisposition;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.rendering.ImageType;
+import org.apache.pdfbox.rendering.PDFRenderer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.env.SystemEnvironmentPropertySource;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.client.RestTemplate;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
+import org.springframework.web.util.UriUtils;
 
 import egovframework.rte.fdl.idgnr.EgovIdGnrService;
 import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
@@ -82,6 +108,7 @@
 import itn.let.utl.user.service.CheckFileUtil;
 import itn.let.utl.user.service.CheckLoginUtil;
 import itn.let.utl.user.service.CheckNoServiceCommon;
+
 
 @Controller
 public class TestController {
@@ -1909,6 +1936,8 @@
         		//일괄변환에 의한 단문, 장문 별개로 전송을 했기 때문에 각각 전송 결과 건수를 합쳐준 후 결과를  modelAndView로 리턴해준다.
         		String returnMessage = "";
         		String returnStatus = "";
+        		String msgGroupIdListComma = "";
+        		String msgTypeListComma = "";
         		
         		//그림 결과 내용
         		if(!returnImgMap.isEmpty()) {
@@ -1925,6 +1954,7 @@
             			
             			returnMessage = returnImgMap.get("message");
             			returnStatus = returnImgMap.get("result");
+            			msgGroupIdListComma = returnImgMap.get("msgGroupId");
             			
         			}else {
             			returnMessage = returnImgMap.get("message");
@@ -1955,6 +1985,12 @@
             			
             			returnMessage = returnLongMap.get("message");
             			returnStatus = returnLongMap.get("result");
+            			msgGroupIdListComma = StringUtils.isNotEmpty(msgGroupIdListComma) 
+            											? msgGroupIdListComma+","+returnLongMap.get("msgGroupId") 
+            											: returnLongMap.get("msgGroupId");
+            			msgTypeListComma = StringUtils.isNotEmpty(msgTypeListComma) 
+            											? msgTypeListComma+","+"6" 
+            											: "6";
             			
         			}else {
             			returnMessage = returnLongMap.get("message");
@@ -1985,6 +2021,12 @@
             			
             			returnMessage = returnShortMap.get("message");
             			returnStatus = returnShortMap.get("result");
+            			msgGroupIdListComma = StringUtils.isNotEmpty(msgGroupIdListComma) 
+            												? msgGroupIdListComma+","+returnShortMap.get("msgGroupId") 
+            												: returnShortMap.get("msgGroupId");
+            			msgTypeListComma = StringUtils.isNotEmpty(msgTypeListComma) 
+															? msgTypeListComma+","+"4" 
+															: "4";
             			
             		}else {
             			returnMessage = returnShortMap.get("message");
@@ -2000,8 +2042,8 @@
         			
         		}
 
-        		modelAndView.addObject("msgType", mjonMsgVO.getMsgType());
-        		modelAndView.addObject("msgGroupId", mjonMsgVO.getMsgGroupId());
+        		modelAndView.addObject("msgType", msgTypeListComma);
+        		modelAndView.addObject("msgGroupId", msgGroupIdListComma);
         		modelAndView.addObject("message", returnMessage);
 				modelAndView.addObject("result", returnStatus);
 				modelAndView.addObject("resultSts", resultSts);
@@ -2545,7 +2587,7 @@
 	    		}
 	    		
 	    		System.out.println("=========================================================================");
-	    		System.out.println("+++++++++++++++++++++++++++++++++++++++++++ resultSts ::: " + resultSts); 
+	    		System.out.println(" 25xx +++++++++++++++++++++++++++++++++++++++++++ resultSts ::: " + resultSts); 
 	    		System.out.println("=========================================================================");
 	    		
 	    		try {
@@ -2645,6 +2687,8 @@
 		
 		returnMap.put("message", "문자 전송이 완료되었습니다.");
 		returnMap.put("result", "success");
+		returnMap.put("msgGroupId", mjonMsgVO.getMsgGroupId());
+		returnMap.put("resultSts", Integer.toString(resultSts));
 		returnMap.put("resultSts", Integer.toString(resultSts));
 		returnMap.put("resultBlockSts", Integer.toString(resultBlockSts));
 		return returnMap;
@@ -3038,9 +3082,198 @@
 
 	
 	
+
+	@RequestMapping(value= {"/web/user/login/fileTest.do"})
+	public void downloadAndSaveFile() throws Exception {
+		
+		String downloadUrl = "http://192.168.0.11:5000/converHWPtoPDF";
+		String filePath = "D:\\Development\\test_dev";
+		String fileNm = "저작권분쟁조정규칙(20220516)";
+//		String fileNm = "testFileName(20220516)";
+		String fileExt = ".pdf";
+		String cnvtfileExt = ".jpg";
+		
+		
+		
+	    byte[] fileData = fileSendAnddownloadFile(downloadUrl, filePath + File.separator + fileNm + ".hwp");
+//	    byte[] fileData = downloadFile(downloadUrl, fileNm);
+	    this.saveFile(fileData, filePath, fileNm+fileExt);
+	    this.pdfToJpg(filePath, fileNm, fileExt, cnvtfileExt);
+	}
+	
+	/** 
+	 * @methodName	: fileSendAnddownloadFile 
+	 * @author		: 이호영
+	 * @date		: 2023.08.04 
+	 * @description	: 파일을 보내서 PFD로 변환한 파일을 받는다
+	 * @param downloadUrl
+	 * @param filePathNm
+	 * @return
+	 * @throws IOException 
+	 */
+	public byte[] fileSendAnddownloadFile(String downloadUrl, String filePathNm) throws IOException {
+	    RestTemplate restTemplate = new RestTemplate();
+
+	    HttpHeaders headers = new HttpHeaders();
+	    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+
+	    // Create a ByteArrayResource to wrap the file content without relying on the file system
+	    FileSystemResource fileResource = new FileSystemResource(filePathNm);
+
+	    // To ensure correct encoding for non-ASCII characters
+	    String encodedFilename = UriUtils.encode(fileResource.getFilename(), "UTF-8");
+
+	    // Create a new HttpEntity for file and use encoded filename
+	    MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
+	    body.add("file", new ByteArrayResource(Files.readAllBytes(fileResource.getFile().toPath())) {
+	        @Override
+	        public String getFilename() {
+	            return encodedFilename;
+	        }
+	    });
+
+
+	    
+	    HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(body, headers);
+
+	    ResponseEntity<byte[]> responseEntity = restTemplate.exchange(downloadUrl, HttpMethod.POST, entity, byte[].class);
+		
+		if (responseEntity.getStatusCodeValue() == 200) {
+			return responseEntity.getBody();
+		} else {
+			throw new RuntimeException("Failed to download file from " + downloadUrl);
+		}
+	}
+	
+	/** 
+	 * @methodName	: downloadFile 
+	 * @author		: 이호영
+	 * @date		: 2023.08.04 
+	 * @description	: 서버에 파일을 요청해서 받는 형식
+	 * @param downloadUrl
+	 * @param fileNm
+	 * @return  
+	public byte[] downloadFile(String downloadUrl, String fileNm) {
+		RestTemplate restTemplate = new RestTemplate();
+		
+		
+		HttpHeaders headers = new HttpHeaders();
+		headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+		
+		MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
+		body.add("fileNm", fileNm);
+		HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(body, headers);
+		
+		
+		ResponseEntity<byte[]> responseEntity = restTemplate.exchange(downloadUrl, HttpMethod.POST, entity, byte[].class);
+		
+//		System.out.println("responseEntity :: "+ responseEntity);
+		if (responseEntity.getStatusCodeValue() == 200) {
+			return responseEntity.getBody();
+		} else {
+			throw new RuntimeException("Failed to download file from " + downloadUrl);
+		}
+	}
+	 */
 	
 	
+	/** 
+	 * @methodName	: saveFile 
+	 * @author		: 이호영
+	 * @date		: 2023.08.04 
+	 * @description	: 파일 저장 
+	 * @param fileData
+	 * @param filePath
+	 * @param fileNm 
+	 */
+	public void saveFile(byte[] fileData, String filePath, String fileNm) {
+	    Path path = Paths.get(filePath, fileNm);
+	    
+	    try {
+	        Files.write(path, fileData);
+	    } catch (IOException e) {
+	        throw new RuntimeException("Failed to save file to " + filePath, e);
+	    }
+	}
 	
 	
+	/** 
+	 * @methodName	: pdfToJpg 
+	 * @author		: 이호영
+	 * @date		: 2023.08.04 
+	 * @description	: 저장한 파일을 불러와서 파일명의 폴더를 생성하여 jpg로 저장
+	 * @param filePath
+	 * @param fileNm
+	 * @param oriFileExt
+	 * @param cnvtfileExt
+	 * @throws Exception 
+	 */
+	public void pdfToJpg(String filePath, String fileNm, String oriFileExt, String cnvtfileExt) throws Exception {
+
+		File file = new File(filePath + File.separator + fileNm + oriFileExt);
+		PDDocument document = PDDocument.load(file);
+		try {
+			
+			int pageCount = document.getNumberOfPages();
+			PDFRenderer pdfRenderer = new PDFRenderer(document);
+			
+			System.out.println("pageCount : "+ pageCount);
+			
+			String saveFilePath = this.filePathChk(filePath + File.separator +fileNm); 
+			
+			if(StringUtils.isNotEmpty(saveFilePath))
+			{
+				
+				for (int i = 0; i < pageCount; i++) {
+					
+					BufferedImage imageObj = pdfRenderer.renderImageWithDPI(i, 100, ImageType.RGB);
+					File outputfile = new File(saveFilePath + File.separator + fileNm + i + cnvtfileExt);
+					ImageIO.write(imageObj, "jpg", outputfile);
+				}
+			}
+			
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+			// TODO: handle exception
+		}finally {
+			if (document != null) {
+			    document.close();
+			}
+		}
+		
+	}
+
+	/** 
+	 * @methodName	: filePathChk 
+	 * @author		: 이호영
+	 * @date		: 2023.08.04 
+	 * @description	: jpg 파일 저장할 디렉토리 생성
+	 * @param filePath
+	 * @return 
+	 */
+	private String filePathChk(String filePath) {
+		// TODO Auto-generated method stub
+        String directoryPath = filePath;
+
+        Path path = Paths.get(directoryPath);
+        
+        if (!Files.exists(path)) {
+            try {
+                
+                Files.createDirectories(path);
+                System.out.println("Directory created");
+        		return directoryPath;
+            } catch (IOException e) {
+                throw new RuntimeException("Failed to create directory!", e);
+            }
+        } else {
+            System.out.println("Directory already exists");
+        }
+		
+		return null;
+		
+	}
+	
 	
 }
src/main/webapp/WEB-INF/jsp/uss/ion/apikey/UserAPIKEYModify.jsp
--- src/main/webapp/WEB-INF/jsp/uss/ion/apikey/UserAPIKEYModify.jsp
+++ src/main/webapp/WEB-INF/jsp/uss/ion/apikey/UserAPIKEYModify.jsp
@@ -649,8 +649,10 @@
 				</c:if>
 				
 				<c:if test="${apiKeyVO.useYn eq 'Y'}">
-					<input type="button" class="btnType2 bg_888888" value="API KEY 미사용 처리" id="btn_fn_delete"
+					<input type="button" class="btnType2 bg_888888" value="API 미사용 처리" id="btn_fn_delete"
 					onclick="fn_delete('N'); return false;">
+					<input type="button" class="btnType2 bg_888888" value="API KEY 중지  처리" id="btn_fn_delete"
+					onclick="fn_delete('W'); return false;">
 					<input type="button" class="btnType2 bg_888888" value="API 승인요청상태로"  id="btn_fn_delete"
 					onclick="fn_delete('A'); return false;">									
 				</c:if>
@@ -667,6 +669,10 @@
 					onclick="fn_delete('Y'); return false;">				
 				</c:if>
 				
+				<c:if test="${apiKeyVO.useYn eq 'W'}">
+					<input type="button" class="btnType2 bg_888888" value="API KEY 사용 처리"  id="btn_fn_delete"
+					onclick="fn_delete('Y'); return false;">									
+				</c:if>	
 					<input type="button" class="btnType2 bg_888888" value="API KEY 사용자 삭제(실제)"  id="btn_fn_delete"
 					onclick="fn_delete_real(); return false;">
 
src/main/webapp/WEB-INF/jsp/web/api/appMgmt.jsp
--- src/main/webapp/WEB-INF/jsp/web/api/appMgmt.jsp
+++ src/main/webapp/WEB-INF/jsp/web/api/appMgmt.jsp
@@ -322,7 +322,7 @@
 												<button type="button" class="btnType btnType14" onclick="fn_delete('${apiVO.accessNo}','A'); return false;">재신청</button>
 											</td>             
 										</c:when>
-										<c:when test="${apiVO.useYn eq 'Y' or (apiVO.useYn eq 'N' and apiVO.accessKey ne '')}"><!-- API 사용 중 -->
+										<c:when test="${apiVO.useYn eq 'Y' or (apiVO.useYn eq 'N' and apiVO.accessKey ne '') or apiVO.useYn eq 'W' }"><!-- API 사용 중 -->
 											<td>${apiVO.frstRegistPnttm}</td>
 											<td>${apiVO.lastUpdtPnttm}</td>
 											<td>승인</td>
@@ -366,7 +366,7 @@
 								<tbody>
 									<tr>
 										<c:choose>
-											<c:when test="${apiVO.useYn eq 'Y'}">
+											<c:when test="${apiVO.useYn eq 'Y' }">
 												<td>
 													${apiVO.lastUpdtPnttm}
 												</td>
@@ -377,11 +377,11 @@
 													사용
 												</td>
 												<td>
-													<button type="button" class="btnType btnType23" onclick="fn_delete('${apiVO.accessNo}','N'); return false;">정지</button>
+													<button type="button" class="btnType btnType23" onclick="fn_delete('${apiVO.accessNo}','W'); return false;">정지</button>
 													<button type="button" class="btnType btnType14" onclick="fn_update_apikey('14'); return false;">재발급</button>
 												</td>
 											</c:when>
-											<%-- <c:when test="${apiVO.useYn eq 'N'}">
+											<c:when test="${apiVO.useYn eq 'W' }">
 												<td>
 													${apiVO.lastUpdtPnttm}
 												</td>
@@ -392,10 +392,9 @@
 													미사용
 												</td>
 												<td>
-													<button type="button" class="btnType btnType23" onclick="fn_delete('${apiVO.accessNo}','Y'); return false;">사용처리</button>
-													<button type="button" class="btnType btnType14" onclick="fn_update_apikey('${apiVO.accessNo}'); return false;">재발급</button>
+													<button type="button" class="btnType btnType14" onclick="fn_delete('${apiVO.accessNo}','Y'); return false;">사용</button>
 												</td>
-											</c:when> --%>
+											</c:when>
 											<c:otherwise>
 												<td colspan="4">API KEY 발급 내역이 없습니다.</td>
 											</c:otherwise>
@@ -427,7 +426,7 @@
 								</thead>
 								<tbody>
 										<c:choose>
-											<c:when test="${apiVO.useYn eq 'Y' or apiVO.useYn eq 'N'}">
+											<c:when test="${apiVO.useYn eq 'Y' or apiVO.useYn eq 'N' or apiVO.useYn eq 'W'}">
 												<c:forEach var="result" items="${apiCallInfoVOList}" varStatus="status">
 													<tr>
 														<td>${result.frstRegistPnttm}</td>
@@ -461,8 +460,9 @@
 <!-- 		                        <p class="admin_info">* IP는 10개 까지만 등록 가능합니다.</p> -->
 	                        </c:otherwise>
                         </c:choose>
-                        <p class="admin_info">* 대역 등록을 원하실 경우 상위 IP만 작성하시면 됩니다. ex&#65289; 92.168.255.0 ~ 192.168.255.255 대역을 등록할 경우 192.168. 255. 입력</p>
-                        <p class="admin_info">* IP는 최대 10개까지 등록 가능합니다. 단, IP 대역은 1개의 IP로 계산합니다.<c:out value="${apiCallInfoVOListSize }" /></p>              
+<!--                         <p class="admin_info">* 대역 등록을 원하실 경우 상위 IP만 작성하시면 됩니다. ex&#65289; 192.168.255.0 ~ 192.168.255.255 대역을 등록할 경우 192.168. 255. 입력</p> -->
+<!--                         <p class="admin_info">* 대역 등록을 원하실 경우 상위 IP만 작성하시면 됩니다. ex&#65289; 192.168.255.0 입력</p> -->
+                        <p class="admin_info">* IP는 최대 10개까지 등록 가능합니다. 단, IP 대역은 1개의 IP로 계산합니다.</p>              
                         <!--//사용 승인 될 경우에만 노출-->
 					</div>
 					<!--// API 사용 IP 관리 : IP등록 전-->
src/main/webapp/sample_mjon/jsp_example_send_msg_r1.jsp
--- src/main/webapp/sample_mjon/jsp_example_send_msg_r1.jsp
+++ src/main/webapp/sample_mjon/jsp_example_send_msg_r1.jsp
@@ -25,7 +25,7 @@
 		//회원아이디, APIKEY - 보안을 위해 실제 서비스 시에는 이곳에 mberId와 apiKey 값을 적어서 사용
 		//실제서비스용
 		final String mberId		=	"dudgusw";	//문자온 로그인 아이디 
-		final String apiKey		=	"769089bdd0363e0d0b1d20761a8d013bd";		//발급받은 api ke
+		final String apiKey		=	"0096519c62100b9eea77c040a6045c";		//발급받은 api ke
 		
 		
 		//테스트용
src/main/webapp/sample_mjon/jsp_example_send_msgs_r1.jsp
--- src/main/webapp/sample_mjon/jsp_example_send_msgs_r1.jsp
+++ src/main/webapp/sample_mjon/jsp_example_send_msgs_r1.jsp
@@ -25,7 +25,7 @@
 		//회원아이디, APIKEY - 보안을 위해 실제 서비스 시에는 이곳에 mberId와 apiKey 값을 적어서 사용
 		//실제서비스용
 		final String mberId		=	"dudgusw";	//문자온 로그인 아이디 
-		final String apiKey		=	"769089bdd0363e0d0b1d20761a8d013bd";		//발급받은 api key
+		final String apiKey		=	"0096519c62100b9eea77c040a6045c";		//발급받은 api ke
 		
 		
 		//테스트용
Add a comment
List