Bladeren bron

Merge remote-tracking branch 'origin/dev' into dev

LHB 2 dagen geleden
bovenliggende
commit
a68ef4ee5e

+ 2 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTreeContract.java

@@ -331,6 +331,7 @@ public class WbsTreeContract extends BaseEntity {
     @ApiModelProperty(value = "是否完成日期填写 1是 2否")
     private Integer dateIsComplete;
 
-
+    @ApiModelProperty(value = "导入Id")
+    private Long importId;
 
 }

+ 2 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeContractMapper.java

@@ -193,4 +193,6 @@ public interface WbsTreeContractMapper extends EasyBaseMapper<WbsTreeContract> {
     List<WbsTreeContract> getChildWbsTreeContractsBatch(@Param("parentKeyId") Long parentKeyId);
 
     void updateAncestors(@Param("contract") WbsTreeContract contract);
+
+    Integer selectImportSize(@Param("importId") Long importId);
 }

+ 3 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeContractMapper.xml

@@ -1104,4 +1104,7 @@
     <select id="getChildWbsTreeContractsBatch" resultType="org.springblade.manager.entity.WbsTreeContract">
         CALL GetChildNodes(#{parentKeyId});
     </select>
+    <select id="selectImportSize" resultType="java.lang.Integer">
+        SELECT count(0) FROM m_wbs_tree_contract where import_id=#{importId} and is_deleted=0;
+    </select>
 </mapper>

+ 56 - 31
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -2982,37 +2982,39 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         try (InputStream inputStream = file.getInputStream()) {
             // 立即处理文件流
             Workbook workbook = new XSSFWorkbook(inputStream);
-            Sheet sheet = workbook.getSheetAt(0);
-            // 处理Excel数据...
-            unmergeCells(sheet);
             List<ImportTreeDto> list = new ArrayList<>();
-            for (int i = 2; i <= sheet.getLastRowNum(); i++) {
-                Row row = sheet.getRow(i);
-                if (row == null) continue;
-//                if(StringUtils.isEmpty(getCellValue(row.getCell(1)))){
-//                    throw new ServerException("单位工程类型名称不能为空");
-//                }
-//                if(StringUtils.isEmpty(getCellValue(row.getCell(3)))){
-//                    throw new ServerException("单位工程名称不能为空");
-//                }
-//                if(StringUtils.isEmpty(getCellValue(row.getCell(5)))){
-//                    throw new ServerException("分部工程名称不能为空");
-//                }
-                // 获取每一列的值
-                String unitCode = getCellValue(row.getCell(0)); // A列:单位工程编号
-                String unitName = getCellValue(row.getCell(1)); // B列:单位工程名称
-                String subUnitCode = getCellValue(row.getCell(2)); // C列:子单位工程编号
-                String subUnitName = getCellValue(row.getCell(3)); // D列:子单位工程名称
-                String divisionCode = getCellValue(row.getCell(4)); // E列:分部工程编号
-                String divisionName = getCellValue(row.getCell(5)); // F列:分部工程名称
-                String subDivisionCode = getCellValue(row.getCell(6)); // G列:子分部工程编号
-                String subDivisionName = getCellValue(row.getCell(7)); // H列:子分部工程名称
-                String itemCode = getCellValue(row.getCell(8)); // I列:分项工程编号
-                String itemName = getCellValue(row.getCell(9)); // J列:分项工程名称
-                String subItemCode = getCellValue(row.getCell(10));// K列:子分项工程编号
-                String subItemName = getCellValue(row.getCell(11)); // L列:子分项工程名称
-                ImportTreeDto dto = new ImportTreeDto(unitName, unitCode, 1, StringUtils.isEmpty(unitName), subUnitName, subUnitCode, 18, StringUtils.isEmpty(subUnitName), divisionName, divisionCode, 2, StringUtils.isEmpty(divisionName), subDivisionName, subDivisionCode, 3, StringUtils.isEmpty(subDivisionName), itemName, itemCode, 4, StringUtils.isEmpty(itemName), subItemName, subItemCode, 5, StringUtils.isEmpty(subItemName));
-                list.add(dto);
+            // 遍历所有工作表
+            for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
+                Sheet sheet = workbook.getSheetAt(sheetIndex);
+                // 处理Excel数据...
+                unmergeCells(sheet);
+                for (int i = 2; i <= sheet.getLastRowNum(); i++) {
+                    Row row = sheet.getRow(i);
+                    if (row == null) continue;
+                    // 获取每一列的值
+                    String unitCode = getCellValue(row.getCell(0)); // A列:单位工程编号
+                    String unitName = getCellValue(row.getCell(1)); // B列:单位工程名称
+                    String subUnitCode = getCellValue(row.getCell(2)); // C列:子单位工程编号
+                    String subUnitName = getCellValue(row.getCell(3)); // D列:子单位工程名称
+                    String divisionCode = getCellValue(row.getCell(4)); // E列:分部工程编号
+                    String divisionName = getCellValue(row.getCell(5)); // F列:分部工程名称
+                    String subDivisionCode = getCellValue(row.getCell(6)); // G列:子分部工程编号
+                    String subDivisionName = getCellValue(row.getCell(7)); // H列:子分部工程名称
+                    String itemCode = getCellValue(row.getCell(8)); // I列:分项工程编号
+                    String itemName = getCellValue(row.getCell(9)); // J列:分项工程名称
+                    String subItemCode = getCellValue(row.getCell(10));// K列:子分项工程编号
+                    String subItemName = getCellValue(row.getCell(11)); // L列:子分项工程名称
+
+                    ImportTreeDto dto = new ImportTreeDto(
+                            unitName, unitCode, 1, StringUtils.isEmpty(unitName),
+                            subUnitName, subUnitCode, 18, StringUtils.isEmpty(subUnitName),
+                            divisionName, divisionCode, 2, StringUtils.isEmpty(divisionName),
+                            subDivisionName, subDivisionCode, 3, StringUtils.isEmpty(subDivisionName),
+                            itemName, itemCode, 4, StringUtils.isEmpty(itemName),
+                            subItemName, subItemCode, 5, StringUtils.isEmpty(subItemName)
+                    );
+                    list.add(dto);
+                }
             }
             if (list.isEmpty()) {
                 throw new ServiceException("导入模版为空,请先填写数据");
@@ -3136,6 +3138,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
             }
             int i = 0;
             int size = list.size();
+            Long importId=SnowFlakeUtil.getId();
             try{
                 String sqlList1 = "Select parent_id,node_name,p_id from m_wbs_tree_contract where contract_id=" + wbsTreeContractRoot.getContractId() + " and wbs_id=" + wbsTreeContractRoot.getWbsId() + " and is_deleted=0";
                 List<WbsTreeContract> WbsTreeContractList = jdbcTemplate.query(sqlList1, new BeanPropertyRowMapper<>(WbsTreeContract.class));
@@ -3166,6 +3169,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                             unit.setDateIsComplete(null);
                             unit.setPId(wbsTreeContractRoot.getPKeyId());
                             unit.setAncestorsPId(wbsTreeContractRoot.getAncestorsPId() + "," + wbsTreeContractRoot.getPKeyId());
+                            unit.setImportId(importId);
                             baseMapper.insert(unit);
                             insertList.add(unit);
                             WbsTreeContractList.add(unit);
@@ -3194,6 +3198,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                             subUnit.setDateIsComplete(null);
                             subUnit.setPId(fatherNode.getPKeyId());
                             subUnit.setAncestorsPId(fatherNode.getAncestorsPId() + "," + fatherNode.getPKeyId());
+                            subUnit.setImportId(importId);
                             baseMapper.insert(subUnit);
                             insertList.add(subUnit);
                             WbsTreeContractList.add(subUnit);
@@ -3242,6 +3247,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                         division.setDateIsComplete(null);
                                         division.setPId(contract.getPKeyId());
                                         division.setAncestorsPId(contract.getAncestorsPId() + "," + contract.getPKeyId());
+                                        division.setImportId(importId);
                                         baseMapper.insert(division);
                                         insertList.add(division);
                                         WbsTreeContractList.add(division);
@@ -3297,6 +3303,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                         subDivision.setDateIsComplete(null);
                                         subDivision.setPId(contract.getPKeyId());
                                         subDivision.setAncestorsPId(contract.getAncestorsPId() + "," + contract.getPKeyId());
+                                        subDivision.setImportId(importId);
                                         baseMapper.insert(subDivision);
                                         insertList.add(subDivision);
                                         WbsTreeContractList.add(subDivision);
@@ -3355,6 +3362,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                         item.setDateIsComplete(null);
                                         item.setPId(contract.getPKeyId());
                                         item.setAncestorsPId(contract.getAncestorsPId() + "," + contract.getPKeyId());
+                                        item.setImportId(importId);
                                         baseMapper.insert(item);
                                         insertList.add(item);
                                         WbsTreeContractList.add(item);
@@ -3416,6 +3424,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                                         subItem.setDateIsComplete(null);
                                         subItem.setPId(contract.getPKeyId());
                                         subItem.setAncestorsPId(contract.getAncestorsPId() + "," + contract.getPKeyId());
+                                        subItem.setImportId(importId);
                                         baseMapper.insert(subItem);
                                         insertList.add(subItem);
                                         WbsTreeContractList.add(subItem);
@@ -3430,7 +3439,6 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
             } catch (Exception e) {
                 bladeRedis.del("import:projectId:"+wbsTreeContractRoot.getProjectId()+"contractId:"+wbsTreeContractRoot.getContractId());
             }finally {
-                bladeRedis.del("import:projectId:"+wbsTreeContractRoot.getProjectId()+"contractId:"+wbsTreeContractRoot.getContractId());
                 try {
                     if (!insertList.isEmpty()) {
                         wbsTreeContractStatisticsClient.updateWbsTreeContractNodes(insertList.stream().map(item -> item.getPKeyId() + "").collect(Collectors.joining(",")));
@@ -3439,11 +3447,28 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
                     e.printStackTrace();
                 }
             }
+            if(!insertList.isEmpty()){
+                int x=insertList.size()/5;
+                int y=0;
+                boolean flag=true;
+                while (flag){
+                    y++;
+                    Thread.sleep(5000);
+                    Integer importSize=baseMapper.selectImportSize(importId);
+                    if(importSize==insertList.size()||y==x){
+                       flag=false;
+                   }
+                }
+            }
             bladeRedis.setEx("import:projectId:"+wbsTreeContractRoot.getProjectId()+"contractId:"+wbsTreeContractRoot.getContractId(), "100",7L);
             return R.success("新增了" + insertList.size() + "个节点" + "," + String.join(",", updateList) + "节点编号已被修改");
         } catch (IOException e) {
             bladeRedis.del("import:projectId:"+wbsTreeContractRoot.getProjectId()+"contractId:"+wbsTreeContractRoot.getContractId());
             return R.fail("文件处理失败: " + e.getMessage());
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }finally {
+            bladeRedis.del("import:projectId:"+wbsTreeContractRoot.getProjectId()+"contractId:"+wbsTreeContractRoot.getContractId());
         }
     }