From 916a3cbabe4e50062fce61ff6f2f5d46c05dfbd1 Mon Sep 17 00:00:00 2001 From: 이민희 <mhlee@maprex.co.kr> Date: 목, 17 3월 2022 17:47:45 +0900 Subject: [PATCH] - api로 이슈 추가 시 url/ip로 업체 찾는 코드 수정 --- src/main/java/kr/wisestone/owl/util/CommonUtil.java | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 168 insertions(+), 11 deletions(-) diff --git a/src/main/java/kr/wisestone/owl/util/CommonUtil.java b/src/main/java/kr/wisestone/owl/util/CommonUtil.java index 0fac1dd..6ee3905 100644 --- a/src/main/java/kr/wisestone/owl/util/CommonUtil.java +++ b/src/main/java/kr/wisestone/owl/util/CommonUtil.java @@ -3,14 +3,16 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Lists; -import com.google.gson.Gson; +import kr.wisestone.owl.constant.Regular; import kr.wisestone.owl.domain.enumType.FileType; import kr.wisestone.owl.type.LikeType; +import kr.wisestone.owl.vo.DepartmentVo; import kr.wisestone.owl.vo.UserVo; import org.apache.commons.codec.binary.*; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.ss.usermodel.Cell; import org.jsoup.Jsoup; import org.slf4j.Logger; @@ -39,7 +41,11 @@ import java.security.MessageDigest; import java.security.spec.KeySpec; import java.text.DecimalFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class CommonUtil { private static final Logger LOGGER = LoggerFactory.getLogger(CommonUtil.class); @@ -50,7 +56,9 @@ private static final String PASS_PHRASE = "1024"; // AES128 �븫�샇�솕�뿉 �궗�슜 private static final int ITERATION_COUNT = 10000; // AES128 �븫�샇�솕�뿉 �궗�슜 private static final int KEY_SIZE = 128; // AES128 �븫�샇�솕�뿉 �궗�슜 - private static final String TMP_UPLOAD_FOLDER = "/tmpUploadFolder/"; // �씠�뒋 �깮�꽦, �닔�젙�뿉�꽌 �뙆�씪 �뾽濡쒕뱶�븷 �븣 �엫�떆 �뤃�뜑濡� �궗�슜 + private static final String TMP_UPLOAD_FOLDER = "/tmpUploadFolder/"; // �씠�뒋 �깮�꽦, �닔�젙�뿉�꽌 �뙆�씪 �뾽濡쒕뱶�븷 �븣 �엫�떆 �뤃�뜑濡� �궗�슜' + public static final String COMMA = ","; // 援щ텇�옄 + public static String getClinetIp() { try { @@ -343,6 +351,24 @@ return fileMap; } + // string file �젙蹂대�� file Map �삎�깭濡� 蹂�寃쏀븳�떎. + public static Map<String, Object> makeFileMap(String fileName, String file, String contentType) { + Map<String, Object> fileMap = new HashMap<>(); + + try { + byte[] bytes = Base64.decodeBase64(file); + + fileMap.put("fileName", fileName); + fileMap.put("fileSize", bytes.length); + fileMap.put("contentType", contentType); + fileMap.put("file", CommonUtil.bytesToFile(fileName, bytes)); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + + return fileMap; + } + public static String getPostDataString(Map<String, String> params) throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); boolean first = true; @@ -372,6 +398,42 @@ multipart.transferTo(convertFile); } catch (IllegalStateException | IOException e) { LOGGER.debug("multipart �뙆�씪 file 蹂��솚 �삤瑜�"); + } + + return convertFile; + } + + // string�쓣 �뙆�씪濡� 蹂��솚 + public static File stringToFile(String fileName, String file) { + + byte[] bytes = null; + try { + bytes = Base64.decodeBase64(file); + + } catch (Exception ex) { + LOGGER.debug("string to bytes 蹂��솚 �삤瑜�"); + } + + if (bytes != null) { + return bytesToFile(fileName, bytes); + } + return null; + } + + // bytes瑜� �뙆�씪濡� 蹂��솚 + public static File bytesToFile(String fileName, byte[] bytes) { + File convertFile = new File(WebAppUtil.getContextRealPath() + TMP_UPLOAD_FOLDER + getFileNameByUUID(fileName)); + if (!convertFile.exists()) { + convertFile.mkdirs(); + } + + try{ + FileOutputStream lFileOutputStream = new FileOutputStream(convertFile); + lFileOutputStream.write(bytes); + lFileOutputStream.close(); + + }catch (IllegalStateException | IOException e) { + LOGGER.debug("bytes �뙆�씪 file 蹂��솚 �삤瑜�"); } return convertFile; @@ -690,6 +752,36 @@ return stringBuilder.toString(); } + // DepartmentVos �뿉�꽌 遺��꽌 �젙蹂대�� 異붿텧�빐�꽌 臾몄옄�뿴濡� 由ы꽩�빐以��떎. - 二쇰줈 �뿊�� download �뿉�꽌 �궗�슜�맂�떎. + public static String convertDepartmentVosToString(List<DepartmentVo> departmentVos) { + StringBuilder stringBuilder = new StringBuilder(); + int count = 0; + + for (DepartmentVo departmentVo : departmentVos) { + if (count > 0) { + stringBuilder.append("\n"); + } + + stringBuilder.append(departmentVo.getDepartmentName()); + count++; + } + return stringBuilder.toString(); + } + + public static List<Date> findSearchPeriod(Date startDate, Date endDate) { + Calendar cal = Calendar.getInstance(); + cal.setTime(endDate); + List<Date> days = Lists.newArrayList(); + + // �씠踰덈떖 �궇吏� 由ъ뒪�듃 媛��졇�삤湲� + while (cal.getTime().after(startDate)){ + days.add(cal.getTime()); + cal.add(Calendar.DATE, -1); + } + + return days; + } + // 寃��깋 �씪�옄瑜� 援ы븳�떎. public static List<Date> findSearchPeriod(String searchPeriod) { List<Date> searchDates = Lists.newArrayList(); @@ -871,17 +963,24 @@ switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC : - double doubleValue = cell.getNumericCellValue(); - int intValue; + + // �궇吏� �삎�떇�씤 寃쎌슦 �궇吏쒕줈 蹂��솚 + if (HSSFDateUtil.isCellDateFormatted(cell)) { + Date date = cell.getDateCellValue(); + cellValue = DateUtil.convertDateToStr(date, "yyyy-MM-dd HH:mm:ss"); - if (doubleValue%1 == 0) { - intValue = (int)doubleValue; - cellValue = intValue + ""; - } - else { - cellValue = doubleValue + ""; - } + } else { + double doubleValue = cell.getNumericCellValue(); + int intValue; + if (doubleValue % 1 == 0) { + intValue = (int)doubleValue; + cellValue = intValue + ""; + } + else { + cellValue = doubleValue + ""; + } + } break; case Cell.CELL_TYPE_STRING : @@ -919,4 +1018,62 @@ } } + // 硫붿씤 url留� 異붿텧 + public static String extractUrl(String content){ + try { + String REGEX = "(http(s)?:\\/\\/)([a-z0-9\\w]+\\.*)+[a-z0-9]{2,4}"; + Pattern p = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE); + Matcher m = p.matcher(content); + if (m.find()) { + return m.group(); + } + return ""; + } catch (Exception e) { + return ""; + } + } + + // 硫붿씤 url 異붿텧�쓣 �쐞�빐 http: �솗�씤 + public static String getUrl(String fullUrl) { + if (fullUrl != null) { + if (fullUrl.indexOf("http") == -1) { + fullUrl = "http://" + fullUrl; + } + + return extractUrl(fullUrl); + } + return ""; + } + + + /** + * �젙洹쒖떇 寃��궗(URL) + * @param url ���긽 臾몄옄�뿴(URL) + * @return 寃��궗 寃곌낵 + */ + public static boolean verifyUrl(String url) { + return verifyRegular(url, Regular.URL); + } + + /** + * �젙洹쒖떇 寃��궗(IP) + * @param ip ���긽 臾몄옄�뿴(IP) + * @return 寃��궗 寃곌낵 + */ + public static boolean verifyIp(String ip) { + return verifyRegular(ip, Regular.IP); + } + + /** + * �젙洹쒖떇 寃��궗 + * @param value ���긽 臾몄옄�뿴 + * @param regular �젙洹쒖떇 寃��궗瑜� �븷 �젙洹쒖떇 援щЦ + * @return 寃��궗 寃곌낵 + */ + public static boolean verifyRegular(String value, String regular) { + if (!StringUtils.isEmpty(value)) { + return Pattern.matches(regular, value); + } + return false; + } } -- Gitblit v1.8.0