refactor(sis): 面板联动梯控
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
- 增加 Redis 缓存处理,避免重复下发权限 - 优化代码结构,提取公共方法 liftAuth
This commit is contained in:
parent
bd742b9f16
commit
6ede822c35
@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.sis.sdk.e8.E8PlatformApi;
|
||||
import org.dromara.sis.sdk.e8.domain.QueryDto;
|
||||
import org.dromara.sis.sdk.e8.domain.accessControl.req.AccessRecordFindReq;
|
||||
@ -15,6 +16,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author lsm
|
||||
@ -38,7 +41,8 @@ public class SyncLiftAuthTask {
|
||||
dto.setPageIndex(1);
|
||||
dto.setMaxResultCount(20);
|
||||
|
||||
String starTime = DateUtil.format(DateUtil.offset(new Date(), DateField.MINUTE, -2), "yyyy-MM-dd HH:mm:ss");
|
||||
// 10秒内
|
||||
String starTime = DateUtil.format(DateUtil.offset(new Date(), DateField.SECOND, -10), "yyyy-MM-dd HH:mm:ss");
|
||||
String endTime = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
AccessRecordFindReq lift = new AccessRecordFindReq();
|
||||
@ -48,21 +52,53 @@ public class SyncLiftAuthTask {
|
||||
|
||||
|
||||
// 9号电梯
|
||||
lift.setDeviceId(545024837750853L);
|
||||
lift.setDeviceId(550757939925061L);
|
||||
dto.setQueryDto(lift);
|
||||
TableDataInfo<AccessRecordFindRes> nineLiftList = apiService.getPageAccessRecordList(dto);
|
||||
if (nineLiftList.getTotal() != 0) {
|
||||
for (int i = 0; i < 18; i++) {
|
||||
HikApiService.getInstance().controlGateway("192.168.24.188", (i + 1), 2);
|
||||
}
|
||||
liftAuth(nineLiftList.getRows(), "nineLift", "192.168.24.188");
|
||||
}
|
||||
|
||||
// 15号电梯
|
||||
// lift.setDeviceId(545024837750853L);
|
||||
// dto.setQueryDto(lift);
|
||||
// TableDataInfo<AccessRecordFindRes> nineLiftList = apiService.getPageAccessRecordList(dto);
|
||||
lift.setDeviceId(545024837750853L);
|
||||
dto.setQueryDto(lift);
|
||||
TableDataInfo<AccessRecordFindRes> fifteenLiftList = apiService.getPageAccessRecordList(dto);
|
||||
if (fifteenLiftList.getTotal() != 0) {
|
||||
liftAuth(fifteenLiftList.getRows(), "fifteenLift", "192.168.24.188");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void liftAuth(List<AccessRecordFindRes> list, String redisKey, String controlIP) {
|
||||
// 取出第一条通行记录
|
||||
Long recordId = list.get(0).getId();
|
||||
|
||||
// 判断redis是否存在数据
|
||||
if (RedisUtils.isExistsObject(redisKey)) {
|
||||
// 取出redis数据
|
||||
Long redisData = RedisUtils.getCacheObject(redisKey);
|
||||
|
||||
// 判断redis数据是否等于返回通行记录
|
||||
if (redisData.equals(recordId)) {
|
||||
log.info("已下发权限,不处理!通行记录={}", recordId);
|
||||
} else {
|
||||
log.info("下发权限!通行记录={}", recordId);
|
||||
RedisUtils.setCacheObject(redisKey, recordId);
|
||||
RedisUtils.expire(redisKey, 10);
|
||||
for (int i = 0; i < 18; i++) {
|
||||
HikApiService.getInstance().controlGateway(controlIP, (i + 1), 2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// redis不存在数据,设置数据,同时下发权限
|
||||
RedisUtils.setCacheObject(redisKey, recordId);
|
||||
RedisUtils.expire(redisKey, 10);
|
||||
for (int i = 0; i < 18; i++) {
|
||||
HikApiService.getInstance().controlGateway(controlIP, (i + 1), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user