if(mapList != null && !mapList.isEmpty()){
List<NumericalReportItem> numericalList = new ArrayList<NumericalReportItem>();
numericalReportConfig.setNumericalList(numericalList);
for (Map<String, Object> map : mapList) {
if(configMap.containsKey(Integer.parseInt(String.valueOf(map.get("id"))))){
LevelItem levelItem = new LevelItem();
levelItem.setLevel1(map.get("level1") == null ? null : Integer.parseInt(map.get("level1").toString()));
levelItem.setLevel2(map.get("level2") == null ? null : Integer.parseInt(map.get("level2").toString()));
configMap.get(Integer.parseInt(String.valueOf(map.get("id")))).add(levelItem);
}else{
NumericalReportItem item = new NumericalReportItem();
item.setId(map.get("id")==null?null:Integer.parseInt(map.get("id").toString()));
item.setProperty(map.get("property") == null ? null : map.get("property").toString());
item.setSourceTableId(map.get("source_table_id") == null ? null : Integer.parseInt(map.get("source_table_id").toString()));
item.setSourceName(map.get("source_name") == null ? null : map.get("source_name").toString());
item.setAccountForm(map.get("account_form") == null ? null : Integer.parseInt(map.get("account_form").toString()));
item.setAccountType(map.get("account_type") == null ? null : Integer.parseInt(map.get("account_type").toString()));
numericalList.add(item);
LevelItem levelItem = new LevelItem();
levelItem.setLevel1(map.get("level1") == null ? null : Integer.parseInt(map.get("level1").toString()));
levelItem.setLevel2(map.get("level2") == null ? null : Integer.parseInt(map.get("level2").toString()));
configMap.put(Integer.parseInt(String.valueOf(map.get("id"))), new ArrayList<LevelItem>());
configMap.get(Integer.parseInt(String.valueOf(map.get("id")))).add(levelItem);
}
}
for (NumericalReportItem numericalReportItem : numericalList) {
if(configMap.containsKey(numericalReportItem.getId())){
numericalReportItem.setLevelList(configMap.get(numericalReportItem.getId()));
}
}
}
组组装对象
for (NumericalReportItem numericalReportItem : numericalList) {
final Integer id =numericalReportItem.getId();
final List<LevelItem> levelList = numericalReportItem.getLevelList();
if(levelList!=null){
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Integer dimId = 0;
Dimension dimension = queryDim(levelList.get(i).getLevel1(),levelList.get(i).getLevel2());
if(dimension != null){
if(dimension.getDimId() != null && dimension.getDimId() != 0){
dimId = dimension.getDimId();
}
}
ps.setInt(1, id);
ps.setInt(2, dimId);
}
@Override
public int getBatchSize() {
return levelList.size();
}
});
}
}
批量处理