|
@@ -19,6 +19,7 @@ import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
@@ -69,6 +70,7 @@ import org.springframework.jdbc.core.SingleColumnRowMapper;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -597,10 +599,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
resultTabs.sort(Comparator.comparing((WbsTreeContract contract) -> contract.getNodeName().contains("JS107"))
|
|
|
.thenComparing(WbsTreeContract::getNodeName));
|
|
|
}
|
|
|
- InformationQuery info = informationQueryClient.getInfoByWbsId(Long.valueOf(primaryKeyId));
|
|
|
- if(info!=null){
|
|
|
- resultTabs.forEach(tab->tab.setFileName(info.getName()));
|
|
|
- }
|
|
|
+// InformationQuery info = informationQueryClient.getInfoByWbsId(Long.valueOf(primaryKeyId));
|
|
|
+// if(info!=null){
|
|
|
+// resultTabs.forEach(tab->tab.setFileName(info.getName()));
|
|
|
+// }
|
|
|
|
|
|
|
|
|
// if (Optional.ofNullable(wbsTreeContract.getIsUseSort()).orElse(0) == 0) {
|
|
@@ -2280,11 +2282,12 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
return null;
|
|
|
}
|
|
|
@Override
|
|
|
- @Transactional(isolation = Isolation.READ_COMMITTED)
|
|
|
+ @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED)
|
|
|
public R importTree(MultipartFile file, Long pkeyId) throws IOException {
|
|
|
InputStream inputStream = file.getInputStream();
|
|
|
org.apache.poi.ss.usermodel.Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ unmergeCells(sheet);
|
|
|
List<ImportTreeDto>list=new ArrayList<>();
|
|
|
for (int i = 2; i <= sheet.getLastRowNum(); i++){
|
|
|
Row row = sheet.getRow(i);
|
|
@@ -2310,10 +2313,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
//过滤出空节点
|
|
|
list=list.stream().filter(o->!o.getIsUnit()||!o.getIsSubUnit()||!o.getIsDivision()||!o.getIsSubDivision()||!o.getIsItem()||!o.getIsSubItem()).collect(Collectors.toList());
|
|
|
- //过滤出相同节点但是编号不同的情况
|
|
|
- if(hasConflictingCodes(list)){
|
|
|
- throw new ServiceException("导入模版存在相同节点但不同编号,请修改");
|
|
|
- }
|
|
|
+// //过滤出相同节点但是编号不同的情况
|
|
|
+// if(hasConflictingCodes(list)){
|
|
|
+// throw new ServiceException("导入模版存在相同节点但不同编号,请修改");
|
|
|
+// }
|
|
|
//最高节点
|
|
|
WbsTreeContract wbsTreeContractRoot = baseMapper.selectOne(Wrappers.<WbsTreeContract>query().lambda().eq(WbsTreeContract::getPKeyId, pkeyId));
|
|
|
//获取当前节点下所有子节点
|
|
@@ -2397,8 +2400,10 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ int i=0;
|
|
|
//新增
|
|
|
for (ImportTreeDto dto : list) {
|
|
|
+ i++;
|
|
|
//单位工程:如果没有被处理过,说明需要新增
|
|
|
String sqlList="Select * from m_wbs_tree_contract where contract_id="+wbsTreeContractRoot.getContractId()+" and wbs_id="+wbsTreeContractRoot.getWbsId()+" and is_deleted=0";
|
|
|
List<WbsTreeContract> WbsTreeContractList = jdbcTemplate.query(sqlList, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
@@ -2418,6 +2423,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
unit.setNodeName(dto.getUnitName());
|
|
|
unit.setFullName(dto.getUnitName());
|
|
|
unit.setIsTypePrivatePid(null);
|
|
|
+ unit.setSort(i);
|
|
|
baseMapper.insert(unit);
|
|
|
insertList.add(unit);
|
|
|
}
|
|
@@ -2441,6 +2447,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
subUnit.setNodeName(dto.getSubUnitName());
|
|
|
subUnit.setFullName(dto.getSubUnitName());
|
|
|
subUnit.setIsTypePrivatePid(null);
|
|
|
+ subUnit.setSort(i);
|
|
|
baseMapper.insert(subUnit);
|
|
|
insertList.add(subUnit);
|
|
|
}
|
|
@@ -2482,6 +2489,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
division.setNodeName(dto.getDivisionName());
|
|
|
division.setFullName(dto.getDivisionName());
|
|
|
division.setIsTypePrivatePid(null);
|
|
|
+ division.setSort(i);
|
|
|
baseMapper.insert(division);
|
|
|
insertList.add(division);
|
|
|
break;
|
|
@@ -2530,6 +2538,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
subDivision.setNodeName(dto.getSubDivisionName());
|
|
|
subDivision.setFullName(dto.getSubDivisionName());
|
|
|
subDivision.setIsTypePrivatePid(null);
|
|
|
+ subDivision.setSort(i);
|
|
|
baseMapper.insert(subDivision);
|
|
|
insertList.add(subDivision);
|
|
|
break;
|
|
@@ -2582,6 +2591,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
item.setNodeName(dto.getItemName());
|
|
|
item.setFullName(dto.getItemName());
|
|
|
item.setIsTypePrivatePid(null);
|
|
|
+ item.setSort(i);
|
|
|
baseMapper.insert(item);
|
|
|
insertList.add(item);
|
|
|
break;
|
|
@@ -2637,6 +2647,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
subItem.setNodeName(dto.getSubItemName());
|
|
|
subItem.setFullName(dto.getSubItemName());
|
|
|
subItem.setIsTypePrivatePid(null);
|
|
|
+ subItem.setSort(i);
|
|
|
baseMapper.insert(subItem);
|
|
|
insertList.add(subItem);
|
|
|
break;
|
|
@@ -2647,12 +2658,70 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ //entityManager.flush();
|
|
|
// if(insertList.size()>0){
|
|
|
// baseMapper.insertBatchSomeColumn(insertList);
|
|
|
// }
|
|
|
return R.success("新增了"+insertList.size()+"个节点"+","+String.join(",",updateList)+"节点编号已被修改");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 展开所有合并单元格并将值填充到每个单元格
|
|
|
+ * @param sheet Excel工作表
|
|
|
+ */
|
|
|
+ public static void unmergeCells(Sheet sheet) {
|
|
|
+ // 获取所有合并区域
|
|
|
+ for (int i = sheet.getNumMergedRegions() - 1; i >= 0; i--) {
|
|
|
+ CellRangeAddress mergedRegion = sheet.getMergedRegion(i);
|
|
|
+
|
|
|
+ // 获取合并区域左上角单元格的值
|
|
|
+ Row firstRow = sheet.getRow(mergedRegion.getFirstRow());
|
|
|
+ Cell cell1 = firstRow.getCell(mergedRegion.getFirstColumn());
|
|
|
+ Object cellValue = getCellValue1(cell1);
|
|
|
+
|
|
|
+ // 展开合并区域
|
|
|
+ sheet.removeMergedRegion(i);
|
|
|
+
|
|
|
+ // 将值填充到原合并区域的所有单元格
|
|
|
+ for (int rowNum = mergedRegion.getFirstRow(); rowNum <= mergedRegion.getLastRow(); rowNum++) {
|
|
|
+ Row row = sheet.getRow(rowNum) != null ? sheet.getRow(rowNum) : sheet.createRow(rowNum);
|
|
|
+
|
|
|
+ for (int colNum = mergedRegion.getFirstColumn(); colNum <= mergedRegion.getLastColumn(); colNum++) {
|
|
|
+ Cell cell = row.getCell(colNum) != null ? row.getCell(colNum) : row.createCell(colNum);
|
|
|
+ setCellValue(cell, cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取单元格值
|
|
|
+ * @param cell 单元格
|
|
|
+ * @return 单元格值
|
|
|
+ */
|
|
|
+ private static Object getCellValue1(Cell cell) {
|
|
|
+ if (cell == null) return null;
|
|
|
+ return cell.getStringCellValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置单元格值
|
|
|
+ * @param cell 单元格
|
|
|
+ * @param value 要设置的值
|
|
|
+ */
|
|
|
+ private static void setCellValue(Cell cell, Object value) {
|
|
|
+ if (cell == null || value == null) return;
|
|
|
+
|
|
|
+ if (value instanceof String) {
|
|
|
+ cell.setCellValue((String) value);
|
|
|
+ } else if (value instanceof Double) {
|
|
|
+ cell.setCellValue((Double) value);
|
|
|
+ } else if (value instanceof Boolean) {
|
|
|
+ cell.setCellValue((Boolean) value);
|
|
|
+ }
|
|
|
+ // 可以根据需要添加其他类型的处理
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// public class NodeInfo {
|
|
|
// private String nodeName;
|