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/service/impl/CompanyFieldServiceImpl.java | 197 ++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 160 insertions(+), 37 deletions(-) diff --git a/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java index 9b50065..b5365d7 100644 --- a/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java +++ b/src/main/java/kr/wisestone/owl/service/impl/CompanyFieldServiceImpl.java @@ -84,30 +84,41 @@ // �뾽泥대챸 以묐났 泥댄겕 this.verifyTitle(companyFieldForm.getName(), null); - if (companyFieldForm.getIpStart() != null && companyFieldForm.getIpEnd() != null) { - // �븘�씠�뵾 �쑀�슚�꽦 泥댄겕 - this.verifyIp(companyFieldForm.getIpStart(), companyFieldForm.getIpEnd()); - } - if (companyFieldForm.getUrl() != null) { // url �쑀�슚�꽦 泥댄겕 this.verifyUrl(companyFieldForm.getUrl(), null); } + if (companyFieldForm.getIpStarts() != null && companyFieldForm.getIpStarts().size() > 0 + && companyFieldForm.getIpEnds() != null && companyFieldForm.getIpEnds().size() > 0) { + + for (int i=0; i<companyFieldForm.getIpStarts().size(); i++) { + // �븘�씠�뵾 �쑀�슚�꽦 泥댄겕 + this.verifyIp(companyFieldForm.getIpStarts().get(i), companyFieldForm.getIpEnds().get(i), null); + } + + String startIps = companyFieldForm.getIpStarts().toString(); + // ��愿꾪샇 �젣嫄� + startIps = this.removeSquare(startIps); + companyFieldForm.setIpStart(startIps.trim()); + + String endIps = companyFieldForm.getIpEnds().toString(); + // ��愿꾪샇 �젣嫄� + endIps = this.removeSquare(endIps); + companyFieldForm.setIpEnd(endIps.trim()); + } + if (companyFieldForm.getTelList() != null && companyFieldForm.getTelList().size() > 0) { String tels = companyFieldForm.getTelList().toString(); - if (tels.contains("[")) { - tels = tels.substring(1, tels.indexOf("]")); - } + // ��愿꾪샇 �젣嫄� + tels = this.removeSquare(tels); companyFieldForm.setTel(tels.trim()); } if (companyFieldForm.getEmailList() != null && companyFieldForm.getEmailList().size() > 0) { String emails = companyFieldForm.getEmailList().toString(); - String email = ""; - if (emails.contains("[")) { - email = emails.substring(1, emails.indexOf("]")); - } - companyFieldForm.setEmail(email.trim()); + // ��愿꾪샇 �젣嫄� + emails = this.removeSquare(emails); + companyFieldForm.setEmail(emails.trim()); } CompanyField companyField = ConvertUtil.copyProperties(companyFieldForm, CompanyField.class); @@ -116,23 +127,118 @@ } /** + * ��愿꾪샇([]) �젣嫄� �븿�닔 + * @param str String + * @return str + */ + private String removeSquare(String str) { + if (str.contains("[")) { + str = str.substring(1, str.indexOf("]")); + } + + return str; + } + + /** * IP �쑀�슚�꽦 泥댄겕 * @param ip String + * @param ip2 String + * @param id Long */ - private void verifyIp(String ip, String ip2) { - if (ip2 == null) { - if (!StringUtils.isEmpty(ip)) { - if (!Pattern.matches("^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\" + - ".(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", ip)) { - throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.IP_NOT_INVALID)); + private void verifyIp(String ip, String ip2, Long id) { + if (!StringUtils.isEmpty(ip)) { + if (!Pattern.matches("^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\" + + ".(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", ip)) { + throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.IP_NOT_INVALID)); + } + } + if (!StringUtils.isEmpty(ip2)) { + if (!Pattern.matches("^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\" + + ".(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", ip2)) { + throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.IP_NOT_INVALID)); + } + } + + if (!StringUtils.isEmpty(ip) && !StringUtils.isEmpty(ip2)) { + long ipStart = ConvertUtil.ipToLong(ip); + long ipEnd = ConvertUtil.ipToLong(ip2); + if (ipEnd < ipStart) { + throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.IP_START_NOT_LARGER_THAN_END)); + } + + List<CompanyField> companyFields = Lists.newArrayList(); + CompanyFieldCondition condition = new CompanyFieldCondition(); + if (id != null) { + condition.setId(id); + companyFields = this.companyFieldRepository.findByIdNot(condition.getId()); + } else { + companyFields = this.companyFieldRepository.findAll(); + } + + // IP���뿭�� 以묐났 泥댄겕 + this.ipOverlapChk(companyFields, ipStart, ipEnd); + + /*if (companyFields != null && companyFields.size() > 0) { + throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.COMPANY_EXIST_IP)); + }*/ + } + } + + /** + * ip ���뿭�� 以묐났 泥댄겕 + * @param companyFields List<CompanyField> + */ + private void ipOverlapChk(List<CompanyField> companyFields, long ipStart, long ipEnd) { + String[] ipStartArr = null; + String[] ipEndArr = null; + List<String> startIpList = Lists.newArrayList(); + List<String> endIpList = Lists.newArrayList(); + String startIp = ""; + String endIp = ""; + List<Long> startIps = Lists.newArrayList(); + List<Long> endIps = Lists.newArrayList(); + + if (companyFields.size() > 0) { + for (CompanyField companyField : companyFields) { + if(companyField.getIpStart() != null && companyField.getIpEnd() != null) { + startIp = companyField.getIpStart(); + if (startIp.contains(" ")) { + startIp = startIp.replace(" ",""); + } + if (startIp.contains(",")) { + ipStartArr = startIp.split(","); + startIpList.addAll(Arrays.asList(ipStartArr)); + } else { + startIpList.add(startIp.trim()); + } + + endIp = companyField.getIpEnd(); + if (endIp.contains(" ")) { + endIp = endIp.replace(" ",""); + } + if (endIp.contains(",")) { + ipEndArr = endIp.split(","); + endIpList.addAll(Arrays.asList(ipEndArr)); + } else { + endIpList.add(endIp.trim()); + } } } - } else { - if (!StringUtils.isEmpty(ip)) { - long ipStart = ConvertUtil.ipToLong(ip); - long ipEnd = ConvertUtil.ipToLong(ip2); - if (ipEnd < ipStart) { - throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.IP_START_NOT_LARGER_THAN_END)); + if (startIpList.size() > 0) { + for (String ipS : startIpList) { + long start = ConvertUtil.ipToLong(ipS); + startIps.add(start); + } + for (String ipE : endIpList) { + long end = ConvertUtil.ipToLong(ipE); + endIps.add(end); + } + } + + for (int i=0; i<startIps.size(); i++) { + if (startIps.get(i) >= ipStart && startIps.get(i) <= ipEnd || endIps.get(i) >= ipStart && endIps.get(i) <= ipEnd + || ipStart >= startIps.get(i) && ipStart <= endIps.get(i) || ipEnd >= startIps.get(i) && ipEnd <= endIps.get(i)) { + throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.COMPANY_EXIST_IP)); } } } @@ -161,7 +267,7 @@ } if (urls.size() > 0) { - condition.setUrl(urls); + condition.setUrls(urls); if(id == null){ companyFieldList = this.companyFieldMapper.findByUrls(condition); @@ -282,18 +388,35 @@ this.verifyUrl(companyFieldForm.getUrl(), companyFieldForm.getId()); } + if (companyFieldForm.getIpStarts() != null && companyFieldForm.getIpStarts().size() > 0 + && companyFieldForm.getIpEnds() != null && companyFieldForm.getIpEnds().size() > 0) { + + for (int i=0; i<companyFieldForm.getIpStarts().size(); i++) { + // �븘�씠�뵾 �쑀�슚�꽦 泥댄겕 + this.verifyIp(companyFieldForm.getIpStarts().get(i), companyFieldForm.getIpEnds().get(i), companyFieldForm.getId()); + } + + String startIps = companyFieldForm.getIpStarts().toString(); + // ��愿꾪샇 �젣嫄� + startIps = this.removeSquare(startIps); + companyFieldForm.setIpStart(startIps.trim()); + + String endIps = companyFieldForm.getIpEnds().toString(); + // ��愿꾪샇 �젣嫄� + endIps = this.removeSquare(endIps); + companyFieldForm.setIpEnd(endIps.trim()); + } + if (companyFieldForm.getTelList() != null && companyFieldForm.getTelList().size() > 0) { String tels = companyFieldForm.getTelList().toString(); - if (tels.contains("[")) { - tels = tels.substring(1, tels.indexOf("]")); - } + // ��愿꾪샇 �젣嫄� + tels = this.removeSquare(tels); companyFieldForm.setTel(tels.trim()); } if (companyFieldForm.getEmailList() != null && companyFieldForm.getEmailList().size() > 0) { String emails = companyFieldForm.getEmailList().toString(); - if (emails.contains("[")) { - emails = emails.substring(1, emails.indexOf("]")); - } + // ��愿꾪샇 �젣嫄� + emails = this.removeSquare(emails); companyFieldForm.setEmail(emails.trim()); } @@ -472,7 +595,7 @@ // �뾽泥대줈 �벑濡앺븯湲� �쐞�빐 CompanyFieldForm �뿉 �뜲�씠�꽣瑜� �뀑�똿�븳�떎. CompanyFieldForm newCompanyFieldForm = this.setCompanyFieldFormToExcelField(row, (rowIndex + 1), ispFieldMaps, hostingFieldMaps, companyTypeMaps, parentSectorMaps, childSectorMaps, regionMaps, statusMaps, headers); // ip �쑀�슚�꽦 泥댄겕 - this.verifyIp(newCompanyFieldForm.getIpStart(), newCompanyFieldForm.getIpEnd()); + this.verifyIp(newCompanyFieldForm.getIpStart(), newCompanyFieldForm.getIpEnd(), null); companyFieldForms.add(newCompanyFieldForm); } @@ -651,7 +774,7 @@ if (ipEnd.contains(" ")) { ipEnd = ipEnd.replace(" ", ""); } - this.verifyIp(ipEnd, null); //ip �쑀�슚�꽦 寃��궗 + this.verifyIp(ipEnd, null, null); //ip �쑀�슚�꽦 寃��궗 companyFieldForm.setIpEnd(ipEnd); } @@ -662,7 +785,7 @@ if (ipStart.contains(" ")) { ipStart = ipStart.replace(" ", ""); } - this.verifyIp(ipStart, null); //ip �쑀�슚�꽦 寃��궗 + this.verifyIp(ipStart, null, null); //ip �쑀�슚�꽦 寃��궗 companyFieldForm.setIpStart(ipStart); } @@ -759,9 +882,9 @@ * @return String */ private String verifyEmail(String email) { - if (!Pattern.matches("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", email)) { + /*if (!Pattern.matches("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", email)) { throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.EMAIL_NOT_INVALID)); - } + }*/ if (email.contains(" ")) { email = email.replace(" ", ""); -- Gitblit v1.8.0