瀏覽代碼

资料填报批量导入记录优化

lvy 2 天之前
父節點
當前提交
e7593c6e8d

+ 20 - 13
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/InformationImportRecordController.java

@@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory;
 import org.springblade.business.entity.InformationQuery;
 import org.springblade.common.constant.CommonConstant;
 import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.common.utils.SystemUtils;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.support.Condition;
@@ -238,9 +239,19 @@ public class InformationImportRecordController extends BladeController {
             Long pId = node.getPKeyId();
             int i = 0;
             for (; i < split.length - 1; i++) {
-                List<WbsTreeContract> query = jdbcTemplate.query("select * from m_wbs_tree_contract where is_deleted = 0 and p_id = " + pId + " and full_name = '" + split[i] + "'",
+                // 使用 like 是因为Windows 和 excel 不支持 ‘/’ 等特殊字符,下载模板时将特殊字符转为了 '_', 而 '_' 在 MySQL like中表示一个任意字符, 所以这里使用 like
+                List<WbsTreeContract> query = jdbcTemplate.query("select * from m_wbs_tree_contract where is_deleted = 0 and p_id = " + pId + " and full_name like '" + split[i] + "'",
                         new BeanPropertyRowMapper<>(WbsTreeContract.class));
-                if (query.isEmpty() || query.get(0) == null) {
+                if ((query.isEmpty() || query.get(0) == null)) {
+                    if (target != null) {
+                        break;
+                    }
+                    if (i == split.length - 2 ) {
+                        if (node.getFullName() != null && node.getFullName().replaceAll("[\\\\/:*?\"<>|]", "_").equals(split[i]) ||
+                            node.getNodeName() != null && node.getNodeName().replaceAll("[\\\\/:*?\"<>|]", "_").equals(split[i])) {
+                            target = node;
+                        }
+                    }
                     continue;
                 }
                 target = query.get(0);
@@ -250,7 +261,7 @@ public class InformationImportRecordController extends BladeController {
                 }
             }
             if (target == null || i < split.length - 2) {
-                informationImportRecordService.updateProcess(record.getId(), null, 3, "节点未找到-客户端::" + split[i], record.getUpdateTime());
+                informationImportRecordService.updateProcess(record.getId(), null, 3, "节点未找到-客户端::" + split[i - 1], record.getUpdateTime());
                 return;
             }
         } else {
@@ -276,11 +287,7 @@ public class InformationImportRecordController extends BladeController {
             }
         }
 
-        if (target.getIsTypePrivatePid() == null) {
-            informationImportRecordService.updateProcess(record.getId(), null, 3, "节点未找到-后管::" + target.getFullName(), record.getUpdateTime());
-            return;
-        }
-        List<WbsTreePrivate> query = jdbcTemplate.query("select * from m_wbs_tree_private where is_deleted = 0 and p_id = " + target.getIsTypePrivatePid() + " and node_name = '" + lastName + "' limit 1",
+        List<WbsTreePrivate> query = jdbcTemplate.query("select * from m_wbs_tree_private where is_deleted = 0 and node_type = 6 and project_id = " + target.getProjectId() + " and node_name like '" + lastName + "' limit 1",
                 new BeanPropertyRowMapper<>(WbsTreePrivate.class));
         if (query.isEmpty()) {
             informationImportRecordService.updateProcess(record.getId(), null, 3, "节点未找到-后管::" + target.getFullName(), record.getUpdateTime());
@@ -382,7 +389,7 @@ public class InformationImportRecordController extends BladeController {
             logger.info("记录[{}]已经不存在或者状态错误,已跳过", id);
             return;
         }
-        if (record.getTargetId() == null) {
+        if (record.getTargetId() == null || record.getTargetId() <= 0) {
             informationImportRecordService.updateProcess(record.getId(), null, 3, record.getRemark() + "::找不到目标节点", record.getUpdateTime());
             return;
         }
@@ -408,7 +415,7 @@ public class InformationImportRecordController extends BladeController {
             logger.info("记录[{}]已经不存在或者状态错误,已跳过", id);
             return;
         }
-        if (record.getTargetId() == null) {
+        if (record.getTargetId() == null || record.getTargetId() <= 0) {
             informationImportRecordService.updateProcess(record.getId(), null, 3, record.getRemark() + "::找不到目标节点", record.getUpdateTime());
             return;
         }
@@ -667,7 +674,7 @@ public class InformationImportRecordController extends BladeController {
     @Scheduled(fixedDelay = 1000L * 60 * 10)
     @Async
     public void importInformationData() {
-        if (!RUNNING.compareAndSet(false, true)) {
+        if (!SystemUtils.isLinux() || !RUNNING.compareAndSet(false, true)) {
             return;
         }
         try {
@@ -683,10 +690,10 @@ public class InformationImportRecordController extends BladeController {
                                 informationImportRecordService.updateProcess(record.getId(), null, 3, "节点未找到-客户端", record.getUpdateTime());
                                 return;
                             }
-                            if (record.getProcess() <= 25) {
+                            if (record.getProcess() <= 15) {
                                 init(record.getId(), node);
                             }
-                            if (record.getProcess() < 70) {
+                            if (record.getProcess() < 60) {
                                 importData(record.getId());
                             }
                             if (record.getProcess() < 100) {