tplink摄像头区域优化

This commit is contained in:
曹磊 2025-03-20 16:45:56 +08:00
parent eaa0d0b6e0
commit 231d42c481
5 changed files with 79 additions and 6 deletions

View File

@ -31,6 +31,7 @@ public enum ApiEnum {
SWITCH_REGION_ORDER("/tums/resource/v2/switchRegionOrder","移动区域信息"),
DELETE_REGION("/tums/resource/v2/deleteRegion","删除区域信息"),
GET_ROOT_REGIONS("/tums/resource/v2/getRootRegions","获取区域列表"),
GET_ROOT_REGION_CHILDREN("/tums/resource/v2/getRegionChildren","获取子区域列表"),
GET_DEVICE_LIST("/tums/deviceManager/v2/getDeviceList","获取设备列表"),
MODIFY_DEVICE_DETAILS("/tums/deviceManager/v1/modifyDeviceDetails","修改设备信息"),
REBOOT_DEVICE_LIST("/tums/deviceManager/v2/rebootDeviceList","重启设备"),

View File

@ -62,7 +62,7 @@ public class RegionInfoController extends JeecgController<RegionInfo, IRegionInf
* @return
*/
@GetMapping(value = "/sync")
public Result getUploadToServerProcess(RegionInfo regionInfo)throws Exception{
public Result sync(RegionInfo regionInfo)throws Exception{
return service.sync(regionInfo);
}

View File

@ -95,7 +95,8 @@
update_time,
media_server_id,
backup_media_server_id,
bind_type
bind_type,
iz_leaf
)
values(
#{regionId},
@ -111,7 +112,8 @@
#{updateTime},
#{mediaServerId},
#{backupMediaServerId},
#{bindType}
#{bindType},
#{izLeaf}
)
</insert>
@ -131,7 +133,8 @@
update_time = #{updateTime},
media_server_id = #{mediaServerId},
backup_media_server_id = #{backupMediaServerId},
bind_type = #{bindType}
bind_type = #{bindType},
iz_leaf = #{izLeaf}
where id = #{id}
</update>
@ -146,8 +149,9 @@
a.region_level as regionLevel,
a.sort,
a.parent_id as parentId,
b.project_name as projectName,
a.project_id as projectId,
ifnull(p.region_name,'无') as parentName,
b.project_name as projectName,
a.sys_type as sysType,
a.stream_way as streamWay,
a.has_children as hasChildren,
@ -159,6 +163,7 @@
a.iz_leaf as izLeaf
from nu_iot_tplink_region a
left join nu_iot_tplink_project b on a.project_id = b.project_id
left join nu_iot_tplink_region p on a.parent_id = p.region_id
where a.parent_id = #{parentId}
and a.project_id = #{projectId}
</select>

View File

@ -83,12 +83,15 @@ public class RegionInfoServiceImpl extends ServiceImpl<RegionInfoMapper, RegionI
RegionInfo entity = baseMapper.getByRegionId(map);
if(entity==null){
//新增
entity = new RegionInfo();
entity.setRegionId(map.get("regionId"));
baseMapper.add(map);
}else{
//修改
map.put("id",String.valueOf(entity.getId()));
baseMapper.updateById(map);
}
String projectId = map.get("projectId");
if(projectId!=null&&!("").equals(projectId)){
Map<String, String> projectMap = new HashMap<>();
@ -96,6 +99,56 @@ public class RegionInfoServiceImpl extends ServiceImpl<RegionInfoMapper, RegionI
projectMap.put("izLeaf", "0");
projectInfoMapper.updateLeafByPId(projectMap);
}
if(hasChildren.equals("1")){
//同步子级
syncChildren(entity);
}
}
}
}
/**
* 接口返回数据同步子区域入库
* @param regionInfo
*/
public void syncChildren(RegionInfo regionInfo){
StringBuffer sb = new StringBuffer();
sb.append("{");
sb.append("\"regionId\"").append(":").append("\"").append(regionInfo.getRegionId()).append("\"");
sb.append("}");
String jsonResponse = tumsApi.getRegionChildren(sb.toString());
JSONObject jsonObject = new JSONObject(jsonResponse);
if(jsonObject.getInt("error_code").equals(0)){
JSONArray list = jsonObject.getJSONArray("result");
for(int i=0;i<list.size();i++){
JSONObject voObject = (JSONObject)list.get(i);
Map<String, String> map = new HashMap<>();
for (String key : voObject.keySet()) {
map.put(key, voObject.getStr(key));
}
map.put("sort", map.get("order"));
String hasChildren = map.get("hasChildren");
if(hasChildren.equals("0")){
map.put("izLeaf", "1");
}else{
map.put("izLeaf", "0");
}
RegionInfo entity = baseMapper.getByRegionId(map);
if(entity==null){
//新增
entity = new RegionInfo();
entity.setRegionId(map.get("regionId"));
baseMapper.add(map);
}else{
//修改
map.put("id",String.valueOf(entity.getId()));
baseMapper.updateById(map);
}
if(hasChildren.equals("1")){
//同步子级
syncChildren(entity);
}
}
}
}

View File

@ -194,8 +194,22 @@ public class TumsApi {
*/
public String getRootRegions(String jsonRequest){
this.createTumsClient();
log.info("getRootRegions:request:{}",jsonRequest);
String jsonResponse = tumsClient.request(jsonRequest, ApiEnum.GET_ROOT_REGIONS.getValue());
log.info("getAllProjectInfo:{}",jsonResponse);
log.info("getRootRegions:response:{}",jsonResponse);
return jsonResponse;
}
/**
* 获取子区域列表
* @param jsonRequest
* @return
*/
public String getRegionChildren(String jsonRequest){
this.createTumsClient();
log.info("getRegionChildren:request:{}",jsonRequest);
String jsonResponse = tumsClient.request(jsonRequest, ApiEnum.GET_ROOT_REGION_CHILDREN.getValue());
log.info("getRegionChildren:response:{}",jsonResponse);
return jsonResponse;
}