浏览代码

批量保存

yangyj 1 年之前
父节点
当前提交
ab05bc2560

+ 92 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -2216,6 +2216,98 @@ public class ExcelTabController extends BladeController {
     }
 
 
+    @PostMapping("/data-batch-refresh")
+    @ApiOperationSupport(order = 100)
+    @ApiOperation(value = "批量重新保存", notes = "批量重新保存")
+    public R saveBussDataBatchRefresh(Long pkeyId){
+        List<Map<String ,Object>> listMaps= this.jdbcTemplate.queryForList("");
+        if(listMaps.size()>0){
+            listMaps.forEach(node->{
+                try {
+                    this.start(node.get("pkeyId").toString());
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+
+            });
+        }
+      return   R.success("无数据");
+    }
+
+
+    public R start(String nodeId) throws Exception {
+        JSONArray dataArray = new JSONArray();
+//        String nodeId = tableInfo1.getString("nodeId");
+        String contractId ="1630017379264610305";
+        String projectId = "1630011899725201410";
+        String classify = "1";
+
+        /*全加载,或者可以优化成依赖加载*/
+
+        List<AppWbsTreeContractVO> tableAll  = wbsTreeContractService.searchNodeAllTable(nodeId, "1", contractId, projectId,null);
+        List<Long> tableAllIds = tableAll.stream().map(AppWbsTreeContractVO::getPKeyId).collect(Collectors.toList());
+        for (Long pk : tableAllIds) {
+            Map<String, Object> jo = this.excelTabService.getBussDataInfo(pk, 1);
+            if (ObjectUtils.isNotEmpty(jo)) {
+                jo.put("pkeyId", pk);
+                dataArray.add(jo);
+            }
+        }
+        List<TableInfo> tableInfoList = this.excelTabService.getTableInfoList(dataArray);
+        /*默认额外加载的默认不更新,除非有元素数据变动*/
+        tableInfoList.removeIf(e -> e.getPkeyId() == null);
+        tableInfoList.forEach(e -> {
+            e.setToBeUpdated(false);
+            e.setBusinessId(null);
+            e.setContractId(contractId);
+            e.setClassify(classify);
+            e.setProjectId(projectId);
+            e.setGroupId("0");
+        });
+        tableInfoList.sort(Comparator.comparingInt(a -> tableAllIds.indexOf(Long.parseLong(a.getPkeyId()))));
+        //公式填充
+        this.excelTabService.formulaFillData(tableInfoList, Long.parseLong(nodeId), ExecuteType.INSPECTION);
+        //保存数据到数据库
+        R<Object> result = this.excelTabService.saveOrUpdateInfo(tableInfoList);
+        if (!result.isSuccess()) {
+            return R.fail(result.getMsg());
+        }
+
+
+        List<String> errorPKeyIds = new ArrayList<>();
+        //单个pdf加载
+        if (tableInfoList != null) {
+            for (TableInfo tableInfo : tableInfoList) {
+                R bussPdfInfo = excelTabService.getBussPdfInfo(Long.parseLong(tableInfo.getPkeyId()));
+
+                if (ObjectUtil.isEmpty(bussPdfInfo) || bussPdfInfo.getCode() != 200) {
+                    //如果返回的单张pdfUrl为空,那么表示发生异常,返回异常信息
+                    errorPKeyIds.add(tableInfo.getPkeyId());
+                }
+            }
+        }
+
+        //发生异常后直接返回,不进行合并
+        if (errorPKeyIds.size() > 0) {
+            List<AppWbsTreeContractVO> errorTabs = new LinkedList<>();
+            for (AppWbsTreeContractVO appWbsTreeContractVO : tableAll) {
+                if (errorPKeyIds.contains(appWbsTreeContractVO.getPKeyId().toString())) {
+                    errorTabs.add(appWbsTreeContractVO);
+                }
+            }
+            if (errorTabs.size() > 0) {
+                List<String> names = errorTabs.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList());
+                return R.fail("以下的表在生成pdf文件时发生了异常【" + StringUtils.join(names, "、") + "】");
+            }
+        }
+
+        //合并pdf加载
+        excelTabService.getBussPdfs(nodeId, classify, contractId, projectId);
+
+        //更新缓存
+        informationQueryClient.delAsyncWbsTree(contractId);
+        return R.success("OK");
+    }
     /***
      * 覆盖上传-  (修改为上传导入模板)
      */

