|
|
@@ -63,13 +63,14 @@ public class CamelJDBCConfiguration {
|
|
63
|
63
|
org = 0;
|
|
64
|
64
|
orgIdPreList = new HashMap<>();
|
|
65
|
65
|
})
|
|
66
|
|
- //先取已有的最大 org_id,新机构从这个值往后排
|
|
67
|
|
- .setBody(simple("select max(org_id) from centralbase.cb_pc_organization"))
|
|
|
66
|
+ //org_id 在库里存的是字符串,直接 max 会按字典序比较("9" 会大于 "10"),
|
|
|
67
|
+ //所以先转成整数再取最大值,新机构从这个值往后排
|
|
|
68
|
+ .setBody(simple("select max(org_id::int) from centralbase.cb_pc_organization"))
|
|
68
|
69
|
.to("jdbc:centralbase")
|
|
69
|
70
|
.process(exchange -> {
|
|
70
|
71
|
HashMap<String, Object> aRow = exchange.getIn().getBody(HashMap.class);
|
|
71
|
72
|
Object max = aRow == null ? null : aRow.get("max");
|
|
72
|
|
- //max(org_id) 的返回类型由列类型决定(numeric 会返回 BigDecimal,toString 得到 "5.00"),
|
|
|
73
|
+ //sql 里已经转成整数,这里再兜一层:驱动可能返回 Integer/BigDecimal/String,
|
|
73
|
74
|
//统一按数值解析再取整,避免 Integer.valueOf 抛 NumberFormatException
|
|
74
|
75
|
org = max == null || StringUtils.isEmpty(max) ? Integer.valueOf(0) : new BigDecimal(max.toString().trim()).intValue();
|
|
75
|
76
|
})
|