2023年8月10日13:21:12

main
litao 3 years ago
parent 3a0549b384
commit b875362e79
  1. 30
      src/main/java/org/springblade/hospital/agent/service/HikAgentService.java
  2. 122
      src/main/java/org/springblade/hospital/controller/AIoTRequestDemo.java
  3. 19
      src/main/java/org/springblade/hospital/controller/AlarmInformationController.java
  4. 49
      src/main/java/org/springblade/hospital/controller/AppDataController.java
  5. 122
      src/main/java/org/springblade/hospital/excel/AlarmInformationExcel.java
  6. 12
      src/main/java/org/springblade/hospital/hik/alarm/AlarmDataParse.java
  7. 35
      src/main/java/org/springblade/hospital/service/impl/AlarmInformationServiceImpl.java
  8. 56
      src/main/java/org/springblade/hospital/utils/CornJobUtil.java
  9. 165
      src/main/java/org/springblade/hospital/utils/ExternalUtils.java

@ -142,18 +142,18 @@ public class HikAgentService extends AgentGrpc.AgentImplBase {
// }
// }
log.info("测试grpc接口调用情况|||||当前线程:" + Thread.currentThread().getId());
byte[] byteValue = DataTrans.intToBytesBigEndian(0);
ByteString byteString = ByteString.copyFrom(byteValue);
Point point = Point.newBuilder().setData(byteString)
.setDataType(1)
.setType(2)
.setDevType(2)
.setChann(4)
.setId("82001")
.setPntType(5)
.setPntTypeValue(6).build();
queueUtils.saveQueueDataStatus(point);
// log.info("测试grpc接口调用情况|||||当前线程:" + Thread.currentThread().getId());
// byte[] byteValue = DataTrans.intToBytesBigEndian(0);
// ByteString byteString = ByteString.copyFrom(byteValue);
// Point point = Point.newBuilder().setData(byteString)
// .setDataType(1)
// .setType(2)
// .setDevType(2)
// .setChann(4)
// .setId("82001")
// .setPntType(5)
// .setPntTypeValue(6).build();
// queueUtils.saveQueueDataStatus(point);
Thread.sleep(20000);
} catch (Exception e) {
log.error("execGetDataFromDevice 从map获取数据异常:{}", e.getMessage());
@ -178,7 +178,9 @@ public class HikAgentService extends AgentGrpc.AgentImplBase {
System.out.println("externalUtils============" + externalUtils);
int page = request.getPage();
int pagesize = request.getPagesize();
List<Map> list = externalUtils.getList(page, pagesize, null);
int devType = request.getDevType();
List<Map> list = externalUtils.getList(page, pagesize, null, String.valueOf(devType));
System.out.println("list======" + list);
// List<RoadwayVo> roadwayVoList = hikService.getTheDeviceInfo();
@ -192,7 +194,7 @@ public class HikAgentService extends AgentGrpc.AgentImplBase {
String s = JSON.toJSONString(map.get("tags")).replace("\\", "");
s = s.substring(1, s.length() - 1);
Map tagsMap = JSONObject.parseObject(s, Map.class);
String macId = tagsMap.get("buildingNo").toString();
String macId = tagsMap.get("mac").toString();
Item item = Item.newBuilder().setId(macId).setName(map.get("name").toString())
.putAllExtField(new HashMap<>()).build();

@ -0,0 +1,122 @@
package org.springblade.hospital.controller;
import com.google.common.collect.Lists;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.util.*;
public class AIoTRequestDemo {
private static final Logger log = LoggerFactory.getLogger(AIoTRequestDemo.class);
private static final String CHARSET = "UTF-8";
private static final String SIGNATURE_ALGORITHM = "HmacSHA256";
static {
Security.addProvider(new BouncyCastleProvider());
}
public static void main(String[] args) throws Exception {
LinkedHashMap<String, List<String>> parameters = new LinkedHashMap<>();
parameters.put("lang", Lists.newArrayList("zh_CN"));
String appKey = "9aON8USr";
String appSecret = "VHc1CBWM0YS204rydm+wWxkQrqJSVyXAAgFRktVpOF4=";
String nonce = "123456";
String timestampStr = "123456789";
String correctSignature = "RdYq6cvBpeF84HO8iQErRF6Aq9XdE2fDx5w4qjDWfrg=";
String signature = renderSignature(
"/report/data/device",
parameters,
nonce,
timestampStr,
"",
appKey,
appSecret
);
System.out.println(signature.equals(correctSignature));
}
/* 封装逻辑
*/
public static String renderSignature(
String uri,
LinkedHashMap<String, List<String>> parameters,
String nonce,
String timestampStr,
String requestBody,
String appKey,
String appSecret
) throws Exception {
long timestamp;
if (StringUtils.isBlank(nonce)) {
throw new Exception("请求nonce未定义");
}
if (StringUtils.isBlank(timestampStr)) {
throw new Exception("请求timestamp未定义");
}
try {
timestamp = Long.parseLong(timestampStr);
} catch (NumberFormatException exception) {
throw new Exception("请求timestamp不合法");
}
if (StringUtils.isBlank(appKey)) {
throw new Exception("请求appKey未定义");
}
return signature(uri, parameters, nonce, timestamp, requestBody, appKey, appSecret);
}
private static String signature(String requestURI, LinkedHashMap<String, List<String>> parameters, String
nonce, long timestamp, String requestBody, String appKey, String appSecret) throws NoSuchAlgorithmException,
InvalidKeyException, UnsupportedEncodingException {
parameters = parametersRank(parameters);
StringBuilder builder = new StringBuilder(requestURI);
for (Map.Entry<String, List<String>> paramEntry : parameters.entrySet()) {
for (String value : paramEntry.getValue()) {
builder
.append(builder.indexOf("?") == -1 ? "?" : "&")
.append(paramEntry.getKey())
.append("=")
.append(value);
}
}
String url = builder.toString();
String signInfo = String.format(
"%sappKey=%s&nonce=%s&timestamp=%s%s",
String.format("%s%s", url, url.contains("?") ? "&" : "?"),
appKey,
nonce,
timestamp,
requestBody
);
SecretKey secretKey = new SecretKeySpec(appSecret.getBytes(CHARSET), SIGNATURE_ALGORITHM);
Mac mac = Mac.getInstance(SIGNATURE_ALGORITHM);
mac.init(secretKey);
String sign = Base64.encodeBase64String(mac.doFinal(signInfo.getBytes(CHARSET)));
log.info("signature completed ...... url [{}] payload [{}] sign [{}]", url, signInfo, sign);
return sign;
}
private static LinkedHashMap<String, List<String>> parametersRank(LinkedHashMap<String, List<String>>
parameters) {
LinkedHashMap<String, List<String>> rankedParameters = new LinkedHashMap<>(parameters.size());
if (parameters.size() != 0) {
List<String> keys = new ArrayList<>(parameters.keySet());
Collections.sort(keys);
for (String key : keys) {
List<String> values = parameters.get(key);
values.sort(Comparator.naturalOrder());
rankedParameters.put(key, values);
}
}
return rankedParameters;
}
}

@ -19,8 +19,6 @@ package org.springblade.hospital.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.gson.Gson;
import com.google.protobuf.ByteString;
@ -33,7 +31,6 @@ import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.hospital.agent.utils.DataTrans;
import org.springblade.hospital.agent.utils.QueueUtils;
import org.springblade.hospital.entity.AlarmInformation;
@ -41,12 +38,12 @@ import org.springblade.hospital.excel.AlarmInformationExcel;
import org.springblade.hospital.hik.alarm.Alarm;
import org.springblade.hospital.service.IAlarmInformationService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* 接口权限控制器
@ -68,7 +65,19 @@ public class AlarmInformationController extends BladeController {
System.out.println("-------params:" + params);
// String data = params.get("data");
// System.out.println("-------data:" + data);
Point point = new Gson().fromJson(JSON.toJSONString(params), Point.class);
// Point point = new Gson().fromJson(JSON.toJSONString(params), Point.class);
int status = Integer.parseInt(String.valueOf(params.get("pntTypeValue_")));
byte[] byteValue = DataTrans.intToBytesBigEndian(status);
ByteString byteString = ByteString.copyFrom(byteValue);
Point point = Point.newBuilder()
.setData(byteString)
.setId(String.valueOf(params.get("id_")))
.setDevType(Integer.parseInt(String.valueOf(params.get("devType_"))))
.setPntType(Integer.parseInt(String.valueOf(params.get("pntType_"))))
// .setPntTypeValue(Integer.parseInt(String.valueOf(params.get("pntTypeValue_"))))
.build();
System.out.println("-------point:" + point);
if (point == null) {
return R.success("请求参数不能为空");

@ -16,10 +16,12 @@
*/
package org.springblade.hospital.controller;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.codec.binary.Base64;
@ -34,6 +36,7 @@ import org.springblade.hospital.entity.AlarmInformation;
import org.springblade.hospital.entity.Alarms;
import org.springblade.hospital.entity.AppData;
import org.springblade.hospital.entity.KeyAndSecret;
import org.springblade.hospital.hik.NetSDKDemo.HCNetSDK;
import org.springblade.hospital.hik.alarm.Alarm;
import org.springblade.hospital.service.IAppDataService;
import org.springblade.hospital.utils.ExternalUtils;
@ -51,10 +54,7 @@ import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
@ -110,24 +110,22 @@ public class AppDataController extends BladeController {
*/
@CrossOrigin
@PostMapping("/escalation")
public R escalation(@RequestBody Alarms alarm) {
String response = "";
public R escalation(@RequestBody Map<String,Object> alarm) {
String uuid = UUID.randomUUID().toString();
alarm.put("regionId", uuid);
alarm.put("sourceId", uuid);
String response = "";
// 请求地址
// String url = "https://test48xwjfile.juhaolian.cn/iot-open-device/report/alarm";
// String url = "https://test48xwjfile.juhaolian.cn/iot-data-receive/alarm/report/forAdapter";
String url = paramService.getValue("url");
// 设置请求Header
String appKey = "BN8ZDpBI";
String appSecret = "5FtRlaVFqvggNUM8/b7u0/MP6zE65V80EPWEK6dDAps=";
// String nonce = Long.toString(IdWorker.getId());
String appKey = "aS6T6X0u";
String appSecret = "F5pFaRzKdUA7jBzQWlg4UV36Hvej5AdntqjqkWRigio=";
String zfcAll = "1234567890";
char[] zfc = zfcAll.toCharArray();
String nonce = RandomStringUtils.random(32, zfc);
// UUID id = UUID.randomUUID();
// String[] idd = id.toString().split("-");
// String nonce = idd[0] + idd[1] + idd[2] + idd[3] + idd[4];
@ -136,27 +134,35 @@ public class AppDataController extends BladeController {
try {
// 基于HMAC-SHA256的base64加密
String message = "/report/data/device?appKey=" + appKey + "&nonce=" + nonce + "&timestamp=" + timestamp;
String message = "/iot-data-receive/alarm/report/forAdapter?appKey=" + appKey + "&nonce=" + nonce + "&timestamp=" + timestamp;
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(appSecret.getBytes(), "HmacSHA256");
sha256_HMAC.init(secret_key);
String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes()));
String signature = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes()));
String content = JSON.toJSONString(alarm);
System.out.println("body请求数据:" + content);
// 请求头参数
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
headers.set("Haiot-appKey", appKey);
headers.set("Haiot-nonce", nonce);
headers.set("Haiot-timestamp", timestamp);
headers.set("Haiot-signature", hash);
System.out.println("url:" + url);
String content = JSON.toJSONString(alarm);
headers.set("Haiot-signature", signature);
HttpEntity<String> httpEntity = new HttpEntity<>(content, headers);
// 发送post请求,并输出结果
response = restTemplate.postForObject(url, httpEntity, String.class);
System.out.println("最终发送url:" + url);
System.out.println("鉴权url:" + message);
System.out.println("appKey:" + appKey);
System.out.println("appSecret:" + appSecret);
System.out.println("nonce:" + nonce);
System.out.println("timestamp:" + timestamp);
System.out.println("signature:" + signature);
System.out.println("fhxx:" + response);
return R.data(response);
// AlarmInformation result = restTemplate.postForObject(url, alarmInformation, AlarmInformation.class);
@ -283,8 +289,9 @@ public class AppDataController extends BladeController {
}
@GetMapping("/test")
public void test() {
Alarm.getStatus();
public R test() {
HCNetSDK.NET_DVR_ALARMHOST_MAIN_STATUS_V40 status = Alarm.getStatus();
// externalUtils.updateStatus();
return R.data(status);
}
}

@ -39,86 +39,98 @@ public class AlarmInformationExcel implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 设备唯一编号
* 设备名称
*/
@ExcelProperty("设备唯一编号")
private String deviceId;
@ExcelProperty("设备名称")
private String deviceName;
/**
*
* 设备唯一编
*/
@ExcelProperty("号")
private String buildId;
@ExcelProperty("设备编号")
private String deviceId;
/**
* 楼层
* 设备类型
*/
@ExcelProperty("楼层")
private String floorNo;
@ExcelProperty("设备类型")
private String productName;
/**
* 经度
* 报警类型
*/
@ExcelProperty("经度")
private String longidute;
@ExcelProperty("报警类型")
private String type;
/**
* 纬度
* 楼号
*/
@ExcelProperty("纬度")
private String latidute;
@ExcelProperty("楼号")
private String buildId;
/**
* 设备类型
* 楼层
*/
@ExcelProperty("设备类型")
private Integer deviceType;
@ExcelProperty("楼层")
private String floorNo;
/**
* 设备状态
*/
@ExcelProperty("设备状态")
private String onlineStatus;
// /**
// * 经度
// */
// @ExcelProperty("经度")
// private String longidute;
//
// /**
// * 纬度
// */
// @ExcelProperty("纬度")
// private String latidute;
//
// /**
// * 设备类型
// */
// @ExcelProperty("设备类型")
// private Integer deviceType;
//
// /**
// * 设备状态
// */
// @ExcelProperty("设备状态")
// private String onlineStatus;
/**
* 报警信息
*/
@ExcelProperty("报警信息")
private String content;
//
// /**
// * 区域编码
// */
// @ExcelProperty("区域编码")
// private String regionCode;
//
// /**
// * 区域名称
// */
// @ExcelProperty("区域名称")
// private String regionName;
//
// /**
// * 报警状态
// */
// @ExcelProperty("报警状态")
// private Integer alarmStatus;
//
// /**
// * 在线状态
// */
// @ExcelProperty("在线状态")
// private String presence;
/**
* 区域编码
*/
@ExcelProperty("区域编码")
private String regionCode;
/**
* 区域名称
*/
@ExcelProperty("区域名称")
private String regionName;
/**
* 报警状态
*/
@ExcelProperty("报警状态")
private Integer alarmStatus;
/**
* 在线状态
*/
@ExcelProperty("在线状态")
private String presence;
/**
* 报警类型
*/
@ExcelProperty("报警类型")
private Integer type;
/**
* 报警时间
* 上报时间
*/
@ExcelProperty("报时间")
@ExcelProperty("上报时间")
private Date reportTime;
}

@ -308,7 +308,7 @@ public class AlarmDataParse {
if (externalUtils == null) {
externalUtils = SpringUtil.getBean(ExternalUtils.class);
}
list = externalUtils.getList(1, 10, "sector_" + Integer.sum(strCIDalarm.wDefenceNo, 1));
list = externalUtils.getList(1, 10, "sector_" + Integer.sum(strCIDalarm.wDefenceNo, 1), null);
}
System.out.println("【CID事件】" + "触发时间:" + TriggerTime + "CID事件号:" + sCIDCode + "CID事件名:" + sCIDDescribe + "子系统号:" +
bySubSysNo);
@ -359,13 +359,15 @@ public class AlarmDataParse {
// if (queueUtils == null) {
// queueUtils = SpringUtil.getBean(QueueUtils.class);
// }
// byte[] byteValue = DataTrans.intToBytesBigEndian(0);
// byte[] byteValue = DataTrans.intToBytesBigEndian(1);
// ByteString byteString = ByteString.copyFrom(byteValue);
// Point point = Point.newBuilder()
// .setId(String.valueOf(Integer.sum(strCIDalarm.wDefenceNo, 1)))
// .setData(byteString)
// .setId("sector_" + Integer.sum(strCIDalarm.wDefenceNo, 1))
// .setDevType(2)
// .setPntType(7)
// .setPntTypeValue(1).build();
//// .setPntTypeValue(1)
// .build();
// boolean b = queueUtils.saveQueueDataStatus(point);
// queueUtils.saveQueueDataAlarm(point);
// System.out.println("===" + b);
@ -379,7 +381,7 @@ public class AlarmDataParse {
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
Map<String, Object> map = new HashMap<>();
map.put("id_", String.valueOf(Integer.sum(strCIDalarm.wDefenceNo, 1)));
map.put("id_", "sector_" + Integer.sum(strCIDalarm.wDefenceNo, 1));
map.put("devType_", 2);
map.put("pntType_", 7);
map.put("pntTypeValue_", 1);

@ -16,27 +16,18 @@
*/
package org.springblade.hospital.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hisense.device.agent.grpc.AgentGrpc;
import com.hisense.device.agent.grpc.CommandRequest;
import com.hisense.device.agent.grpc.CommonResult;
import com.hisense.device.agent.grpc.Point;
import io.grpc.ManagedChannel;
import org.apache.commons.lang3.RandomStringUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.AllArgsConstructor;
import org.springblade.common.cache.DictBizCache;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.hospital.entity.AlarmInformation;
import org.springblade.hospital.excel.AlarmInformationExcel;
import org.springblade.hospital.mapper.AlarmInformationMapper;
import org.springblade.hospital.service.IAlarmInformationService;
import org.springblade.modules.system.service.IDictBizService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
@ -47,14 +38,18 @@ import java.util.List;
@Service
public class AlarmInformationServiceImpl extends BaseServiceImpl<AlarmInformationMapper, AlarmInformation> implements IAlarmInformationService {
@Override
public List<AlarmInformationExcel> export(AlarmInformation alarmInformation) {
// LambdaQueryWrapper<AlarmInformation> wrapper = Wrappers.lambdaQuery(alarmInformation);
// if (alarmInformation.getStartTime() != null && alarmInformation.getEndTime() != null) {
// wrapper.between(AlarmInformation::getReportTime, alarmInformation.getStartTime(), alarmInformation.getEndTime());
// }
// wrapper.orderByDesc(AlarmInformation::getReportTime);
// List<AlarmInformation> list = this.list(wrapper);
return baseMapper.export(alarmInformation);
List<AlarmInformationExcel> excels = baseMapper.export(alarmInformation);
if (CollectionUtils.isNotEmpty(excels)) {
excels.forEach(excel -> {
String type = DictBizCache.getValue("alarm_message_type", excel.getType());
if (StringUtils.isNotBlank(type)) {
excel.setType(type);
}
});
}
return excels;
}
}

@ -41,33 +41,33 @@ public class CornJobUtil {
@Scheduled(initialDelay = 5000, fixedRate = 180000)
public void task() {
System.out.println("定时任务执行了2");
List<CornJob> jobs = cornJobService.list(Wrappers.<CornJob>lambdaQuery().eq(CornJob::getStatus, 1));
if (CollectionUtils.isNotEmpty(jobs)) {
List<CornJob> jobList = new ArrayList<>();
for (CornJob job : jobs) {
Date nextExecuteTime = job.getNextExecuteTime();
if (new Date().compareTo(nextExecuteTime) < 0) {
continue;
}
System.out.println("-----------------====================");
// 布防
if (job.getType() == 1) {
Alarm.fqbf(Integer.parseInt(job.getDeviceId()) - 1);
}
// 撤防
else if (job.getType() == 2) {
Alarm.fqcf(Integer.parseInt(job.getDeviceId()) - 1);
}
// 修改下次执行之间
Calendar calendar = new GregorianCalendar();
calendar.setTime(nextExecuteTime);
// 把日期往后增加一天,整数 往后推,负数往前移动
calendar.add(Calendar.DATE, 1);
job.setNextExecuteTime(calendar.getTime());
jobList.add(job);
}
cornJobService.updateBatchById(jobList);
}
// List<CornJob> jobs = cornJobService.list(Wrappers.<CornJob>lambdaQuery().eq(CornJob::getStatus, 1));
// if (CollectionUtils.isNotEmpty(jobs)) {
// List<CornJob> jobList = new ArrayList<>();
// for (CornJob job : jobs) {
// Date nextExecuteTime = job.getNextExecuteTime();
// if (new Date().compareTo(nextExecuteTime) < 0) {
// continue;
// }
// System.out.println("-----------------====================");
// // 布防
// if (job.getType() == 1) {
// Alarm.fqbf(Integer.parseInt(job.getDeviceId()) - 1);
// }
// // 撤防
// else if (job.getType() == 2) {
// Alarm.fqcf(Integer.parseInt(job.getDeviceId()) - 1);
// }
//
// // 修改下次执行之间
// Calendar calendar = new GregorianCalendar();
// calendar.setTime(nextExecuteTime);
// // 把日期往后增加一天,整数 往后推,负数往前移动
// calendar.add(Calendar.DATE, 1);
// job.setNextExecuteTime(calendar.getTime());
// jobList.add(job);
// }
// cornJobService.updateBatchById(jobList);
// }
}
}

@ -66,17 +66,18 @@ public class ExternalUtils {
/**
* 获取物联网平台设备列表
*/
public List<Map> getList(int page, int pageSize, String id) {
public List<Map> getList(int page, int pageSize, String id, String type) {
String token = CacheUtil.get(SYS_CACHE, "token:id:", "wlwtoken", String.class);
Map map = getMap(token, page, pageSize, id);
Map map = getMap(token, page, pageSize, id, type);
int code = Integer.parseInt(map.get("code").toString());
if (code == 401) {
token = getToken("Arf7bd4f26", "kb207044c8");
CacheUtil.put(SYS_CACHE, "token:id:", "wlwtoken", token);
map = getMap(token, page, pageSize, id);
map = getMap(token, page, pageSize, id, type);
}
// 设备列表
@ -88,9 +89,20 @@ public class ExternalUtils {
return mapList;
}
private Map getMap(String token, int page, int pageSize, String id) {
private Map getMap(String token, int page, int pageSize, String id, String type) {
String url = "http://182.139.182.190:60032/prod-api/api/bizDevice/list?pid=100";
String url = "http://182.139.182.190:60032/prod-api/api/bizDevice/list?";
String pid = "pid=100";
if (StringUtils.isNotBlank(type)) {
if ("4".equals(type)) {
pid = "pid=98";
url += pid;
} else {
url += pid + "&params[type]=" + type;
}
}else {
url += pid;
}
// 分页参数
if (page > 0 && pageSize > 0) {
@ -119,7 +131,7 @@ public class ExternalUtils {
*/
public void updateStatus() {
// 设备列表信息
List<Map> list = getList(0, 0, null);
List<Map> list = getList(0, 0, null, null);
// 遍历设备列表更新设备状态信息
if (CollectionUtils.isNotEmpty(list)) {
@ -135,8 +147,10 @@ public class ExternalUtils {
String s = JSON.toJSONString(map.get("tags")).replace("\\", "");
s = s.substring(1, s.length() - 1);
Map tagsMap = JSONObject.parseObject(s, Map.class);
String id = tagsMap.get("buildingNo").toString();
// 防区号
String id = tagsMap.get("mac").toString();
String type = tagsMap.get("type").toString();
// 防区号/子系统号
int sCIDCode = Integer.parseInt(tagsMap.get("buildingNo").toString());
// 设备真实状态
@ -144,36 +158,46 @@ public class ExternalUtils {
int presence = 0;
if (status != null) {
presence = 1;
// 防区布防状态 0-对应防区处于撤防状态,1-对应防区处于布防状态
byte bySetupAlarmStatus = status.bySetupAlarmStatus[sCIDCode - 1];
// 防区旁路状态 0-表示防区没有旁路 1-表示防区旁路
byte byBypassStatus = status.byBypassStatus[sCIDCode - 1];
// 防区故障状态,0-对应防区处于正常状态,1-对应防区处于故障状态
byte byAlarmInFaultStatus = status.byAlarmInFaultStatus[sCIDCode - 1];
if (byAlarmInFaultStatus == 0) {
if (bySetupAlarmStatus == 1) {
fqStatus = 5;
} else if (bySetupAlarmStatus == 0 && byBypassStatus == 0) {
if ("2".equals(type)) {
presence = 1;
// 防区布防状态 0-对应防区处于撤防状态,1-对应防区处于布防状态
byte bySetupAlarmStatus = status.bySetupAlarmStatus[sCIDCode - 1];
// 防区旁路状态 0-表示防区没有旁路 1-表示防区旁路
byte byBypassStatus = status.byBypassStatus[sCIDCode - 1];
// 防区故障状态,0-对应防区处于正常状态,1-对应防区处于故障状态
byte byAlarmInFaultStatus = status.byAlarmInFaultStatus[sCIDCode - 1];
if (byAlarmInFaultStatus == 0) {
if (bySetupAlarmStatus == 1) {
fqStatus = 5;
} else if (bySetupAlarmStatus == 0 && byBypassStatus == 0) {
fqStatus = 6;
} else if (byBypassStatus == 1) {
fqStatus = 7;
}
} else {
fqStatus = 4;
}
} else if ("3".equals(type)) {
presence = 2;
//子系统布防状态,0-对应子系统处于撤防状态,1-对应子系统处于布防状态
byte bySubSystemGuardStatus = status.bySubSystemGuardStatus[sCIDCode - 1];
if (bySubSystemGuardStatus == 0) {
fqStatus = 6;
} else if (byBypassStatus == 1) {
fqStatus = 7;
} else {
fqStatus = 5;
}
} else {
fqStatus = 4;
}
}
// 海信iot
// updateById(id, fqStatus,presence,type);
test(id, fqStatus, presence, type);
if (fqStatus == state) {
// updateById(id, fqStatus, presence);
test(id, fqStatus, presence);
continue;
}
// 海信iot
// updateById(id, fqStatus,presence);
test(id, fqStatus, presence);
// 物联网平台
bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), fqStatus);
}
@ -183,56 +207,66 @@ public class ExternalUtils {
/**
* 根据设备id修改设备状态信息-海信iot
*/
public void updateById(String id, int byBypassStatus, int presence) {
public void updateById(String id, int byBypassStatus, int presence, String type) {
int pntType = 6;
int pntTypeValue = 0;
// 离线状态
if (presence == 0) {
queue(id, pntType, pntTypeValue);
int typeInt = "1".equals(type) ? 2 : 3;
queue(id, pntType, pntTypeValue, typeInt);
}
// 子系统
else if (presence == 2) {
pntTypeValue = 1;
queue(id, pntType, pntTypeValue, 3);
pntType = 10;
pntTypeValue = byBypassStatus == 5 ? 0 : 1;
queue(id, pntType, pntTypeValue, 3);
}
// 在线状态
else {
pntTypeValue = 1;
queue(id, pntType, pntTypeValue);
queue(id, pntType, pntTypeValue, 2);
pntType = 9;
// 故障
if (byBypassStatus == 4) {
pntTypeValue = 1;
queue(id, pntType, pntTypeValue);
queue(id, pntType, pntTypeValue, 2);
}
// 未故障
else {
pntTypeValue = 0;
queue(id, pntType, pntTypeValue);
queue(id, pntType, pntTypeValue, 2);
pntType = 8;
// 旁路
if (byBypassStatus == 7) {
pntTypeValue = 1;
queue(id, pntType, pntTypeValue);
}
// 未旁路
else {
pntTypeValue = 0;
queue(id, pntType, pntTypeValue);
}
pntTypeValue = byBypassStatus == 7 ? 1 : 0;
queue(id, pntType, pntTypeValue, 2);
}
}
}
/**
* // 设备状态信息上报给海信iot
*
* @param id
* @param pntType
* @param pntTypeValue
*/
private void queue(String id, int pntType, int pntTypeValue) {
private void queue(String id, int pntType, int pntTypeValue, int devType) {
if (queueUtils == null) {
queueUtils = SpringUtil.getBean(QueueUtils.class);
}
Point point = Point.newBuilder().setId(id).setDevType(2).setPntType(pntType).setPntTypeValue(pntTypeValue).build();
byte[] byteValue = DataTrans.intToBytesBigEndian(pntTypeValue);
ByteString byteString = ByteString.copyFrom(byteValue);
Point point = Point.newBuilder().setData(byteString)
.setId(id)
.setDevType(devType)
.setPntType(pntType)
// .setPntTypeValue(pntTypeValue)
.build();
boolean b = queueUtils.saveQueueDataStatus(point);
}
@ -280,53 +314,56 @@ public class ExternalUtils {
* @param id
* @param byBypassStatus
*/
public void test(String id, int byBypassStatus, int presence) {
public void test(String id, int byBypassStatus, int presence, String type) {
int pntType = 6;
int pntTypeValue = 0;
// 离线状态
if (presence == 0) {
test1(id, pntType, pntTypeValue);
int typeInt = "1".equals(type) ? 2 : 3;
test1(id, pntType, pntTypeValue, typeInt);
}
// 在线状态
// 子系统
else if (presence == 2) {
pntTypeValue = 1;
test1(id, pntType, pntTypeValue, 3);
pntType = 10;
pntTypeValue = byBypassStatus == 5 ? 0 : 1;
test1(id, pntType, pntTypeValue, 3);
}
// 防区
else {
pntTypeValue = 1;
test1(id, pntType, pntTypeValue);
test1(id, pntType, pntTypeValue, 2);
pntType = 9;
// 故障
if (byBypassStatus == 4) {
pntTypeValue = 1;
test1(id, pntType, pntTypeValue);
test1(id, pntType, pntTypeValue, 2);
}
// 未故障
else {
pntTypeValue = 0;
test1(id, pntType, pntTypeValue);
test1(id, pntType, pntTypeValue, 2);
pntType = 8;
// 旁路
if (byBypassStatus == 7) {
pntTypeValue = 1;
test1(id, pntType, pntTypeValue);
}
// 未旁路
else {
pntTypeValue = 0;
test1(id, pntType, pntTypeValue);
}
pntTypeValue = byBypassStatus == 7 ? 1 : 0;
test1(id, pntType, pntTypeValue, 2);
}
}
}
public void test1(String id, int pntType, int pntTypeValue) {
public void test1(String id, int pntType, int pntTypeValue, int devType) {
String url = "http://152.136.119.150:81/alarmInformation/hikRemote";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
Map<String, Object> map = new HashMap<>();
map.put("id_", id);
map.put("devType_", 2);
map.put("devType_", devType);
map.put("pntType_", pntType);
map.put("pntTypeValue_", pntTypeValue);
String content = JSON.toJSONString(map);

Loading…
Cancel
Save