+ 43 - 61
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -482,73 +482,55 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
    }
 
     public void missingFill(List<String> missingList){
-        /*数据池里面没有任何元素匹配和当前依赖匹配*/
-        if(Func.isNotEmpty(missingList)){
-            StaticLog.info("需要挂载的元素{}", String.join(";", missingList));
-            Map<String, Object> elementInfoMap=this.getElementInfoByCodes(String.join(",",missingList));
-            /*1从当前节点其它表格中查找匹配的元素*/
-            List<String> removeList=new ArrayList<>();
-            /*if(false) {*//*全加载后,关闭当前节的搜索,假如后期改成依赖加载可以再次利用*//*
-                for (String r : missingList) {
-                    String tn = r.substring(0, r.indexOf(StringPool.COLON));
-                    String key = r.substring(r.indexOf(StringPool.COLON) + 1);
-                    List<NodeTable> nodeList = this.tec.getTableAll().stream().filter(e -> e.getInitTableName().equals(tn)).collect(Collectors.toList());
-                    if (Func.isNotEmpty(nodeList)) {
-                        removeList.add(r);
-                        @SuppressWarnings("unchecked")
-                        Map<String, Object> elementInfo = (Map<String, Object>) elementInfoMap.get(r);
-                        String tableName = nodeList.get(0).getInitTableName();
-                        if (!this.tec.getCoordinateMap().containsKey(tableName)) {
-                            this.tec.getCoordinateMap().put(tableName, FormulaUtils.getElementCell(nodeList.get(0).getHtmlUrl()));
-                        }
-                        List<Map<String, Object>> tableDatas = this.jdbcTemplate.queryForList("select * from " + tableName + " where p_key_id in(" + nodeList.stream().map(NodeTable::getPKeyId).map(StringUtils::handleNull).collect(Collectors.joining(",")) + ")");
-                        fill(tableDatas, removeList, tn, key, StringUtils.handleNull(elementInfo.get("ename")));
+        try {
+            /*数据池里面没有任何元素匹配和当前依赖匹配*/
+            if (Func.isNotEmpty(missingList)) {
+                StaticLog.info("需要挂载的元素{}", String.join(";", missingList));
+                Map<String, Object> elementInfoMap = this.getElementInfoByCodes(String.join(",", missingList));
+                /*1从当前节点其它表格中查找匹配的元素*/
+                List<String> removeList = new ArrayList<>();
+                if (Func.isNotEmpty(missingList)) {
+                    /*2从当前节点的兄弟节点中查找匹配的元素*/
+                    CurrentNode currentNode = this.tec.getCurrentNode();
+                    /*List<Map<String,Object>> tableNamePkIdsMaps= this.jdbcTemplate.queryForList("select c.init_table_name tableName,c.p_key_id pkId,c.html_url url from (select b.id from m_wbs_tree_contract a join m_wbs_tree_contract b on (a.contract_id=b.contract_id and b.ancestors like CONCAT(a.ancestors,'%')) where a.p_key_id="+currentNode.getPkId()+" and b.is_deleted=0 and b.node_type=6 ORDER BY b.sort) k join m_wbs_tree_contract c on c.parent_id = k.id where  c.contract_id="+tec.getContractId()+" and c.is_deleted=0 ");*/
+                    WbsTreeContract parent = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId, currentNode.getParentPkeyId()));
+                    if (parent == null) {
+                        return;
+                    }
+                    List<Map<String, Object>> tableNamePkIdsMaps = this.jdbcTemplate.queryForList(
+                            "select c.init_table_name tableName,c.p_key_id pkId,c.html_url url from" +
+                                    " (select id from m_wbs_tree_contract where contract_id=" + currentNode.getContractId() + " and is_deleted=0 and node_type=6 and tree_code like '" + parent.getTreeCode() + "%' ORDER BY sort) k" +
+                                    " join m_wbs_tree_contract c on c.parent_id = k.id " +
+                                    "where  c.contract_id=" + currentNode.getContractId() + " and c.is_deleted=0 "
+                    );
+                    if (Func.isNotEmpty(tableNamePkIdsMaps)) {
+                        // removeList.clear();
+                        missingList.forEach(miss -> {
+                            @SuppressWarnings("unckecked")
+                            Map<String, Object> elementInfo = (Map<String, Object>) elementInfoMap.get(miss);
+                            String tn = miss.substring(0, miss.indexOf(StringPool.COLON));
+                            String key = miss.substring(miss.indexOf(StringPool.COLON) + 1);
+                            String targetIds = tableNamePkIdsMaps.stream().filter(m -> StringUtils.isEquals(m.get("tableName"), tn)).map(m -> m.get("pkId")).map(StringUtils::handleNull).collect(Collectors.joining(","));
+                            if (Func.isNotEmpty(targetIds)) {
+                                if (!this.tec.getCoordinateMap().containsKey(tn)) {
+                                    tableNamePkIdsMaps.stream().filter(m -> StringUtils.isEquals(m.get("tableName"), tn)).findAny().ifPresent(m -> {
+                                        this.tec.getCoordinateMap().put(tn, FormulaUtils.getElementCell(StringUtils.handleNull(m.get("url"))));
+                                    });
+                                }
+                                List<Map<String, Object>> tableDatas = this.jdbcTemplate.queryForList("select * from " + tn + " where p_key_id in (" + targetIds + ")");
+                                String tmp = elementInfo == null ? "" : StringUtils.handleNull(elementInfo.get("ename"));
+                                fill(tableDatas, removeList, tn, key, tmp);
+                            }
+                        });
                     }
                 }
                 if (Func.isNotEmpty(removeList)) {
-                    *//*移除已经找到的元素数据*//*
+                    /*移除已经找到的元素数据*/
                     missingList.removeIf(removeList::contains);
                 }
-            }*/
-            if(Func.isNotEmpty(missingList)){
-                /*2从当前节点的兄弟节点中查找匹配的元素*/
-                CurrentNode currentNode = this.tec.getCurrentNode();
-                /*List<Map<String,Object>> tableNamePkIdsMaps= this.jdbcTemplate.queryForList("select c.init_table_name tableName,c.p_key_id pkId,c.html_url url from (select b.id from m_wbs_tree_contract a join m_wbs_tree_contract b on (a.contract_id=b.contract_id and b.ancestors like CONCAT(a.ancestors,'%')) where a.p_key_id="+currentNode.getPkId()+" and b.is_deleted=0 and b.node_type=6 ORDER BY b.sort) k join m_wbs_tree_contract c on c.parent_id = k.id where  c.contract_id="+tec.getContractId()+" and c.is_deleted=0 ");*/
-                WbsTreeContract parent = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId,currentNode.getParentPkeyId()));
-                if(parent==null){
-                    return;
-                }
-                List<Map<String,Object>> tableNamePkIdsMaps= this.jdbcTemplate.queryForList(
-                        "select c.init_table_name tableName,c.p_key_id pkId,c.html_url url from" +
-                                " (select id from m_wbs_tree_contract where contract_id="+currentNode.getContractId()+" and is_deleted=0 and node_type=6 and tree_code like '"+parent.getTreeCode()+"%' ORDER BY sort) k" +
-                                " join m_wbs_tree_contract c on c.parent_id = k.id " +
-                                "where  c.contract_id="+currentNode.getContractId()+" and c.is_deleted=0 "
-                );
-                if(Func.isNotEmpty(tableNamePkIdsMaps)){
-                   // removeList.clear();
-                    missingList.forEach(miss->{
-                        @SuppressWarnings("unckecked")
-                        Map<String,Object> elementInfo= (Map<String, Object>) elementInfoMap.get(miss);
-                        String tn = miss.substring(0,miss.indexOf(StringPool.COLON));
-                        String key =miss.substring(miss.indexOf(StringPool.COLON)+1);
-                        String targetIds=tableNamePkIdsMaps.stream().filter(m->StringUtils.isEquals(m.get("tableName"),tn)).map(m->m.get("pkId")).map(StringUtils::handleNull).collect(Collectors.joining(","));
-                        if(Func.isNotEmpty(targetIds)){
-                            if(!this.tec.getCoordinateMap().containsKey(tn)){
-                                tableNamePkIdsMaps.stream().filter(m->StringUtils.isEquals(m.get("tableName"),tn)).findAny().ifPresent(m->{
-                                    this.tec.getCoordinateMap().put(tn,FormulaUtils.getElementCell(StringUtils.handleNull(m.get("url"))));
-                                });
-                            }
-                            List<Map<String,Object>> tableDatas= this.jdbcTemplate.queryForList("select * from "+tn+" where p_key_id in ("+targetIds+")");
-                            String tmp =elementInfo==null?"":StringUtils.handleNull(elementInfo.get("ename"));
-                            fill(tableDatas,removeList,tn,key,tmp);
-                        }
-                    });
-                }
-            }
-            if(Func.isNotEmpty(removeList)){
-                /*移除已经找到的元素数据*/
-                missingList.removeIf(removeList::contains);
             }
+        }catch (Exception e){
+            e.printStackTrace();
         }
     }
     public void missingFill2(List<String> missingList){