song 5 月之前
父節點
當前提交
0d2a0ff469

+ 4 - 1
src/main/java/com/dashitech/migration/SqlTask.java

@@ -14,6 +14,9 @@ public interface SqlTask {
14 14
 
15 15
     /**
16 16
      * 如果之前执行有报错,需要重新加载特定字段缓存数据
17
+     * 字段缓存可根据指定key加载
17 18
      */
18
-    FieldMapper loadCache();
19
+    FieldMapper loadCache(String key);
20
+
21
+
19 22
 }

+ 4 - 0
src/main/java/com/dashitech/migration/StartApplication.java

@@ -1,5 +1,6 @@
1 1
 package com.dashitech.migration;
2 2
 
3
+import com.dashitech.migration.task.uc.HospitalTask;
3 4
 import org.apache.commons.logging.Log;
4 5
 import org.apache.commons.logging.LogFactory;
5 6
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,6 +21,9 @@ public class StartApplication {
20 21
     @Autowired
21 22
     SqlTask userTask;
22 23
 
24
+    @Autowired
25
+    HospitalTask hospitalTask;
26
+
23 27
     public void start() {
24 28
         log.info("########### 开始迁移任务!###########");
25 29
 

+ 42 - 0
src/main/java/com/dashitech/migration/task/uc/DictionaryTask.java

@@ -0,0 +1,42 @@
1
+package com.dashitech.migration.task.uc;
2
+
3
+import com.dashitech.migration.BaseTask;
4
+import com.dashitech.migration.core.FieldMapper;
5
+import org.apache.commons.logging.Log;
6
+import org.apache.commons.logging.LogFactory;
7
+import org.springframework.stereotype.Component;
8
+import org.springframework.util.Assert;
9
+
10
+import java.util.HashMap;
11
+import java.util.Map;
12
+
13
+/**
14
+ * @author song
15
+ * @date 2024年10月12日
16
+ */
17
+
18
+@Component
19
+public class DictionaryTask extends BaseTask {
20
+
21
+    public static Log log = LogFactory.getLog(DictionaryTask.class);
22
+    @Override
23
+    public void start() {
24
+
25
+    }
26
+
27
+    @Override
28
+    public FieldMapper loadCache(String key) {
29
+        log.info(" *** 加载字典缓存 *** ");
30
+        FieldMapper mapper = new FieldMapper();
31
+        Map<Long, Long> dicIdCache = new HashMap<>();
32
+        mapper.setIdCache(dicIdCache);
33
+        if ("solution".equals(key)) {
34
+            dicIdCache.put(71L, 20404L); //待审核
35
+            dicIdCache.put(72L, 20405L); //已发布
36
+            dicIdCache.put(73L, 20406L); //待整改
37
+            dicIdCache.put(74L, 20407L); //已停用
38
+
39
+        }
40
+        return mapper;
41
+    }
42
+}

+ 3 - 3
src/main/java/com/dashitech/migration/task/uc/GroupTask.java

@@ -40,7 +40,7 @@ public class GroupTask extends BaseTask {
40 40
         mapper.addOperationRemove("id").addOperationRemove("duty_id");
41 41
         mapper.addOperationUpdate("_hospital_id", "branch_id");
42 42
         mapper.addOperationAdd("type", 3);
43
-        Map<Long, Long> hosIdCache = hospitalTask.loadCache().getIdCache();
43
+        Map<Long, Long> hosIdCache = hospitalTask.loadCache(null).getIdCache();
44 44
         mapper.addOperationReplace("branch_id", hosIdCache);
45 45
         mapper.trans2JdbcRow(list);
46 46
 
@@ -52,7 +52,7 @@ public class GroupTask extends BaseTask {
52 52
     }
53 53
 
54 54
     @Override
55
-    public FieldMapper loadCache() {
55
+    public FieldMapper loadCache(String key) {
56 56
         log.info(" *** 加载工作组group缓存 *** ");
57 57
 
58 58
         String sql = " select id,groupname,delete_flag,_hospital_id from itsm_uc_groups ";
@@ -64,7 +64,7 @@ public class GroupTask extends BaseTask {
64 64
         mapper.addFieldMapper("groupname", "groupname");
65 65
         mapper.addFieldMapper("delete_flag", "delete_flag");
66 66
         mapper.addFieldMapper("_hospital_id", "branch_id");
67
-        Map<Long, Long> hosIdCache = hospitalTask.loadCache().getIdCache();
67
+        Map<Long, Long> hosIdCache = hospitalTask.loadCache(null).getIdCache();
68 68
         mapper.addOperationReplace("branch_id", hosIdCache);
69 69
 
70 70
         DataMigrationter.loadCache(list, list2, mapper);

+ 11 - 3
src/main/java/com/dashitech/migration/task/uc/HospitalTask.java

@@ -1,11 +1,10 @@
1 1
 package com.dashitech.migration.task.uc;
2 2
 
3 3
 import com.dashitech.migration.BaseTask;
4
-import com.dashitech.migration.SqlTask;
5 4
 import com.dashitech.migration.core.FieldMapper;
5
+import com.dashitech.migration.util.JdbcUtil;
6 6
 import org.apache.commons.logging.Log;
7 7
 import org.apache.commons.logging.LogFactory;
8
-import org.springframework.beans.factory.annotation.Autowired;
9 8
 import org.springframework.stereotype.Component;
10 9
 import org.springframework.transaction.annotation.Transactional;
11 10
 
@@ -24,11 +23,20 @@ public class HospitalTask extends BaseTask {
24 23
     @Override
25 24
     @Transactional
26 25
     public void start() {
26
+        StringBuffer sql = new StringBuffer("SELECT 0 as version,branch_id as parentId,dept as _hos_name,IFNULL(code,py) as _hos_no,delete_flag,now() as operator_time ");
27
+        sql.append(" FROM `itsm_uc_duty_dept` where dept not like 'Z%'  and dept not like '%保卫%' and id not in (20,21)");
28
+        List<Map<String, Object>> hosList = jdbcTemplateMdv2.queryForList(sql.toString());
29
+        FieldMapper mapper = new FieldMapper();
30
+        mapper.trans2JdbcRow(hosList);
31
+        JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
32
+        //jdbcUtil.batchPageInsert("itsm_uc_hospital", mapper.getRows());
27 33
 
34
+        //clear释放内存
35
+        mapper.clear();
28 36
     }
29 37
 
30 38
     @Override
31
-    public FieldMapper loadCache() {
39
+    public FieldMapper loadCache(String key) {
32 40
         log.info(" *** 加载院区Hospital缓存 *** ");
33 41
 
34 42
         FieldMapper mapper = new FieldMapper();

+ 30 - 0
src/main/java/com/dashitech/migration/task/uc/SolutionTask.java

@@ -0,0 +1,30 @@
1
+package com.dashitech.migration.task.uc;
2
+
3
+import com.dashitech.migration.BaseTask;
4
+import com.dashitech.migration.core.FieldMapper;
5
+import org.springframework.transaction.annotation.Transactional;
6
+
7
+import java.util.List;
8
+import java.util.Map;
9
+
10
+/**
11
+ * @author song
12
+ * @date 2024年10月12日
13
+ */
14
+public class SolutionTask extends BaseTask {
15
+
16
+    @Override
17
+    @Transactional
18
+    public void start() {
19
+        StringBuffer sql = new StringBuffer("SELECT id,version,case when categoryId is null then 20342 else 20340 end as type,title,keywords,content,STATUS,");
20
+        sql.append("create_user_id,createtime as create_time,renew_user_id,renewtime as renew_time,solutionnumber as solution_number,");
21
+        sql.append("version_number,star,categoryId as category_id,introduce_count,file_abstract,duty_dept,IF( `status` = 74, 1, 0 ) AS delete_flag FROM itsm_solution");
22
+        List<Map<String, Object>> solutionList = jdbcTemplateMdv2.queryForList(sql.toString());
23
+        FieldMapper mapper = new FieldMapper();
24
+    }
25
+
26
+    @Override
27
+    public FieldMapper loadCache(String key) {
28
+        return null;
29
+    }
30
+}

+ 2 - 2
src/main/java/com/dashitech/migration/task/uc/UserTask.java

@@ -32,14 +32,14 @@ public class UserTask extends BaseTask {
32 32
 
33 33
         List list = jdbcTemplateHsms.queryForList(sb.toString());
34 34
 
35
-        FieldMapper groupMapper = groupTask.loadCache();
35
+        FieldMapper groupMapper = groupTask.loadCache(null);
36 36
         System.out.println(groupMapper.getIdCache());
37 37
 
38 38
 
39 39
     }
40 40
 
41 41
     @Override
42
-    public FieldMapper loadCache() {
42
+    public FieldMapper loadCache(String key) {
43 43
         log.info(" *** 加载用户user缓存 *** ");
44 44
 
45 45