2024-03-14 13:50:57 +08:00
|
|
|
|
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;
|
2024-03-14 15:18:45 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2024-03-14 13:50:57 +08:00
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 海康门禁sdk
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
public class HikvisionUfaceUtil {
|
2024-03-14 15:18:45 +08:00
|
|
|
|
private static String mqttTopic = "hikvision/uface/worker/";
|
2024-03-14 13:50:57 +08:00
|
|
|
|
|
2024-03-14 15:18:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 添加人员
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param workerInfo
|
|
|
|
|
|
* @param tempProjectUfaceConfig
|
|
|
|
|
|
* @param devSn
|
|
|
|
|
|
*/
|
2024-03-14 13:50:57 +08:00
|
|
|
|
public static void addOrUpdatePerson(WorkerInfo workerInfo, ProjectUfaceConfig tempProjectUfaceConfig, String devSn) {
|
|
|
|
|
|
if (StrUtil.isNotBlank(devSn)) {
|
2024-03-14 15:18:45 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2024-03-14 13:50:57 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
log.error("海康门禁sdk,未查询到设备sn");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|