|
@@ -15,6 +15,10 @@ import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.ListUtil;
|
|
|
import com.management.platform.util.WorkDayCalculateUtils;
|
|
|
import org.apache.poi.EncryptedDocumentException;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.CellType;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
@@ -2219,195 +2223,470 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
}
|
|
|
inputStream.close();
|
|
|
outputStream.close();
|
|
|
- //然后解析表格
|
|
|
- XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
- //我们只需要第一个sheet
|
|
|
- XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
- //获取全部人员
|
|
|
- List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId()));
|
|
|
- List<Project> projectList = new ArrayList<Project>();
|
|
|
- //由于第一行需要指明列对应的标题
|
|
|
- int rowNum = sheet.getLastRowNum();
|
|
|
-
|
|
|
- HashMap<String, Integer> projectLevelMap = new HashMap<>();
|
|
|
- projectLevelMap.put("正常", 1);
|
|
|
- projectLevelMap.put("紧急", 2);
|
|
|
- projectLevelMap.put("重要", 3);
|
|
|
- projectLevelMap.put("重要且紧急", 4);
|
|
|
- projectLevelMap.put("低风险", 5);
|
|
|
- projectLevelMap.put("中风险", 6);
|
|
|
- projectLevelMap.put("高风险", 7);
|
|
|
- List<String> existCodeList = new ArrayList<>();
|
|
|
- int importCount = 0;
|
|
|
- for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
- XSSFRow row = sheet.getRow(rowIndex);
|
|
|
- if (row == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- //跳过空行
|
|
|
- if (ExcelUtil.isRowEmpty(row)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- //项目编号 项目名称 参与人 负责人 级别 开始日期 截止日期 合同金额
|
|
|
- XSSFCell codeCell = row.getCell(0);
|
|
|
- XSSFCell categoryCell = row.getCell(1);
|
|
|
- XSSFCell isPublicCell = row.getCell(2);
|
|
|
- XSSFCell nameCell = row.getCell(3);
|
|
|
- XSSFCell subNameCell = row.getCell(4);
|
|
|
- XSSFCell participatorCell = row.getCell(5);
|
|
|
- XSSFCell inchargerCell = row.getCell(6);
|
|
|
- XSSFCell levelCell = row.getCell(7);
|
|
|
- XSSFCell startDateCell = row.getCell(8);
|
|
|
- XSSFCell endDateCell = row.getCell(9);
|
|
|
- XSSFCell amountCell = row.getCell(10);
|
|
|
-
|
|
|
-
|
|
|
- if (codeCell != null)codeCell.setCellType(CellType.STRING);
|
|
|
- if (nameCell != null)nameCell.setCellType(CellType.STRING);
|
|
|
- if (categoryCell != null)categoryCell.setCellType(CellType.STRING);
|
|
|
- if (isPublicCell != null)isPublicCell.setCellType(CellType.STRING);
|
|
|
- if (subNameCell != null)subNameCell.setCellType(CellType.STRING);
|
|
|
- if (participatorCell != null)participatorCell.setCellType(CellType.STRING);
|
|
|
- if (inchargerCell != null)inchargerCell.setCellType(CellType.STRING);
|
|
|
- if (levelCell != null)levelCell.setCellType(CellType.STRING);
|
|
|
- if (startDateCell != null)startDateCell.setCellType(CellType.NUMERIC);
|
|
|
- if (endDateCell != null)endDateCell.setCellType(CellType.NUMERIC);
|
|
|
- if (amountCell != null)amountCell.setCellType(CellType.STRING);
|
|
|
- if (nameCell == null) {//项目名称为空的直接跳过
|
|
|
- throw new Exception("项目名称不能为空");
|
|
|
- }
|
|
|
- Project project = new Project();
|
|
|
- if (codeCell != null) {
|
|
|
- String code = codeCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
- if (code.equals("项目编号") && rowIndex == 0) {
|
|
|
- //检查是否有子项目列
|
|
|
- if (!subNameCell.getStringCellValue().trim().startsWith("子项目")) {
|
|
|
- throw new Exception("缺少子项目列,请下载最新模板");
|
|
|
- }
|
|
|
- //跳过第一行标题
|
|
|
+ if(fileName.endsWith(".xlsx")){
|
|
|
+ //然后解析表格
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
+ //我们只需要第一个sheet
|
|
|
+ XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
+ //获取全部人员
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId()));
|
|
|
+ //获取全部供货商分类列表
|
|
|
+ List<ProviderCategory> providerCategoryList = providerCategoryMapper.selectList(new QueryWrapper<ProviderCategory>().eq("company_id", user.getCompanyId()));
|
|
|
+ Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
+ //获取全部客户
|
|
|
+ List<CustomerInfo> customerInfoList = customerInfoMapper.selectList(new QueryWrapper<CustomerInfo>().eq("company_id", user.getCompanyId()));
|
|
|
+ //获取全部供货商
|
|
|
+ List<ProviderInfo> providerInfoList = providerInfoMapper.selectList(new QueryWrapper<ProviderInfo>().eq("company_id", user.getCompanyId()));
|
|
|
+ List<Project> projectList = new ArrayList<Project>();
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ HashMap<String, Integer> projectLevelMap = new HashMap<>();
|
|
|
+ projectLevelMap.put("正常", 1);
|
|
|
+ projectLevelMap.put("紧急", 2);
|
|
|
+ projectLevelMap.put("重要", 3);
|
|
|
+ projectLevelMap.put("重要且紧急", 4);
|
|
|
+ projectLevelMap.put("低风险", 5);
|
|
|
+ projectLevelMap.put("中风险", 6);
|
|
|
+ projectLevelMap.put("高风险", 7);
|
|
|
+ List<String> existCodeList = new ArrayList<>();
|
|
|
+ int importCount = 0;
|
|
|
+ for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- //检查项目是否存在
|
|
|
- List<ProjectCategory> projectCategoryList = projectCategoryMapper.selectList(new QueryWrapper<ProjectCategory>().eq("company_id", user.getCompanyId()));
|
|
|
- if (categoryCell != null && !StringUtils.isEmpty(categoryCell.getStringCellValue())) {
|
|
|
- Optional<ProjectCategory> category = projectCategoryList.stream().filter(pc -> pc.getName().equals(categoryCell.getStringCellValue())).findFirst();
|
|
|
- if(!category.isPresent()){
|
|
|
- throw new Exception("项目分类["+categoryCell.getStringCellValue()+"]不存在");
|
|
|
+ //跳过空行
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //项目编号 项目名称 参与人 负责人 级别 开始日期 截止日期 合同金额
|
|
|
+ XSSFCell codeCell = row.getCell(0);
|
|
|
+ XSSFCell categoryCell = row.getCell(1);
|
|
|
+ XSSFCell isPublicCell = row.getCell(2);
|
|
|
+ XSSFCell nameCell = row.getCell(3);
|
|
|
+ XSSFCell subNameCell = row.getCell(4);
|
|
|
+ XSSFCell participatorCell = row.getCell(5);
|
|
|
+ XSSFCell inchargerCell = row.getCell(6);
|
|
|
+ XSSFCell levelCell = row.getCell(7);
|
|
|
+ XSSFCell startDateCell = row.getCell(8);
|
|
|
+ XSSFCell endDateCell = row.getCell(9);
|
|
|
+ XSSFCell amountCell = row.getCell(10);
|
|
|
+
|
|
|
+
|
|
|
+ if (codeCell != null)codeCell.setCellType(CellType.STRING);
|
|
|
+ if (nameCell != null)nameCell.setCellType(CellType.STRING);
|
|
|
+ if (categoryCell != null)categoryCell.setCellType(CellType.STRING);
|
|
|
+ if (isPublicCell != null)isPublicCell.setCellType(CellType.STRING);
|
|
|
+ if (subNameCell != null)subNameCell.setCellType(CellType.STRING);
|
|
|
+ if (participatorCell != null)participatorCell.setCellType(CellType.STRING);
|
|
|
+ if (inchargerCell != null)inchargerCell.setCellType(CellType.STRING);
|
|
|
+ if (levelCell != null)levelCell.setCellType(CellType.STRING);
|
|
|
+ if (startDateCell != null)startDateCell.setCellType(CellType.NUMERIC);
|
|
|
+ if (endDateCell != null)endDateCell.setCellType(CellType.NUMERIC);
|
|
|
+ if (amountCell != null)amountCell.setCellType(CellType.STRING);
|
|
|
+ if (nameCell == null) {//项目名称为空的直接跳过
|
|
|
+ throw new Exception("项目名称不能为空");
|
|
|
+ }
|
|
|
+ Project project = new Project();
|
|
|
+ if (codeCell != null) {
|
|
|
+ String code = codeCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ if (code.equals("项目编号") && rowIndex == 0) {
|
|
|
+ //检查是否有子项目列
|
|
|
+ if (!subNameCell.getStringCellValue().trim().startsWith("子项目")) {
|
|
|
+ throw new Exception("缺少子项目列,请下载最新模板");
|
|
|
+ }
|
|
|
+ //跳过第一行标题
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //检查项目是否存在
|
|
|
+ List<ProjectCategory> projectCategoryList = projectCategoryMapper.selectList(new QueryWrapper<ProjectCategory>().eq("company_id", user.getCompanyId()));
|
|
|
+ if (categoryCell != null && !StringUtils.isEmpty(categoryCell.getStringCellValue())) {
|
|
|
+ Optional<ProjectCategory> category = projectCategoryList.stream().filter(pc -> pc.getName().equals(categoryCell.getStringCellValue())).findFirst();
|
|
|
+ if(!category.isPresent()){
|
|
|
+ throw new Exception("项目分类["+categoryCell.getStringCellValue()+"]不存在");
|
|
|
+ }
|
|
|
+ project.setCategory(category.get().getId());
|
|
|
+ project.setCategoryName(categoryCell.getStringCellValue());
|
|
|
+ }
|
|
|
+ //检查编号是否已经存在
|
|
|
+ if (!StringUtils.isEmpty(code)) {
|
|
|
+ int cnt = projectMapper.selectCount(new QueryWrapper<Project>().eq("project_code", code).eq("company_id", user.getCompanyId()));
|
|
|
+ if (cnt > 0) {
|
|
|
+// throw new Exception("项目编号存在重复: " + code);
|
|
|
+ existCodeList.add(code);
|
|
|
+ //跳过编号重复的数据
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ project.setProjectCode(code);
|
|
|
+ }
|
|
|
+ String name = nameCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ project.setCompanyId(user.getCompanyId());
|
|
|
+ project.setCreatorId(userId);
|
|
|
+ project.setCreatorName(user.getName());
|
|
|
+ project.setProjectName(name);
|
|
|
+
|
|
|
+ //处理人员
|
|
|
+ if (inchargerCell != null) {
|
|
|
+ String inchargerName = inchargerCell.getStringCellValue().trim();
|
|
|
+ if (!StringUtils.isEmpty(inchargerName)) {
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(inchargerName)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ project.setInchargerId(first.get().getId());
|
|
|
+ project.setInchargerName(inchargerName);
|
|
|
+ } else {
|
|
|
+ throw new Exception("项目负责人["+inchargerName+"]不存在");
|
|
|
+ }
|
|
|
}
|
|
|
- project.setCategory(category.get().getId());
|
|
|
- project.setCategoryName(categoryCell.getStringCellValue());
|
|
|
}
|
|
|
|
|
|
|
|
|
- //检查编号是否已经存在
|
|
|
- if (!StringUtils.isEmpty(code)) {
|
|
|
- int cnt = projectMapper.selectCount(new QueryWrapper<Project>().eq("project_code", code).eq("company_id", user.getCompanyId()));
|
|
|
- if (cnt > 0) {
|
|
|
-// throw new Exception("项目编号存在重复: " + code);
|
|
|
- existCodeList.add(code);
|
|
|
- //跳过编号重复的数据
|
|
|
- continue;
|
|
|
+ if (levelCell != null) {
|
|
|
+ String levelStr = levelCell.getStringCellValue();
|
|
|
+ if (!StringUtils.isEmpty(levelStr)) {
|
|
|
+ project.setLevel(projectLevelMap.get(levelStr));
|
|
|
}
|
|
|
}
|
|
|
- project.setProjectCode(code);
|
|
|
- }
|
|
|
- String name = nameCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
- project.setCompanyId(user.getCompanyId());
|
|
|
- project.setCreatorId(userId);
|
|
|
- project.setCreatorName(user.getName());
|
|
|
- project.setProjectName(name);
|
|
|
-
|
|
|
- //处理人员
|
|
|
- if (inchargerCell != null) {
|
|
|
- String inchargerName = inchargerCell.getStringCellValue().trim();
|
|
|
- if (!StringUtils.isEmpty(inchargerName)) {
|
|
|
- Optional<User> first = userList.stream().filter(u -> u.getName().equals(inchargerName)).findFirst();
|
|
|
- if (first.isPresent()) {
|
|
|
- project.setInchargerId(first.get().getId());
|
|
|
- project.setInchargerName(inchargerName);
|
|
|
- } else {
|
|
|
- throw new Exception("项目负责人["+inchargerName+"]不存在");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ if (startDateCell !=null && !StringUtils.isEmpty(startDateCell.getDateCellValue())) {
|
|
|
+ project.setPlanStartDate(LocalDate.parse(sdf.format(startDateCell.getDateCellValue()), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+ }
|
|
|
+ if (endDateCell !=null && !StringUtils.isEmpty(endDateCell.getDateCellValue())) {
|
|
|
+ project.setPlanEndDate(LocalDate.parse(sdf.format(endDateCell.getDateCellValue()), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+ }
|
|
|
+ if (amountCell !=null && !StringUtils.isEmpty(amountCell.getStringCellValue())) {
|
|
|
+ project.setContractAmount(Double.parseDouble(amountCell.getStringCellValue()));
|
|
|
+ }
|
|
|
+ if (isPublicCell != null && !StringUtils.isEmpty(isPublicCell.getStringCellValue())) {
|
|
|
+ project.setIsPublic("是".equals(isPublicCell.getStringCellValue())?1:0);
|
|
|
+ }
|
|
|
+ if(projectMapper.insert(project)>0){
|
|
|
+ ProjectAuditor projectAuditor=new ProjectAuditor();
|
|
|
+ projectAuditor.setAuditorId(project.getInchargerId());
|
|
|
+ projectAuditor.setAuditorName(project.getInchargerName());
|
|
|
+ projectAuditor.setProjectId(project.getId());
|
|
|
+ projectAuditorMapper.insert(projectAuditor);
|
|
|
+ }
|
|
|
+ importCount++;
|
|
|
+ //处理子项目
|
|
|
+ if (subNameCell != null) {
|
|
|
+ //兼容中英文逗号
|
|
|
+ String[] subNames = subNameCell.getStringCellValue().trim().split(",|\\,");
|
|
|
+ if (subNames != null) {
|
|
|
+ for (String s : subNames) {
|
|
|
+ if (!StringUtils.isEmpty(s)) {
|
|
|
+ SubProject sp = new SubProject();
|
|
|
+ sp.setName(s);
|
|
|
+ sp.setProjectId(project.getId());
|
|
|
+ subProjectMapper.insert(sp);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (levelCell != null) {
|
|
|
- String levelStr = levelCell.getStringCellValue();
|
|
|
- if (!StringUtils.isEmpty(levelStr)) {
|
|
|
- project.setLevel(projectLevelMap.get(levelStr));
|
|
|
+ //参与人
|
|
|
+ if (participatorCell != null) {
|
|
|
+ String part = participatorCell.getStringCellValue().trim();
|
|
|
+ //将项目负责人也添加到参与人当中来
|
|
|
+ String incharger = inchargerCell.getStringCellValue().trim();
|
|
|
+ if (!StringUtils.isEmpty(part)) {
|
|
|
+ String[] partSplit = part.split("\\,|\\,");
|
|
|
+ if(!StringUtils.isEmpty(incharger)){
|
|
|
+ String[] inchargerSplit = incharger.split("\\,|\\,");
|
|
|
+ int strLen1 = partSplit.length;// 保存第一个数组长度
|
|
|
+ int strLen2 = inchargerSplit.length;
|
|
|
+ partSplit=Arrays.copyOf(partSplit, strLen1+strLen2);
|
|
|
+ System.arraycopy(inchargerSplit, 0, partSplit, strLen1, strLen2);
|
|
|
+ }
|
|
|
+ for (String str : partSplit) {
|
|
|
+ Participation p = new Participation();
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(str)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ p.setUserId(first.get().getId());
|
|
|
+ p.setProjectId(project.getId());
|
|
|
+ participationMapper.insert(p);
|
|
|
+ } else {
|
|
|
+ projectMapper.deleteById(project.getId());
|
|
|
+ throw new Exception("参与人["+str+"]不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- if (startDateCell !=null && !StringUtils.isEmpty(startDateCell.getDateCellValue())) {
|
|
|
- project.setPlanStartDate(LocalDate.parse(sdf.format(startDateCell.getDateCellValue()), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
- }
|
|
|
- if (endDateCell !=null && !StringUtils.isEmpty(endDateCell.getDateCellValue())) {
|
|
|
- project.setPlanEndDate(LocalDate.parse(sdf.format(endDateCell.getDateCellValue()), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
- }
|
|
|
- if (amountCell !=null && !StringUtils.isEmpty(amountCell.getStringCellValue())) {
|
|
|
- project.setContractAmount(Double.parseDouble(amountCell.getStringCellValue()));
|
|
|
- }
|
|
|
- if (isPublicCell != null && !StringUtils.isEmpty(isPublicCell.getStringCellValue())) {
|
|
|
- project.setIsPublic("是".equals(isPublicCell.getStringCellValue())?1:0);
|
|
|
- }
|
|
|
- if(projectMapper.insert(project)>0){
|
|
|
- ProjectAuditor projectAuditor=new ProjectAuditor();
|
|
|
- projectAuditor.setAuditorId(project.getInchargerId());
|
|
|
- projectAuditor.setAuditorName(project.getInchargerName());
|
|
|
- projectAuditor.setProjectId(project.getId());
|
|
|
- projectAuditorMapper.insert(projectAuditor);
|
|
|
- }
|
|
|
- importCount++;
|
|
|
- //处理子项目
|
|
|
- if (subNameCell != null) {
|
|
|
- //兼容中英文逗号
|
|
|
- String[] subNames = subNameCell.getStringCellValue().trim().split(",|\\,");
|
|
|
- if (subNames != null) {
|
|
|
- for (String s : subNames) {
|
|
|
- if (!StringUtils.isEmpty(s)) {
|
|
|
- SubProject sp = new SubProject();
|
|
|
- sp.setName(s);
|
|
|
- sp.setProjectId(project.getId());
|
|
|
- subProjectMapper.insert(sp);
|
|
|
+ msg.data = "成功导入"+importCount+"条数据。";
|
|
|
+ if (existCodeList.size() > 0) {
|
|
|
+ String collect = existCodeList.stream().collect(Collectors.joining(","));
|
|
|
+ msg.data += "自动跳过"+existCodeList.size()+"条已存在项目编码:"+collect;
|
|
|
+ }
|
|
|
+ }else if(fileName.endsWith(".xls")){
|
|
|
+ //然后解析表格
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(file));
|
|
|
+ //我们只需要第一个sheet
|
|
|
+ HSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
+ //获取全部人员
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId()));
|
|
|
+ //获取全部供货商分类列表
|
|
|
+ List<ProviderCategory> providerCategoryList = providerCategoryMapper.selectList(new QueryWrapper<ProviderCategory>().eq("company_id", user.getCompanyId()));
|
|
|
+ Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
+ //获取全部客户
|
|
|
+ List<CustomerInfo> customerInfoList = customerInfoMapper.selectList(new QueryWrapper<CustomerInfo>().eq("company_id", user.getCompanyId()));
|
|
|
+ //获取全部供货商
|
|
|
+ List<ProviderInfo> providerInfoList = providerInfoMapper.selectList(new QueryWrapper<ProviderInfo>().eq("company_id", user.getCompanyId()));
|
|
|
+ List<Project> projectList = new ArrayList<Project>();
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ HashMap<String, Integer> projectLevelMap = new HashMap<>();
|
|
|
+ projectLevelMap.put("正常", 1);
|
|
|
+ projectLevelMap.put("紧急", 2);
|
|
|
+ projectLevelMap.put("重要", 3);
|
|
|
+ projectLevelMap.put("重要且紧急", 4);
|
|
|
+ projectLevelMap.put("低风险", 5);
|
|
|
+ projectLevelMap.put("中风险", 6);
|
|
|
+ projectLevelMap.put("高风险", 7);
|
|
|
+ List<String> existCodeList = new ArrayList<>();
|
|
|
+ int importCount = 0;
|
|
|
+ for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
+ HSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //跳过空行
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //项目编号 项目名称 参与人 负责人 级别 开始日期 截止日期 合同金额
|
|
|
+ HSSFCell codeCell = row.getCell(0);
|
|
|
+ HSSFCell categoryCell = row.getCell(1);
|
|
|
+ HSSFCell isPublicCell = row.getCell(2);
|
|
|
+ HSSFCell nameCell = row.getCell(3);
|
|
|
+ HSSFCell subNameCell = row.getCell(4);
|
|
|
+ HSSFCell participatorCell = row.getCell(5);
|
|
|
+ HSSFCell inchargerCell = row.getCell(6);
|
|
|
+ HSSFCell levelCell = row.getCell(7);
|
|
|
+ HSSFCell customerCell=null;
|
|
|
+ int i=0;
|
|
|
+ int k=0;
|
|
|
+ if(company.getPackageCustomer()==1){
|
|
|
+ customerCell=row.getCell(8);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ if(company.getPackageProvider()==1){
|
|
|
+ for (int j = 0; j < providerCategoryList.size(); j++) {
|
|
|
+ if(company.getPackageProvider()==1){
|
|
|
+ k++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- //参与人
|
|
|
- if (participatorCell != null) {
|
|
|
- String part = participatorCell.getStringCellValue().trim();
|
|
|
- //将项目负责人也添加到参与人当中来
|
|
|
- String incharger = inchargerCell.getStringCellValue().trim();
|
|
|
- if (!StringUtils.isEmpty(part)) {
|
|
|
- String[] partSplit = part.split("\\,|\\,");
|
|
|
- if(!StringUtils.isEmpty(incharger)){
|
|
|
- String[] inchargerSplit = incharger.split("\\,|\\,");
|
|
|
- int strLen1 = partSplit.length;// 保存第一个数组长度
|
|
|
- int strLen2 = inchargerSplit.length;
|
|
|
- partSplit=Arrays.copyOf(partSplit, strLen1+strLen2);
|
|
|
- System.arraycopy(inchargerSplit, 0, partSplit, strLen1, strLen2);
|
|
|
+ HSSFCell startDateCell = row.getCell(8+i+k);
|
|
|
+ HSSFCell endDateCell = row.getCell(9+i+k);
|
|
|
+ HSSFCell amountCell = row.getCell(10+i+k);
|
|
|
+
|
|
|
+
|
|
|
+ if (codeCell != null)codeCell.setCellType(CellType.STRING);
|
|
|
+ if (nameCell != null)nameCell.setCellType(CellType.STRING);
|
|
|
+ if (categoryCell != null)categoryCell.setCellType(CellType.STRING);
|
|
|
+ if (isPublicCell != null)isPublicCell.setCellType(CellType.STRING);
|
|
|
+ if (subNameCell != null)subNameCell.setCellType(CellType.STRING);
|
|
|
+ if (participatorCell != null)participatorCell.setCellType(CellType.STRING);
|
|
|
+ if (inchargerCell != null)inchargerCell.setCellType(CellType.STRING);
|
|
|
+ if (levelCell != null)levelCell.setCellType(CellType.STRING);
|
|
|
+ if (customerCell != null)customerCell.setCellType(CellType.STRING);
|
|
|
+ /*if (startDateCell != null)startDateCell.setCellType(CellType.NUMERIC);
|
|
|
+ if (endDateCell != null)endDateCell.setCellType(CellType.NUMERIC);*/
|
|
|
+ if (amountCell != null)amountCell.setCellType(CellType.STRING);
|
|
|
+ if (nameCell == null) {//项目名称为空的直接跳过
|
|
|
+ throw new Exception("项目名称不能为空");
|
|
|
+ }
|
|
|
+ Project project = new Project();
|
|
|
+ if (codeCell != null) {
|
|
|
+ String code = codeCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ if (code.equals("项目编号") && rowIndex == 0) {
|
|
|
+ //检查是否有子项目列
|
|
|
+ if (!subNameCell.getStringCellValue().trim().startsWith("子项目")) {
|
|
|
+ throw new Exception("缺少子项目列,请下载最新模板");
|
|
|
+ }
|
|
|
+ //跳过第一行标题
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //检查项目是否存在
|
|
|
+ List<ProjectCategory> projectCategoryList = projectCategoryMapper.selectList(new QueryWrapper<ProjectCategory>().eq("company_id", user.getCompanyId()));
|
|
|
+ if (categoryCell != null && !StringUtils.isEmpty(categoryCell.getStringCellValue())) {
|
|
|
+ Optional<ProjectCategory> category = projectCategoryList.stream().filter(pc -> pc.getName().equals(categoryCell.getStringCellValue())).findFirst();
|
|
|
+ if(!category.isPresent()){
|
|
|
+ throw new Exception("项目分类["+categoryCell.getStringCellValue()+"]不存在");
|
|
|
+ }
|
|
|
+ project.setCategory(category.get().getId());
|
|
|
+ project.setCategoryName(categoryCell.getStringCellValue());
|
|
|
+ }
|
|
|
+ //检查编号是否已经存在
|
|
|
+ if (!StringUtils.isEmpty(code)) {
|
|
|
+ int cnt = projectMapper.selectCount(new QueryWrapper<Project>().eq("project_code", code).eq("company_id", user.getCompanyId()));
|
|
|
+ if (cnt > 0) {
|
|
|
+// throw new Exception("项目编号存在重复: " + code);
|
|
|
+ existCodeList.add(code);
|
|
|
+ //跳过编号重复的数据
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
- for (String str : partSplit) {
|
|
|
- Participation p = new Participation();
|
|
|
- Optional<User> first = userList.stream().filter(u -> u.getName().equals(str)).findFirst();
|
|
|
+ project.setProjectCode(code);
|
|
|
+ }
|
|
|
+ String name = nameCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ project.setCompanyId(user.getCompanyId());
|
|
|
+ project.setCreatorId(userId);
|
|
|
+ project.setCreatorName(user.getName());
|
|
|
+ project.setProjectName(name);
|
|
|
+
|
|
|
+ //处理人员
|
|
|
+ if (inchargerCell != null) {
|
|
|
+ String inchargerName = inchargerCell.getStringCellValue().trim();
|
|
|
+ if (!StringUtils.isEmpty(inchargerName)) {
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(inchargerName)).findFirst();
|
|
|
if (first.isPresent()) {
|
|
|
- p.setUserId(first.get().getId());
|
|
|
- p.setProjectId(project.getId());
|
|
|
- participationMapper.insert(p);
|
|
|
+ project.setInchargerId(first.get().getId());
|
|
|
+ project.setInchargerName(inchargerName);
|
|
|
} else {
|
|
|
- projectMapper.deleteById(project.getId());
|
|
|
- throw new Exception("参与人["+str+"]不存在");
|
|
|
+ throw new Exception("项目负责人["+inchargerName+"]不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (levelCell != null) {
|
|
|
+ String levelStr = levelCell.getStringCellValue();
|
|
|
+ if (!StringUtils.isEmpty(levelStr)) {
|
|
|
+ project.setLevel(projectLevelMap.get(levelStr));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(customerCell!=null){
|
|
|
+ String cellStringCellValue = customerCell.getStringCellValue();
|
|
|
+ if(!StringUtils.isEmpty(cellStringCellValue)){
|
|
|
+ Optional<CustomerInfo> first = customerInfoList.stream().filter(ci -> ci.getCustomerName().equals(cellStringCellValue)).findFirst();
|
|
|
+ if(!first.isPresent()){
|
|
|
+ msg.setError("客户["+cellStringCellValue+"]不存在");
|
|
|
+ return msg;
|
|
|
+ }else {
|
|
|
+ project.setCustomerId(first.get().getId());
|
|
|
+ project.setCustomerName(first.get().getCustomerName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(company.getPackageProvider()==1){
|
|
|
+ String nameString = "";
|
|
|
+ String idString = "";
|
|
|
+ HSSFCell providerCell;
|
|
|
+ for (int j = 0; j < providerCategoryList.size(); j++) {
|
|
|
+ String nameSb = "";
|
|
|
+ String idSb = "";
|
|
|
+ providerCell=row.getCell(8+i);
|
|
|
+ HSSFCell cell = row.getCell(10);
|
|
|
+ if(providerCell!=null){
|
|
|
+ providerCell.setCellType(CellType.STRING);
|
|
|
+ String stringCellValue = providerCell.getStringCellValue();
|
|
|
+ if(!StringUtils.isEmpty(stringCellValue)){
|
|
|
+ String[] split = stringCellValue.split(",");
|
|
|
+ for (int i1 = 0; i1 < split.length; i1++) {
|
|
|
+ int finalJ = j;
|
|
|
+ int finalI = i1;
|
|
|
+ Optional<ProviderInfo> first = providerInfoList.stream().filter(pd -> pd.getProviderName().equals(split[finalI])&&pd.getProviderCategoryId().equals(providerCategoryList.get(finalJ).getId())).findFirst();
|
|
|
+ if(!first.isPresent()){
|
|
|
+ msg.setError("供应商["+split[i1]+"]在供应商分类["+providerCategoryList.get(j).getProviderCategoryName()+"]不存在");
|
|
|
+ return msg;
|
|
|
+ }else {
|
|
|
+ if(i1==split.length-1){
|
|
|
+ nameSb+=first.get().getProviderName();
|
|
|
+ idSb+=first.get().getId();
|
|
|
+ }else {
|
|
|
+ nameSb+=first.get().getProviderName()+",";
|
|
|
+ idSb+=first.get().getId()+",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }else {
|
|
|
+ i++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(j==providerCategoryList.size()-1){
|
|
|
+ nameString+=nameSb;
|
|
|
+ idString+=idSb;
|
|
|
+ }else {
|
|
|
+ nameString+=nameSb+",";
|
|
|
+ idString+=idSb+",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ project.setProviderIds(idString);
|
|
|
+ project.setProviderNames(nameString);
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ if (startDateCell !=null && !StringUtils.isEmpty(startDateCell.getDateCellValue())) {
|
|
|
+ project.setPlanStartDate(LocalDate.parse(sdf.format(startDateCell.getDateCellValue()), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+ }
|
|
|
+ if (endDateCell !=null && !StringUtils.isEmpty(endDateCell.getDateCellValue())) {
|
|
|
+ project.setPlanEndDate(LocalDate.parse(sdf.format(endDateCell.getDateCellValue()), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+ }
|
|
|
+ if (amountCell !=null && !StringUtils.isEmpty(amountCell.getStringCellValue())) {
|
|
|
+ project.setContractAmount(Double.parseDouble(amountCell.getStringCellValue()));
|
|
|
+ }
|
|
|
+ if (isPublicCell != null && !StringUtils.isEmpty(isPublicCell.getStringCellValue())) {
|
|
|
+ project.setIsPublic("是".equals(isPublicCell.getStringCellValue())?1:0);
|
|
|
+ }
|
|
|
+ if(projectMapper.insert(project)>0){
|
|
|
+ ProjectAuditor projectAuditor=new ProjectAuditor();
|
|
|
+ projectAuditor.setAuditorId(project.getInchargerId());
|
|
|
+ projectAuditor.setAuditorName(project.getInchargerName());
|
|
|
+ projectAuditor.setProjectId(project.getId());
|
|
|
+ projectAuditorMapper.insert(projectAuditor);
|
|
|
+ }
|
|
|
+ importCount++;
|
|
|
+ //处理子项目
|
|
|
+ if (subNameCell != null) {
|
|
|
+ //兼容中英文逗号
|
|
|
+ String[] subNames = subNameCell.getStringCellValue().trim().split(",|\\,");
|
|
|
+ if (subNames != null) {
|
|
|
+ for (String s : subNames) {
|
|
|
+ if (!StringUtils.isEmpty(s)) {
|
|
|
+ SubProject sp = new SubProject();
|
|
|
+ sp.setName(s);
|
|
|
+ sp.setProjectId(project.getId());
|
|
|
+ subProjectMapper.insert(sp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //参与人
|
|
|
+ if (participatorCell != null) {
|
|
|
+ String part = participatorCell.getStringCellValue().trim();
|
|
|
+ //将项目负责人也添加到参与人当中来
|
|
|
+ String incharger = inchargerCell.getStringCellValue().trim();
|
|
|
+ if (!StringUtils.isEmpty(part)) {
|
|
|
+ String[] partSplit = part.split("\\,|\\,");
|
|
|
+ if(!StringUtils.isEmpty(incharger)){
|
|
|
+ String[] inchargerSplit = incharger.split("\\,|\\,");
|
|
|
+ int strLen1 = partSplit.length;// 保存第一个数组长度
|
|
|
+ int strLen2 = inchargerSplit.length;
|
|
|
+ partSplit=Arrays.copyOf(partSplit, strLen1+strLen2);
|
|
|
+ System.arraycopy(inchargerSplit, 0, partSplit, strLen1, strLen2);
|
|
|
+ }
|
|
|
+ for (String str : partSplit) {
|
|
|
+ Participation p = new Participation();
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(str)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ p.setUserId(first.get().getId());
|
|
|
+ p.setProjectId(project.getId());
|
|
|
+ participationMapper.insert(p);
|
|
|
+ } else {
|
|
|
+ projectMapper.deleteById(project.getId());
|
|
|
+ throw new Exception("参与人["+str+"]不存在");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- msg.data = "成功导入"+importCount+"条数据。";
|
|
|
- if (existCodeList.size() > 0) {
|
|
|
- String collect = existCodeList.stream().collect(Collectors.joining(","));
|
|
|
- msg.data += "自动跳过"+existCodeList.size()+"条已存在项目编码:"+collect;
|
|
|
+ msg.data = "成功导入"+importCount+"条数据。";
|
|
|
+ if (existCodeList.size() > 0) {
|
|
|
+ String collect = existCodeList.stream().collect(Collectors.joining(","));
|
|
|
+ msg.data += "自动跳过"+existCodeList.size()+"条已存在项目编码:"+collect;
|
|
|
+ }
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
@@ -2491,9 +2770,11 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
headList.add(s);
|
|
|
}
|
|
|
}
|
|
|
+ if(company.getPackageCustomer()==1){
|
|
|
+ headList.add("客户");
|
|
|
+ }
|
|
|
if (company.getPackageProject() == 1) {
|
|
|
//项目管理专业版以上的,导出的数据更全面
|
|
|
- headList.add("客户");
|
|
|
headList.add("项目级别");
|
|
|
headList.add("合同金额");
|
|
|
}
|