|
@@ -25,56 +25,79 @@ class EtlCamelHugeApplicationTests {
|
25
|
25
|
@Resource(name = "oracle")
|
26
|
26
|
DataSource oracle;
|
27
|
27
|
|
28
|
|
- @Resource(name="centralbase")
|
|
28
|
+ @Resource(name = "centralbase")
|
29
|
29
|
DataSource centralbase;
|
30
|
30
|
|
31
|
31
|
@Test
|
32
|
|
- public void testOracle(){
|
|
32
|
+ public void testOracle() {
|
33
|
33
|
JdbcTemplate template = new JdbcTemplate(oracle);
|
34
|
34
|
String sql = String.format("select WELL_ID,well_common_name,org_id from " +
|
35
|
35
|
"zy_dxgw.pc_dev_well_attr_info where well_purpose_name='采油井'");
|
36
|
36
|
List<Map<String, Object>> maps = template.queryForList(sql);
|
37
|
|
- maps.get(0).forEach((k,v)->{
|
38
|
|
- System.out.printf("k: %s, v: %s\n",k,v);
|
|
37
|
+ maps.get(0).forEach((k, v) -> {
|
|
38
|
+ System.out.printf("k: %s, v: %s\n", k, v);
|
39
|
39
|
});
|
40
|
40
|
}
|
41
|
41
|
|
42
|
42
|
@Test
|
43
|
|
- public void orgCreate(){
|
|
43
|
+ public void orgCreate() {
|
44
|
44
|
JdbcTemplate oracleTemplate = new JdbcTemplate(oracle);
|
45
|
45
|
final JdbcTemplate centralbaseTemplate = new JdbcTemplate(centralbase);
|
46
|
46
|
String sql = String.format("select * from zy_dxgw.V_PC_ORGANIZATION_T where CANTON = '重油公司'");
|
47
|
47
|
List<Map<String, Object>> results = oracleTemplate.queryForList(sql);
|
48
|
48
|
|
49
|
|
- Map<String,Map<String,Object>> parentObjMap = new HashMap<>();
|
50
|
|
- Map<String, Map<String,Object>> orgIdMap = new HashMap<>();
|
51
|
|
- results.forEach(rowMap->{
|
52
|
|
- orgIdMap.put(rowMap.get("ORG_ID").toString(),rowMap);
|
|
49
|
+ Map<String, Map<String, Object>> parentObjMap = new HashMap<>();
|
|
50
|
+ Map<String, Map<String, Object>> orgIdMap = new HashMap<>();
|
|
51
|
+ results.forEach(rowMap -> {
|
|
52
|
+ orgIdMap.put(rowMap.get("ORG_ID").toString(), rowMap);
|
53
|
53
|
});
|
54
|
|
- results.forEach(rowMap->{
|
55
|
|
- parentObjMap.put(rowMap.get("ORG_ID").toString(),orgIdMap.get(rowMap.get("PARENT_ID")));
|
|
54
|
+ results.forEach(rowMap -> {
|
|
55
|
+ parentObjMap.put(rowMap.get("ORG_ID").toString(), orgIdMap.get(rowMap.get("PARENT_ID")));
|
56
|
56
|
});
|
57
|
57
|
|
58
|
|
- results.forEach(rowMap->{
|
|
58
|
+ results.forEach(rowMap -> {
|
59
|
59
|
Stack<String> orgPreStack = new Stack<>();
|
60
|
|
- Map<String,Object> parentObj = rowMap;
|
|
60
|
+ Map<String, Object> parentObj = rowMap;
|
61
|
61
|
|
62
|
|
- while((parentObj=parentObjMap.get(parentObj .get("ORG_ID").toString()))!=null){
|
|
62
|
+ while ((parentObj = parentObjMap.get(parentObj.get("ORG_ID").toString())) != null) {
|
63
|
63
|
orgPreStack.push(parentObj.get("ORG_NAME").toString());
|
64
|
64
|
}
|
65
|
65
|
StringBuilder orgIdPre = new StringBuilder();
|
66
|
|
- while (!orgPreStack.isEmpty()){
|
|
66
|
+ while (!orgPreStack.isEmpty()) {
|
67
|
67
|
orgIdPre.append(orgPreStack.pop()).append("@");
|
68
|
68
|
}
|
69
|
69
|
orgIdPre.append(rowMap.get("ORG_NAME"));
|
70
|
70
|
String orgIdPreStr = orgIdPre.toString();
|
|
71
|
+ rowMap.put("ORG_ID_PRE",orgIdPreStr);
|
|
72
|
+
|
71
|
73
|
String sqlInsertOrg = String.format("insert into centralbase.cb_pc_organization(" +
|
72
|
|
- "org_id,org_name,org_code,org_level,parent_id,org_id_pre) " +
|
73
|
|
- "values('%s','%s','%s','%s','%s','%s')",rowMap.get("ORG_ID"),rowMap.get("ORG_NAME"),rowMap.get("ORG_CODE"),rowMap.get("ORG_LEVEL")
|
74
|
|
- ,rowMap.get("PARENT_ID"),orgIdPreStr);
|
|
74
|
+ "org_id,org_name,org_code,org_level,parent_id,org_id_pre) " +
|
|
75
|
+ "values('%s','%s','%s','%s','%s','%s')", rowMap.get("ORG_ID"), rowMap.get("ORG_NAME"), rowMap.get("ORG_CODE"), rowMap.get("ORG_LEVEL")
|
|
76
|
+ , rowMap.get("PARENT_ID"), orgIdPreStr);
|
75
|
77
|
// System.out.println(sqlInsertOrg);
|
76
|
|
- centralbaseTemplate.execute(sqlInsertOrg);
|
|
78
|
+// centralbaseTemplate.execute(sqlInsertOrg); //excute finish, unused
|
|
79
|
+ });
|
77
|
80
|
|
|
81
|
+ //excute wellsource
|
|
82
|
+ sql = String.format("select WELL_ID,well_common_name,org_id from " +
|
|
83
|
+ "zy_dxgw.pc_dev_well_attr_info where well_purpose_name='采油井'");
|
|
84
|
+ results = oracleTemplate.queryForList(sql);
|
|
85
|
+ results.forEach(rowMap -> {
|
|
86
|
+ String wellId = rowMap.get("WELL_ID").toString();
|
|
87
|
+ String wellCommonName = rowMap.get("WELL_COMMON_NAME").toString();
|
|
88
|
+ String wellLegalName = rowMap.get("WELL_COMMON_NAME").toString();
|
|
89
|
+ String orgId = rowMap.get("ORG_ID").toString();
|
|
90
|
+ String stationId = orgIdMap.get(orgId).get("ORG_ID_PRE").toString();
|
|
91
|
+ String sqlInsertWellSource = String.format("insert into centralbase.cb_pc_well_source(well_id,well_common_name," +
|
|
92
|
+ "well_legal_name,org_id,station_id) values('%s','%s','%s','%s','%s')",
|
|
93
|
+ wellId, wellCommonName, wellLegalName, orgId, stationId);
|
|
94
|
+ System.out.println(sqlInsertWellSource);
|
78
|
95
|
});
|
|
96
|
+
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ @Test
|
|
100
|
+ public void wellSourceCreate(){
|
|
101
|
+
|
79
|
102
|
}
|
80
|
103
|
}
|