| | |
| | | import kr.wisestone.owl.util.MapUtil; |
| | | import kr.wisestone.owl.web.condition.CompanyFieldCondition; |
| | | import kr.wisestone.owl.web.form.CompanyFieldForm; |
| | | import kr.wisestone.owl.web.form.IssueForm; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.*; |
| | | import java.util.regex.Pattern; |
| | | |
| | | @Service |
| | | public class CompanyFieldServiceImpl extends AbstractServiceImpl<CompanyField, Long, JpaRepository<CompanyField, Long>> implements CompanyFieldService { |
| | |
| | | public CompanyField addCompany(CompanyFieldForm companyFieldForm) { |
| | | // 업체명 중복 체크 |
| | | this.verifyTitle(companyFieldForm.getName(), null); |
| | | // url 유효성 체크 |
| | | this.verifyUrl(companyFieldForm.getUrl(), null); |
| | | |
| | | if (companyFieldForm.getUrl() != null) { |
| | | // url 유효성 체크 |
| | | this.verifyUrl(companyFieldForm.getUrl(), null); |
| | | } |
| | | |
| | | if (companyFieldForm.getTelList() != null && companyFieldForm.getTelList().size() > 0) { |
| | | String tels = companyFieldForm.getTelList().toString(); |
| | |
| | | |
| | | // url 유효성 체크 |
| | | private void verifyUrl(String url, Long id) { |
| | | if (StringUtils.isEmpty(url)) { |
| | | /*if (StringUtils.isEmpty(url)) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.COMPANY_NOT_URL)); |
| | | } |
| | | CompanyField companyField; |
| | | }*/ |
| | | if (!StringUtils.isEmpty(url)) { |
| | | CompanyField companyField; |
| | | if(id == null){ |
| | | companyField = this.companyFieldRepository.findByUrl(url); |
| | | } else { |
| | | companyField = this.companyFieldRepository.findByUrlAndIdNot(url,id); |
| | | } |
| | | |
| | | if(id == null){ |
| | | companyField = this.companyFieldRepository.findByUrl(url); |
| | | } else { |
| | | companyField = this.companyFieldRepository.findByUrlAndIdNot(url,id); |
| | | } |
| | | |
| | | if (companyField != null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.COMPANY_USED_URL)); |
| | | if (companyField != null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.COMPANY_USED_URL)); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | companyFieldVo.setRegionName(region.getUseValue()); |
| | | } |
| | | } |
| | | if (companyField.getStatusName() != null && !companyField.getStatusName().equals("")) { |
| | | companyFieldVo.setStatusName(companyField.getStatusName()); |
| | | } |
| | | return companyFieldVo; |
| | | } |
| | | |
| | |
| | | public void modifyCompany(CompanyFieldForm companyFieldForm) { |
| | | // 업체명 유효성 체크 |
| | | this.verifyTitle(companyFieldForm.getName(), companyFieldForm.getId()); |
| | | // url 유효성 체크 |
| | | this.verifyUrl(companyFieldForm.getUrl(), companyFieldForm.getId()); |
| | | |
| | | if (companyFieldForm.getUrl() != null) { |
| | | // url 유효성 체크 |
| | | this.verifyUrl(companyFieldForm.getUrl(), companyFieldForm.getId()); |
| | | } |
| | | |
| | | if (companyFieldForm.getTelList() != null && companyFieldForm.getTelList().size() > 0) { |
| | | String tels = companyFieldForm.getTelList().toString(); |
| | |
| | | |
| | | if (companyFieldForm.getChildSectorId() != null) { |
| | | CompanyFieldCategory companyFieldCategory = this.companyFieldCategoryService.find(companyFieldForm.getChildSectorId()); |
| | | if (!companyFieldCategory.getParentId().equals(companyFieldForm.getParentSectorId())) { |
| | | if (companyFieldCategory != null && !companyFieldCategory.getParentId().equals(companyFieldForm.getParentSectorId())) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.PARENT_SECTOR_NOT_EQUAL)); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // 엑셀 import 로 이슈를 등록한다. |
| | | // 엑셀 import 로 업체를 등록한다. |
| | | @Override |
| | | @Transactional |
| | | public void importExcel(MultipartFile multipartFile) throws Exception { |
| | |
| | | } |
| | | |
| | | /** |
| | | * cell String으로 변환 함수 |
| | | * @param cell Cell |
| | | * @param isNull boolean |
| | | * @return String |
| | | */ |
| | | private String stringToCell (Cell cell, boolean isNull) { |
| | | String cellStr = ""; |
| | | if (!isNull) { |
| | | cellStr = CommonUtil.convertExcelStringToCell(cell); |
| | | // 공백 제거 |
| | | cell.setCellValue(cellStr.trim()); |
| | | } else { |
| | | cell.setCellValue(cellStr); |
| | | } |
| | | return cellStr; |
| | | } |
| | | |
| | | /** |
| | | * cell NULL 체크 함수 |
| | | * @param cell Cell |
| | | * @return boolean |
| | | */ |
| | | private Boolean cellNullCheck (Cell cell) { |
| | | return cell != null && cell.getStringCellValue() != null && cell.getCellType() != Cell.CELL_TYPE_BLANK; |
| | | int cellType = cell.getCellType(); |
| | | if (cellType < Cell.CELL_TYPE_BLANK) { |
| | | if (cellType == Cell.CELL_TYPE_STRING) { |
| | | if (cell.getStringCellValue() != null && !cell.getStringCellValue().equals("")) { |
| | | return false; |
| | | } |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 전화번호 CellType 체크 함수 |
| | | * @param cell Cell |
| | | * @param rowIndex int |
| | | */ |
| | | private void telTypeCheck (Cell cell, int rowIndex) { |
| | | if (cell != null && cell.getCellType() != cell.CELL_TYPE_STRING) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_TEL_NOT_STRING_TYPE, rowIndex)); |
| | | } |
| | | } |
| | | |
| | | // 엑셀 필드에 있는 정보를 업체 form 으로 옮긴다. |
| | |
| | | |
| | | for (int cellIndex = 0; cellIndex < headers.size(); cellIndex++) { |
| | | Cell cell = row.getCell(cellIndex); |
| | | |
| | | String cellStr = ""; |
| | | boolean isNull = true; |
| | | |
| | | if (cell != null) { |
| | | isNull = cellNullCheck(cell); |
| | | cellStr = stringToCell(cell, isNull); //cell을 String으로 변환 |
| | | } |
| | | |
| | | switch (cellIndex) { |
| | | case 0: |
| | | // 업체명 |
| | | this.setCompanyFormName(cell, companyFieldForm, rowIndex); |
| | | if (isNull) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_COMPANY_NAME_IS_NULL, rowIndex)); |
| | | } |
| | | this.setCompanyFormName(cellStr, companyFieldForm); |
| | | break; |
| | | |
| | | case 1: |
| | | // url |
| | | this.setCompanyFormUrl(cell, companyFieldForm, rowIndex); |
| | | this.setCompanyFormUrl(cellStr, companyFieldForm, isNull); |
| | | break; |
| | | |
| | | case 2: |
| | | // isp명 |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormIspName(cell, ispFieldMaps, companyFieldForm, rowIndex); |
| | | } |
| | | this.setCompanyFormIspName(cellStr, ispFieldMaps, companyFieldForm, rowIndex, isNull); |
| | | break; |
| | | |
| | | case 3: |
| | | // 호스팅명 |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormHostingName(cell, hostingFieldMaps, companyFieldForm, rowIndex); |
| | | } |
| | | this.setCompanyFormHostingName(cellStr, hostingFieldMaps, companyFieldForm, rowIndex, isNull); |
| | | break; |
| | | |
| | | case 4: |
| | | // 연락처 |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormTel(cell, companyFieldForm, rowIndex); |
| | | } |
| | | telTypeCheck(cell, rowIndex); |
| | | this.setCompanyFormTel(cellStr, companyFieldForm, isNull); |
| | | break; |
| | | |
| | | case 5: |
| | | // 이메일 |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormEmail(cell, companyFieldForm, rowIndex); |
| | | } |
| | | this.setCompanyFormEmail(cellStr, companyFieldForm, isNull); |
| | | break; |
| | | |
| | | case 6: |
| | | // 담당자 |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormManager(cell, companyFieldForm, rowIndex); |
| | | } |
| | | this.setCompanyFormManager(cellStr, companyFieldForm, isNull); |
| | | break; |
| | | |
| | | case 7: |
| | | // 기업구분 |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormCompanyType(cell, companyTypeMaps, companyFieldForm, rowIndex); |
| | | } |
| | | this.setCompanyFormCompanyType(cellStr, companyTypeMaps, companyFieldForm, rowIndex, isNull); |
| | | break; |
| | | |
| | | case 8: |
| | | // 업종(대분류) |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormParentSector(cell, parentSectorMaps, companyFieldForm, rowIndex); |
| | | } |
| | | this.setCompanyFormParentSector(cellStr, parentSectorMaps, companyFieldForm, rowIndex, isNull); |
| | | break; |
| | | |
| | | case 9: |
| | | // 업종(중분류) |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormChildSector(cell, childSectorMaps, companyFieldForm, rowIndex); |
| | | } |
| | | this.setCompanyFormChildSector(cellStr, childSectorMaps, companyFieldForm, rowIndex, isNull); |
| | | break; |
| | | |
| | | case 10: |
| | | // 지역 |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormRegion(cell, regionMaps, companyFieldForm, rowIndex); |
| | | } |
| | | this.setCompanyFormRegion(cellStr, regionMaps, companyFieldForm, rowIndex, isNull); |
| | | break; |
| | | |
| | | case 11: |
| | | // 상태 |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormStatus(cell, statusMaps, companyFieldForm, rowIndex); |
| | | } |
| | | this.setCompanyFormStatus(cellStr, statusMaps, companyFieldForm, isNull); |
| | | break; |
| | | |
| | | case 12: |
| | | // 비고 |
| | | if (cellNullCheck(cell)) { |
| | | this.setCompanyFormMemo(cell, companyFieldForm, rowIndex); |
| | | } |
| | | break; |
| | | this.setCompanyFormMemo(cellStr, companyFieldForm, isNull); |
| | | } |
| | | } |
| | | |
| | | return companyFieldForm; |
| | | } |
| | | |
| | | private void setCompanyFormMemo(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | companyFieldForm.setMemo(CommonUtil.convertExcelStringToCell(cell)); |
| | | private void setCompanyFormMemo(String cellStr, CompanyFieldForm companyFieldForm, boolean isNull) { |
| | | if (!isNull) { |
| | | companyFieldForm.setMemo(cellStr); |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormStatus(Cell cell, Map<String, Map<String, Object>> statusMaps, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | Map<String, Object> statusMap = statusMaps.get(CommonUtil.convertExcelStringToCell(cell)); |
| | | private void setCompanyFormStatus(String cellStr, Map<String, Map<String, Object>> statusMaps, CompanyFieldForm companyFieldForm, boolean isNull) { |
| | | if (!isNull) { |
| | | Map<String, Object> statusMap = statusMaps.get(cellStr); |
| | | if (MapUtil.getLong(statusMap, "id") != null) { |
| | | companyFieldForm.setStatusId(MapUtil.getLong(statusMap, "id")); |
| | | } else { |
| | | companyFieldForm.setStatusId(120L); |
| | | } |
| | | companyFieldForm.setStatusName(CommonUtil.convertExcelStringToCell(cell)); |
| | | companyFieldForm.setStatusName(cellStr); |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormRegion(Cell cell, Map<String, Map<String, Object>> regionMaps, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | Map<String, Object> regionMap = regionMaps.get(CommonUtil.convertExcelStringToCell(cell)); |
| | | private void setCompanyFormRegion(String cellStr, Map<String, Map<String, Object>> regionMaps, CompanyFieldForm companyFieldForm, int rowIndex, boolean isNull) { |
| | | if (!isNull) { |
| | | Map<String, Object> regionMap = regionMaps.get(cellStr); |
| | | if (regionMap == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_REGION_NOT_EXIST, rowIndex)); |
| | |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormChildSector(Cell cell, Map<String, Map<String, Object>> childSectorMaps, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | Map<String, Object> childSectorMap = childSectorMaps.get(CommonUtil.convertExcelStringToCell(cell)); |
| | | private void setCompanyFormChildSector(String cellStr, Map<String, Map<String, Object>> childSectorMaps, CompanyFieldForm companyFieldForm, int rowIndex, boolean isNull) { |
| | | if (!isNull) { |
| | | Map<String, Object> childSectorMap = childSectorMaps.get(cellStr); |
| | | |
| | | // 대분류 없이 중분류만 입력했을경우 |
| | | if (companyFieldForm.getParentSectorId() == null) { |
| | |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormParentSector(Cell cell, Map<String, Map<String, Object>> parentSectorMaps, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | Map<String, Object> parentSectorMap = parentSectorMaps.get(CommonUtil.convertExcelStringToCell(cell)); |
| | | private void setCompanyFormParentSector(String cellStr, Map<String, Map<String, Object>> parentSectorMaps, CompanyFieldForm companyFieldForm, int rowIndex, boolean isNull) { |
| | | if (!isNull) { |
| | | Map<String, Object> parentSectorMap = parentSectorMaps.get(cellStr); |
| | | if (parentSectorMap == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_PARENT_SECTOR_NOT_EXIST, rowIndex)); |
| | |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormCompanyType(Cell cell, Map<String, Map<String, Object>> companyTypeMaps, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | Map<String, Object> companyTypeMap = companyTypeMaps.get(CommonUtil.convertExcelStringToCell(cell)); |
| | | private void setCompanyFormCompanyType(String cellStr, Map<String, Map<String, Object>> companyTypeMaps, CompanyFieldForm companyFieldForm, int rowIndex, boolean isNull) { |
| | | if (!isNull) { |
| | | Map<String, Object> companyTypeMap = companyTypeMaps.get(cellStr); |
| | | if (companyTypeMap == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_COMPANY_TYPE_NOT_EXIST, rowIndex)); |
| | |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormManager(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | companyFieldForm.setManager(CommonUtil.convertExcelStringToCell(cell)); |
| | | private void setCompanyFormManager(String manager, CompanyFieldForm companyFieldForm, boolean isNull) { |
| | | if (!isNull) { |
| | | companyFieldForm.setManager(manager); |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormEmail(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | String email = CommonUtil.convertExcelStringToCell(cell); |
| | | if (CommonUtil.convertExcelStringToCell(cell).contains(" ")) { |
| | | email = CommonUtil.convertExcelStringToCell(cell).replace(" ", ""); |
| | | } |
| | | private void setCompanyFormEmail(String email, CompanyFieldForm companyFieldForm, boolean isNull) { |
| | | if (!isNull) { |
| | | // 이메일 유효성 검사 |
| | | email = this.verifyEmail(email); |
| | | companyFieldForm.setEmail(email); |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormTel(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | String tel = CommonUtil.convertExcelStringToCell(cell); |
| | | if (tel.contains("-")) { |
| | | tel = tel.replace("-", ""); |
| | | } |
| | | if (tel.contains(" ")) { |
| | | tel = tel.replace(" ", ""); |
| | | } |
| | | /** |
| | | * 이메일 유효성 검사 |
| | | * @param email String |
| | | * @return String |
| | | */ |
| | | private String verifyEmail(String 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(" ", ""); |
| | | } |
| | | |
| | | return email; |
| | | } |
| | | |
| | | private void setCompanyFormTel(String tel, CompanyFieldForm companyFieldForm, boolean isNull) { |
| | | if (!isNull) { |
| | | // 연락처 유효성 검사 |
| | | tel = this.verifyTel(tel); |
| | | companyFieldForm.setTel(tel); |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormHostingName(Cell cell, Map<String, HostingField> hostingFieldMaps, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | HostingField hostingField = hostingFieldMaps.get(CommonUtil.convertExcelStringToCell(cell)); |
| | | /** |
| | | * 연락처 유효성 검사 |
| | | * @param tel String |
| | | * @return String |
| | | */ |
| | | private String verifyTel(String tel) { |
| | | if (!Pattern.matches("^[0-9-]{2,20}$", tel)) { |
| | | throw new OwlRuntimeException(this.messageAccessor.getMessage(MsgConstants.TEL_NOT_INVALID)); |
| | | } |
| | | |
| | | if (tel.contains("-")) { |
| | | tel = tel.replace("-", ""); |
| | | } |
| | | if (tel.contains(" ")) { |
| | | tel = tel.replace(" ", ""); |
| | | } |
| | | |
| | | return tel; |
| | | } |
| | | |
| | | private void setCompanyFormHostingName(String cellStr, Map<String, HostingField> hostingFieldMaps, CompanyFieldForm companyFieldForm, int rowIndex, boolean isNull) { |
| | | if (!isNull) { |
| | | HostingField hostingField = hostingFieldMaps.get(cellStr); |
| | | if (hostingField == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_HOSTING_NOT_EXIST, rowIndex)); |
| | |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormIspName(Cell cell, Map<String, IspField> ispFieldMaps, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell != null) { |
| | | IspField ispField = ispFieldMaps.get(CommonUtil.convertExcelStringToCell(cell)); |
| | | private void setCompanyFormIspName(String cellStr, Map<String, IspField> ispFieldMaps, CompanyFieldForm companyFieldForm, int rowIndex, boolean isNull) { |
| | | if (!isNull) { |
| | | IspField ispField = ispFieldMaps.get(cellStr); |
| | | if (ispField == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_ISP_NOT_EXIST, rowIndex)); |
| | |
| | | } |
| | | } |
| | | |
| | | private void setCompanyFormName(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_COMPANY_NAME_IS_NULL, rowIndex)); |
| | | } |
| | | |
| | | String title = CommonUtil.convertExcelStringToCell(cell); |
| | | |
| | | private void setCompanyFormName(String title, CompanyFieldForm companyFieldForm) { |
| | | // 업체명 유효성 체크 |
| | | this.verifyTitle(title, null); |
| | | companyFieldForm.setName(title); |
| | | } |
| | | |
| | | private void setCompanyFormUrl(Cell cell, CompanyFieldForm companyFieldForm, int rowIndex) { |
| | | if (cell == null) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.EXCEL_IMPORT_URL_IS_NULL, rowIndex)); |
| | | } |
| | | String url = CommonUtil.convertExcelStringToCell(cell); |
| | | if (url.contains(" ")) { |
| | | url = url.replace(" ", ""); |
| | | } |
| | | this.verifyUrl(url, null); //url 유효성 검사 |
| | | private void setCompanyFormUrl(String url, CompanyFieldForm companyFieldForm, boolean isNull) { |
| | | if (!isNull) { |
| | | if (url.contains(" ")) { |
| | | url = url.replace(" ", ""); |
| | | } |
| | | this.verifyUrl(url, null); //url 유효성 검사 |
| | | |
| | | companyFieldForm.setUrl(url); |
| | | companyFieldForm.setUrl(url); |
| | | } |
| | | } |
| | | |
| | | // 업체명 유효성 체크 |