Browse Source

各种bug

CX 5 months ago
parent
commit
e74ae6d72c

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

@@ -28,6 +28,8 @@ public class StartApplication {
28 28
 //        task.start();
29 29
 //        task = SpringContextHolder.getBean("attachmentTask");
30 30
 //        task.start();
31
+//        task = SpringContextHolder.getBean("opLogTask");
32
+//        task.start();
31 33
 //        task = SpringContextHolder.getBean("hospitalTask");
32 34
 //        task.start();
33 35
 //        task = SpringContextHolder.getBean("hospitalConfigTask");
@@ -38,8 +40,8 @@ public class StartApplication {
38 40
 //        task.start();
39 41
 //        task = SpringContextHolder.getBean("companyTask");
40 42
 //        task.start();
41
-//        task = SpringContextHolder.getBean("userTask");
42
-//        task.start();
43
+        task = SpringContextHolder.getBean("userTask");
44
+        task.start();
43 45
 //        task = SpringContextHolder.getBean("userGroupTask");
44 46
 //        task.start();
45 47
 //        task = SpringContextHolder.getBean("roleUserTask");

+ 9 - 0
src/main/java/com/dashitech/migration/core/DataMapper.java

@@ -24,6 +24,7 @@ public class DataMapper implements Serializable{
24 24
     private boolean update = false;
25 25
     private boolean add = false;
26 26
     private boolean replace = false;
27
+    private boolean nullDefault = false;
27 28
 
28 29
     /**
29 30
      * 匹配完成后的id对照,source:target
@@ -38,6 +39,14 @@ public class DataMapper implements Serializable{
38 39
         this.sourceName = sourceName;
39 40
     }
40 41
 
42
+    public boolean isNullDefault() {
43
+        return nullDefault;
44
+    }
45
+
46
+    public void setNullDefault(boolean nullDefault) {
47
+        this.nullDefault = nullDefault;
48
+    }
49
+
41 50
     public boolean isAdd() {
42 51
         return add;
43 52
     }

+ 18 - 0
src/main/java/com/dashitech/migration/core/FieldMapper.java

@@ -57,6 +57,13 @@ public class FieldMapper {
57 57
                     if (dataMapper.isAdd()) {
58 58
                         row.put(dataMapper.getSourceName(), dataMapper.getTargetValue());
59 59
                     }
60
+                    //如果是null默认值,判断后put
61
+                    if (dataMapper.isNullDefault()) {
62
+                        Object value = row.get(dataMapper.getTargetName());
63
+                        if(value == null) {
64
+                            row.put(dataMapper.getTargetName(), dataMapper.getTargetValue());
65
+                        }
66
+                    }
60 67
                     //如果是要替换的,使用id缓存替换
61 68
                     if (dataMapper.isReplace() && row.containsKey(dataMapper.getSourceName())) {
62 69
                         Object value = row.get(dataMapper.getSourceName());
@@ -124,6 +131,17 @@ public class FieldMapper {
124 131
     }
125 132
 
126 133
     /**
134
+     * 字段是null的默认值
135
+     */
136
+    public FieldMapper addOperationNull(String target, Object value) {
137
+        DataMapper mapper = new DataMapper(target, target);
138
+        mapper.setNullDefault(true);
139
+        mapper.setTargetValue(value);
140
+        rowsOperationList.add(mapper);
141
+        return this;
142
+    }
143
+
144
+    /**
127 145
      * 待替换的字段,每次加入都在队列最前面。注意:如果是loadCache过滤,使用target名称,如果是start转换,使用source名称
128 146
      */
129 147
     public FieldMapper addOperationReplace(String name, Map<Long, Long> idCache) {

+ 1 - 0
src/main/java/com/dashitech/migration/task/incident/IncidentLogTask.java

@@ -46,6 +46,7 @@ public class IncidentLogTask extends BaseTask {
46 46
         Map<Long, Long> userCache = userTask.loadCache().getIdCache();
47 47
         mapper.addOperationUpdate("hos_id", "branch_id");
48 48
         mapper.addOperationReplace("log_type", dictionaryTask.loadCache().getIdCache());
49
+        mapper.addOperationReplace("next_log_type", dictionaryTask.loadCache().getIdCache());
49 50
         mapper.addOperationReplace("appointor_id", userCache);
50 51
         mapper.addOperationReplace("worker_id", userCache);
51 52
         mapper.addOperationReplace("group_id", groupTask.loadCache().getIdCache());

+ 55 - 0
src/main/java/com/dashitech/migration/task/other/OpLogTask.java

@@ -0,0 +1,55 @@
1
+package com.dashitech.migration.task.other;
2
+
3
+import com.dashitech.migration.BaseTask;
4
+import com.dashitech.migration.SqlTask;
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.beans.factory.annotation.Autowired;
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
+ * Created by CX on 2024/10/10.
18
+ */
19
+@Component
20
+public class OpLogTask extends BaseTask {
21
+
22
+    public static Log log = LogFactory.getLog(OpLogTask.class);
23
+
24
+    @Autowired
25
+    SqlTask dictionaryTask;
26
+
27
+    @Override
28
+    @Transactional(rollbackFor = Exception.class)
29
+    public void start() {
30
+        log.info(" *** TokenTask start开始 *** ");
31
+        StringBuffer sql = new StringBuffer("select * from itsm_base_operation_log where op_type = 'handlerLog' ");
32
+        List<Map<String, Object>> tokenList = jdbcTemplateMdv2.queryForList(sql.toString());
33
+
34
+        FieldMapper mapper = new FieldMapper();
35
+        mapper.addOperationRemove("id").addOperationRemove("repair_type").addOperationRemove("expected_day");
36
+        mapper.addOperationUpdate("hos_id", "branch_id");
37
+        mapper.trans2JdbcRow(tokenList);
38
+
39
+        JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
40
+        jdbcUtil.batchPageInsert("itsm_base_operation_log", mapper.getRows());
41
+
42
+        //clear释放内存
43
+        mapper.clear();
44
+    }
45
+
46
+    @Override
47
+    public FieldMapper loadCache() {
48
+        log.info(" *** AttachmentTask loadCache开始 *** ");
49
+
50
+
51
+        return null;
52
+    }
53
+
54
+
55
+}

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

@@ -27,6 +27,8 @@ public class UserTask extends BaseTask {
27 27
     SqlTask hospitalTask;
28 28
     @Autowired
29 29
     SqlTask departmentTask;
30
+    @Autowired
31
+    SqlTask dictionaryTask;
30 32
 
31 33
     public static Log log = LogFactory.getLog(UserTask.class);
32 34
 
@@ -48,6 +50,7 @@ public class UserTask extends BaseTask {
48 50
         mapper.addOperationAdd("usertype", getDicId(jdbcTemplateHsms,"usertype","4")); //用户类型-默认三方人员
49 51
         mapper.addOperationReplace("hospital_id", hospitalTask.loadCache().getIdCache());
50 52
         mapper.addOperationReplace("duty_dept", hospitalTask.loadCache().getIdCache());
53
+        mapper.addOperationReplace("GENDER", dictionaryTask.loadCache().getIdCache());
51 54
         if ("xiangyang".equals(appName)) {
52 55
             mapper.addOperationReplace("DEPTID", departmentTask.loadCache().getIdCache());
53 56
         }
@@ -62,6 +65,10 @@ public class UserTask extends BaseTask {
62 65
         updateRows = updateRows.stream().filter(s -> s.getRow().get("WEIXIN") != null).collect(Collectors.toList());
63 66
         jdbcUtil.batchPageUpdate("itsm_uc_user", updateRows);
64 67
 
68
+        //性别有null的
69
+        String sql = " update itsm_uc_user SET GENDER = (SELECT id from itsm_base_dictionary WHERE _key = 'user_gender' and _value = '0' ) WHERE GENDER is null ";
70
+        jdbcTemplateHsms.execute(sql);
71
+
65 72
         //clear释放内存
66 73
         mapper.clear();
67 74
         userMapper.clear();

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