feat(sis): 添加模拟上下文登录功能
This commit is contained in:
parent
5ad0f652fe
commit
1a900ad3db
@ -1,5 +1,7 @@
|
|||||||
package org.dromara.sis.config.timer;
|
package org.dromara.sis.config.timer;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.context.mock.SaTokenContextMockUtil;
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
@ -9,12 +11,10 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.dromara.common.core.constant.CodePrefixConstants;
|
import org.dromara.common.core.constant.CodePrefixConstants;
|
||||||
import org.dromara.common.tenant.helper.TenantHelper;
|
|
||||||
import org.dromara.property.api.RemoteResidentPersonService;
|
import org.dromara.property.api.RemoteResidentPersonService;
|
||||||
import org.dromara.property.api.domain.vo.RemoteResidentPersonVo;
|
import org.dromara.property.api.domain.vo.RemoteResidentPersonVo;
|
||||||
import org.dromara.resource.api.RemoteFileService;
|
import org.dromara.resource.api.RemoteFileService;
|
||||||
import org.dromara.sis.api.domain.RemotePersonAuth;
|
import org.dromara.sis.api.domain.RemotePersonAuth;
|
||||||
import org.dromara.sis.domain.bo.SisPersonLibImgBo;
|
|
||||||
import org.dromara.sis.domain.vo.*;
|
import org.dromara.sis.domain.vo.*;
|
||||||
import org.dromara.sis.sdk.e8.E8PlatformApi;
|
import org.dromara.sis.sdk.e8.E8PlatformApi;
|
||||||
import org.dromara.sis.sdk.e8.domain.accessControl.req.CustomerAuthAddReq;
|
import org.dromara.sis.sdk.e8.domain.accessControl.req.CustomerAuthAddReq;
|
||||||
@ -26,15 +26,12 @@ import org.dromara.sis.service.ISisAccessControlService;
|
|||||||
import org.dromara.sis.service.ISisAuthGroupRefService;
|
import org.dromara.sis.service.ISisAuthGroupRefService;
|
||||||
import org.dromara.sis.service.ISisAuthRecordService;
|
import org.dromara.sis.service.ISisAuthRecordService;
|
||||||
import org.dromara.sis.service.ISisPersonLibImgService;
|
import org.dromara.sis.service.ISisPersonLibImgService;
|
||||||
import org.dromara.sis.service.impl.SisPersonLibImgServiceImpl;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Base64;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lsm
|
* @author lsm
|
||||||
@ -63,47 +60,55 @@ public class AuthTimer {
|
|||||||
/**
|
/**
|
||||||
* 每两分钟执行一次
|
* 每两分钟执行一次
|
||||||
*/
|
*/
|
||||||
// @Scheduled(cron = "0 */1 * * * ?")
|
@Scheduled(cron = "0 */2 * * * ?")
|
||||||
public void autoAuth() {
|
public void autoAuth() {
|
||||||
List<RemoteResidentPersonVo> unAuthPerson = remoteResidentPersonService.queryUnAuthPerson();
|
AtomicReference<List<RemoteResidentPersonVo>> unAuthPersonRef = new AtomicReference<>(new ArrayList<>());
|
||||||
// if (CollUtil.isNotEmpty(unAuthPerson)) {
|
// 需要先设置模拟上下文
|
||||||
//
|
SaTokenContextMockUtil.setMockContext(() -> {
|
||||||
// try {
|
// 模拟登录
|
||||||
// for (RemoteResidentPersonVo person : unAuthPerson) {
|
StpUtil.login(-8); // 模拟登录
|
||||||
// log.info("开始定时授权:{}", person.getId());
|
unAuthPersonRef.set(remoteResidentPersonService.queryUnAuthPerson());
|
||||||
//
|
});
|
||||||
// // 判断是否已存在授权
|
|
||||||
// SisAuthRecordVo authRecord = sisAuthRecordService.queryByGroupIdAndPersonId(person.getAuthGroupId(), person.getId());
|
List<RemoteResidentPersonVo> unAuthPerson = unAuthPersonRef.get();
|
||||||
// if (ObjectUtil.isEmpty(authRecord)) {
|
if (CollUtil.isNotEmpty(unAuthPerson)) {
|
||||||
// // 无授权记录时,补录
|
try {
|
||||||
// this.syncAuthRecord(person);
|
for (RemoteResidentPersonVo person : unAuthPerson) {
|
||||||
// }
|
log.info("开始定时授权:{}", person.getId());
|
||||||
//
|
|
||||||
// // 读取人像
|
// 判断是否已存在授权
|
||||||
// byte[] imgByte = remoteFileService.downloadToByteArray(Long.parseLong(person.getOssId()));
|
SisAuthRecordVo authRecord = sisAuthRecordService.queryByGroupIdAndPersonId(person.getAuthGroupId(), person.getId());
|
||||||
// if (imgByte == null) continue;
|
if (ObjectUtil.isEmpty(authRecord)) {
|
||||||
//
|
// 无授权记录时,补录
|
||||||
// // 写入华为盒子
|
this.syncAuthRecord(person);
|
||||||
// Long huaweiId = syncHuaweiBox(person, imgByte);
|
}
|
||||||
// if (huaweiId == null) continue;
|
|
||||||
//
|
// 读取人像
|
||||||
// // 更新人像信息huaweiBoxId
|
byte[] imgByte = remoteFileService.downloadToByteArray(Long.parseLong(person.getOssId()));
|
||||||
// Boolean update = sisPersonLibImgService.updateByPersonId(person.getId(), huaweiId);
|
if (imgByte == null) continue;
|
||||||
// if (!update) continue;
|
|
||||||
//
|
// 写入华为盒子
|
||||||
// // 同步E8平台
|
Long huaweiId = syncHuaweiBox(person, imgByte);
|
||||||
// Long e8Id = syncE8Plat(person, imgByte);
|
if (huaweiId == null) continue;
|
||||||
// if (e8Id == null) continue;
|
|
||||||
//
|
// 更新人像信息huaweiBoxId
|
||||||
// // 更新入驻员工E8平台id
|
Boolean update = sisPersonLibImgService.updateByPersonId(person.getId(), huaweiId);
|
||||||
// remoteResidentPersonService.updateE8Id(person.getId(), e8Id);
|
if (!update) continue;
|
||||||
//
|
|
||||||
// }
|
// 同步E8平台
|
||||||
// } catch (Exception e) {
|
Long e8Id = syncE8Plat(person, imgByte);
|
||||||
// throw new RuntimeException(e);
|
if (e8Id == null) continue;
|
||||||
// }
|
|
||||||
//
|
// 更新入驻员工E8平台id
|
||||||
// }
|
remoteResidentPersonService.updateE8Id(person.getId(), e8Id);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("无待授权人员");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncAuthRecord(RemoteResidentPersonVo person) {
|
private void syncAuthRecord(RemoteResidentPersonVo person) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.dromara.sis.runner;
|
package org.dromara.sis.runner;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.context.mock.SaTokenContextMockUtil;
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -20,6 +22,7 @@ import org.springframework.scheduling.annotation.Async;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@ -40,7 +43,7 @@ public class HikDeviceApplicationRunner implements ApplicationRunner {
|
|||||||
// 现在查询全部,后面要更具需要查询指定厂商的设备
|
// 现在查询全部,后面要更具需要查询指定厂商的设备
|
||||||
HikDeviceApplicationRunner runner = SpringUtils.getAopProxy(this);
|
HikDeviceApplicationRunner runner = SpringUtils.getAopProxy(this);
|
||||||
// 梯控登录
|
// 梯控登录
|
||||||
// runner.hikElevatorInfoLogin();
|
runner.hikElevatorInfoLogin();
|
||||||
// 网络摄像头登录
|
// 网络摄像头登录
|
||||||
runner.hikNetCameraLogin();
|
runner.hikNetCameraLogin();
|
||||||
}
|
}
|
||||||
@ -52,8 +55,17 @@ public class HikDeviceApplicationRunner implements ApplicationRunner {
|
|||||||
sisElevatorInfoVos.forEach(item -> {
|
sisElevatorInfoVos.forEach(item -> {
|
||||||
// 执行设备登录操作
|
// 执行设备登录操作
|
||||||
HikApiService.getInstance().login(item.getControlIp(), item.getControlPort().shortValue(), item.getControlAccount(), item.getControlPwd());
|
HikApiService.getInstance().login(item.getControlIp(), item.getControlPort().shortValue(), item.getControlAccount(), item.getControlPwd());
|
||||||
|
|
||||||
|
AtomicReference<List<RemoteFloorVo>> floorInfoRef = new AtomicReference<>();
|
||||||
|
// 模拟上下文
|
||||||
|
SaTokenContextMockUtil.setMockContext(() -> {
|
||||||
|
// 模拟登录
|
||||||
|
StpUtil.login(-8);
|
||||||
|
floorInfoRef.set(remoteFloorService.queryByUnitId(item.getUnitId()));
|
||||||
|
});
|
||||||
|
|
||||||
// 根据单元ID获取楼层信息
|
// 根据单元ID获取楼层信息
|
||||||
List<RemoteFloorVo> floorInfo = remoteFloorService.queryByUnitId(item.getUnitId());
|
List<RemoteFloorVo> floorInfo = floorInfoRef.get();
|
||||||
|
|
||||||
// 下发权限
|
// 下发权限
|
||||||
for (int i = 0; i < floorInfo.size(); i++) {
|
for (int i = 0; i < floorInfo.size(); i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user