工作组导入提示修改

This commit is contained in:
梁琦涛
2021-09-06 11:22:59 +08:00
parent ffef58d00e
commit edad18a8bc
@@ -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<PayWorkingGro
public void addPayWorkingGroupSubItem(PayWorkingGroupSubItem payWorkingGroupSubItem) {
if(payWorkingGroupSubItem.getChargeWay() == PayProjectCommon.CHARGE_WAY2){
if(Objects.isNull(payWorkingGroupSubItem.getReceivableAmount())){
throw new RuntimeException("应收金额不能为空");
throw new JeroBootException("应收金额不能为空");
}
if(StringUtils.isBlank(payWorkingGroupSubItem.getContractNum())){
throw new RuntimeException("合同号不能为空");
throw new JeroBootException("合同号不能为空");
}
}
if(payWorkingGroupSubItem.getChargeWay() == PayProjectCommon.CHARGE_WAY3){
if(Objects.isNull(payWorkingGroupSubItem.getChargeNoticeNo())){
throw new RuntimeException("收费通知号不能为空");
throw new JeroBootException("收费通知号不能为空");
}
if(Objects.isNull(payWorkingGroupSubItem.getReceivableAmount())){
throw new RuntimeException("应收金额不能为空");
throw new JeroBootException("应收金额不能为空");
}
}
PayWorkingGroup payWorkingGroup = payWorkingGroupService.getById(payWorkingGroupSubItem.getWorkingGroupId());
if(Objects.isNull(payWorkingGroup)){
throw new RuntimeException("工作组不存在!");
throw new JeroBootException("工作组不存在!");
}
try {
@@ -112,11 +113,11 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl<PayWorkingGro
PayWorkingGroupSubItem payWorkingGroupSubItemNew = payWorkingGroupSubItemService.getOne(queryWrapper);
// 企业和联系人同时存在,则校验不通过
if(!Objects.isNull(payWorkingGroupSubItemNew)) {
throw new RuntimeException("工作组成员单位已存在!");
throw new JeroBootException("工作组成员单位已存在!");
}
}catch (Exception e){
log.info("工作组成员-添加异常",e);
throw new RuntimeException("工作组成员单位已存在!");
throw new JeroBootException("工作组成员单位已存在!");
}
payWorkingGroupSubItem = setPayWorkingGroupSubItem(payWorkingGroupSubItem);
@@ -132,23 +133,23 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl<PayWorkingGro
public void editPayWorkingGroupSubItem(PayWorkingGroupSubItem payWorkingGroupSubItem) {
if(payWorkingGroupSubItem.getChargeWay() == PayProjectCommon.CHARGE_WAY2){
if(Objects.isNull(payWorkingGroupSubItem.getReceivableAmount())){
throw new RuntimeException("应收金额不能为空");
throw new JeroBootException("应收金额不能为空");
}
if(StringUtils.isBlank(payWorkingGroupSubItem.getContractNum())){
throw new RuntimeException("合同号不能为空");
throw new JeroBootException("合同号不能为空");
}
}
if(payWorkingGroupSubItem.getChargeWay() == PayProjectCommon.CHARGE_WAY3){
if(Objects.isNull(payWorkingGroupSubItem.getChargeNoticeNo())){
throw new RuntimeException("收费通知号不能为空");
throw new JeroBootException("收费通知号不能为空");
}
if(Objects.isNull(payWorkingGroupSubItem.getReceivableAmount())){
throw new RuntimeException("应收金额不能为空");
throw new JeroBootException("应收金额不能为空");
}
}
PayWorkingGroup payWorkingGroup = payWorkingGroupService.getById(payWorkingGroupSubItem.getWorkingGroupId());
if(Objects.isNull(payWorkingGroup)){
throw new RuntimeException("工作组不存在!");
throw new JeroBootException("工作组不存在!");
}
try {
// 编辑保存前再次校验来款项目是否存在
@@ -160,11 +161,11 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl<PayWorkingGro
// 来款项目存在,并且编辑id与查询不同,则校验不通过
if(!Objects.isNull(payWorkingGroupSubItemNew)
&& !Objects.equals(payWorkingGroupSubItemNew.getId(),payWorkingGroupSubItem.getId())) {
throw new RuntimeException("工作组成员单位已存在!");
throw new JeroBootException("工作组成员单位已存在!");
}
}catch (Exception e){
log.info("工作组成员-编辑异常",e);
throw new RuntimeException("工作组成员单位已存在!");
throw new JeroBootException("工作组成员单位已存在!");
}
payWorkingGroupSubItem = setPayWorkingGroupSubItem(payWorkingGroupSubItem);
@@ -180,29 +181,33 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl<PayWorkingGro
workGroupId = multipartRequest.getParameter("workGroupId");
}catch (Exception e){
log.error("获取工作组id异常",e);
throw new RuntimeException("工作组id不能为空 ");
throw new JeroBootException("工作组id不能为空 ");
}
if(StringUtils.isBlank(workGroupId)){
throw new RuntimeException("工作组id不能为空 ");
throw new JeroBootException("工作组id不能为空 ");
}
StringBuilder msg = new StringBuilder();
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> 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<PayWorkingGroupSubItem> list = ExcelImportUtil.importExcel(file.getInputStream(), PayWorkingGroupSubItem.class, params);
if(!CollectionUtils.isEmpty(list)){
// 校验重复成员的集合
List<PayWorkingGroupSubItem> listCompanyAndContacts = new ArrayList<>();
StringBuilder msg = new StringBuilder();
// 获取excel中的企业名称
List<String> listCompanyName = list.stream().map(PayWorkingGroupSubItem::getChargeCompanyTemporaryName).collect(Collectors.toList());
// 获取excel企业信息
@@ -210,7 +215,7 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl<PayWorkingGro
companyWrapper.in(PayCompanyManagement::getCompanyName,listCompanyName);
List<PayCompanyManagement> listCompanyInfo = payCompanyManagementService.list(companyWrapper);
if(CollectionUtils.isEmpty(listCompanyInfo)){
throw new RuntimeException("excel中企业不存在 ");
msg.append("excel中企业不存在 ");
}
List<String> listContactsName = new ArrayList<>();
// 获取excel中联系人一名称
@@ -238,160 +243,160 @@ public class PayWorkingGroupSubItemServiceImpl extends ServiceImpl<PayWorkingGro
contactsWrapper.in(PayContactsManagement::getName,listContactsName);
List<PayContactsManagement> 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<PayWorkingGroupSubItem> query = new LambdaQueryWrapper<>();
query.eq(PayWorkingGroupSubItem::getWorkingGroupId,workGroupId);
List<PayWorkingGroupSubItem> listData = payWorkingGroupSubItemService.list(query);
list.forEach(p->{
p.setWorkingGroupId(workGroupId);
int count = list.indexOf(p);
// 校验企业名称
List<PayCompanyManagement> listCompany = new ArrayList<>();
if(StringUtils.isBlank(p.getChargeCompanyTemporaryName())){
msg.append("").append(count + 3).append(" 行:企业名称不能为空,请修改。</br>");
}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(" 行:企业名称不存在,请修改。</br>");
}else{
p.setChargeCompanyId(listCompany.get(0).getId());
}
}
// 校验联系人一
if(StringUtils.isBlank(p.getContactsTemporaryNameOne())){
msg.append("").append(count + 3).append(" 行:联系人不能为空,请修改。</br>");
}else{
if(!CollectionUtils.isEmpty(listCompany)){
// 通过联系人获取联系人id
List<PayCompanyManagement> finalListCompany = listCompany;
List<PayContactsManagement> 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(" 行:该企业下不存在该联系人一,请修改。</br>");
}else{
p.setContactsIdOne(listContacts.get(0).getId());
if(StringUtils.isBlank(msg)) {
// 获取工作组成员
LambdaQueryWrapper<PayWorkingGroupSubItem> query = new LambdaQueryWrapper<>();
query.eq(PayWorkingGroupSubItem::getWorkingGroupId, workGroupId);
List<PayWorkingGroupSubItem> listData = payWorkingGroupSubItemService.list(query);
list.forEach(p -> {
p.setWorkingGroupId(workGroupId);
int count = list.indexOf(p);
// 校验企业名称
List<PayCompanyManagement> listCompany = new ArrayList<>();
if (StringUtils.isBlank(p.getChargeCompanyTemporaryName())) {
msg.append("").append(count + 3).append(" 行:企业名称不能为空,请修改。</br>");
} 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(" 行:企业名称不存在,请修改。</br>");
} else {
p.setChargeCompanyId(listCompany.get(0).getId());
}
}
}
// 校验工作组成员单位是否已存在
if(!StringUtils.isBlank(p.getChargeCompanyId())){
List<PayWorkingGroupSubItem> listDateNew = listData.stream().filter(item->Objects.equals(p.getChargeCompanyId(),item.getChargeCompanyId())).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(listDateNew)){
msg.append("").append(count + 3).append(" 行:工作组成员单位已存在,请修改。</br>");
}
}
// 校验联系人二
if(!StringUtils.isBlank(p.getContactsTemporaryNameTwo()) && !CollectionUtils.isEmpty(listCompany)){
if(!CollectionUtils.isEmpty(listCompany)){
// 通过联系人获取联系人id
List<PayCompanyManagement> finalListCompany = listCompany;
List<PayContactsManagement> 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(" 行:该企业下不存在该联系人二,请修改。</br>");
}else{
p.setContactsIdTwo(listContacts.get(0).getId());
// 校验联系人一
if (StringUtils.isBlank(p.getContactsTemporaryNameOne())) {
msg.append("").append(count + 3).append(" 行:联系人不能为空,请修改。</br>");
} else {
if (!CollectionUtils.isEmpty(listCompany)) {
// 通过联系人获取联系人id
List<PayCompanyManagement> finalListCompany = listCompany;
List<PayContactsManagement> 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(" 行:该企业下不存在该联系人一,请修改。</br>");
} else {
p.setContactsIdOne(listContacts.get(0).getId());
}
}
}
}
// 校验联系人三
if(!StringUtils.isBlank(p.getContactsTemporaryNameThree()) && !CollectionUtils.isEmpty(listCompany)){
if(!CollectionUtils.isEmpty(listCompany)){
// 通过联系人获取联系人id
List<PayCompanyManagement> finalListCompany = listCompany;
List<PayContactsManagement> 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(" 行:该企业下不存在该联系人三,请修改。</br>");
}else{
p.setContactsIdThree(listContacts.get(0).getId());
// 校验工作组成员单位是否已存在
if (!StringUtils.isBlank(p.getChargeCompanyId())) {
List<PayWorkingGroupSubItem> listDateNew = listData.stream().filter(item -> Objects.equals(p.getChargeCompanyId(), item.getChargeCompanyId())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(listDateNew)) {
msg.append("").append(count + 3).append(" 行:工作组成员单位已存在,请修改。</br>");
}
}
}
// 校验邮寄联系人
if(StringUtils.isBlank(p.getMailContactsTemporaryName())){
msg.append("").append(count + 3).append(" 行:邮寄联系人不能为空,请修改。</br>");
}else{
if(!CollectionUtils.isEmpty(listCompany)){
// 通过联系人获取联系人id
List<PayCompanyManagement> finalListCompany = listCompany;
List<PayContactsManagement> 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(" 行:该企业下不存在该邮寄联系人,请修改。</br>");
}else{
p.setMailContactsId(listContacts.get(0).getId());
// 校验联系人二
if (!StringUtils.isBlank(p.getContactsTemporaryNameTwo()) && !CollectionUtils.isEmpty(listCompany)) {
if (!CollectionUtils.isEmpty(listCompany)) {
// 通过联系人获取联系人id
List<PayCompanyManagement> finalListCompany = listCompany;
List<PayContactsManagement> 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(" 行:该企业下不存在该联系人二,请修改。</br>");
} else {
p.setContactsIdTwo(listContacts.get(0).getId());
}
}
}
}
// 校验成员唯一性
List<PayWorkingGroupSubItem> listCompanyAndContactsNew = listCompanyAndContacts.stream().filter(item->Objects.equals(p.getChargeCompanyTemporaryName(),item.getChargeCompanyTemporaryName())).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(listCompanyAndContactsNew)){
msg.append("").append(count + 3).append(" 行:工作组成员单位重复出现,请修改。</br>");
}
listCompanyAndContacts.add(p);
// 校验
if(Objects.equals(p.getChargeWay(), PayProjectCommon.CHARGE_WAY2)){
if(Objects.isNull(p.getReceivableAmount())){
msg.append("").append(count + 3).append(" 行:应收金额不能为空,请修改。</br>");
}
if(StringUtils.isBlank(p.getContractNum())){
msg.append("").append(count + 3).append(" 行:合同号不能为空,请修改。</br>");
}
}
if(Objects.equals(p.getChargeWay(),PayProjectCommon.CHARGE_WAY3)){
if(Objects.isNull(p.getChargeNoticeNo())){
msg.append("").append(count + 3).append(" 行:收费通知号不能为空,请修改。</br>");
}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(" 行:收费通知号不存在,请修改。</br>");
// 校验联系人三
if (!StringUtils.isBlank(p.getContactsTemporaryNameThree()) && !CollectionUtils.isEmpty(listCompany)) {
if (!CollectionUtils.isEmpty(listCompany)) {
// 通过联系人获取联系人id
List<PayCompanyManagement> finalListCompany = listCompany;
List<PayContactsManagement> 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(" 行:该企业下不存在该联系人三,请修改。</br>");
} else {
p.setContactsIdThree(listContacts.get(0).getId());
}
}
}
if(Objects.isNull(p.getReceivableAmount())){
msg.append("").append(count + 3).append(" 行:应收金额不能为空,请修改。</br>");
// 校验邮寄联系人
if (StringUtils.isBlank(p.getMailContactsTemporaryName())) {
msg.append("").append(count + 3).append(" 行:邮寄联系人不能为空,请修改。</br>");
} else {
if (!CollectionUtils.isEmpty(listCompany)) {
// 通过联系人获取联系人id
List<PayCompanyManagement> finalListCompany = listCompany;
List<PayContactsManagement> 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(" 行:该企业下不存在该邮寄联系人,请修改。</br>");
} else {
p.setMailContactsId(listContacts.get(0).getId());
}
}
}
// 校验成员唯一性
List<PayWorkingGroupSubItem> listCompanyAndContactsNew = listCompanyAndContacts.stream().filter(item -> Objects.equals(p.getChargeCompanyTemporaryName(), item.getChargeCompanyTemporaryName())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(listCompanyAndContactsNew)) {
msg.append("").append(count + 3).append(" 行:工作组成员单位重复出现,请修改。</br>");
}
listCompanyAndContacts.add(p);
// 校验
if (Objects.equals(p.getChargeWay(), PayProjectCommon.CHARGE_WAY2)) {
if (Objects.isNull(p.getReceivableAmount())) {
msg.append("").append(count + 3).append(" 行:应收金额不能为空,请修改。</br>");
}
if (StringUtils.isBlank(p.getContractNum())) {
msg.append("").append(count + 3).append(" 行:合同号不能为空,请修改。</br>");
}
}
if (Objects.equals(p.getChargeWay(), PayProjectCommon.CHARGE_WAY3)) {
if (Objects.isNull(p.getChargeNoticeNo())) {
msg.append("").append(count + 3).append(" 行:收费通知号不能为空,请修改。</br>");
} 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(" 行:收费通知号不存在,请修改。</br>");
}
}
if (Objects.isNull(p.getReceivableAmount())) {
msg.append("").append(count + 3).append(" 行:应收金额不能为空,请修改。</br>");
}
}
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<PayWorkingGro
e.printStackTrace();
}
}
if(!StringUtils.isBlank(msg)){
throw new JeroBootException(msg.toString());
}
}
}