diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ExcelPoiUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ExcelPoiUtils.java index ee92fbeb26..199fe6dcdb 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ExcelPoiUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ExcelPoiUtils.java @@ -7,6 +7,7 @@ import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; +import cn.afterturn.easypoi.excel.imports.ExcelImportService; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.web.multipart.MultipartFile; @@ -228,6 +229,27 @@ public class ExcelPoiUtils { throw new IOException(e.getMessage()); } } + + public static ExcelImportResult importExcel1(InputStream inputStream, Integer titleRows, Integer headerRows, Class pojoClass) throws IOException { + if (inputStream == null) { + return null; + } + ImportParams params = new ImportParams(); + params.setTitleRows(titleRows); + params.setHeadRows(headerRows); + params.setSaveUrl("/tmp/excel/"); + params.setNeedSave(true); + try { + // return ExcelImportUtil.importExcel(inputStream, pojoClass, params); + return (new ExcelImportService()).importExcelByIs(inputStream, pojoClass, params, false); + } catch (NoSuchElementException e) { + throw new IOException("excel文件不能为空"); + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } + + /** * excel 导入,有错误信息 * diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java index 9c03fdf2b5..52b11d72a1 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java @@ -161,11 +161,11 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl l = new LambdaQueryWrapper<>(); l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName()) .eq(IcCommunitySelfOrganizationEntity::getCustomerId,customerId) @@ -200,13 +200,16 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl { + /** + * 2022-06-14 需求变动 去掉号码校验 + */ + /*formDTO.getOrganizationPersonnel().forEach(p -> { boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone()); boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone()); if (!m && !t){ throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); } - }); + });*/ List persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); Map> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); List phones = new ArrayList<>(); @@ -243,11 +246,11 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl l = new LambdaQueryWrapper<>(); l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName()) .eq(IcCommunitySelfOrganizationEntity::getCustomerId,tokenDto.getCustomerId()) @@ -263,13 +266,16 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl { + /** + * 2022-06-14 需求变动 去掉号码校验 + */ + /*formDTO.getOrganizationPersonnel().forEach(p -> { boolean mobile = PhoneValidatorUtils.isMobile(p.getPersonPhone()); boolean tel = PhoneValidatorUtils.isTel(p.getPersonPhone()); if (!mobile && !tel){ throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); } - }); + });*/ List persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); Map> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); List phones = new ArrayList<>(); @@ -504,16 +510,18 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl fileList = new ArrayList<>(); CommunitySelfOrgImportExcel excel = null; //1.读取Excel数据 - ExcelImportResult testExcelImportResult = ExcelPoiUtils.importExcelMore(inputStream,0,2,ImportCommunitySelfOrganization.class); + ExcelImportResult testExcelImportResult = ExcelPoiUtils.importExcel1(inputStream,0,2,ImportCommunitySelfOrganization.class); //2.存在错误行数据时存入错误数据集合中 - for (ImportCommunitySelfOrganization entity : testExcelImportResult.getFailList()) { - //打印失败的行 和失败的信息 - log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); - excel = new CommunitySelfOrgImportExcel(); - //excel.setAgencyName(entity.getOrganizationName()); - excel.setSocietyName(entity.getOrganizationName()); - excel.setErrorInfo(entity.getErrorMsg()); - fileList.add(excel); + if(CollectionUtils.isNotEmpty(testExcelImportResult.getFailList())){ + for (ImportCommunitySelfOrganization entity : testExcelImportResult.getFailList()) { + //打印失败的行 和失败的信息 + log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); + excel = new CommunitySelfOrgImportExcel(); + //excel.setAgencyName(entity.getOrganizationName()); + excel.setSocietyName(entity.getOrganizationName()); + excel.setErrorInfo(entity.getErrorMsg()); + fileList.add(excel); + } } //正确行数据集合 List list = testExcelImportResult.getList(); @@ -539,14 +547,17 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl { + /*l.getPersons().forEach(p -> { boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone()); boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone()); if (!m && !t){ @@ -590,7 +602,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl> groupByPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); List phones = new ArrayList<>();