bug修复和mysql批量替换值
This commit is contained in:
parent
a5cc7c8874
commit
5b678c3ee1
@ -175,8 +175,8 @@ public class RiskListSourceDataCenterController {
|
|||||||
if (CollUtil.isEmpty(sourceVos)) {
|
if (CollUtil.isEmpty(sourceVos)) {
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
Date begin = DateUtil.parseDateTime(MapUtils.getString(param, "effectiveTimeEnd_begin"));
|
Date begin = DateUtil.parseDate(MapUtils.getString(param, "effectiveTimeEnd_begin"));
|
||||||
Date end = DateUtil.parseDateTime(MapUtils.getString(param, "effectiveTimeBegin_end"));
|
Date end = DateUtil.parseDate(MapUtils.getString(param, "effectiveTimeBegin_end"));
|
||||||
List<SourceCheckNumBo> checkNumBos = getSourceCheckNumBo(sourceVos);
|
List<SourceCheckNumBo> checkNumBos = getSourceCheckNumBo(sourceVos);
|
||||||
//1. 计算有效期内的source的应排查、(未施工+已排查)数量
|
//1. 计算有效期内的source的应排查、(未施工+已排查)数量
|
||||||
for (RiskListSourceVo sourceVo : sourceVos) {
|
for (RiskListSourceVo sourceVo : sourceVos) {
|
||||||
|
|||||||
@ -170,6 +170,9 @@ public class XzSecurityDangerItemRecordController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "查询我使用过的最近三天的三条数据", notes = "查询我使用过的最近三天的三条数据", httpMethod = "GET")
|
@ApiOperation(value = "查询我使用过的最近三天的三条数据", notes = "查询我使用过的最近三天的三条数据", httpMethod = "GET")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "projectSn", value = "项目唯一标识", paramType = "body", required = true, dataType = "String"),
|
||||||
|
})
|
||||||
@GetMapping(value = "/getNewestUseRecords")
|
@GetMapping(value = "/getNewestUseRecords")
|
||||||
public Result<List<XzSecurityDangerItemRecord>> getNewestUseRecords(@ApiIgnore @RequestParam HashMap<String, Object> param) {
|
public Result<List<XzSecurityDangerItemRecord>> getNewestUseRecords(@ApiIgnore @RequestParam HashMap<String, Object> param) {
|
||||||
List<XzSecurityDangerItemRecord> list = dangerItemRecordService.getNewestUseRecords(param);
|
List<XzSecurityDangerItemRecord> list = dangerItemRecordService.getNewestUseRecords(param);
|
||||||
|
|||||||
@ -40,12 +40,14 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getNewestUseRecords" resultType="com.zhgd.xmgl.modules.xz.security.entity.XzSecurityDangerItemRecord">
|
<select id="getNewestUseRecords" resultType="com.zhgd.xmgl.modules.xz.security.entity.XzSecurityDangerItemRecord">
|
||||||
SELECT a.*
|
SELECT DISTINCT a.*
|
||||||
from xz_security_danger_item_record a
|
from xz_security_danger_item_record a
|
||||||
join xz_security_quality_inspection_record xsqir on xsqir.danger_item_id = a.id
|
join xz_security_quality_inspection_record xsqir on xsqir.danger_item_id = a.id
|
||||||
JOIN (SELECT * FROM xz_security_project_danger_type_disable WHERE project_sn = #{projectSn} and type = 2) b
|
|
||||||
ON b.danger_type_id = a.id
|
|
||||||
WHERE xsqir.inspect_man_id=#{inspectManId}
|
WHERE xsqir.inspect_man_id=#{inspectManId}
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM xz_security_project_danger_type_disable WHERE project_sn = #{projectSn} AND type = 2 and
|
||||||
|
danger_type_id=a.id
|
||||||
|
)
|
||||||
order by xsqir.create_time desc limit 3
|
order by xsqir.create_time desc limit 3
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
138
src/main/java/com/zhgd/xmgl/util/MysqlUrlReplacer.java
Normal file
138
src/main/java/com/zhgd/xmgl/util/MysqlUrlReplacer.java
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
package com.zhgd.xmgl.util;
|
||||||
|
|
||||||
|
import cn.hutool.db.Db;
|
||||||
|
import cn.hutool.db.Entity;
|
||||||
|
import cn.hutool.db.ds.simple.SimpleDataSource;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MysqlUrlReplacer {
|
||||||
|
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
public MysqlUrlReplacer(String url, String username, String password) {
|
||||||
|
this.dataSource = new SimpleDataSource(url, username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量替换所有表中的HTTP URL
|
||||||
|
*/
|
||||||
|
public void batchReplaceUrls(String oldDomain, String newDomain) throws SQLException {
|
||||||
|
// 获取所有表名
|
||||||
|
List<Entity> tables = Db.use(dataSource).query(
|
||||||
|
"SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE()"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (Entity table : tables) {
|
||||||
|
String tableName = table.getStr("table_name");
|
||||||
|
processTable(tableName, oldDomain, newDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理单个表
|
||||||
|
*/
|
||||||
|
private void processTable(String tableName, String oldDomain, String newDomain) throws SQLException {
|
||||||
|
// 获取表的字符串类型字段
|
||||||
|
List<Entity> columns = Db.use(dataSource).query(
|
||||||
|
"SELECT column_name FROM information_schema.columns " +
|
||||||
|
"WHERE table_schema = DATABASE() AND table_name = ? " +
|
||||||
|
"AND data_type IN ('varchar', 'text', 'longtext', 'mediumtext', 'char')",
|
||||||
|
tableName
|
||||||
|
);
|
||||||
|
|
||||||
|
for (Entity column : columns) {
|
||||||
|
String columnName = column.getStr("column_name");
|
||||||
|
replaceColumnData(tableName, columnName, oldDomain, newDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 替换单个字段的数据
|
||||||
|
*/
|
||||||
|
private void replaceColumnData(String tableName, String columnName,
|
||||||
|
String oldDomain, String newDomain) throws SQLException {
|
||||||
|
String sql = String.format(
|
||||||
|
"UPDATE %s SET %s = REPLACE(%s, ?, ?) WHERE %s LIKE ?",
|
||||||
|
tableName, columnName, columnName, columnName
|
||||||
|
);
|
||||||
|
|
||||||
|
int affectedRows = Db.use(dataSource).execute(
|
||||||
|
sql,
|
||||||
|
oldDomain,
|
||||||
|
newDomain,
|
||||||
|
"%" + oldDomain + "%"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (affectedRows > 0) {
|
||||||
|
System.out.printf("表 %s 的字段 %s 更新了 %d 行数据%n",
|
||||||
|
tableName, columnName, affectedRows);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全模式:先查询再更新(推荐用于生产环境)
|
||||||
|
*/
|
||||||
|
public void safeBatchReplaceUrls(String oldDomain, String newDomain) throws SQLException {
|
||||||
|
List<Entity> tables = Db.use(dataSource).query(
|
||||||
|
"SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE()"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (Entity table : tables) {
|
||||||
|
String tableName = table.getStr("table_name");
|
||||||
|
safeProcessTable(tableName, oldDomain, newDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void safeProcessTable(String tableName, String oldDomain, String newDomain) throws SQLException {
|
||||||
|
List<Entity> columns = Db.use(dataSource).query(
|
||||||
|
"SELECT column_name FROM information_schema.columns " +
|
||||||
|
"WHERE table_schema = DATABASE() AND table_name = ? " +
|
||||||
|
"AND data_type IN ('varchar', 'text', 'longtext', 'mediumtext', 'char')",
|
||||||
|
tableName
|
||||||
|
);
|
||||||
|
|
||||||
|
for (Entity column : columns) {
|
||||||
|
String columnName = column.getStr("column_name");
|
||||||
|
// 先查询受影响的数据
|
||||||
|
List<Entity> affectedData = Db.use(dataSource).query(
|
||||||
|
String.format("SELECT COUNT(*) as count FROM %s WHERE %s LIKE ?",
|
||||||
|
tableName, columnName),
|
||||||
|
"%" + oldDomain + "%"
|
||||||
|
);
|
||||||
|
|
||||||
|
long count = affectedData.get(0).getLong("count");
|
||||||
|
if (count > 0) {
|
||||||
|
System.out.printf("表 %s 字段 %s 有 %d 条数据需要更新%n",
|
||||||
|
tableName, columnName, count);
|
||||||
|
|
||||||
|
// 确认后再更新
|
||||||
|
replaceColumnData(tableName, columnName, oldDomain, newDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws SQLException {
|
||||||
|
// 使用方法2
|
||||||
|
MysqlUrlReplacer replacer = new MysqlUrlReplacer(
|
||||||
|
"jdbc:mysql://localhost:3306/uface",
|
||||||
|
"root",
|
||||||
|
"root"
|
||||||
|
);
|
||||||
|
|
||||||
|
// 批量替换
|
||||||
|
// replacer.batchReplaceUrls(
|
||||||
|
// "http://jxj.zhgdyun.com:21000",
|
||||||
|
// "http://new.domain.com:8080"
|
||||||
|
// );
|
||||||
|
|
||||||
|
// 或者安全模式批量替换
|
||||||
|
replacer.safeBatchReplaceUrls(
|
||||||
|
"http://jxj.zhgdyun.com:21000",
|
||||||
|
"http://new.domain.com:8080"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user