refactor(sis): 楼层下发权限修改

This commit is contained in:
zcxlsm 2025-07-16 11:16:55 +08:00
parent 3511a0b8c1
commit c2c0d1ffb4
2 changed files with 51 additions and 86 deletions

View File

@ -3,7 +3,10 @@ package org.dromara.sis.runner;
import cn.hutool.core.collection.CollUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.property.api.RemoteFloorService;
import org.dromara.property.api.domain.vo.RemoteFloorVo;
import org.dromara.sis.domain.bo.SisDeviceManageBo;
import org.dromara.sis.domain.vo.SisDeviceManageVo;
import org.dromara.sis.domain.vo.SisElevatorInfoVo;
@ -28,6 +31,9 @@ public class HikDeviceApplicationRunner implements ApplicationRunner {
private final ISisDeviceManageService deviceManageService;
private final ISisElevatorInfoService elevatorInfoService;
@DubboReference
private RemoteFloorService remoteFloorService;
@Override
public void run(ApplicationArguments args) throws Exception {
// 先布放在登录
@ -47,14 +53,14 @@ public class HikDeviceApplicationRunner implements ApplicationRunner {
sisElevatorInfoVos.forEach(item -> {
// 执行设备登录操作
HikApiService.getInstance().login(item.getControlIp(), item.getControlPort().shortValue(), item.getControlAccount(), item.getControlPwd());
// 根据建筑ID获取楼层信息
// SisFloorInfoVo floorInfo = floorInfoService.queryByBuildingId(item.getBuildingId());
// 获取楼层数组
// List<Integer> layerArray = generateFloorArray(floorInfo.getMinLayer().intValue(), floorInfo.getMaxLayer().intValue());
// 根据单元ID获取楼层信息
List<RemoteFloorVo> floorInfo = remoteFloorService.queryByUnitId(item.getUnitId());
// 下发权限
// for (int i = 0; i < layerArray.size(); i++) {
// HikApiService.getInstance().controlGateway(item.getControlIp(), (i + 1), layerArray.get(i));
// }
for (int i = 0; i < floorInfo.size(); i++) {
// 初始权限默认禁用状态
HikApiService.getInstance().controlGateway(item.getControlIp(), (i + 1), 3);
}
});
}
// String ip = "192.168.24.188";
@ -68,27 +74,6 @@ public class HikDeviceApplicationRunner implements ApplicationRunner {
// }
}
//输入最低层最高层返回楼层数组
public List<Integer> generateFloorArray(int minLayer, int maxLayer) {
// 验证输入范围
if (minLayer > maxLayer) {
throw new IllegalArgumentException("最低层不能大于最高层");
}
// 使用List动态收集楼层
List<Integer> layerList = new ArrayList<>();
// 遍历所有楼层跳过0层
for (int layer = minLayer; layer <= maxLayer; layer++) {
if (layer != 0) {
// 初始数组赋值为3不下发权限
layerList.add(3);
}
}
return layerList;
}
@Async
public void hikNetCameraLogin() {
List<SisDeviceManageVo> deviceList = deviceManageService.queryList(new SisDeviceManageBo());

View File

@ -5,6 +5,9 @@ import cn.hutool.core.collection.CollUtil;
import com.sun.jna.Pointer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.property.api.RemoteFloorService;
import org.dromara.property.api.domain.vo.RemoteFloorVo;
import org.dromara.sis.domain.vo.*;
import org.dromara.sis.sdk.e8.AccessControlService;
import org.dromara.sis.sdk.e8.domain.accessControl.req.RemoteOpenDoorReq;
@ -33,6 +36,9 @@ public class HikAlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {
private final AccessControlService e8AccessControlService;
@DubboReference
private RemoteFloorService remoteFloorService;
private static final int COMM_UPLOAD_FACESNAP_RESULT = 0x1112;
@Override
@ -87,7 +93,7 @@ public class HikAlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {
Long deviceId = bindRefList.stream().filter(vo -> vo.getBindId().equals(id)).findFirst().map(SisDeviceBindRefVo::getDeviceId).orElse(null);
SisAccessControlVo ac = accessControlService.queryById(deviceId);
if (ac != null) {
log.info("调用门禁服务远程开门");
log.info("调用门禁服务远程开门doorName:{}", ac.getAccessName());
RemoteOpenDoorReq req = new RemoteOpenDoorReq();
req.setType(0);
RemoteOpenDoorReq.ControlData data = new RemoteOpenDoorReq.ControlData();
@ -102,44 +108,38 @@ public class HikAlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {
// 获取电梯ids
// Collection<Long> eleIds = authVoList.stream().filter(vo -> vo.getDeviceType() == 2).map(SisAuthRecordVo::getDeviceId).toList();
// if (CollUtil.isNotEmpty(eleIds)) {
// eleIds.forEach(id -> {
// Long deviceId = bindRefList.stream().filter(vo -> vo.getBindId().equals(id)).findFirst().map(SisDeviceBindRefVo::getDeviceId).orElse(null);
// SisElevatorInfoVo ele = elevatorInfoService.queryById(deviceId);
// if (ele != null) {
// log.info("下发电梯权限");
// // 根据建筑ID获取楼层信息
// SisFloorInfoVo floorInfo = floorInfoService.queryByBuildingId(ele.getBuildingId());
// // 获取电梯楼层关联信息
// List<SisElevatorFloorRefVo> floorRefList = elevatorFloorRefService.queryByElevatorId(deviceId);
// // 获取楼层数组
// List<Integer> layerArray = generateFloorArray(floorInfo.getMinLayer().intValue(), floorInfo.getMaxLayer().intValue());
//
//
// layerArray.forEach(layer -> {
// SisElevatorFloorRefVo floorRef = floorRefList.stream()
// .filter(vo -> vo.getLayerNum().intValue() == layer) // 直接使用 layer
// .findFirst()
// .orElse(null);
//
// if (floorRef == null) {
// HikApiService.getInstance().controlGateway(ele.getControlIp(), layer, 3);
// } else {
// HikApiService.getInstance().controlGateway(ele.getControlIp(), layer, 2);
// }
// });
// }
//
// });
// }
Collection<Long> eleIds = authVoList.stream().filter(vo -> vo.getDeviceType() == 2).map(SisAuthRecordVo::getDeviceId).toList();
if (CollUtil.isNotEmpty(eleIds)) {
eleIds.forEach(id -> {
Long deviceId = bindRefList.stream().filter(vo -> vo.getBindId().equals(id)).findFirst().map(SisDeviceBindRefVo::getDeviceId).orElse(null);
SisElevatorInfoVo ele = elevatorInfoService.queryById(deviceId);
if (ele != null) {
log.info("下发电梯权限");
// 根据单元ID获取楼层信息
List<RemoteFloorVo> floorInfo = remoteFloorService.queryByUnitId(ele.getUnitId());
// 获取电梯楼层关联信息
List<SisElevatorFloorRefVo> floorRefList = elevatorFloorRefService.queryByElevatorId(deviceId);
// 获取楼层数组
List<Long> layerArray = floorInfo.stream().map(RemoteFloorVo::getFloorNumber).sorted().toList();
layerArray.forEach(layer -> {
SisElevatorFloorRefVo floorRef = floorRefList.stream()
.filter(vo -> vo.getLayerNum().intValue() == layer) // 直接使用 layer
.findFirst()
.orElse(null);
if (floorRef == null) {
HikApiService.getInstance().controlGateway(ele.getControlIp(), layer.intValue(), 3);
} else {
HikApiService.getInstance().controlGateway(ele.getControlIp(), layer.intValue(), 2);
}
});
}
});
}
log.info("权限下发执行完成,耗时:{}", System.currentTimeMillis() - s);
// List<Integer> arrs = Arrays.asList(2, 2, 2, 3, 3, 3 ,3, 3, 3, 3, 3, 3, 3, 3, 3, 3);
// List<Integer> arrs = Arrays.asList(3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2);
// for (int i = 0; i < arrs.size(); i++) {
// HikApiService.getInstance().controlGateway("192.168.24.188", (i + 1), arrs.get(i));
// }
// log.info("权限下发执行完成,耗时:{}", System.currentTimeMillis() - s);
// try {
// Thread.sleep(10000L);
// List<Integer> ass = Arrays.asList(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3);
@ -149,29 +149,9 @@ public class HikAlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
} else {
log.info("未知报警类型,lCommand={}", lCommand);
}
return true;
}
//输入最低层最高层返回楼层数组
public List<Integer> generateFloorArray(int minLayer, int maxLayer) {
// 验证输入范围
if (minLayer > maxLayer) {
throw new IllegalArgumentException("最低层不能大于最高层");
}
// 使用List动态收集楼层
List<Integer> layerList = new ArrayList<>();
// 遍历所有楼层跳过0层
for (int layer = minLayer; layer <= maxLayer; layer++) {
if (layer != 0) {
layerList.add(layer);
}
}
return layerList;
}
}