Commit e6e32733 authored by 李松's avatar 李松

修改bug

parent f073cc23
......@@ -60,8 +60,8 @@ public class AdpterController {
@ApiOperation(value = "主设备关联信息同步")
@RequestMapping(value = "/syncMainDeviceRelation", method = RequestMethod.POST)
public void syncMainDeviceRelation() throws IOException {
adpterService.syncMainDeviceRelation();
public void syncMainDeviceRelation(@RequestParam(value = "orgCode") String orgCode) throws IOException {
adpterService.syncMainDeviceRelation(orgCode);
}
@ApiOperation(value = "视频信息及主设备绑定视频关系同步")
......
......@@ -780,13 +780,13 @@ public class AdpterService {
});
}
public void syncMainDeviceRelation() throws IOException {
public void syncMainDeviceRelation(String orgCode) throws IOException {
// 获取主设备关联物联设备记录
Resource mainResource = new ClassPathResource("sql/mainDeviceRelation.sql");
String mainSql = new String(Files.readAllBytes(mainResource.getFile().toPath()));
List<Map<String, Object>> mainList = query(dlBuss, mainSql);
// 构建入库sql
execute(mainList, dataView, userName, pwd);
execute(mainList, dataView, userName, pwd, orgCode);
}
public void syncPlanRelation() {
......@@ -1079,7 +1079,7 @@ public class AdpterService {
}
}
private void execute(List<Map<String, Object>> params, String url, String username, String password) {
private void execute(List<Map<String, Object>> params, String url, String username, String password, String orgCode) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Connection connection = null;
Statement statement = null;
......@@ -1132,15 +1132,20 @@ public class AdpterService {
throwables.printStackTrace();
}
});
String updateSql = new StringBuilder().append("UPDATE iot_device_bind_relation a ")
.append("JOIN iot_device_info b1 ON b1.DEVICE_CODE = a.DEVICE_ID ")
.append("JOIN iot_device_info b2 ON b2.DEVICE_CODE = a.SUB_DEVICE_ID ")
.append("SET a.DEVICE_SEQ = b1.SEQUENCE_NBR,")
.append(" a.DEVICE_ID = b1.DEVICE_ID,")
.append(" a.SUB_DEVICE_SEQ = b2.SEQUENCE_NBR,")
.append(" a.SUB_DEVICE_ID = b2.DEVICE_ID")
.append(" WHERE a.DEVICE_ID IS NOT NULL AND a.SUB_DEVICE_ID IS NOT NULL and b1.ORG_CODE = ")
.append("'")
.append(orgCode)
.append("'").append(" and b2.ORG_CODE = ")
.append("'").append(orgCode).append("'").toString();
// 更新数据
finalStatement.addBatch("UPDATE iot_device_bind_relation a " +
"JOIN iot_device_info b1 ON b1.DEVICE_CODE = a.DEVICE_ID " +
"JOIN iot_device_info b2 ON b2.DEVICE_CODE = a.SUB_DEVICE_ID " +
"SET a.DEVICE_SEQ = b1.SEQUENCE_NBR," +
" a.DEVICE_ID = b1.DEVICE_ID," +
" a.SUB_DEVICE_SEQ = b2.SEQUENCE_NBR," +
" a.SUB_DEVICE_ID = b2.DEVICE_ID" +
" WHERE a.DEVICE_ID IS NOT NULL AND a.SUB_DEVICE_ID IS NOT NULL");
finalStatement.addBatch(updateSql);
// 执行批处理
int[] result = statement.executeBatch();
// 提交事务
......
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