update 功能安全中心成员单位导入

This commit is contained in:
lijiarao
2024-07-04 15:06:23 +08:00
parent 9f79d887eb
commit 3009127bdf
5 changed files with 209 additions and 9 deletions
@@ -12,6 +12,7 @@ import com.jero.common.system.query.QueryGenerator;
import com.jero.drafting.entity.PayDraftingGroupSubItem; import com.jero.drafting.entity.PayDraftingGroupSubItem;
import com.jero.functionalsafetycenter.entity.SafetyCenterSubitem; import com.jero.functionalsafetycenter.entity.SafetyCenterSubitem;
import com.jero.functionalsafetycenter.service.SafetyCenterSubitemService; import com.jero.functionalsafetycenter.service.SafetyCenterSubitemService;
import com.jero.functionalsafetycenter.vo.SafetyCenterSubitemImport;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -175,7 +176,15 @@ public class SafetyCenterSubitemController extends JeroController<SafetyCenterSu
@ApiOperation(value = "功能安全中心成员-通过excel导入数据") @ApiOperation(value = "功能安全中心成员-通过excel导入数据")
@PostMapping(value = "/importExcel") @PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
List<Object> excelData = super.getExcelData(request, SafetyCenterSubitem.class); String projectId = request.getParameter("projectId");
if (StringUtils.isBlank(projectId)){
throw new JeroBootException(Result.NULL_ID);
}
List<Object> excelData = super.getExcelData(request, SafetyCenterSubitemImport.class);
if (excelData.isEmpty()) {
throw new JeroBootException(Result.NULL_DATA);
}
safetyCenterSubitemService.importExcelData(projectId,excelData);
return super.importExcel(request, response, SafetyCenterSubitem.class); return super.importExcel(request, response, SafetyCenterSubitem.class);
} }
@@ -71,6 +71,7 @@ public class SafetyCenterSubitem {
*/ */
@TableField(value = "remarks") @TableField(value = "remarks")
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
@Excel(name = "备注")
private String remarks; private String remarks;
/** /**
@@ -5,11 +5,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.exception.JeroBootException; import com.jero.common.exception.JeroBootException;
import com.jero.company.entity.PayCompanyManagement;
import com.jero.company.entity.PayContactsManagement;
import com.jero.company.service.IPayCompanyManagementService;
import com.jero.company.service.IPayContactsManagementService;
import com.jero.functionalsafetycenter.common.SafetyCenterCommon; import com.jero.functionalsafetycenter.common.SafetyCenterCommon;
import com.jero.functionalsafetycenter.entity.SafetyCenter; import com.jero.functionalsafetycenter.entity.SafetyCenter;
import com.jero.functionalsafetycenter.entity.SafetyCenterSubitemContacts; import com.jero.functionalsafetycenter.entity.SafetyCenterSubitemContacts;
import com.jero.functionalsafetycenter.vo.SafetyCenterSubitemContactsImport;
import com.jero.functionalsafetycenter.vo.SafetyCenterSubitemImport;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -33,6 +41,10 @@ public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemM
private SafetyCenterService safetyCenterService; private SafetyCenterService safetyCenterService;
@Resource @Resource
private SafetyCenterSubitemContactsService contactsService; private SafetyCenterSubitemContactsService contactsService;
@Resource
private IPayCompanyManagementService payCompanyManagementService;
@Resource
private IPayContactsManagementService payContactsManagementService;
public void add(SafetyCenterSubitem safetyCenterSubitem) { public void add(SafetyCenterSubitem safetyCenterSubitem) {
String projectId = safetyCenterSubitem.getProjectId(); String projectId = safetyCenterSubitem.getProjectId();
@@ -42,11 +54,14 @@ public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemM
} }
//判重,公司是否重复 //判重,公司是否重复
String companyId = safetyCenterSubitem.getCompanyId(); String companyId = safetyCenterSubitem.getCompanyId();
PayCompanyManagement companyManagement = payCompanyManagementService.getById(companyId);
String companyName = companyManagement.getCompanyName();
LambdaQueryWrapper<SafetyCenterSubitem> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SafetyCenterSubitem> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SafetyCenterSubitem::getProjectId,projectId); wrapper.eq(SafetyCenterSubitem::getProjectId,projectId);
wrapper.eq(SafetyCenterSubitem::getCompanyId,companyId); wrapper.eq(SafetyCenterSubitem::getCompanyId,companyId);
if (this.count(wrapper) > 0){ if (this.count(wrapper) > 0){
throw new JeroBootException("成员单位已经存在"); throw new JeroBootException("当前项目中已经存在,成员单位:"+companyName+"");
} }
//判重,联系人是否重复 //判重,联系人是否重复
List<SafetyCenterSubitemContacts> contactsList = safetyCenterSubitem.getContactsList(); List<SafetyCenterSubitemContacts> contactsList = safetyCenterSubitem.getContactsList();
@@ -67,14 +82,21 @@ public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemM
wrapper1.eq(SafetyCenterSubitem::getCompanyId,companyId); wrapper1.eq(SafetyCenterSubitem::getCompanyId,companyId);
SafetyCenterSubitem parentCenterSubitem = this.getOne(wrapper1); SafetyCenterSubitem parentCenterSubitem = this.getOne(wrapper1);
if (parentCenterSubitem == null){ if (parentCenterSubitem == null){
throw new JeroBootException("该成员单位无法添加到当前项目"); throw new JeroBootException("成员单位:"+ companyName +",无法添加到当前项目");
} }
//判断联系人 //判断联系人
String parentCenterSubitemId = parentCenterSubitem.getId(); String parentCenterSubitemId = parentCenterSubitem.getId();
List<SafetyCenterSubitemContacts> parentContactList = contactsService.listBySubitemId(parentCenterSubitemId); List<SafetyCenterSubitemContacts> parentContactList = contactsService.listBySubitemId(parentCenterSubitemId);
List<String> parentContactIdList = parentContactList.stream().map(SafetyCenterSubitemContacts::getContactsId).distinct().collect(Collectors.toList()); List<String> parentContactIdList = parentContactList.stream().map(SafetyCenterSubitemContacts::getContactsId).distinct().collect(Collectors.toList());
if (!parentContactIdList.containsAll(contactIdList)) { List<String> contactNameList = new ArrayList<>();
throw new JeroBootException("联系人无法添加到当前项目"); for (String contactId : contactIdList) {
if (!parentContactIdList.contains(contactId)){
PayContactsManagement contactsManagement = payContactsManagementService.getById(contactId);
contactNameList.add(contactsManagement.getName());
}
}
if (!contactNameList.isEmpty()){
throw new JeroBootException("企业联系人:"+ String.join(",",contactNameList) +",无法添加到当前项目");
} }
} }
//保存成员 //保存成员
@@ -99,12 +121,15 @@ public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemM
//判重,公司是否重复 //判重,公司是否重复
String companyId = safetyCenterSubitem.getCompanyId(); String companyId = safetyCenterSubitem.getCompanyId();
PayCompanyManagement companyManagement = payCompanyManagementService.getById(companyId);
String companyName = companyManagement.getCompanyName();
LambdaQueryWrapper<SafetyCenterSubitem> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SafetyCenterSubitem> wrapper = new LambdaQueryWrapper<>();
wrapper.ne(SafetyCenterSubitem::getId,subitemId); wrapper.ne(SafetyCenterSubitem::getId,subitemId);
wrapper.eq(SafetyCenterSubitem::getProjectId,projectId); wrapper.eq(SafetyCenterSubitem::getProjectId,projectId);
wrapper.eq(SafetyCenterSubitem::getCompanyId,companyId); wrapper.eq(SafetyCenterSubitem::getCompanyId,companyId);
if (this.count(wrapper) > 0){ if (this.count(wrapper) > 0){
throw new JeroBootException("成员单位已经存在"); throw new JeroBootException("当前项目中已经存在,成员单位:"+companyName+"");
} }
//判重,联系人是否重复 //判重,联系人是否重复
List<SafetyCenterSubitemContacts> contactsList = safetyCenterSubitem.getContactsList(); List<SafetyCenterSubitemContacts> contactsList = safetyCenterSubitem.getContactsList();
@@ -125,14 +150,21 @@ public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemM
wrapper1.eq(SafetyCenterSubitem::getCompanyId,companyId); wrapper1.eq(SafetyCenterSubitem::getCompanyId,companyId);
SafetyCenterSubitem parentCenterSubitem = this.getOne(wrapper1); SafetyCenterSubitem parentCenterSubitem = this.getOne(wrapper1);
if (parentCenterSubitem == null){ if (parentCenterSubitem == null){
throw new JeroBootException("该成员单位无法添加到当前项目"); throw new JeroBootException("成员单位:"+ companyName +",无法添加到当前项目");
} }
//判断联系人 //判断联系人
String parentCenterSubitemId = parentCenterSubitem.getId(); String parentCenterSubitemId = parentCenterSubitem.getId();
List<SafetyCenterSubitemContacts> parentContactList = contactsService.listBySubitemId(parentCenterSubitemId); List<SafetyCenterSubitemContacts> parentContactList = contactsService.listBySubitemId(parentCenterSubitemId);
List<String> parentContactIdList = parentContactList.stream().map(SafetyCenterSubitemContacts::getContactsId).distinct().collect(Collectors.toList()); List<String> parentContactIdList = parentContactList.stream().map(SafetyCenterSubitemContacts::getContactsId).distinct().collect(Collectors.toList());
if (!parentContactIdList.containsAll(contactIdList)) { List<String> contactNameList = new ArrayList<>();
throw new JeroBootException("联系人无法添加到当前项目"); for (String contactId : contactIdList) {
if (!parentContactIdList.contains(contactId)){
PayContactsManagement contactsManagement = payContactsManagementService.getById(contactId);
contactNameList.add(contactsManagement.getName());
}
}
if (!contactNameList.isEmpty()){
throw new JeroBootException("企业联系人:"+ String.join(",",contactNameList) +",无法添加到当前项目");
} }
//区分删除的联系人 //区分删除的联系人
List<SafetyCenterSubitemContacts> oldContactList = contactsService.listBySubitemId(subitemId); List<SafetyCenterSubitemContacts> oldContactList = contactsService.listBySubitemId(subitemId);
@@ -233,4 +265,92 @@ public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemM
deleteChildrenByParentId(projectId,contactIdList); deleteChildrenByParentId(projectId,contactIdList);
} }
} }
/**
* 导入数据
* @param projectId
* @param excelData
*/
public void importExcelData(String projectId, List<Object> excelData) {
SafetyCenter safetyCenter = safetyCenterService.getById(projectId);
if (safetyCenter == null){
throw new JeroBootException("项目不存在");
}
List<String> errorMessage = new ArrayList<>();
List<String> companyNameList = new ArrayList<>();
int errorRowNum = 3;
int errorRowNum2 = 3;
for (Object obj : excelData) {
errorRowNum += 1;
SafetyCenterSubitemImport subitemImport = (SafetyCenterSubitemImport) obj;
String companyName = subitemImport.getCompanyName();
List<SafetyCenterSubitemContactsImport> contactsList = subitemImport.getContactsList();
if (errorRowNum != 4){
errorRowNum += contactsList.size() -1;
}
PayCompanyManagement company = null;
if (StringUtils.isBlank(companyName)){
errorMessage.add("第" + errorRowNum + "行:成员单位不能为空");
continue;
}else {
company = payCompanyManagementService.getCompanyByName(companyName);
if (company == null){
errorMessage.add("第" + errorRowNum + "行:成员单位不存在");
errorRowNum2 += contactsList.size();
continue;
}
if (companyNameList.contains(companyName)) {
errorMessage.add("第" + errorRowNum + "行:成员单位重复");
errorRowNum2 += contactsList.size();
continue;
}else {
companyNameList.add(companyName);
}
}
String companyId = company.getId();
List<String> distinctContactsList = new ArrayList<>();
List<SafetyCenterSubitemContacts> subitemContactsList = new ArrayList<>();
for (SafetyCenterSubitemContactsImport contactsImport : contactsList) {
errorRowNum2 += 1;
String contacts = contactsImport.getContacts();
if (StringUtils.isBlank(contacts)){
errorMessage.add("第" + errorRowNum2 + "行:企业联系人不能为空");
continue;
}
PayContactsManagement payContactsManagement = payContactsManagementService.checkByCompanyIdAndName(contacts, companyId);
if (payContactsManagement == null){
errorMessage.add("第" + errorRowNum2 + "行:企业联系人不存在");
continue;
}
if (distinctContactsList.contains(contacts)){
errorMessage.add("第" + errorRowNum + "行:企业联系人重复");
continue;
}else {
distinctContactsList.add(contacts);
}
SafetyCenterSubitemContacts contacts1 = new SafetyCenterSubitemContacts();
contacts1.setContactsId(payContactsManagement.getId());
subitemContactsList.add(contacts1);
}
SafetyCenterSubitem subitem = new SafetyCenterSubitem();
subitem.setProjectId(projectId);
subitem.setCompanyId(companyId);
subitem.setRemarks(subitemImport.getRemarks());
subitem.setContactsList(subitemContactsList);
try {
this.add(subitem);
}catch (JeroBootException e){
log.error("",e);
errorMessage.add(e.getMessage());
}
}
if (!errorMessage.isEmpty()){
StringBuilder msg = new StringBuilder();
for (String s : errorMessage) {
msg.append(s).append(",请修改!<br/>");
}
throw new JeroBootException(msg.toString());
}
}
} }
@@ -0,0 +1,31 @@
package com.jero.functionalsafetycenter.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
/**
* 功能安全中心成员-联系人
*
* @author liJiaRao
* @date 2024-06-12 15:13
*/
@Data
public class SafetyCenterSubitemContactsImport {
/**
* 企业联系人
*/
@ApiModelProperty(value = "企业联系人")
@Excel(name = "企业联系人")
private String contacts;
/**
* 备注
*/
@ApiModelProperty(value = "备注")
@Excel(name = "备注")
private String remarks;
}
@@ -0,0 +1,39 @@
package com.jero.functionalsafetycenter.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
import java.util.List;
/**
* 功能安全中心成员
*
* @author liJiaRao
* @date 2024-06-12 16:40
*/
@Data
public class SafetyCenterSubitemImport {
/**
* 成员单位
*/
@ApiModelProperty(value = "成员单位")
@Excel(name = "成员单位")
private String companyName;
/**
* 企业联系人列表
*/
@ApiModelProperty(value = "企业联系人列表")
@ExcelCollection(name = "企业联系人列表")
private List<SafetyCenterSubitemContactsImport> contactsList;
/**
* 备注
*/
@ApiModelProperty(value = "备注")
private String remarks;
}