diff --git a/jero-boot-incoming-payment/src/main/java/com/jero/project/service/impl/PayWorkingGroupSubItemServiceImpl.java b/jero-boot-incoming-payment/src/main/java/com/jero/project/service/impl/PayWorkingGroupSubItemServiceImpl.java index 7cc587f0..142f611d 100644 --- a/jero-boot-incoming-payment/src/main/java/com/jero/project/service/impl/PayWorkingGroupSubItemServiceImpl.java +++ b/jero-boot-incoming-payment/src/main/java/com/jero/project/service/impl/PayWorkingGroupSubItemServiceImpl.java @@ -37,6 +37,7 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -83,24 +84,24 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl fileMap = multipartRequest.getFileMap(); for (Map.Entry entity : fileMap.entrySet()) { MultipartFile file = entity.getValue();// 获取上传文件对象 ImportParams params = new ImportParams(); params.setTitleRows(1); params.setHeadRows(1); + //导入Excel格式校验,看匹配的字段文本概率 try { - //导入Excel格式校验,看匹配的字段文本概率 Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), PayWorkingGroupSubItem.class, params); if(!t){ - throw new RuntimeException("导入Excel校验失败 !"); + throw new JeroBootException("导入Excel校验失败 !"); } + } catch (IOException e) { + e.printStackTrace(); + throw new JeroBootException("导入Excel校验失败 !"); + } + try { List list = ExcelImportUtil.importExcel(file.getInputStream(), PayWorkingGroupSubItem.class, params); if(!CollectionUtils.isEmpty(list)){ // 校验重复成员的集合 List listCompanyAndContacts = new ArrayList<>(); - StringBuilder msg = new StringBuilder(); // 获取excel中的企业名称 List listCompanyName = list.stream().map(PayWorkingGroupSubItem::getChargeCompanyTemporaryName).collect(Collectors.toList()); // 获取excel企业信息 @@ -210,7 +215,7 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl listCompanyInfo = payCompanyManagementService.list(companyWrapper); if(CollectionUtils.isEmpty(listCompanyInfo)){ - throw new RuntimeException("excel中企业不存在 !"); + msg.append("excel中企业不存在 !"); } List listContactsName = new ArrayList<>(); // 获取excel中联系人一名称 @@ -238,160 +243,160 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl listContactsInfo = payContactsManagementService.list(contactsWrapper); if(CollectionUtils.isEmpty(listContactsInfo)){ - throw new RuntimeException("excel中联系人不存在 !"); + msg.append("excel中联系人不存在 !"); } // 获取工作组信息 PayWorkingGroup payWorkingGroup = payWorkingGroupService.getById(workGroupId); if(Objects.isNull(payWorkingGroup)){ - throw new RuntimeException("工作组不存在 !"); + msg.append("工作组不存在 !"); } - - // 获取工作组成员 - LambdaQueryWrapper query = new LambdaQueryWrapper<>(); - query.eq(PayWorkingGroupSubItem::getWorkingGroupId,workGroupId); - List listData = payWorkingGroupSubItemService.list(query); - list.forEach(p->{ - p.setWorkingGroupId(workGroupId); - int count = list.indexOf(p); - // 校验企业名称 - List listCompany = new ArrayList<>(); - if(StringUtils.isBlank(p.getChargeCompanyTemporaryName())){ - msg.append("第 ").append(count + 3).append(" 行:企业名称不能为空,请修改。
"); - }else{ - // 通过企业名称获取企业id - listCompany = listCompanyInfo.stream().filter(item-> - Objects.equals(item.getCompanyName(),p.getChargeCompanyTemporaryName())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(listCompany)){ - msg.append("第 ").append(count + 3).append(" 行:企业名称不存在,请修改。
"); - }else{ - p.setChargeCompanyId(listCompany.get(0).getId()); - } - } - // 校验联系人一 - if(StringUtils.isBlank(p.getContactsTemporaryNameOne())){ - msg.append("第 ").append(count + 3).append(" 行:联系人不能为空,请修改。
"); - }else{ - if(!CollectionUtils.isEmpty(listCompany)){ - // 通过联系人获取联系人id - List finalListCompany = listCompany; - List listContacts = listContactsInfo.stream().filter(item-> - Objects.equals(item.getName(),p.getContactsTemporaryNameOne()) - && Objects.equals(item.getCompanyId(), finalListCompany.get(0).getId())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(listContacts)){ - msg.append("第 ").append(count + 3).append(" 行:该企业下不存在该联系人一,请修改。
"); - }else{ - p.setContactsIdOne(listContacts.get(0).getId()); + if(StringUtils.isBlank(msg)) { + // 获取工作组成员 + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(PayWorkingGroupSubItem::getWorkingGroupId, workGroupId); + List listData = payWorkingGroupSubItemService.list(query); + list.forEach(p -> { + p.setWorkingGroupId(workGroupId); + int count = list.indexOf(p); + // 校验企业名称 + List listCompany = new ArrayList<>(); + if (StringUtils.isBlank(p.getChargeCompanyTemporaryName())) { + msg.append("第 ").append(count + 3).append(" 行:企业名称不能为空,请修改。
"); + } else { + // 通过企业名称获取企业id + listCompany = listCompanyInfo.stream().filter(item -> + Objects.equals(item.getCompanyName(), p.getChargeCompanyTemporaryName())).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(listCompany)) { + msg.append("第 ").append(count + 3).append(" 行:企业名称不存在,请修改。
"); + } else { + p.setChargeCompanyId(listCompany.get(0).getId()); } } - } - // 校验工作组成员单位是否已存在 - if(!StringUtils.isBlank(p.getChargeCompanyId())){ - List listDateNew = listData.stream().filter(item->Objects.equals(p.getChargeCompanyId(),item.getChargeCompanyId())).collect(Collectors.toList()); - if(!CollectionUtils.isEmpty(listDateNew)){ - msg.append("第 ").append(count + 3).append(" 行:工作组成员单位已存在,请修改。
"); - } - } - // 校验联系人二 - if(!StringUtils.isBlank(p.getContactsTemporaryNameTwo()) && !CollectionUtils.isEmpty(listCompany)){ - if(!CollectionUtils.isEmpty(listCompany)){ - // 通过联系人获取联系人id - List finalListCompany = listCompany; - List listContacts = listContactsInfo.stream().filter(item-> - Objects.equals(item.getName(),p.getContactsTemporaryNameTwo()) - && Objects.equals(item.getCompanyId(), finalListCompany.get(0).getId())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(listContacts)){ - msg.append("第 ").append(count + 3).append(" 行:该企业下不存在该联系人二,请修改。
"); - }else{ - p.setContactsIdTwo(listContacts.get(0).getId()); + // 校验联系人一 + if (StringUtils.isBlank(p.getContactsTemporaryNameOne())) { + msg.append("第 ").append(count + 3).append(" 行:联系人不能为空,请修改。
"); + } else { + if (!CollectionUtils.isEmpty(listCompany)) { + // 通过联系人获取联系人id + List finalListCompany = listCompany; + List listContacts = listContactsInfo.stream().filter(item -> + Objects.equals(item.getName(), p.getContactsTemporaryNameOne()) + && Objects.equals(item.getCompanyId(), finalListCompany.get(0).getId())).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(listContacts)) { + msg.append("第 ").append(count + 3).append(" 行:该企业下不存在该联系人一,请修改。
"); + } else { + p.setContactsIdOne(listContacts.get(0).getId()); + } } } - } - // 校验联系人三 - if(!StringUtils.isBlank(p.getContactsTemporaryNameThree()) && !CollectionUtils.isEmpty(listCompany)){ - if(!CollectionUtils.isEmpty(listCompany)){ - // 通过联系人获取联系人id - List finalListCompany = listCompany; - List listContacts = listContactsInfo.stream().filter(item-> - Objects.equals(item.getName(),p.getContactsTemporaryNameThree()) - && Objects.equals(item.getCompanyId(), finalListCompany.get(0).getId())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(listContacts)){ - msg.append("第 ").append(count + 3).append(" 行:该企业下不存在该联系人三,请修改。
"); - }else{ - p.setContactsIdThree(listContacts.get(0).getId()); + // 校验工作组成员单位是否已存在 + if (!StringUtils.isBlank(p.getChargeCompanyId())) { + List listDateNew = listData.stream().filter(item -> Objects.equals(p.getChargeCompanyId(), item.getChargeCompanyId())).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(listDateNew)) { + msg.append("第 ").append(count + 3).append(" 行:工作组成员单位已存在,请修改。
"); } } - } - // 校验邮寄联系人 - if(StringUtils.isBlank(p.getMailContactsTemporaryName())){ - msg.append("第 ").append(count + 3).append(" 行:邮寄联系人不能为空,请修改。
"); - }else{ - if(!CollectionUtils.isEmpty(listCompany)){ - // 通过联系人获取联系人id - List finalListCompany = listCompany; - List listContacts = listContactsInfo.stream().filter(item-> - Objects.equals(item.getName(),p.getMailContactsTemporaryName()) - && Objects.equals(item.getCompanyId(), finalListCompany.get(0).getId())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(listContacts)){ - msg.append("第 ").append(count + 3).append(" 行:该企业下不存在该邮寄联系人,请修改。
"); - }else{ - p.setMailContactsId(listContacts.get(0).getId()); + // 校验联系人二 + if (!StringUtils.isBlank(p.getContactsTemporaryNameTwo()) && !CollectionUtils.isEmpty(listCompany)) { + if (!CollectionUtils.isEmpty(listCompany)) { + // 通过联系人获取联系人id + List finalListCompany = listCompany; + List listContacts = listContactsInfo.stream().filter(item -> + Objects.equals(item.getName(), p.getContactsTemporaryNameTwo()) + && Objects.equals(item.getCompanyId(), finalListCompany.get(0).getId())).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(listContacts)) { + msg.append("第 ").append(count + 3).append(" 行:该企业下不存在该联系人二,请修改。
"); + } else { + p.setContactsIdTwo(listContacts.get(0).getId()); + } } } - } - // 校验成员唯一性 - List listCompanyAndContactsNew = listCompanyAndContacts.stream().filter(item->Objects.equals(p.getChargeCompanyTemporaryName(),item.getChargeCompanyTemporaryName())).collect(Collectors.toList()); - if(!CollectionUtils.isEmpty(listCompanyAndContactsNew)){ - msg.append("第 ").append(count + 3).append(" 行:工作组成员单位重复出现,请修改。
"); - } - listCompanyAndContacts.add(p); - // 校验 - if(Objects.equals(p.getChargeWay(), PayProjectCommon.CHARGE_WAY2)){ - if(Objects.isNull(p.getReceivableAmount())){ - msg.append("第 ").append(count + 3).append(" 行:应收金额不能为空,请修改。
"); - } - if(StringUtils.isBlank(p.getContractNum())){ - msg.append("第 ").append(count + 3).append(" 行:合同号不能为空,请修改。
"); - } - } - if(Objects.equals(p.getChargeWay(),PayProjectCommon.CHARGE_WAY3)){ - if(Objects.isNull(p.getChargeNoticeNo())){ - msg.append("第 ").append(count + 3).append(" 行:收费通知号不能为空,请修改。
"); - }else{ - if(Objects.equals(payWorkingGroup.getChargeNoticeNoA(),p.getChargeNoticeNo())) { - p.setChargeNoticeId(payWorkingGroup.getChargeNoticeAId()); - }else if(Objects.equals(payWorkingGroup.getChargeNoticeNoB(),p.getChargeNoticeNo()) ){ - p.setChargeNoticeId(payWorkingGroup.getChargeNoticeBId()); - }else{ - msg.append("第 ").append(count + 3).append(" 行:收费通知号不存在,请修改。
"); + // 校验联系人三 + if (!StringUtils.isBlank(p.getContactsTemporaryNameThree()) && !CollectionUtils.isEmpty(listCompany)) { + if (!CollectionUtils.isEmpty(listCompany)) { + // 通过联系人获取联系人id + List finalListCompany = listCompany; + List listContacts = listContactsInfo.stream().filter(item -> + Objects.equals(item.getName(), p.getContactsTemporaryNameThree()) + && Objects.equals(item.getCompanyId(), finalListCompany.get(0).getId())).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(listContacts)) { + msg.append("第 ").append(count + 3).append(" 行:该企业下不存在该联系人三,请修改。
"); + } else { + p.setContactsIdThree(listContacts.get(0).getId()); + } } } - if(Objects.isNull(p.getReceivableAmount())){ - msg.append("第 ").append(count + 3).append(" 行:应收金额不能为空,请修改。
"); + // 校验邮寄联系人 + if (StringUtils.isBlank(p.getMailContactsTemporaryName())) { + msg.append("第 ").append(count + 3).append(" 行:邮寄联系人不能为空,请修改。
"); + } else { + if (!CollectionUtils.isEmpty(listCompany)) { + // 通过联系人获取联系人id + List finalListCompany = listCompany; + List listContacts = listContactsInfo.stream().filter(item -> + Objects.equals(item.getName(), p.getMailContactsTemporaryName()) + && Objects.equals(item.getCompanyId(), finalListCompany.get(0).getId())).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(listContacts)) { + msg.append("第 ").append(count + 3).append(" 行:该企业下不存在该邮寄联系人,请修改。
"); + } else { + p.setMailContactsId(listContacts.get(0).getId()); + } + } } + // 校验成员唯一性 + List listCompanyAndContactsNew = listCompanyAndContacts.stream().filter(item -> Objects.equals(p.getChargeCompanyTemporaryName(), item.getChargeCompanyTemporaryName())).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(listCompanyAndContactsNew)) { + msg.append("第 ").append(count + 3).append(" 行:工作组成员单位重复出现,请修改。
"); + } + listCompanyAndContacts.add(p); + // 校验 + if (Objects.equals(p.getChargeWay(), PayProjectCommon.CHARGE_WAY2)) { + if (Objects.isNull(p.getReceivableAmount())) { + msg.append("第 ").append(count + 3).append(" 行:应收金额不能为空,请修改。
"); + } + if (StringUtils.isBlank(p.getContractNum())) { + msg.append("第 ").append(count + 3).append(" 行:合同号不能为空,请修改。
"); + } + } + if (Objects.equals(p.getChargeWay(), PayProjectCommon.CHARGE_WAY3)) { + if (Objects.isNull(p.getChargeNoticeNo())) { + msg.append("第 ").append(count + 3).append(" 行:收费通知号不能为空,请修改。
"); + } else { + if (Objects.equals(payWorkingGroup.getChargeNoticeNoA(), p.getChargeNoticeNo())) { + p.setChargeNoticeId(payWorkingGroup.getChargeNoticeAId()); + } else if (Objects.equals(payWorkingGroup.getChargeNoticeNoB(), p.getChargeNoticeNo())) { + p.setChargeNoticeId(payWorkingGroup.getChargeNoticeBId()); + } else { + msg.append("第 ").append(count + 3).append(" 行:收费通知号不存在,请修改。
"); + } + } + if (Objects.isNull(p.getReceivableAmount())) { + msg.append("第 ").append(count + 3).append(" 行:应收金额不能为空,请修改。
"); + } + } + p.setPack(PayProjectCommon.PACKAGING0); + p.setInAccount(PayProjectCommon.IN_ACCOUNT0); + p.setMakeInvoice(PayProjectCommon.MAKE_INVOICE0); + p.setMail(PayProjectCommon.MAIL0); + // 校验字段值 + StringBuilder s = ValidUtil.validateExcel(p, (count + 3)); + if (!StringUtils.isBlank(s)) { + msg.append(s); + } + }); + if (StringUtils.isBlank(msg)) { + // 拷贝企业,联系人 + list.forEach(p -> { + setPayWorkingGroupSubItem(p); + }); + // 更新数据 + payWorkingGroupSubItemService.saveBatch(list); } - p.setPack(PayProjectCommon.PACKAGING0); - p.setInAccount(PayProjectCommon.IN_ACCOUNT0); - p.setMakeInvoice(PayProjectCommon.MAKE_INVOICE0); - p.setMail(PayProjectCommon.MAIL0); - // 校验字段值 - StringBuilder s = ValidUtil.validateExcel(p,(count+3)); - if(!StringUtils.isBlank(s)){ - msg.append(s); - } - }); - if(!StringUtils.isBlank(msg)){ - throw new RuntimeException(msg.toString()); } - // 拷贝企业,联系人 - list.forEach(p->{ - setPayWorkingGroupSubItem(p); - }); - // 更新数据 - payWorkingGroupSubItemService.saveBatch(list); } } catch (Exception e) { log.error(e.getMessage(),e); - throw new RuntimeException("文件导入失败!"); + throw new JeroBootException("文件导入失败!"); } finally { try { file.getInputStream().close(); @@ -399,6 +404,9 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl