Browse Source

加日志

CX 5 months ago
parent
commit
a5d132eb0f

+ 54 - 11
src/main/java/com/dashitech/migration/StartApplication.java

@@ -1,14 +1,15 @@
1 1
 package com.dashitech.migration;
2 2
 
3
-import com.dashitech.migration.task.other.DictionaryTask;
4
-import com.dashitech.migration.task.uc.HospitalTask;
3
+import com.dashitech.utils.SpringContextHolder;
5 4
 import org.apache.commons.logging.Log;
6 5
 import org.apache.commons.logging.LogFactory;
7 6
 import org.springframework.beans.factory.annotation.Autowired;
8 7
 import org.springframework.beans.factory.annotation.Value;
8
+import org.springframework.context.ApplicationContext;
9 9
 import org.springframework.stereotype.Service;
10 10
 
11 11
 import java.util.List;
12
+import java.util.Map;
12 13
 
13 14
 /**
14 15
  * 迁移数据启动类
@@ -20,24 +21,66 @@ public class StartApplication {
20 21
     public static Log log = LogFactory.getLog(StartApplication.class);
21 22
 
22 23
     @Autowired
23
-    private List<SqlTask> sqlTasks;
24
+    SqlTask hospitalTask;
24 25
 
25 26
     @Value("${application.name}")
26 27
     private String appName;
27 28
 
28 29
     public void start() {
29 30
         log.info("########### 开始迁移任务!###########");
30
-        for (SqlTask sqlTask : sqlTasks) {
31
-            if (sqlTask instanceof DictionaryTask) {
32
-                continue;
33
-            }
34
-            if ("xiangyang".equals(appName) && sqlTask instanceof HospitalTask) {
35
-                sqlTask.start();
36
-            }
37
-        }
31
+        SqlTask task = null;
32
+        task = SpringContextHolder.getBean("dictionaryTask");
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");
55
+//        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();
74
+
75
+
76
+
77
+//        test();
38 78
 
39 79
         log.info("########### 迁移任务完成!###########");
40 80
     }
41 81
 
82
+    public void startOrder() {
83
+        hospitalTask.start();
84
+    }
42 85
 
43 86
 }

+ 1 - 1
src/main/java/com/dashitech/migration/task/category/IncidentCategoryConfigTask.java

@@ -23,7 +23,7 @@ public class IncidentCategoryConfigTask extends BaseTask {
23 23
     @Override
24 24
     @Transactional
25 25
     public void start() {
26
-        StringBuffer sql = new StringBuffer("SELECT version,a.category_id,b._priority as priority,a.duty_id,a.branch_user_group_type as user_group,a.group_id,");
26
+        StringBuffer sql = new StringBuffer("SELECT a.version,a.category_id,b._priority as priority,a.duty_id,a.branch_user_group_type as user_group,a.group_id,");
27 27
         sql.append("a.user_id,NOW() as add_time,a.branch_id as hos_id FROM itsm_incident_category_usergroup a ");
28 28
         sql.append(" JOIN itsm_incident_category b ON a.category_id = b.id");
29 29
         if ("xiangyang".equals(appName)) {

+ 1 - 1
src/main/java/com/dashitech/migration/task/category/IncidentCategoryTask.java

@@ -23,7 +23,7 @@ public class IncidentCategoryTask extends BaseTask {
23 23
     @Transactional
24 24
     public void start() {
25 25
         StringBuffer sql = new StringBuffer("SELECT id,version,category,parentid as parent,delete_flag,quanPinyin as qp,suoPinyin as jp,now() as add_time,");
26
-        sql.append("hierarchy,muti_category,muti_suoPinyin as muti_jp,muti_quanPinyin as muti_qp,alias,IFNULL(branch_id,1) as hos_id ");
26
+        sql.append("hierarchy,muti_category,muti_suoPinyin as muti_jp,muti_quanPinyin as muti_qp,IFNULL(branch_id,1) as hos_id ");
27 27
         sql.append(" FROM itsm_incident_category ");
28 28
         List<Map<String, Object>> categoryList = jdbcTemplateMdv2.queryForList(sql.toString());
29 29
 

+ 85 - 0
src/main/java/com/dashitech/migration/task/incident/IncidentTask.java

@@ -0,0 +1,85 @@
1
+package com.dashitech.migration.task.incident;
2
+
3
+import com.dashitech.migration.BaseTask;
4
+import com.dashitech.migration.SqlTask;
5
+import com.dashitech.migration.core.DataMigrationter;
6
+import com.dashitech.migration.core.FieldMapper;
7
+import com.dashitech.migration.core.RowsWrap;
8
+import com.dashitech.migration.util.JdbcUtil;
9
+import org.apache.commons.logging.Log;
10
+import org.apache.commons.logging.LogFactory;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.core.annotation.Order;
13
+import org.springframework.stereotype.Component;
14
+import org.springframework.transaction.annotation.Transactional;
15
+
16
+import java.util.List;
17
+import java.util.Map;
18
+
19
+/**
20
+ * Created by CX on 2024/10/10.
21
+ */
22
+@Component
23
+@Order(4)
24
+public class IncidentTask extends BaseTask {
25
+
26
+    @Autowired
27
+    SqlTask hospitalTask;
28
+
29
+    @Autowired
30
+    SqlTask departmentTask;
31
+
32
+    public static Log log = LogFactory.getLog(IncidentTask.class);
33
+
34
+    @Override
35
+    @Transactional
36
+    public void start() {
37
+        log.info(" *** DepartmentTask start 开始 *** ");
38
+
39
+        StringBuffer sb = new StringBuffer();
40
+        sb.append(" select version,ACCOUNT,GENDER,NAME,PHONE,PWD,WEIXIN,DEPTID,delete_flag, ");
41
+        sb.append(" pinyin,py as 'input_code',online,branch_id as 'hospital_id', ");
42
+        sb.append(" duty_id as 'duty_dept',company as 'company_id',engineer ");
43
+        sb.append(" from itsm_uc_user ");
44
+        sb.append(" where ACCOUNT != 'dsadmin' ");
45
+
46
+        List list = jdbcTemplateMdv2.queryForList(sb.toString());
47
+
48
+        FieldMapper mapper = new FieldMapper();
49
+        mapper.addOperationAdd("usertype", getDicId(jdbcTemplateHsms,"usertype","4")); //用户类型-默认三方人员
50
+        mapper.addOperationReplace("hospital_id", hospitalTask.loadCache().getIdCache());
51
+        mapper.addOperationReplace("duty_dept", hospitalTask.loadCache().getIdCache());
52
+        if ("xiangyang".equals(appName)) {
53
+            mapper.addOperationReplace("DEPTID", departmentTask.loadCache().getIdCache());
54
+        }
55
+        mapper.trans2JdbcRow(list);
56
+
57
+        FieldMapper userMapper = loadCache();
58
+        RowsWrap rw = DataMigrationter.getRowsWrap(mapper,userMapper);
59
+        JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
60
+        jdbcUtil.batchPageInsert("itsm_uc_user", rw.getInsertRows());
61
+        jdbcUtil.batchPageUpdate("itsm_uc_user", rw.getUpdateRows());
62
+
63
+        //clear释放内存
64
+        mapper.clear();
65
+        userMapper.clear();
66
+    }
67
+
68
+    @Override
69
+    public FieldMapper loadCache() {
70
+        log.info(" *** DepartmentTask loadCache 开始 *** ");
71
+
72
+        String sql = " select id,ACCOUNT,delete_flag from itsm_uc_user ";
73
+        List<Map<String, Object>> list = jdbcTemplateHsms.queryForList(sql);
74
+        sql = " select id,ACCOUNT,delete_flag from itsm_uc_user ";
75
+        List<Map<String, Object>> list2 = jdbcTemplateMdv2.queryForList(sql);
76
+
77
+        FieldMapper mapper = new FieldMapper();
78
+        mapper.addFieldMapper("ACCOUNT", "ACCOUNT");
79
+        mapper.addFieldMapper("delete_flag", "delete_flag");
80
+
81
+        DataMigrationter.loadCache(list, list2, mapper);
82
+
83
+        return mapper;
84
+    }
85
+}

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

@@ -19,7 +19,7 @@ import java.util.Map;
19 19
  * Created by CX on 2024/10/10.
20 20
  */
21 21
 @Component
22
-@Order(7)
22
+@Order(3)
23 23
 public class CompanyTask extends BaseTask {
24 24
 
25 25
     public static Log log = LogFactory.getLog(CompanyTask.class);

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

@@ -27,6 +27,7 @@ public class DepartmentTask extends BaseTask {
27 27
     @Override
28 28
     @Transactional
29 29
     public void start() {
30
+        log.info(" *** DepartmentTask start 开始 *** ");
30 31
         StringBuffer sql = new StringBuffer("SELECT dept,CODE,parentId,email,delete_flag,address as _address,place_id as floor_id,area_id as building_id,pinyin,");
31 32
         sql.append("branch_id as _hospital_id,dept_alias,input_code,phone as many_phone,qrcode,1 as flag,IF(phone is not null,SUBSTRING_INDEX(phone,',',1),null) as _phone ");
32 33
         sql.append(" FROM itsm_uc_dept where id in (select distinct b.id from itsm_incident a join itsm_uc_dept b on a.dept = b.id where a.dept > 1204)");
@@ -48,7 +49,7 @@ public class DepartmentTask extends BaseTask {
48 49
 
49 50
     @Override
50 51
     public FieldMapper loadCache() {
51
-        log.info(" *** 加载科室缓存 *** ");
52
+        log.info(" *** DepartmentTask load开始 *** ");
52 53
         StringBuffer sql = new StringBuffer("select id,dept from itsm_uc_dept");
53 54
         List<Map<String, Object>> hsmsDeptList = jdbcTemplateHsms.queryForList(sql.toString());
54 55
         List<Map<String, Object>> itsmDeptList = jdbcTemplateMdv2.queryForList(sql.toString());

+ 46 - 0
src/main/java/com/dashitech/migration/task/uc/HospitalConfigTask.java

@@ -0,0 +1,46 @@
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.util.JdbcUtil;
7
+import org.apache.commons.logging.Log;
8
+import org.apache.commons.logging.LogFactory;
9
+import org.springframework.core.annotation.Order;
10
+import org.springframework.stereotype.Component;
11
+import org.springframework.transaction.annotation.Transactional;
12
+
13
+import java.util.HashMap;
14
+import java.util.List;
15
+import java.util.Map;
16
+
17
+/**
18
+ * Created by CX on 2024/10/10.
19
+ */
20
+@Component
21
+@Order(1)
22
+public class HospitalConfigTask extends BaseTask {
23
+
24
+    public static Log log = LogFactory.getLog(HospitalConfigTask.class);
25
+
26
+    @Override
27
+    @Transactional
28
+    public void start() {
29
+        log.info(" *** HospitalConfigTask start开始 *** ");
30
+        FieldMapper mapper = new FieldMapper();
31
+
32
+        //clear释放内存
33
+        mapper.clear();
34
+    }
35
+
36
+    @Override
37
+    public FieldMapper loadCache() {
38
+        log.info(" *** HospitalConfigTask loadCache开始 *** ");
39
+        FieldMapper mapper = new FieldMapper();
40
+
41
+
42
+        return mapper;
43
+    }
44
+
45
+
46
+}

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

@@ -26,11 +26,34 @@ public class HospitalTask extends BaseTask {
26 26
     @Override
27 27
     @Transactional
28 28
     public void start() {
29
+        log.info(" *** HospitalTask start开始 *** ");
30
+        if ("xiangyang".equals(appName)) {
31
+            startXy();
32
+        } else {
33
+            startNj();
34
+        }
35
+    }
36
+
37
+    public void startXy() {
29 38
         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 ");
30 39
         sql.append(" FROM `itsm_uc_duty_dept` where dept not like 'Z%'  and dept not like '%保卫%' and id not in (20,21)");
31 40
         List<Map<String, Object>> hosList = jdbcTemplateMdv2.queryForList(sql.toString());
32 41
         FieldMapper mapper = new FieldMapper();
33
-        mapper.addOperationAdd("type", 20390L);//院区类型 维修科室
42
+        mapper.addOperationAdd("type", getDicId(jdbcTemplateHsms,"hospital_type","6"));//院区类型 维修科室
43
+        mapper.trans2JdbcRow(hosList);
44
+        JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
45
+        jdbcUtil.batchPageInsert("itsm_uc_hospital", mapper.getRows());
46
+
47
+        //clear释放内存
48
+        mapper.clear();
49
+    }
50
+
51
+    public void startNj() {
52
+        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 ");
53
+        sql.append(" FROM `itsm_uc_duty_dept` ");
54
+        List<Map<String, Object>> hosList = jdbcTemplateMdv2.queryForList(sql.toString());
55
+        FieldMapper mapper = new FieldMapper();
56
+        mapper.addOperationAdd("type", getDicId(jdbcTemplateHsms,"hospital_type","6"));//院区类型 维修科室
34 57
         mapper.trans2JdbcRow(hosList);
35 58
         JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
36 59
         jdbcUtil.batchPageInsert("itsm_uc_hospital", mapper.getRows());

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

@@ -31,7 +31,7 @@ public class UserGroupTask extends BaseTask {
31 31
     @Override
32 32
     @Transactional
33 33
     public void start() {
34
-        log.info(" *** UserGroupTask 转换开始 *** ");
34
+        log.info(" *** UserGroupTask 转换 开始 *** ");
35 35
 
36 36
         StringBuffer sb = new StringBuffer();
37 37
         //只拿运维人员
@@ -58,7 +58,7 @@ public class UserGroupTask extends BaseTask {
58 58
 
59 59
     @Override
60 60
     public FieldMapper loadCache() {
61
-
61
+        log.info(" *** UserGroupTask loadCache 开始 *** ");
62 62
 
63 63
         return null;
64 64
     }

+ 4 - 4
src/main/java/com/dashitech/migration/util/JdbcUtil.java

@@ -190,13 +190,13 @@ public class JdbcUtil {
190 190
 
191 191
 
192 192
     /**
193
-     * 分批执行批量操作,默认1000条
193
+     * 分批执行批量操作,默认10000
194 194
      */
195 195
     public boolean batchPageInsert(String table, final List<JdbcRow> rows) {
196 196
         if (table == null || table.length()== 0 || rows == null || rows.size() == 0) {
197 197
             return false;
198 198
         }
199
-        List<List<JdbcRow>> pageList = pageList(rows, 1000);
199
+        List<List<JdbcRow>> pageList = pageList(rows, 10000);
200 200
         for (List<JdbcRow> jdbcRows : pageList) {
201 201
             batchInsert(table, jdbcRows);
202 202
         }
@@ -204,13 +204,13 @@ public class JdbcUtil {
204 204
     }
205 205
 
206 206
     /**
207
-     * 分批执行批量操作,默认1000条
207
+     * 分批执行批量操作,默认10000
208 208
      */
209 209
     public boolean batchPageUpdate(String table, final List<JdbcRow> rows) {
210 210
         if (table == null || table.length()== 0 || rows == null || rows.size() == 0) {
211 211
             return false;
212 212
         }
213
-        List<List<JdbcRow>> pageList = pageList(rows, 1000);
213
+        List<List<JdbcRow>> pageList = pageList(rows, 10000);
214 214
         for (List<JdbcRow> jdbcRows : pageList) {
215 215
             batchUpdate(table, jdbcRows);
216 216
         }

File diff suppressed because it is too large
+ 669 - 2
src/main/resources/migration.sql