Browse Source

Merge remote-tracking branch 'origin/dev_change_communitySelfOrganization'

master
yinzuomei 3 years ago
parent
commit
5bdf0b3715
  1. 22
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ExcelPoiUtils.java
  2. 78
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java

22
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.TemplateExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.afterturn.easypoi.excel.imports.ExcelImportService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -228,6 +229,27 @@ public class ExcelPoiUtils {
throw new IOException(e.getMessage()); throw new IOException(e.getMessage());
} }
} }
public static <T> ExcelImportResult<T> importExcel1(InputStream inputStream, Integer titleRows, Integer headerRows, Class<T> 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 导入有错误信息 * excel 导入有错误信息
* *

78
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<IcCo
@Override @Override
public void addCommunitySelfOrganization(TokenDto tokenDto, AddCommunitySelfOrganizationFormDTO formDTO) { public void addCommunitySelfOrganization(TokenDto tokenDto, AddCommunitySelfOrganizationFormDTO formDTO) {
String customerId = tokenDto.getCustomerId(); String customerId = tokenDto.getCustomerId();
boolean mobile = PhoneValidatorUtils.isMobile(formDTO.getPrincipalPhone()); /*boolean mobile = PhoneValidatorUtils.isMobile(formDTO.getPrincipalPhone());
boolean tel = PhoneValidatorUtils.isTel(formDTO.getPrincipalPhone()); boolean tel = PhoneValidatorUtils.isTel(formDTO.getPrincipalPhone());
if (!mobile && !tel){ if (!mobile && !tel){
throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
} }*/
LambdaQueryWrapper<IcCommunitySelfOrganizationEntity> l = new LambdaQueryWrapper<>(); LambdaQueryWrapper<IcCommunitySelfOrganizationEntity> l = new LambdaQueryWrapper<>();
l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName()) l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName())
.eq(IcCommunitySelfOrganizationEntity::getCustomerId,customerId) .eq(IcCommunitySelfOrganizationEntity::getCustomerId,customerId)
@ -200,13 +200,16 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
baseDao.insert(orgEntity); baseDao.insert(orgEntity);
if(CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){ if(CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){
// 号码校验 // 号码校验
formDTO.getOrganizationPersonnel().forEach(p -> { /**
* 2022-06-14 需求变动 去掉号码校验
*/
/*formDTO.getOrganizationPersonnel().forEach(p -> {
boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone()); boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone());
boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone()); boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone());
if (!m && !t){ if (!m && !t){
throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
} }
}); });*/
List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class);
Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone));
List<String> phones = new ArrayList<>(); List<String> phones = new ArrayList<>();
@ -243,11 +246,11 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void editCommunitySelfOrganization(TokenDto tokenDto, EditCommunitySelfOrganizationFormDTO formDTO) { public void editCommunitySelfOrganization(TokenDto tokenDto, EditCommunitySelfOrganizationFormDTO formDTO) {
boolean m = PhoneValidatorUtils.isMobile(formDTO.getPrincipalPhone()); /*boolean m = PhoneValidatorUtils.isMobile(formDTO.getPrincipalPhone());
boolean t = PhoneValidatorUtils.isTel(formDTO.getPrincipalPhone()); boolean t = PhoneValidatorUtils.isTel(formDTO.getPrincipalPhone());
if (!m && !t){ if (!m && !t){
throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
} }*/
LambdaQueryWrapper<IcCommunitySelfOrganizationEntity> l = new LambdaQueryWrapper<>(); LambdaQueryWrapper<IcCommunitySelfOrganizationEntity> l = new LambdaQueryWrapper<>();
l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName()) l.eq(IcCommunitySelfOrganizationEntity::getOrganizationName,formDTO.getOrganizationName())
.eq(IcCommunitySelfOrganizationEntity::getCustomerId,tokenDto.getCustomerId()) .eq(IcCommunitySelfOrganizationEntity::getCustomerId,tokenDto.getCustomerId())
@ -263,13 +266,16 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
baseDao.updateCommunitySelfOrganization(e); baseDao.updateCommunitySelfOrganization(e);
personnelService.deleteByOrgId(formDTO.getOrgId()); personnelService.deleteByOrgId(formDTO.getOrgId());
if (CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){ if (CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){
formDTO.getOrganizationPersonnel().forEach(p -> { /**
* 2022-06-14 需求变动 去掉号码校验
*/
/*formDTO.getOrganizationPersonnel().forEach(p -> {
boolean mobile = PhoneValidatorUtils.isMobile(p.getPersonPhone()); boolean mobile = PhoneValidatorUtils.isMobile(p.getPersonPhone());
boolean tel = PhoneValidatorUtils.isTel(p.getPersonPhone()); boolean tel = PhoneValidatorUtils.isTel(p.getPersonPhone());
if (!mobile && !tel){ if (!mobile && !tel){
throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
} }
}); });*/
List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class);
Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone));
List<String> phones = new ArrayList<>(); List<String> phones = new ArrayList<>();
@ -504,16 +510,18 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
List<CommunitySelfOrgImportExcel> fileList = new ArrayList<>(); List<CommunitySelfOrgImportExcel> fileList = new ArrayList<>();
CommunitySelfOrgImportExcel excel = null; CommunitySelfOrgImportExcel excel = null;
//1.读取Excel数据 //1.读取Excel数据
ExcelImportResult<ImportCommunitySelfOrganization> testExcelImportResult = ExcelPoiUtils.importExcelMore(inputStream,0,2,ImportCommunitySelfOrganization.class); ExcelImportResult<ImportCommunitySelfOrganization> testExcelImportResult = ExcelPoiUtils.importExcel1(inputStream,0,2,ImportCommunitySelfOrganization.class);
//2.存在错误行数据时存入错误数据集合中 //2.存在错误行数据时存入错误数据集合中
for (ImportCommunitySelfOrganization entity : testExcelImportResult.getFailList()) { if(CollectionUtils.isNotEmpty(testExcelImportResult.getFailList())){
//打印失败的行 和失败的信息 for (ImportCommunitySelfOrganization entity : testExcelImportResult.getFailList()) {
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); //打印失败的行 和失败的信息
excel = new CommunitySelfOrgImportExcel(); log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg());
//excel.setAgencyName(entity.getOrganizationName()); excel = new CommunitySelfOrgImportExcel();
excel.setSocietyName(entity.getOrganizationName()); //excel.setAgencyName(entity.getOrganizationName());
excel.setErrorInfo(entity.getErrorMsg()); excel.setSocietyName(entity.getOrganizationName());
fileList.add(excel); excel.setErrorInfo(entity.getErrorMsg());
fileList.add(excel);
}
} }
//正确行数据集合 //正确行数据集合
List<ImportCommunitySelfOrganization> list = testExcelImportResult.getList(); List<ImportCommunitySelfOrganization> list = testExcelImportResult.getList();
@ -539,14 +547,17 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
bl.set(true); bl.set(true);
} }
}); });
// //手机号不合规 //手机号不合规
// boolean m = PhoneValidatorUtils.isMobile(obj.getPrincipalPhone()); /**
// boolean t = PhoneValidatorUtils.isTel(obj.getPrincipalPhone()); * 2022-06-14 需求变动 去掉号码校验
// if (!m && !t){ */
// errMsg.append("手机号码不合法;"); /*boolean m = PhoneValidatorUtils.isMobile(obj.getPrincipalPhone());
// bl.set(true); boolean t = PhoneValidatorUtils.isTel(obj.getPrincipalPhone());
// log.warn("手机号码不合法,自组织名称{}", obj.getOrganizationName()); if (!m && !t){
// } errMsg.append("手机号码不合法;");
bl.set(true);
log.warn("手机号码不合法,自组织名称{}", obj.getOrganizationName());
}*/
if(bl.get()){ if(bl.get()){
excel = new CommunitySelfOrgImportExcel(); excel = new CommunitySelfOrgImportExcel();
//excel.setAgencyName(obj.getOrganizationName()); //excel.setAgencyName(obj.getOrganizationName());
@ -565,22 +576,23 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
e.setOrgType(IcCommunitySelfOrganizationConstant.ORG_TYPE_AGENCY); e.setOrgType(IcCommunitySelfOrganizationConstant.ORG_TYPE_AGENCY);
e.setPid(agencyInfo.getPid()); e.setPid(agencyInfo.getPid());
e.setPids(agencyInfo.getPids()); e.setPids(agencyInfo.getPids());
e.setOrganizationCreatedTime(StringUtils.isNotBlank(l.getOrganizationCreatedTime()) ? DateUtils.parse(l.getOrganizationCreatedTime(), DATE_PATTERN) : new Date()); e.setOrganizationCreatedTime(StringUtils.isNotBlank(l.getOrganizationCreatedTime()) ? DateUtils.stringToDate(l.getOrganizationCreatedTime(), DATE_PATTERN) : new Date());
//赋值分类编码,excel输入的是分类名称,需要找到admin字典库中的key //赋值分类编码,excel输入的是分类名称,需要找到admin字典库中的key
String categoryName=l.getCategoryCode();
for (String key : categoryMap.keySet()) { for (String key : categoryMap.keySet()) {
log.info("*******key="+key+";categoryMap.get(key)="+categoryMap.get(key)+";e.getCategoryCode()="+e.getCategoryCode()); if (StringUtils.isNotBlank(categoryMap.get(key)) && categoryMap.get(key).equals(categoryName)) {
if (StringUtils.isNotBlank(categoryMap.get(key)) && categoryMap.get(key).equals(e.getCategoryCode())) {
e.setCategoryCode(key); e.setCategoryCode(key);
break;
}else{
e.setCategoryCode(StrConstant.EPMETY_STR);
} }
} }
//未匹配到分类默认是其他
if(categoryName.equals(e.getCategoryCode())){
e.setCategoryCode(SelfOrgCategoryEnum.OTHER.getCode());
}
List<IcCommunitySelfOrganizationPersonnelEntity> persons = new ArrayList<>(); List<IcCommunitySelfOrganizationPersonnelEntity> persons = new ArrayList<>();
AtomicReference<Boolean> bl = new AtomicReference<>(false); AtomicReference<Boolean> bl = new AtomicReference<>(false);
StringBuffer msg = new StringBuffer(""); StringBuffer msg = new StringBuffer("");
if (CollectionUtils.isNotEmpty(l.getPersons())){ if (CollectionUtils.isNotEmpty(l.getPersons())){
l.getPersons().forEach(p -> { /*l.getPersons().forEach(p -> {
boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone()); boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone());
boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone()); boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone());
if (!m && !t){ if (!m && !t){
@ -590,7 +602,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
return; return;
//throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); //throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
} }
}); });*/
persons = ConvertUtils.sourceToTarget(l.getPersons(), IcCommunitySelfOrganizationPersonnelEntity.class); persons = ConvertUtils.sourceToTarget(l.getPersons(), IcCommunitySelfOrganizationPersonnelEntity.class);
Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupByPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupByPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone));
List<String> phones = new ArrayList<>(); List<String> phones = new ArrayList<>();

Loading…
Cancel
Save