Commit f7b207b1 authored by 李松's avatar 李松

添加预案关系同步接口

parent 52f50dc6
...@@ -71,6 +71,12 @@ public class AdpterController { ...@@ -71,6 +71,12 @@ public class AdpterController {
adpterService.syncMainVideoRelation(orgCode, agencyCode); adpterService.syncMainVideoRelation(orgCode, agencyCode);
} }
@ApiOperation(value = "预案关联关系数据同步")
@RequestMapping(value = "/syncPlanRelation", method = RequestMethod.POST)
public void syncPlanRelation() {
adpterService.syncPlanRelation();
}
@ApiOperation(value = "建筑信息") @ApiOperation(value = "建筑信息")
@RequestMapping(value = "/buildingExcel", method = RequestMethod.POST) @RequestMapping(value = "/buildingExcel", method = RequestMethod.POST)
public void systemExcel(HttpServletResponse response,@RequestParam(value = "gatewayId") String gatewayId) throws IOException { public void systemExcel(HttpServletResponse response,@RequestParam(value = "gatewayId") String gatewayId) throws IOException {
......
...@@ -97,7 +97,7 @@ public class AdpterService { ...@@ -97,7 +97,7 @@ public class AdpterService {
String systemUserRecTime; String systemUserRecTime;
public Map<String, String> handle() { public Map<String, String> handle() {
Map<String, String> rMap = new HashMap<>(); Map<String, String> rMap = new HashMap<>();
...@@ -789,6 +789,98 @@ public class AdpterService { ...@@ -789,6 +789,98 @@ public class AdpterService {
execute(mainList, dataView, userName, pwd); execute(mainList, dataView, userName, pwd);
} }
public void syncPlanRelation() {
// 查询原主设备信息
String mainSql = "SELECT id , name ,code from f_equipment ";
List<Map<String, Object>> mainList = query(dlBuss, mainSql);
// 查询主设备绑定物联设备关系
String mainRelationSql = "SELECT a.id,\n" +
"a.equipment_id, \n" +
"a.fire_equipment_id," +
"(SELECT code from f_equipment b where b.id = a.equipment_id ) as mainCode,\n" +
"(SELECT code from wl_equipment_specific b where b.id = a.fire_equipment_id ) as equipCode\n" +
"from f_equipment_fire_equipment a";
List<Map<String, Object>> mainRelationList = query(dlBuss, mainRelationSql);
// 构建更新sql
executePlanRelation(mainList, mainRelationList, dataView, userName, pwd);
}
public void executePlanRelation(List<Map<String, Object>> mainList, List<Map<String, Object>> mainRelationList, String url, String username, String password) {
// 视频信息入库
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Connection connection = null;
Statement statement = null;
String getIdSql = "(SELECT SEQUENCE_NBR from iot_device_info where DEVICE_CODE = %s)";
try {
// 获取数据库连接
connection = DriverManager.getConnection(url, username, password);
connection.setAutoCommit(false);
statement = connection.createStatement();
Statement finalStatement = statement;
// 主设备信息
mainList.forEach(a -> {
StringBuilder sql = new StringBuilder();
sql.append("UPDATE `c_plan_equipment` SET `fire_equipment_code` = ");
sql.append("'");
sql.append(a.get("code"));
sql.append("', fire_equipment_name = ").append("'");
sql.append(a.get("name")).append("'");
sql.append(" WHERE `fire_equipment_id` = '").append(a.get("id")).append("'");
try {
finalStatement.addBatch(sql.toString());
} catch (SQLException throwables) {
throwables.printStackTrace();
}
});
// 更新c_plan_equipment表主设备id
String updateMainSql = "UPDATE c_plan_equipment a SET a.fire_equipment_id = " +
"(SELECT SEQUENCE_NBR from iot_device_info where DEVICE_CODE = a.fire_equipment_code and a.fire_equipment_code is not null )";
finalStatement.addBatch(updateMainSql);
mainRelationList.forEach(m -> {
StringBuilder sql = new StringBuilder();
sql.append("UPDATE `c_equipment_fire_equipment` SET `equipment_id` = ");
sql.append(String.format(getIdSql, "'" + m.get("mainCode") + "'"));
sql.append(",");
sql.append("equipment_specific_id = ");
sql.append(String.format(getIdSql, "'" + m.get("equipCode") + "'"));
sql.append(" where id = '");
sql.append(m.get("id")).append("'");
try {
finalStatement.addBatch(sql.toString());
} catch (SQLException throwables) {
throwables.printStackTrace();
}
});
String updateIdSql = "UPDATE c_equipment a SET a.id = " +
"(SELECT SEQUENCE_NBR from iot_device_info where DEVICE_CODE = a.code and a.code is not null )";
finalStatement.addBatch(updateIdSql);
// 执行批处理
int[] result = statement.executeBatch();
// 提交事务
connection.commit();
System.out.println("批量插入完成,影响行数: " + Arrays.toString(result));
} catch (SQLException e) {
if (connection != null) {
try {
connection.rollback();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
e.printStackTrace();
} finally {
// 关闭资源
try {
if (statement != null) statement.close();
if (connection != null) connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void syncMainVideoRelation(String orgCode, String agencyCode) { public void syncMainVideoRelation(String orgCode, String agencyCode) {
// 获取自动化中视频信息 // 获取自动化中视频信息
String videoSql = "SELECT \n" + String videoSql = "SELECT \n" +
......
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