Commit 06aee774 authored by Gwofoo's avatar Gwofoo

修复导出删除的弹窗

parent 950116bb
......@@ -25,6 +25,7 @@ import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
......@@ -61,6 +62,8 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
String[] sequenceNbrs = StringUtil.string2Array(sequenceNbrsString);
Connection connection = dataSource.getConnection();
print(sequenceNbrs[0], "开始执行", "start");
// 查询所有数据库,将sequenceNbrs转为具体的数据库名称databaseNames
List<String> allDbs = DatabaseUtils.getAllDatabaseNames(connection);
List<String> databaseNames = new ArrayList<>();
......@@ -68,7 +71,6 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
int idx = Integer.parseInt(sequenceNbr);
databaseNames.add(allDbs.get(idx - 1)); // sequenceNbrs序号从1开始
}
// 查询studio_resource表中的RESOURCE_CODE
String sql = "SELECT RESOURCE_CODE FROM studio_resource;";
List<String> fastDeleteDbs = DatabaseUtils.getList(sql, connection);
......@@ -76,6 +78,8 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
// 对于每一个待删除数据库,如果出现在resourceCodes中,则采用新的快速删除方式;否则采用旧的全表查找删除方式
for (String dbName : databaseNames) {
print(sequenceNbrs[0], "正在删除" + dbName + "机构...", "running");
String fastDeleteDbResourceCode = "no";
for (String fastDeleteDb : fastDeleteDbs) {
if (dbName.contains(fastDeleteDb)) {
......@@ -111,7 +115,7 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
List<String> list = getList(sql, conn);
// 仅在tableName有AGENCY_CODE字段时,删除tableName中的对应行数据
if (list.size() > 0) {
sql = "DELETE " + // TODO 改成DELETE即可
sql = "DELETE " +
" FROM " + tableName +
" WHERE AGENCY_CODE = '" + agencyCode + "';";
List<Map<String, Object>> deleteRes = getMaps(sql, conn);
......@@ -123,6 +127,7 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
conn.close();
}
connection.close(); // atl
print(sequenceNbrs[0], "执行结束", "end");
}
/**
......@@ -279,10 +284,10 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
File file = new File(sqlFilePath);
FileOutputStream out;
OutputStreamWriter writer = null;
OutputStreamWriter writer;
out = new FileOutputStream(file);
writer = new OutputStreamWriter(out, "utf8");
writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
StringBuffer insertSql = new StringBuffer();
......
......@@ -18,7 +18,6 @@ import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.text.StringSubstitutor;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
......@@ -29,6 +28,7 @@ import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
......@@ -136,17 +136,17 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
String sqlFilePath = backPath + SLASH + fileName;
File file = new File(sqlFilePath);
FileOutputStream out;
OutputStreamWriter writer = null;
OutputStreamWriter writer;
out = new FileOutputStream(file);
writer = new OutputStreamWriter(out, "utf8");
writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
String fileName2="project"+DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX;
String sqlFilePath2 = backPath + SLASH + fileName2;
File file2 = new File(sqlFilePath2);
FileOutputStream out2;
OutputStreamWriter writer2 = null;
OutputStreamWriter writer2;
out2 = new FileOutputStream(file2);
writer2 = new OutputStreamWriter(out2, "utf8");
writer2 = new OutputStreamWriter(out2, StandardCharsets.UTF_8);
StringBuffer deleteSql = new StringBuffer();
StringBuffer insertSql = new StringBuffer();
......@@ -303,7 +303,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
fileName = fileName + fileExtension; // 例如 "example.zip"
File downloadFile = new File(fileName); // 获取要下载的文件路径和名称
response.setContentType("application/octet-stream"); // 设置响应内容类型为二进制流,适用于下载文件
response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFile.getName() + "\""); // 设置响应头,指定要下载的文件名
response.setHeader("Content-Disposition", "attachment; filename=" + downloadFile.getName() + ""); // 设置响应头,指定要下载的文件名
OutputStream outputStream = response.getOutputStream(); // 获取输出流,用于将文件写入响应中
FileInputStream inputStream = new FileInputStream(downloadFile); // 打开文件输入流以读取要下载的文件内容
byte[] buffer = new byte[4096]; // 创建一个缓冲区来存储从文件中读取的数据块,可以根据需要调整大小
......@@ -374,15 +374,18 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
if (!sqlDirectory.exists()) {
sqlDirectory.mkdir();
}
print(queryDbSeqs[0], "开始执行", "start");
// 备份文件路径名称
// String fileName = (SourceEnum.IDX.getSource().equals(resourceCode.toLowerCase()) ? (resourceCode.toLowerCase() + "_") : "studio_") + DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX;
String fileName = databaseName + DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX;
String sqlFilePath = backPath + SLASH + fileName;
File file = new File(sqlFilePath);
FileOutputStream out;
OutputStreamWriter writer = null;
OutputStreamWriter writer;
out = new FileOutputStream(file);
writer = new OutputStreamWriter(out, "utf8");
writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
StringBuffer deleteSql = new StringBuffer();
for (String tableName : tableNames) {
Statement statement = connection.createStatement();
......@@ -403,23 +406,23 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
}
if (deleteSql.length() > 0) {
print(variables.get(dimension).toString(), "开始创建delete语句...", "running");
print(queryDbSeqs[0], "开始创建delete语句...", "running");
writer.write(BR + DELIMITER + BR);
writer.write("/**" + BR + "* 删除历史资源数据 " + BR + "**/" + BR);
writer.write(BR + DELIMITER + BR);
writer.write(deleteSql.toString());
writer.write(BR + BR + DELIMITER + BR);
print(variables.get(dimension).toString(), "delete语句创建完成...", "running");
print(queryDbSeqs[0], "delete语句创建完成...", "running");
}
if (insertSql.length() > 0) {
print(variables.get(dimension).toString(), "开始创建insert语句...", "running");
print(queryDbSeqs[0], "开始创建insert语句...", "running");
writer.write(BR + DELIMITER + BR);
writer.write("/**" + BR + "* 资源数据" + BR + "**/" + BR);
writer.write(BR + DELIMITER + BR);
writer.write(insertSql.toString());
writer.write(BR + BR + DELIMITER + BR);
print(variables.get(dimension).toString(), "insert语句创建完成...", "running");
print(queryDbSeqs[0], "insert语句创建完成...", "running");
}
writer.flush();
......@@ -428,6 +431,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
download(response, fileName, sqlFilePath);
}
connection.close();
print(queryDbSeqs[0], "执行结束", "end");
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment