package itn.let.fax.user.web; import java.awt.image.BufferedImage; import java.io.File; import java.time.LocalDateTime; import javax.annotation.Resource; import javax.imageio.ImageIO; import org.apache.commons.lang3.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.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartHttpServletRequest; import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper; import itn.com.cmm.JsonResult; import itn.com.cmm.LoginVO; import itn.com.cmm.util.FaxUtil; import itn.com.utl.fcc.service.EgovStringUtil; import itn.let.fax.user.service.FaxConvertMngVO; import itn.let.fax.user.service.FaxConvertVO; import itn.let.fax.user.service.FaxService; import itn.let.fax.user.service.FaxTranVO; import itn.let.mail.service.StatusResponse; /** * * @author : 이호영 * @fileName : FaxRestController.java * @date : 2023.03.20 * @description : 팩스 Rest Controller * =========================================================== * DATE AUTHOR NOTE * ----------------------------------------------------------- * * 2023.03.20 이호영 최초 생성 * * * */ @RestController public class FaxRestController { @Resource(name = "faxService") private FaxService faxService; private static final Logger logger = LoggerFactory.getLogger(FaxRestController.class); /** * @methodName : selectMsgDataView * @author : 이호영 * @date : 2023.02.07 * @description : * @param cateCode * @param request * @param model * @param redirectAttributes * @return * @throws Exception */ @RequestMapping(value= {"/web/mjon/fax/faxFileConvertAjax.do"}) public ResponseEntity selectMsgDataView(final MultipartHttpServletRequest multiRequest, FaxConvertMngVO faxMngVO) throws Exception{ //로그인 권한정보 불러오기 LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null; String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId()); // 로그인 안되어있음 return if(StringUtils.isEmpty(userId)) return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "로그인 후 이용해 주세요", LocalDateTime.now())); faxMngVO.setUserId(userId); try { return ResponseEntity.ok().body(faxService.faxFileConvert(multiRequest, faxMngVO)); } catch (Exception e) { e.printStackTrace(); // TODO: handle exception return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "파일 변환중 에러가 발생하였습니다.", LocalDateTime.now())); } } /** * @methodName : findByConvertTbStatus * @author : 이호영 * @date : 2023.03.13 * @description : * @param faxConvertVO * @return * @throws Exception */ @RequestMapping(value= {"/web/mjon/fax/findByConvertTbStatus.do"}) public ResponseEntity findByConvertTbStatus(FaxConvertVO faxConvertVO) throws Exception{ //로그인 권한정보 불러오기 LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null; String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId()); // 로그인 안되어있음 return if(StringUtils.isEmpty(userId)) return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "로그인 후 이용해 주세요", LocalDateTime.now())); System.out.println("faxConvertVO.getFaxConvertSeq() : "+ faxConvertVO.getFaxConvertSeq()); try { return ResponseEntity.ok().body(faxService.findByConvertTbStatus(faxConvertVO.getFaxConvertSeq())); } catch (Exception e) { e.printStackTrace(); // TODO: handle exception return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "파일 변환 체크 중 에러가 발생하였습니다.", LocalDateTime.now())); } } /** * @methodName : sendData * @author : 이호영 * @date : 2023.03.21 * @description : 팩스 발송 * @param faxConvertVO * @return * @throws Exception */ @RequestMapping(value= {"/web/mjon/fax/sendData.do"}) public ResponseEntity sendData(FaxTranVO faxTranVO) throws Exception{ //로그인 권한정보 불러오기 LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null; String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId()); // 로그인 안되어있음 return if(StringUtils.isEmpty(userId)) return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "로그인 후 이용해 주세요", LocalDateTime.now())); try { return ResponseEntity.ok().body(faxService.sendData(faxTranVO, userId)); // return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "임시 성공.", LocalDateTime.now())); } catch (Exception e) { e.printStackTrace(); // TODO: handle exception return ResponseEntity.ok().body(new StatusResponse(HttpStatus.BAD_REQUEST, "발송 요청 중 오류가 발생하였습니다.", LocalDateTime.now())); } } /** * @methodName : sendExelFilePhoneNumAjax * @author : 이준호 * @date : 2023.03.20 * @description : * @param multiRequest * @return * @throws Exception */ @RequestMapping(value = "/web/mjon/fax/sendExelFileFaxNumAjax.do") public Object sendExelFileFaxNumAjax(final MultipartHttpServletRequest multiRequest) throws Exception { JsonResult jr = FaxUtil.exelFileConvertForFax(multiRequest); return jr; } /** * @methodName : test * @author : 이호영 * @date : 2023.04.06 * @description : pdf -> image 변환 추후 진행 예정 * @throws Exception */ @RequestMapping(value = "/web/mjon/fax/test.do") public void test() throws Exception { File file = new File("D:\\usr\\local\\tomcat\\file\\sht\\fax\\Convert\\00000000602.pdf"); PDDocument document = PDDocument.load(file); try { int pageCount = document.getNumberOfPages(); PDFRenderer pdfRenderer = new PDFRenderer(document); System.out.println("pageCount : "+ pageCount); for (int i = 0; i < pageCount; i++) { BufferedImage imageObj = pdfRenderer.renderImageWithDPI(i, 100, ImageType.RGB); File outputfile = new File("D:\\usr\\local\\tomcat\\file\\sht\\fax\\Convert\\images\\00000000602_"+i+".jpg"); ImageIO.write(imageObj, "jpg", outputfile); } } catch (Exception e) { e.printStackTrace(); // TODO: handle exception }finally { if (document != null) { document.close(); } } } }