song 5 months ago
parent
commit
51f6beea4b

+ 51 - 45
src/main/java/com/dashitech/migration/StartApplication.java

@@ -25,52 +25,58 @@ public class StartApplication {
25 25
     public void start() {
26 26
         log.info("########### 开始迁移任务!###########");
27 27
         SqlTask task = null;
28
-//        task = SpringContextHolder.getBean("dictionaryTask");
29
-//        task.start();
30
-//        task = SpringContextHolder.getBean("tokenTask");
31
-//        task.start();
32
-//        task = SpringContextHolder.getBean("attachmentTask");
33
-//        task.start();
34
-//        task = SpringContextHolder.getBean("hospitalTask");
35
-//        task.start();
36
-//        task = SpringContextHolder.getBean("hospitalConfigTask");
37
-//        task.start();
38
-//        task = SpringContextHolder.getBean("groupTask");
39
-//        task.start();
40
-//        task = SpringContextHolder.getBean("departmentTask");
41
-//        task.start();
42
-//        task = SpringContextHolder.getBean("companyTask");
43
-//        task.start();
44
-//        task = SpringContextHolder.getBean("userTask");
45
-//        task.start();
46
-//        task = SpringContextHolder.getBean("userGroupTask");
47
-//        task.start();
48
-//        task = SpringContextHolder.getBean("roleUserTask");
49
-//        task.start();
50
-//        task = SpringContextHolder.getBean("incidentCategoryTask");
51
-//        task.start();
52
-//        task = SpringContextHolder.getBean("incidentCategoryConfigTask");
53
-//        task.start();
54
-        task = SpringContextHolder.getBean("incidentTask");
28
+        //task = SpringContextHolder.getBean("dictionaryTask");
29
+        //task.start();
30
+        //task = SpringContextHolder.getBean("tokenTask");
31
+        //task.start();
32
+        //task = SpringContextHolder.getBean("attachmentTask");
33
+        //task.start();
34
+        //task = SpringContextHolder.getBean("hospitalTask");
35
+        //task.start();
36
+        //task = SpringContextHolder.getBean("hospitalConfigTask");
37
+        //task.start();
38
+        //task = SpringContextHolder.getBean("groupTask");
39
+        //task.start();
40
+        //task = SpringContextHolder.getBean("departmentTask");
41
+        //task.start();
42
+        //task = SpringContextHolder.getBean("companyTask");
43
+        //task.start();
44
+        //task = SpringContextHolder.getBean("userTask");
45
+        //task.start();
46
+        //task = SpringContextHolder.getBean("userGroupTask");
47
+        //task.start();
48
+        //task = SpringContextHolder.getBean("roleUserTask");
49
+        //task.start();
50
+        //task = SpringContextHolder.getBean("areaTask");
51
+        //task.start();
52
+        task = SpringContextHolder.getBean("placeTask");
55 53
         task.start();
56
-//        task = SpringContextHolder.getBean("workHourManagementTask");
57
-//        task.start();
58
-//        task = SpringContextHolder.getBean("solutionTask");
59
-//        task.start();
60
-//        task = SpringContextHolder.getBean("solutionIntroduceTask");
61
-//        task.start();
62
-//        task = SpringContextHolder.getBean("consumableTask");
63
-//        task.start();
64
-//        task = SpringContextHolder.getBean("consumableHistoryTask");
65
-//        task.start();
66
-//        task = SpringContextHolder.getBean("repairSummaryTask");
67
-//        task.start();
68
-//        task = SpringContextHolder.getBean("summaryConsumableTask");
69
-//        task.start();
70
-//        task = SpringContextHolder.getBean("callLogTask");
71
-//        task.start();
72
-//        task = SpringContextHolder.getBean("hjzxRecordTask");
73
-//        task.start();
54
+        //task = SpringContextHolder.getBean("incidentCategoryTask");
55
+        //task.start();
56
+        //task = SpringContextHolder.getBean("incidentCategoryConfigTask");
57
+        //task.start();
58
+        //task = SpringContextHolder.getBean("incidentAssignManagerTask");
59
+        //task.start();
60
+        //task = SpringContextHolder.getBean("incidentTask");
61
+        //task.start();
62
+        //task = SpringContextHolder.getBean("workHourManagementTask");
63
+        //task.start();
64
+        //task = SpringContextHolder.getBean("solutionTask");
65
+        //task.start();
66
+        //task = SpringContextHolder.getBean("solutionIntroduceTask");
67
+        //task.start();
68
+        //task = SpringContextHolder.getBean("consumableTask");
69
+        //task.start();
70
+        //task = SpringContextHolder.getBean("consumableHistoryTask");
71
+        //task.start();
72
+        //task = SpringContextHolder.getBean("repairSummaryTask");
73
+        //task.start();
74
+        //task = SpringContextHolder.getBean("summaryConsumableTask");
75
+        //task.start();
76
+        //task = SpringContextHolder.getBean("callLogTask");
77
+        //task.start();
78
+        //task = SpringContextHolder.getBean("hjzxRecordTask");
79
+        //task.start();
74 80
 
75 81
 
76 82
         log.info("########### 迁移任务完成!###########");

+ 1 - 1
src/main/java/com/dashitech/migration/core/DataMigrationter.java

@@ -29,7 +29,7 @@ public class DataMigrationter {
29 29
                 //拼接联合主键,判断是更新,还是新增
30 30
                 StringBuffer key = new StringBuffer();
31 31
                 for (DataMapper fieldMapper : cacheMapper.getFieldList()) {
32
-                    Object value = row.get(fieldMapper.getSourceName());
32
+                    Object value = row.get(fieldMapper.getTargetName());
33 33
                     //可能构建联合主键时,需要替换成新数据
34 34
                     value = getOprationReplaceValue(dataMapper, fieldMapper, value);
35 35
                     key.append(value).append("_");

+ 16 - 6
src/main/java/com/dashitech/migration/task/incident/IncidentAssignManagerTask.java

@@ -8,7 +8,6 @@ import com.dashitech.migration.util.JdbcUtil;
8 8
 import org.apache.commons.logging.Log;
9 9
 import org.apache.commons.logging.LogFactory;
10 10
 import org.springframework.beans.factory.annotation.Autowired;
11
-import org.springframework.core.annotation.Order;
12 11
 import org.springframework.stereotype.Component;
13 12
 import org.springframework.transaction.annotation.Transactional;
14 13
 
@@ -27,6 +26,12 @@ public class IncidentAssignManagerTask extends BaseTask {
27 26
     @Autowired
28 27
     SqlTask departmentTask;
29 28
 
29
+    @Autowired
30
+    SqlTask userTask;
31
+
32
+    @Autowired
33
+    SqlTask groupTask;
34
+
30 35
     public static Log log = LogFactory.getLog(IncidentAssignManagerTask.class);
31 36
 
32 37
     @Override
@@ -35,21 +40,26 @@ public class IncidentAssignManagerTask extends BaseTask {
35 40
         log.info(" *** IncidentAssignManagerTask start 开始 *** ");
36 41
 
37 42
         StringBuffer sb = new StringBuffer();
38
-        sb.append(" select * from itsm_incident ");
43
+        sb.append(" select * from itsm_incident_assign_manager ");
39 44
 
40 45
         List list = jdbcTemplateMdv2.queryForList(sb.toString());
41 46
 
42 47
         FieldMapper mapper = new FieldMapper();
43
-        mapper.addOperationRemove("id").addOperationRemove("version");
48
+        mapper.addOperationRemove("id").addOperationRemove("userOrGroupType").addOperationRemove("branch_id");
49
+        mapper.addOperationUpdate("handle_group", "_group");
50
+        mapper.addOperationUpdate("batch_no", "batch_id");
51
+        mapper.addOperationUpdate("hos_id", "duty_id");
52
+        mapper.addOperationReplace("duty_id", hospitalTask.loadCache().getIdCache());
53
+        mapper.addOperationReplace("dept_id", departmentTask.loadCache().getIdCache());
54
+        mapper.addOperationReplace("handle_user", userTask.loadCache().getIdCache());
55
+        mapper.addOperationReplace("_group", groupTask.loadCache().getIdCache());
44 56
         mapper.trans2JdbcRow(list);
45 57
 
46
-        FieldMapper userMapper = loadCache();
47 58
         JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
48
-        jdbcUtil.batchPageInsert("itsm_itsm_incident", mapper.getRows());
59
+        jdbcUtil.batchPageInsert("itsm_itsm_incident_assign_manager", mapper.getRows());
49 60
 
50 61
         //clear释放内存
51 62
         mapper.clear();
52
-        userMapper.clear();
53 63
     }
54 64
 
55 65
     @Override

+ 4 - 1
src/main/java/com/dashitech/migration/task/incident/IncidentTask.java

@@ -4,7 +4,6 @@ import com.dashitech.migration.BaseTask;
4 4
 import com.dashitech.migration.SqlTask;
5 5
 import com.dashitech.migration.core.DataMigrationter;
6 6
 import com.dashitech.migration.core.FieldMapper;
7
-import com.dashitech.migration.core.RowsWrap;
8 7
 import com.dashitech.migration.util.JdbcUtil;
9 8
 import org.apache.commons.logging.Log;
10 9
 import org.apache.commons.logging.LogFactory;
@@ -35,6 +34,9 @@ public class IncidentTask extends BaseTask {
35 34
     @Autowired
36 35
     SqlTask dictionaryTask;
37 36
 
37
+    @Autowired
38
+    SqlTask placeTask;
39
+
38 40
     public static Log log = LogFactory.getLog(IncidentTask.class);
39 41
 
40 42
     @Override
@@ -71,6 +73,7 @@ public class IncidentTask extends BaseTask {
71 73
         //只有襄阳需要处理科室,南京不用
72 74
         if ("xiangyang".equals(appName)) {
73 75
             mapper.addOperationReplace("dept", departmentTask.loadCache().getIdCache());
76
+            mapper.addOperationReplace("placeid", placeTask.loadCache().getIdCache());
74 77
         }
75 78
         mapper.trans2JdbcRow(list);
76 79
 

+ 60 - 0
src/main/java/com/dashitech/migration/task/uc/AreaTask.java

@@ -0,0 +1,60 @@
1
+package com.dashitech.migration.task.uc;
2
+
3
+import com.dashitech.migration.BaseTask;
4
+import com.dashitech.migration.core.DataMigrationter;
5
+import com.dashitech.migration.core.FieldMapper;
6
+import com.dashitech.migration.core.RowsWrap;
7
+import com.dashitech.migration.util.JdbcUtil;
8
+import org.apache.commons.logging.Log;
9
+import org.apache.commons.logging.LogFactory;
10
+import org.springframework.stereotype.Component;
11
+import org.springframework.transaction.annotation.Transactional;
12
+
13
+import java.util.List;
14
+import java.util.Map;
15
+
16
+/**
17
+ * @author song
18
+ * @date 2024年10月14日
19
+ */
20
+@Component
21
+public class AreaTask extends BaseTask {
22
+
23
+    public static Log log = LogFactory.getLog(AreaTask.class);
24
+
25
+    @Override
26
+    @Transactional(rollbackFor = Exception.class)
27
+    public void start() {
28
+        log.info(" *** 楼栋AreaTask转换开始 *** ");
29
+        StringBuffer sql = new StringBuffer("select 0 as version,IF(branch_id=4,3,branch_id) as hos_id,area as building_name,now() as operator_time, ");
30
+        sql.append(" delete_flag as _delete from itsm_uc_area");
31
+        List<Map<String, Object>> areaList = jdbcTemplateMdv2.queryForList(sql.toString());
32
+        FieldMapper mapper = new FieldMapper();
33
+        mapper.trans2JdbcRow(areaList);
34
+
35
+        FieldMapper areaMapper = this.loadCache();
36
+        RowsWrap rw = DataMigrationter.getRowsWrap(mapper,areaMapper);
37
+        JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
38
+        //科室只做更新 已有的科室不做处理
39
+        jdbcUtil.batchPageInsert("itsm_uc_building", rw.getInsertRows());
40
+
41
+        mapper.clear();
42
+    }
43
+
44
+    @Override
45
+    public FieldMapper loadCache() {
46
+        log.info(" *** 加载楼栋area缓存 *** ");
47
+        StringBuffer sql = new StringBuffer("select id,hos_id,building_name from itsm_uc_building ");
48
+        List<Map<String, Object>> buildingList = jdbcTemplateHsms.queryForList(sql.toString());
49
+        sql = new StringBuffer("select id,IF(branch_id=4,3,branch_id) as branch_id,area from itsm_uc_area ");
50
+        List<Map<String, Object>> areaList = jdbcTemplateMdv2.queryForList(sql.toString());
51
+
52
+        FieldMapper mapper = new FieldMapper();
53
+        mapper.addFieldMapper("building_name", "area");
54
+        mapper.addFieldMapper("hos_id", "branch_id");
55
+
56
+        DataMigrationter.loadCache(buildingList, areaList, mapper);
57
+
58
+        return mapper;
59
+    }
60
+}

+ 64 - 0
src/main/java/com/dashitech/migration/task/uc/PlaceTask.java

@@ -0,0 +1,64 @@
1
+package com.dashitech.migration.task.uc;
2
+
3
+import com.dashitech.migration.BaseTask;
4
+import com.dashitech.migration.core.DataMigrationter;
5
+import com.dashitech.migration.core.FieldMapper;
6
+import com.dashitech.migration.core.RowsWrap;
7
+import com.dashitech.migration.util.JdbcUtil;
8
+import org.apache.commons.logging.Log;
9
+import org.apache.commons.logging.LogFactory;
10
+import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.stereotype.Component;
12
+import org.springframework.transaction.annotation.Transactional;
13
+
14
+import java.util.List;
15
+import java.util.Map;
16
+
17
+/**
18
+ * @author song
19
+ * @date 2024年10月14日
20
+ */
21
+@Component
22
+public class PlaceTask extends BaseTask {
23
+
24
+    public static Log log = LogFactory.getLog(PlaceTask.class);
25
+
26
+    @Autowired
27
+    private AreaTask areaTask;
28
+
29
+    @Override
30
+    @Transactional(rollbackFor = Exception.class)
31
+    public void start() {
32
+        log.info(" *** 楼层PlaceTask转换开始 *** ");
33
+        StringBuffer sql = new StringBuffer("select 0 as version,area_id as build_id,SUBSTRING_INDEX(SUBSTRING_INDEX(place,'楼',1),'号',1) as floor_name,IF(branch_id=4,3,branch_id) as hos_id,now() as operator_time, ");
34
+        sql.append(" delete_flag as _delete from itsm_uc_place");
35
+        List<Map<String, Object>> placeList = jdbcTemplateMdv2.queryForList(sql.toString());
36
+        FieldMapper mapper = new FieldMapper();
37
+        mapper.addOperationReplace("build_id", areaTask.loadCache().getIdCache());
38
+        mapper.trans2JdbcRow(placeList);
39
+
40
+        FieldMapper areaMapper = this.loadCache();
41
+        RowsWrap rw = DataMigrationter.getRowsWrap(mapper,areaMapper);
42
+        JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
43
+        //科室只做更新 已有的科室不做处理
44
+        jdbcUtil.batchPageInsert("itsm_uc_floor", rw.getInsertRows());
45
+    }
46
+
47
+    @Override
48
+    public FieldMapper loadCache() {
49
+        log.info(" *** 加载楼层place缓存 *** ");
50
+        StringBuffer sql = new StringBuffer("select id,hos_id,build_id,floor_name from itsm_uc_floor ");
51
+        List<Map<String, Object>> floorList = jdbcTemplateHsms.queryForList(sql.toString());
52
+        sql = new StringBuffer("select id,IF(branch_id=4,3,branch_id) as branch_id,area_id,SUBSTRING_INDEX(SUBSTRING_INDEX(place,'楼',1),'号',1) as place from itsm_uc_place ");
53
+        List<Map<String, Object>> placeList = jdbcTemplateMdv2.queryForList(sql.toString());
54
+
55
+        FieldMapper mapper = new FieldMapper();
56
+        mapper.addFieldMapper("floor_name", "place");
57
+        mapper.addFieldMapper("build_id", "area_id");
58
+        mapper.addFieldMapper("hos_id", "branch_id");
59
+
60
+        DataMigrationter.loadCache(floorList, placeList, mapper);
61
+
62
+        return mapper;
63
+    }
64
+}