//防止数据量过大,分批批量插入
int maxCount = 5000;
for (int i = 0; i < serverInfoRecordVoList.size(); i += maxCount) {
if (i + maxCount > serverInfoRecordVoList.size()) {
// 批量处理操作
batchHandleForServerInfoRecord(serverInfoRecordVoList.subList(i,serverInfoRecordVoList.size()));
} else {
batchHandleForServerInfoRecord(serverInfoRecordVoList.subList(i, i + maxCount));
}
}
/**
* 分批处理服务器数据
* @param serverInfoRecordVoList
*/
private void batchHandleForServerInfoRecord(List<ServerInfoVo> serverInfoRecordVoList) {
Map<String, Object>[] paramMaps = new HashMap[serverInfoRecordVoList.size()];
for (int i = 0; i < serverInfoRecordVoList.size(); i++) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("serverIp", serverInfoRecordVoList.get(i).getServerIp());
paramMap.put("serverName", serverInfoRecordVoList.get(i).getServerName());
paramMap.put("systemShortName", serverInfoRecordVoList.get(i).getSystemShortName());
paramMap.put("ldc", serverInfoRecordVoList.get(i).getLdc());
paramMap.put("envType", serverInfoRecordVoList.get(i).getEnvType());
paramMap.put("cpu", serverInfoRecordVoList.get(i).getCpu());
paramMap.put("memory", serverInfoRecordVoList.get(i).getMemory());
paramMap.put("diskSize", serverInfoRecordVoList.get(i).getDiskSize());
paramMap.put("dataDiskSize", serverInfoRecordVoList.get(i).getDataDiskSize());
paramMap.put("serverType", serverInfoRecordVoList.get(i).getServerType());
paramMap.put("softwareType", serverInfoRecordVoList.get(i).getSoftwareType());
paramMap.put("softwareName", serverInfoRecordVoList.get(i).getSoftwareName());
paramMap.put("useType", serverInfoRecordVoList.get(i).getUseType());
paramMap.put("hostIp", serverInfoRecordVoList.get(i).getHostIp());
paramMap.put("serverStatus", serverInfoRecordVoList.get(i).getServerStatus());
paramMap.put("osType", serverInfoRecordVoList.get(i).getOsType());
paramMap.put("osName", serverInfoRecordVoList.get(i).getOsName());
paramMaps[i] = paramMap;
}
// 数据插入处理操作
Long nowTime = System.currentTimeMillis();
serverInfoRecordDataDao.batchInsertServerInfoRecordData(paramMaps);
log.info("一次处理插入服务器记录表耗时:{}", System.currentTimeMillis() - nowTime);
}