修改
This commit is contained in:
@@ -119,7 +119,6 @@ public class hostJob {
|
||||
bizDeviceInfo.setDevice(diskInfo.getDevice());
|
||||
bizDeviceInfo.setMountPoint(diskInfo.getMountPoint());
|
||||
List<BizDeviceInfo> deviceInfoList = deviceInfoService.findList(bizDeviceInfo);
|
||||
|
||||
BizDeviceInfo deviceInfo = deviceInfoList.isEmpty() ? new BizDeviceInfo() : deviceInfoList.get(0);
|
||||
deviceInfo.setHostId(host.getHostId());
|
||||
deviceInfo.setDevice(diskInfo.getDevice());
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.jeesite.modules.app.dao;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ExecResult implements Serializable {
|
||||
|
||||
private String code;
|
||||
|
||||
private String fileName;
|
||||
|
||||
public ExecResult() {
|
||||
}
|
||||
|
||||
public ExecResult(String code, String fileName) {
|
||||
this.code = code;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.jeesite.modules.app.utils;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.poi.excel.BigExcelWriter;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.jeesite.modules.app.dao.TableTree;
|
||||
import com.jeesite.modules.app.dao.ExecResult;
|
||||
import com.jeesite.modules.biz.entity.BizDbConfig;
|
||||
import com.jeesite.modules.biz.entity.BizTableField;
|
||||
import com.jeesite.modules.biz.entity.BizTableInfo;
|
||||
@@ -18,6 +22,10 @@ public class MysqlUtils {
|
||||
|
||||
private static final LoggerUtils logger = LoggerUtils.getInstance();
|
||||
|
||||
private static final String filePath = "/ogsapp/resultList/";
|
||||
|
||||
private static String EXEC_CODE = "0";
|
||||
|
||||
// 需要排除的系统数据库
|
||||
private static final List<String> SYSTEM_DATABASES = Arrays.asList(
|
||||
"information_schema", "mysql", "performance_schema", "sys", "test"
|
||||
@@ -202,4 +210,42 @@ public class MysqlUtils {
|
||||
}
|
||||
return tableTrees;
|
||||
}
|
||||
|
||||
|
||||
public static ExecResult getExecResult(BizDbConfig dbConfig, String sql) {
|
||||
String fileName = filePath + vId.getCid() + "_data.xlsx";
|
||||
try {
|
||||
Connection conn = getConnection(dbConfig.getDbIp(), dbConfig.getDbPort(), dbConfig.getDbUsername(), dbConfig.getDbPassword());
|
||||
Statement statement = conn.createStatement();
|
||||
boolean isQuery = sql.trim().toUpperCase().startsWith("SELECT");
|
||||
if (isQuery) {
|
||||
ResultSet rs = statement.executeQuery(sql);
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> rowMap = new LinkedHashMap<>();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
String columnName = metaData.getColumnName(i);
|
||||
Object value = rs.getObject(i);
|
||||
rowMap.put(columnName, value);
|
||||
}
|
||||
resultList.add(rowMap);
|
||||
}
|
||||
List<Map<String, Object>> mapList = CollUtil.newArrayList(resultList);
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(fileName);
|
||||
writer.write(mapList);
|
||||
writer.close();
|
||||
logger.info(sql, "执行成功,影响行数:", resultList.size(), "执行结果:", fileName);
|
||||
} else {
|
||||
int affectedRows = statement.executeUpdate(sql);
|
||||
logger.info(sql, "执行成功,影响行数:", affectedRows);
|
||||
}
|
||||
EXEC_CODE = "1";
|
||||
} catch (Exception e) {
|
||||
EXEC_CODE = "0";
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
return new ExecResult(EXEC_CODE, fileName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user