| | |
| | | package kr.wisestone.owl.service.impl; |
| | | |
| | | import kr.wisestone.owl.domain.CompanyField; |
| | | import kr.wisestone.owl.service.UserService; |
| | | import kr.wisestone.owl.domain.*; |
| | | import kr.wisestone.owl.repository.HostingFieldRepository; |
| | | import kr.wisestone.owl.repository.IspFieldRepository; |
| | | import kr.wisestone.owl.service.*; |
| | | import kr.wisestone.owl.util.CommonUtil; |
| | | import kr.wisestone.owl.web.condition.CompanyFieldCategoryCondition; |
| | | import kr.wisestone.owl.web.condition.CompanyFieldCondition; |
| | | import kr.wisestone.owl.web.form.CompanyFieldForm; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.ui.Model; |
| | | import com.google.common.collect.Lists; |
| | | import kr.wisestone.owl.common.ExcelConditionCheck; |
| | |
| | | import kr.wisestone.owl.exception.OwlRuntimeException; |
| | | import kr.wisestone.owl.mapper.CompanyFieldMapper; |
| | | import kr.wisestone.owl.repository.CompanyFieldRepository; |
| | | import kr.wisestone.owl.service.CompanyFieldService; |
| | | import kr.wisestone.owl.service.WorkspaceService; |
| | | import kr.wisestone.owl.util.ConvertUtil; |
| | | import kr.wisestone.owl.vo.*; |
| | | import kr.wisestone.owl.web.view.ExcelView; |
| | |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | | public class CompanyFieldServiceImpl extends AbstractServiceImpl<CompanyField, Long, JpaRepository<CompanyField, Long>> implements CompanyFieldService { |
| | |
| | | |
| | | @Autowired |
| | | private CompanyFieldMapper companyFieldMapper; |
| | | |
| | | @Autowired |
| | | private IspFieldRepository ispFieldRepository; |
| | | |
| | | @Autowired |
| | | private HostingFieldRepository hostingFieldRepository; |
| | | |
| | | @Autowired |
| | | private IspFieldService ispFieldService; |
| | | |
| | | @Autowired |
| | | private HostingFieldService hostingFieldService; |
| | | |
| | | @Autowired |
| | | private CompanyFieldCategoryService companyFieldCategoryService; |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | |
| | | // 업체 추가 |
| | | @Override |
| | | public CompanyField addCompany(CompanyFieldForm companyFieldForm) { |
| | | // url 유효성 체크 |
| | | this.verifyUrl(companyFieldForm.getUrl(), null); |
| | | |
| | | if (companyFieldForm.getTelList() != null && companyFieldForm.getTelList().size() > 0) { |
| | | String[] tels = ConvertUtil.ToArray(companyFieldForm.getTelList()); |
| | | companyFieldForm.setTel(Arrays.toString(tels)); |
| | | } |
| | | if (companyFieldForm.getEmailList() != null && companyFieldForm.getEmailList().size() > 0) { |
| | | String[] emails = ConvertUtil.ToArray(companyFieldForm.getEmailList()); |
| | | companyFieldForm.setEmail(Arrays.toString(emails)); |
| | | } |
| | | |
| | | CompanyField companyField = ConvertUtil.copyProperties(companyFieldForm, CompanyField.class); |
| | | companyFieldRepository.saveAndFlush(companyField); |
| | | return companyField; |
| | | } |
| | | |
| | | // url 유효성 체크 |
| | | private void verifyUrl(String url, Long id) { |
| | | if (StringUtils.isEmpty(url)) { |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.COMPANYFIELD_NOT_URL)); |
| | | } |
| | | CompanyField companyField; |
| | | |
| | | 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.COMPANYFIELD_USED_URL)); |
| | | } |
| | | } |
| | | |
| | | // 업체 목록을 가져온다. |
| | |
| | | return this.convertCompanyVoToMap(results, totalCompanyCount, pageable, resJsonData); |
| | | } |
| | | |
| | | public List<Map<String, Object>> find(CompanyFieldCondition condition) { |
| | | return this.companyFieldMapper.find(condition); |
| | | } |
| | | |
| | | // 업체 상세 조회한다. |
| | | @Override |
| | | @Transactional |
| | | public void detailCompany(Map<String, Object> resJsonData, CompanyFieldCondition companyFieldCondition) { |
| | | CompanyFieldVo companyFieldVo = new CompanyFieldVo(); |
| | | IspFieldVo ispFieldVo = new IspFieldVo(); |
| | | HostingFieldVo hostingFieldVo = new HostingFieldVo(); |
| | | |
| | | IspField ispField = new IspField(); |
| | | HostingField hostingField = new HostingField(); |
| | | |
| | | Long companyId = companyFieldCondition.getId(); |
| | | if (companyId != null) { |
| | | CompanyField companyField = this.getCompany(companyId); |
| | | if(companyField.getIspId() != null && companyField.getIspId() != -1){ |
| | | ispField = this.ispFieldRepository.getOne(companyField.getIspId()); |
| | | } |
| | | if(companyField.getHostingId() != null && companyField.getHostingId() != -1){ |
| | | hostingField = this.hostingFieldRepository.getOne(companyField.getHostingId()); |
| | | } |
| | | companyFieldVo = ConvertUtil.copyProperties(companyField, CompanyFieldVo.class); |
| | | ispFieldVo = ConvertUtil.copyProperties(ispField, IspFieldVo.class); |
| | | hostingFieldVo = ConvertUtil.copyProperties(hostingField, HostingFieldVo.class); |
| | | |
| | | if (companyField.getCompanyTypeId() != null && companyField.getCompanyTypeId() != -1) { |
| | | CompanyFieldCategory companyType = this.companyFieldCategoryService.find(companyField.getCompanyTypeId()); |
| | | if (companyType != null) { |
| | | companyFieldVo.setCompanyTypeName(companyType.getUseValue()); |
| | | } |
| | | } |
| | | if (companyField.getParentSectorId() != null && companyField.getParentSectorId() != -1) { |
| | | CompanyFieldCategory parentSector = this.companyFieldCategoryService.find(companyField.getParentSectorId()); |
| | | if (parentSector != null) { |
| | | companyFieldVo.setParentSectorName(parentSector.getUseValue()); |
| | | } |
| | | } |
| | | if (companyField.getChildSectorId() != null && companyField.getChildSectorId() != -1) { |
| | | CompanyFieldCategory childSector = this.companyFieldCategoryService.find(companyField.getChildSectorId()); |
| | | if (childSector != null) { |
| | | companyFieldVo.setChildSectorName(childSector.getUseValue()); |
| | | } |
| | | } |
| | | if (companyField.getRegionId() != null && companyField.getRegionId() != -1) { |
| | | CompanyFieldCategory region = this.companyFieldCategoryService.find(companyField.getRegionId()); |
| | | if (region != null) { |
| | | companyFieldVo.setRegionName(region.getUseValue()); |
| | | } |
| | | } |
| | | /*if (companyField.getStatusId() != null && companyField.getStatusId() != -1) { |
| | | CompanyFieldCategory status = this.companyFieldCategoryService.find(companyField.getStatusId()); |
| | | if (status != null) { |
| | | companyFieldVo.setStatusName(status.getUseValue()); |
| | | } |
| | | }*/ |
| | | |
| | | companyFieldVo.setIspFieldVo(ispFieldVo); |
| | | companyFieldVo.setHostingFieldVo(hostingFieldVo); |
| | | } |
| | | resJsonData.put(Constants.REQ_KEY_CONTENT, companyFieldVo); |
| | | } |
| | |
| | | // 업체 정로를 수정한다. |
| | | @Override |
| | | public void modifyCompany(CompanyFieldForm companyFieldForm) { |
| | | // url 유효성 체크 |
| | | this.verifyUrl(companyFieldForm.getUrl(), companyFieldForm.getId()); |
| | | |
| | | if (companyFieldForm.getTelList() != null && companyFieldForm.getTelList().size() > 0) { |
| | | String[] tels = ConvertUtil.ToArray(companyFieldForm.getTelList()); |
| | | companyFieldForm.setTel(Arrays.toString(tels)); |
| | | } |
| | | if (companyFieldForm.getEmailList() != null && companyFieldForm.getEmailList().size() > 0) { |
| | | String[] emails = ConvertUtil.ToArray(companyFieldForm.getEmailList()); |
| | | companyFieldForm.setEmail(Arrays.toString(emails)); |
| | | } |
| | | |
| | | CompanyField companyField = ConvertUtil.copyProperties(companyFieldForm, CompanyField.class); |
| | | companyFieldRepository.saveAndFlush(companyField); |
| | | } |
| | |
| | | } |
| | | |
| | | CompanyFieldCondition companyFieldCondition = CompanyFieldCondition.make(conditions); |
| | | |
| | | |
| | | List<Map<String, Object>> results = this.companyFieldMapper.find(companyFieldCondition); |
| | | List<CompanyFieldVo> companyFieldVos = ConvertUtil.convertListToListClass(results, CompanyFieldVo.class); |
| | | |
| | | // code_ko_KR 에 code명 설정 |
| | | ExportExcelVo excelInfo = new ExportExcelVo(); |
| | | excelInfo.setFileName(this.messageAccessor.message("업체 목록")); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("companyName", this.messageAccessor.message("companyField.companyName"), 6, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("companyManager", this.messageAccessor.message("companyField.companyManager"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("companyTel", this.messageAccessor.message("companyField.companyTel"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("companyEmail", this.messageAccessor.message("companyField.companyEmail"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("companyMemo", this.messageAccessor.message("companyField.companyMemo"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("name", this.messageAccessor.message("companyField.companyName"), 6, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("manager", this.messageAccessor.message("companyField.companyManager"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("tel", this.messageAccessor.message("companyField.companyTel"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("email", this.messageAccessor.message("companyField.companyEmail"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("url", this.messageAccessor.message("companyField.companyUrl"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("companyTypeName", this.messageAccessor.message("companyField.companyTypeName"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("parentSectorName", this.messageAccessor.message("companyField.parentSectorName"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("childSectorName", this.messageAccessor.message("companyField.childSectorName"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("regionName", this.messageAccessor.message("companyField.regionName"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("statusName", this.messageAccessor.message("companyField.statusName"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | excelInfo.addAttrInfos(new ExportExcelAttrVo("memo", this.messageAccessor.message("companyField.companyMemo"), 10, ExportExcelAttrVo.ALIGN_CENTER)); |
| | | |
| | | excelInfo.setDatas(companyFieldVos); |
| | | |
| | | System.out.println(excelInfo); |
| | | model.addAttribute(Constants.EXCEL, excelInfo); |
| | | return new ModelAndView(this.excelView); |
| | | } |
| | |
| | | |
| | | for (Map<String, Object> result : results) { |
| | | CompanyFieldVo companyFieldVo = ConvertUtil.convertMapToClass(result, CompanyFieldVo.class); |
| | | |
| | | if (companyFieldVo.getCompanyTypeId() != null && companyFieldVo.getCompanyTypeId() != -1) { |
| | | CompanyFieldCategory companyType = this.companyFieldCategoryService.find(companyFieldVo.getCompanyTypeId()); |
| | | if (companyType != null) { |
| | | companyFieldVo.setCompanyTypeName(companyType.getUseValue()); |
| | | } |
| | | } |
| | | if (companyFieldVo.getParentSectorId() != null && companyFieldVo.getParentSectorId() != -1) { |
| | | CompanyFieldCategory parentSector = this.companyFieldCategoryService.find(companyFieldVo.getParentSectorId()); |
| | | if (parentSector != null) { |
| | | companyFieldVo.setParentSectorName(parentSector.getUseValue()); |
| | | } |
| | | } |
| | | if (companyFieldVo.getChildSectorId() != null && companyFieldVo.getChildSectorId() != -1) { |
| | | CompanyFieldCategory childSector = this.companyFieldCategoryService.find(companyFieldVo.getChildSectorId()); |
| | | if (childSector != null) { |
| | | companyFieldVo.setChildSectorName(childSector.getUseValue()); |
| | | } |
| | | } |
| | | if (companyFieldVo.getRegionId() != null && companyFieldVo.getRegionId() != -1) { |
| | | CompanyFieldCategory region = this.companyFieldCategoryService.find(companyFieldVo.getRegionId()); |
| | | if (region != null) { |
| | | companyFieldVo.setRegionName(region.getUseValue()); |
| | | } |
| | | } |
| | | |
| | | if(companyFieldVo.getIspId() != null && companyFieldVo.getIspId() != -1){ |
| | | IspField ispField = this.ispFieldService.getIsp(companyFieldVo.getIspId()); |
| | | if(ispField != null){ |
| | | IspFieldVo ispFieldVo = ConvertUtil.copyProperties(ispField, IspFieldVo.class); |
| | | companyFieldVo.setIspFieldVo(ispFieldVo); |
| | | } |
| | | } |
| | | if(companyFieldVo.getHostingId() != null && companyFieldVo.getHostingId() != -1){ |
| | | HostingField hostingField = this.hostingFieldService.getHosting(companyFieldVo.getHostingId()); |
| | | if(hostingField != null){ |
| | | HostingFieldVo hostingFieldVo = ConvertUtil.copyProperties(hostingField, HostingFieldVo.class); |
| | | companyFieldVo.setHostingFieldVo(hostingFieldVo); |
| | | } |
| | | } |
| | | companyFieldVos.add(companyFieldVo); |
| | | } |
| | | |
| | |
| | | throw new OwlRuntimeException( |
| | | this.messageAccessor.getMessage(MsgConstants.COMPANYFIELD_NOT_EXIST)); |
| | | } |
| | | |
| | | CompanyField companyField = this.findOne(id); |
| | | |
| | | if (companyField == null) { |