소스 검색

添加项目标识获取不同缓存和运行不同转换

song 5 달 전
부모
커밋
2201de07e7

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

@@ -2,6 +2,7 @@ package com.dashitech.migration;
2
 
2
 
3
 import org.springframework.beans.factory.annotation.Autowired;
3
 import org.springframework.beans.factory.annotation.Autowired;
4
 import org.springframework.beans.factory.annotation.Qualifier;
4
 import org.springframework.beans.factory.annotation.Qualifier;
5
+import org.springframework.beans.factory.annotation.Value;
5
 import org.springframework.jdbc.core.JdbcTemplate;
6
 import org.springframework.jdbc.core.JdbcTemplate;
6
 
7
 
7
 import java.util.LinkedHashMap;
8
 import java.util.LinkedHashMap;
@@ -14,6 +15,9 @@ public abstract class BaseTask implements SqlTask {
14
 
15
 
15
     protected Map cache = new LinkedHashMap();
16
     protected Map cache = new LinkedHashMap();
16
 
17
 
18
+    @Value("${application.name}")
19
+    protected String appName;
20
+
17
     @Autowired
21
     @Autowired
18
     @Qualifier("jdbcTemplateHsms")
22
     @Qualifier("jdbcTemplateHsms")
19
     protected JdbcTemplate jdbcTemplateHsms;
23
     protected JdbcTemplate jdbcTemplateHsms;

+ 21 - 3
src/main/java/com/dashitech/migration/StartApplication.java

@@ -1,9 +1,11 @@
1
 package com.dashitech.migration;
1
 package com.dashitech.migration;
2
 
2
 
3
 import com.dashitech.migration.task.uc.HospitalTask;
3
 import com.dashitech.migration.task.uc.HospitalTask;
4
+import com.dashitech.migration.task.uc.XyGroupTask;
4
 import org.apache.commons.logging.Log;
5
 import org.apache.commons.logging.Log;
5
 import org.apache.commons.logging.LogFactory;
6
 import org.apache.commons.logging.LogFactory;
6
 import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.beans.factory.annotation.Value;
7
 import org.springframework.stereotype.Service;
9
 import org.springframework.stereotype.Service;
8
 
10
 
9
 /**
11
 /**
@@ -24,13 +26,29 @@ public class StartApplication {
24
     @Autowired
26
     @Autowired
25
     HospitalTask hospitalTask;
27
     HospitalTask hospitalTask;
26
 
28
 
29
+    @Autowired
30
+    XyGroupTask xyGroupTask;
31
+
32
+    @Value("${application.name}")
33
+    private String appName;
34
+
27
     public void start() {
35
     public void start() {
28
         log.info("########### 开始迁移任务!###########");
36
         log.info("########### 开始迁移任务!###########");
29
 
37
 
30
-        //工作组
31
-//        groupTask.start();
38
+        if ("xiangyang".equals(appName)) {
39
+            //责任科室转院区
40
+            //hospitalTask.start();
41
+            //工作组
42
+            //xyGroupTask.start();
43
+        } else {
44
+            //工作组
45
+            groupTask.start();
46
+        }
47
+
48
+
49
+
32
 
50
 
33
-//        userTask.start();
51
+        userTask.start();
34
 
52
 
35
         groupTask.loadCache();
53
         groupTask.loadCache();
36
 
54
 

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

@@ -1,4 +1,4 @@
1
-package com.dashitech.migration.task.uc;
1
+package com.dashitech.migration.task.other;
2
 
2
 
3
 import com.dashitech.migration.BaseTask;
3
 import com.dashitech.migration.BaseTask;
4
 import com.dashitech.migration.core.FieldMapper;
4
 import com.dashitech.migration.core.FieldMapper;

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

@@ -1,4 +1,4 @@
1
-package com.dashitech.migration.task.uc;
1
+package com.dashitech.migration.task.solution;
2
 
2
 
3
 import com.dashitech.migration.BaseTask;
3
 import com.dashitech.migration.BaseTask;
4
 import com.dashitech.migration.core.FieldMapper;
4
 import com.dashitech.migration.core.FieldMapper;

+ 9 - 4
src/main/java/com/dashitech/migration/task/uc/HospitalTask.java

@@ -1,6 +1,7 @@
1
 package com.dashitech.migration.task.uc;
1
 package com.dashitech.migration.task.uc;
2
 
2
 
3
 import com.dashitech.migration.BaseTask;
3
 import com.dashitech.migration.BaseTask;
4
+import com.dashitech.migration.core.DataMigrationter;
4
 import com.dashitech.migration.core.FieldMapper;
5
 import com.dashitech.migration.core.FieldMapper;
5
 import com.dashitech.migration.util.JdbcUtil;
6
 import com.dashitech.migration.util.JdbcUtil;
6
 import org.apache.commons.logging.Log;
7
 import org.apache.commons.logging.Log;
@@ -27,9 +28,10 @@ public class HospitalTask extends BaseTask {
27
         sql.append(" FROM `itsm_uc_duty_dept` where dept not like 'Z%'  and dept not like '%保卫%' and id not in (20,21)");
28
         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
         List<Map<String, Object>> hosList = jdbcTemplateMdv2.queryForList(sql.toString());
29
         FieldMapper mapper = new FieldMapper();
30
         FieldMapper mapper = new FieldMapper();
31
+        mapper.addOperationAdd("type", 20390L);//院区类型 维修科室
30
         mapper.trans2JdbcRow(hosList);
32
         mapper.trans2JdbcRow(hosList);
31
         JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
33
         JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
32
-        //jdbcUtil.batchPageInsert("itsm_uc_hospital", mapper.getRows());
34
+        jdbcUtil.batchPageInsert("itsm_uc_hospital", mapper.getRows());
33
 
35
 
34
         //clear释放内存
36
         //clear释放内存
35
         mapper.clear();
37
         mapper.clear();
@@ -45,11 +47,14 @@ public class HospitalTask extends BaseTask {
45
     }
47
     }
46
 
48
 
47
     public FieldMapper loadXiangyangCache() {
49
     public FieldMapper loadXiangyangCache() {
50
+        StringBuffer sql = new StringBuffer("SELECT id,dept FROM `itsm_uc_duty_dept` where dept not like 'Z%'  and dept not like '%保卫%' and id not in (20,21)");
51
+        List<Map<String, Object>> dutyList = jdbcTemplateMdv2.queryForList(sql.toString());
52
+        sql = new StringBuffer("select id,_hos_name from itsm_uc_hospital where type = (select id from itsm_base_dictionary where _key = 'hospital_type' and _value = '6')");
53
+        List<Map<String, Object>> hosList = jdbcTemplateHsms.queryForList(sql.toString());
48
         FieldMapper mapper = new FieldMapper();
54
         FieldMapper mapper = new FieldMapper();
49
-        Map<Long, Long> hosIdCache = new HashMap<>();
50
-        mapper.setIdCache(hosIdCache);
51
-
55
+        mapper.addFieldMapper("_hos_name", "dept");
52
 
56
 
57
+        DataMigrationter.loadCache(hosList, dutyList, mapper);
53
 
58
 
54
         return mapper;
59
         return mapper;
55
     }
60
     }

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

@@ -22,6 +22,9 @@ public class UserTask extends BaseTask {
22
     @Autowired
22
     @Autowired
23
     SqlTask groupTask;
23
     SqlTask groupTask;
24
 
24
 
25
+    @Autowired
26
+    HospitalTask hospitalTask;
27
+
25
     public static Log log = LogFactory.getLog(UserTask.class);
28
     public static Log log = LogFactory.getLog(UserTask.class);
26
 
29
 
27
     @Override
30
     @Override
@@ -35,6 +38,12 @@ public class UserTask extends BaseTask {
35
         List list = jdbcTemplateHsms.queryForList(sb.toString());
38
         List list = jdbcTemplateHsms.queryForList(sb.toString());
36
 
39
 
37
         FieldMapper groupMapper = groupTask.loadCache();
40
         FieldMapper groupMapper = groupTask.loadCache();
41
+        Map<Long, Long> hosIdCache = null;
42
+        if ("xiangyang".equals(appName)) {
43
+            hosIdCache = hospitalTask.loadXiangyangCache().getIdCache();
44
+        } else {
45
+            hosIdCache = hospitalTask.loadNanjingCache().getIdCache();
46
+        }
38
         System.out.println(groupMapper.getIdCache());
47
         System.out.println(groupMapper.getIdCache());
39
 
48
 
40
 
49
 

+ 56 - 0
src/main/java/com/dashitech/migration/task/uc/XyGroupTask.java

@@ -0,0 +1,56 @@
1
+package com.dashitech.migration.task.uc;
2
+
3
+import com.dashitech.migration.BaseTask;
4
+import com.dashitech.migration.core.FieldMapper;
5
+import com.dashitech.migration.util.JdbcUtil;
6
+import org.apache.commons.logging.Log;
7
+import org.apache.commons.logging.LogFactory;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.stereotype.Component;
10
+
11
+import java.util.List;
12
+import java.util.Map;
13
+
14
+/**
15
+ * @author song
16
+ * @date 2024年10月12日
17
+ */
18
+@Component
19
+public class XyGroupTask extends BaseTask {
20
+
21
+    public static Log log = LogFactory.getLog(XyGroupTask.class);
22
+
23
+    @Autowired
24
+    private HospitalTask hospitalTask;
25
+
26
+
27
+    @Override
28
+    public void start() {
29
+        log.info(" *** 襄阳工作组group转换开始 *** ");
30
+
31
+        StringBuffer sql = new StringBuffer("select 0 as version,a.groupname,a.delete_flag,a.duty_id ,now() as operator_time,1 as schedule_class_id");
32
+        sql.append(" from itsm_uc_groups a join itsm_uc_duty_dept b on a.duty_id = b.id ");
33
+        sql.append("where b.dept not like 'Z%' and dept not like '%保卫%' and b.id not in (20,21)");
34
+
35
+        List<Map<String, Object>> groupList = jdbcTemplateMdv2.queryForList(sql.toString());
36
+
37
+        //测试
38
+        FieldMapper mapper = new FieldMapper();
39
+        mapper.addOperationUpdate("_hospital_id", "duty_id");
40
+        mapper.addOperationAdd("type", 3);
41
+        Map<Long, Long> hosIdCache = hospitalTask.loadXiangyangCache().getIdCache();
42
+        mapper.addOperationReplace("duty_id", hosIdCache);
43
+        mapper.trans2JdbcRow(groupList);
44
+
45
+        JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
46
+        //jdbcUtil.batchPageInsert("itsm_uc_groups", mapper.getRows());
47
+
48
+        //clear释放内存
49
+        mapper.clear();
50
+    }
51
+
52
+    @Override
53
+    public FieldMapper loadCache() {
54
+        return null;
55
+    }
56
+}

+ 3 - 0
src/main/resources/application.properties

@@ -53,3 +53,6 @@ server.tomcat.compression=on
53
 
53
 
54
 spring.jackson.parser.allow-numeric-leading-zeros=true
54
 spring.jackson.parser.allow-numeric-leading-zeros=true
55
 
55
 
56
+#\u5F53\u524D\u73AF\u5883\u540D\u79F0
57
+application.name=xiangyang
58
+