CX vor 8 Monaten
Ursprung
Commit
68b125aff0

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

@@ -36,4 +36,15 @@ public abstract class BaseTask implements SqlTask {
36
         return null;
36
         return null;
37
     }
37
     }
38
 
38
 
39
+    public Object getSingleObj(JdbcTemplate jt,String sql, Object... args) {
40
+        List<Map<String,Object>> list = jt.queryForList(sql,args);
41
+        if(list != null && list.size() > 0) {
42
+            Map<String, Object> map = list.get(0);
43
+            for (Map.Entry<String, Object> entry : map.entrySet()) {
44
+                return entry.getValue();
45
+            }
46
+        }
47
+        return null;
48
+    }
49
+
39
 }
50
 }

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

@@ -31,6 +31,8 @@ public class StartApplication {
31
     XyGroupTask xyGroupTask;
31
     XyGroupTask xyGroupTask;
32
     @Autowired
32
     @Autowired
33
     CompanyTask companyTask;
33
     CompanyTask companyTask;
34
+    @Autowired
35
+    SqlTask roleTask;
34
 
36
 
35
     @Value("${application.name}")
37
     @Value("${application.name}")
36
     private String appName;
38
     private String appName;
@@ -51,7 +53,7 @@ public class StartApplication {
51
 
53
 
52
 //            userGroupTask.start();
54
 //            userGroupTask.start();
53
 
55
 
54
-            userTask.loadCache();
56
+//            roleTask.start();
55
 
57
 
56
             System.out.println("AAAAA");
58
             System.out.println("AAAAA");
57
         }
59
         }

+ 30 - 5
src/main/java/com/dashitech/migration/task/uc/RoleTask.java

@@ -1,12 +1,17 @@
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.SqlTask;
4
 import com.dashitech.migration.core.FieldMapper;
5
 import com.dashitech.migration.core.FieldMapper;
6
+import com.dashitech.migration.util.JdbcUtil;
5
 import org.apache.commons.logging.Log;
7
 import org.apache.commons.logging.Log;
6
 import org.apache.commons.logging.LogFactory;
8
 import org.apache.commons.logging.LogFactory;
9
+import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.stereotype.Component;
10
 import org.springframework.stereotype.Component;
8
 import org.springframework.transaction.annotation.Transactional;
11
 import org.springframework.transaction.annotation.Transactional;
9
 
12
 
13
+import java.util.List;
14
+
10
 /**
15
 /**
11
  * Created by CX on 2024/10/10.
16
  * Created by CX on 2024/10/10.
12
  */
17
  */
@@ -15,20 +20,40 @@ public class RoleTask extends BaseTask {
15
 
20
 
16
     public static Log log = LogFactory.getLog(RoleTask.class);
21
     public static Log log = LogFactory.getLog(RoleTask.class);
17
 
22
 
23
+    @Autowired
24
+    SqlTask userTask;
25
+
18
     @Override
26
     @Override
19
     @Transactional
27
     @Transactional
20
     public void start() {
28
     public void start() {
29
+        log.info(" *** 加载角色Role缓存 *** ");
21
 
30
 
22
-    }
31
+        StringBuffer sb = new StringBuffer();
32
+        //只拿运维人员
33
+        sb.append(" SELECT id as 'user_id' from itsm_uc_user where ACCOUNT != 'dsadmin' and delete_flag = 0 ");
23
 
34
 
24
-    @Override
25
-    public FieldMapper loadCache() {
26
-        log.info(" *** 加载角色Role缓存 *** ");
35
+        Object roleId = getSingleObj(jdbcTemplateHsms," SELECT id from itsm_uc_role WHERE rolecode = 'first-line support' ");
36
+
37
+        List list = jdbcTemplateMdv2.queryForList(sb.toString());
27
 
38
 
28
         FieldMapper mapper = new FieldMapper();
39
         FieldMapper mapper = new FieldMapper();
40
+        FieldMapper userMapper = userTask.loadCache();
41
+        mapper.addOperationAdd("role_id", Long.valueOf(roleId.toString()));
42
+        mapper.addOperationReplace("user_id", userMapper.getIdCache());
43
+        mapper.trans2JdbcRow(list);
44
+
45
+        JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
46
+        jdbcUtil.batchPageInsert("itsm_uc_user_role", mapper.getRows());
29
 
47
 
48
+        //clear释放内存
49
+        mapper.clear();
50
+        userMapper.clear();
51
+    }
30
 
52
 
53
+    @Override
54
+    public FieldMapper loadCache() {
55
+        log.info(" *** 加载角色Role缓存 *** ");
31
 
56
 
32
-        return mapper;
57
+        return null;
33
     }
58
     }
34
 }
59
 }

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

@@ -48,8 +48,6 @@ public class UserGroupTask extends BaseTask {
48
         mapper.addOperationReplace("user_id", userMapper.getIdCache());
48
         mapper.addOperationReplace("user_id", userMapper.getIdCache());
49
         mapper.trans2JdbcRow(list);
49
         mapper.trans2JdbcRow(list);
50
 
50
 
51
-
52
-
53
         JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
51
         JdbcUtil jdbcUtil = new JdbcUtil(jdbcTemplateHsms);
54
         jdbcUtil.batchPageInsert("itsm_uc_user_group", mapper.getRows());
52
         jdbcUtil.batchPageInsert("itsm_uc_user_group", mapper.getRows());
55
 
53