wisdomisite-java/src/main/java/com/zhgd/xmgl/util/HikvisionUfaceUtil.java
2024-03-14 15:18:45 +08:00

73 lines
2.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.zhgd.xmgl.util;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.zhgd.jeecg.common.util.SpringContextUtils;
import com.zhgd.mqtt.server.IMqttSender;
import com.zhgd.xmgl.modules.project.entity.ProjectUfaceConfig;
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
/**
* 海康门禁sdk
*/
@Slf4j
public class HikvisionUfaceUtil {
private static String mqttTopic = "hikvision/uface/worker/";
/**
* 添加人员
*
* @param workerInfo
* @param tempProjectUfaceConfig
* @param devSn
*/
public static void addOrUpdatePerson(WorkerInfo workerInfo, ProjectUfaceConfig tempProjectUfaceConfig, String devSn) {
if (StrUtil.isNotBlank(devSn)) {
String[] splitArr = StringUtils.split(devSn, ",");
for (int i = 0; i < splitArr.length; i++) {
String ds = splitArr[i];
Map<String, Object> map = BeanUtil.beanToMap(workerInfo);
map.put("isDelete", false);
map.put("devSn", ds);
String payload = JSON.toJSONString(map);
String topic = mqttTopic + ds;
log.info("发送主题信息:{},主题为:{}", payload, topic);
IMqttSender mqttSender = SpringContextUtils.getBean(IMqttSender.class);
mqttSender.sendToMqtt(topic, 2, payload);
}
} else {
log.info("海康门禁sdk未查询到设备sn");
}
}
/**
* 删除人员
*
* @param workerInfo
* @param tempProjectUfaceConfig
*/
public static void deletePerson(WorkerInfo workerInfo, ProjectUfaceConfig tempProjectUfaceConfig, String devSn) {
if (StrUtil.isNotBlank(devSn)) {
String[] splitArr = StringUtils.split(devSn, ",");
for (int i = 0; i < splitArr.length; i++) {
String ds = splitArr[i];
Map<String, Object> map = BeanUtil.beanToMap(workerInfo);
map.put("isDelete", true);
map.put("devSn", ds);
String payload = JSON.toJSONString(map);
String topic = mqttTopic + ds;
log.info("发送主题信息:{},主题为:{}", payload, topic);
IMqttSender mqttSender = SpringContextUtils.getBean(IMqttSender.class);
mqttSender.sendToMqtt(topic, 2, payload);
}
} else {
log.error("海康门禁sdk未查询到设备sn");
}
}
}