海康摄像头维护

main
litao 2 years ago
parent 80a61baea9
commit 7f5e71aeea
  1. 2
      src/main/java/org/springblade/hospital/controller/AlarmInformationController.java
  2. 42
      src/main/java/org/springblade/hospital/controller/AppDataController.java
  3. 51
      src/main/java/org/springblade/hospital/controller/HikvisionCameraController.java
  4. 50
      src/main/java/org/springblade/hospital/entity/HikvisionCamera.java
  5. 29
      src/main/java/org/springblade/hospital/mapper/HikvisionCameraMapper.java
  6. 5
      src/main/java/org/springblade/hospital/mapper/HikvisionCameraMapper.xml
  7. 28
      src/main/java/org/springblade/hospital/service/IHikvisionCameraService.java
  8. 34
      src/main/java/org/springblade/hospital/service/impl/HikvisionCameraServiceImpl.java
  9. 17
      src/main/java/org/springblade/hospital/utils/CornJobUtil.java
  10. 15
      src/main/java/org/springblade/hospital/utils/ExternalUtils.java
  11. 144
      src/main/java/org/springblade/hospital/utils/ImageBase64Util.java
  12. 12
      src/main/java/org/springblade/modules/system/controller/DictBizController.java

@ -117,7 +117,7 @@ public class AlarmInformationController extends BladeController {
}
/**
* 导出用户
* 导出报警记录
*/
@GetMapping("export")
public void exportUser(AlarmInformation alarmInformation, HttpServletResponse response) {

@ -22,7 +22,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.lang3.RandomStringUtils;
import org.springblade.common.cache.ParamCache;
import org.springblade.core.boot.ctrl.BladeController;
@ -33,10 +32,9 @@ import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.hospital.entity.*;
import org.springblade.hospital.hik.alarm.Alarm;
import org.springblade.hospital.newalarm.communicationCom.HTTPClientUtil;
import org.springblade.hospital.service.IAppDataService;
import org.springblade.hospital.utils.ExternalUtils;
import org.springblade.hospital.websocket.WebSocketServer;
import org.springblade.hospital.utils.ImageBase64Util;
import org.springblade.modules.system.service.IParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
@ -45,16 +43,13 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import static org.springblade.common.constant.CommonConstant.IOT_PLATFORM_URL;
@ -124,6 +119,28 @@ public class AppDataController extends BladeController {
String uuid = UUID.randomUUID().toString();
alarm.put("regionId", uuid);
alarm.put("sourceId", uuid);
if (alarm.get("pictureList") != null) {
List<Map<String, Object>> pictureList = JSON.parseObject(JSON.toJSONString(alarm.get("pictureList")), List.class);
for (Map<String, Object> map : pictureList) {
String url = String.valueOf(map.get("url"));
String substring = url.substring(url.lastIndexOf(".") + 1);
if ("png".equals(substring) || "jpg".equals(substring)) {
map.put("type", 2);
String base64 = ImageBase64Util.encodeImgageToBase64(url);
map.put("base64", base64);
map.remove("url");
} else if ("mp3".equals(substring)) {
map.put("type", 2);
map.put("base64", ImageBase64Util.getBase64(url));
map.remove("url");
} else {
map.put("type", 1);
map.put("url", url);
}
}
alarm.put("pictures", pictureList);
alarm.remove("pictureList");
}
String response = "";
// 请求地址
@ -139,7 +156,6 @@ public class AppDataController extends BladeController {
// UUID id = UUID.randomUUID();
// String[] idd = id.toString().split("-");
// String nonce = idd[0] + idd[1] + idd[2] + idd[3] + idd[4];
String timestamp = String.valueOf(System.currentTimeMillis());
try {
@ -349,4 +365,10 @@ public class AppDataController extends BladeController {
return R.data(new JoysuchCoordinate((double) x, (double) y, lng, lat));
}
public static void main(String[] args) throws IOException {
String url = "http://171.16.8.51:9000/hospital/upload/20231221/afe50cd7d6bc8227e6079193cbb9f00c.mp3";
String base64 = ImageBase64Util.getBase64(url);
System.out.println("base64:" + base64);
}
}

@ -0,0 +1,51 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.hospital.controller;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.hospital.entity.HikvisionCamera;
import org.springblade.hospital.service.IHikvisionCameraService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* 接口权限控制器
* @author BladeX
*/
@NonDS
@RestController
@AllArgsConstructor
@RequestMapping("/hikvisionCamera")
public class HikvisionCameraController extends BladeController {
private final IHikvisionCameraService hikvisionCameraService;
@PostMapping("/import-user")
public R importUser(MultipartFile file) {
List<HikvisionCamera> read = ExcelUtil.read(file, HikvisionCamera.class);
for (HikvisionCamera hikvisionCamera : read) {
hikvisionCamera.setName(hikvisionCamera.getName().split(" ")[0]);
}
return R.status(hikvisionCameraService.saveBatch(read));
}
}

@ -0,0 +1,50 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.hospital.entity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.mp.base.BaseEntity;
import java.sql.Time;
import java.util.Date;
/**
* 布防撤防记录
* @author BladeX
*/
@Data
@TableName("ho_hikvision_camera")
@EqualsAndHashCode(callSuper = true)
public class HikvisionCamera extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 任务标题
*/
@ExcelProperty("设备名称")
private String name;
/**
* 任务执行时间
*/
@ExcelProperty("设备编号")
private String code;
}

@ -0,0 +1,29 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.hospital.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springblade.hospital.entity.HikvisionCamera;
/**
* Mapper 接口
*
* @author BladeX
*/
public interface HikvisionCameraMapper extends BaseMapper<HikvisionCamera> {
}

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.hospital.mapper.HikvisionCameraMapper">
</mapper>

@ -0,0 +1,28 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.hospital.service;
import org.springblade.core.mp.base.BaseService;
import org.springblade.hospital.entity.HikvisionCamera;
/**
* 服务类
* @author BladeX
*/
public interface IHikvisionCameraService extends BaseService<HikvisionCamera> {
}

@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.hospital.service.impl;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.hospital.entity.HikvisionCamera;
import org.springblade.hospital.mapper.HikvisionCameraMapper;
import org.springblade.hospital.service.IHikvisionCameraService;
import org.springframework.stereotype.Service;
/**
* 服务实现类
*
* @author BladeX
*/
@Service
public class HikvisionCameraServiceImpl extends BaseServiceImpl<HikvisionCameraMapper, HikvisionCamera> implements IHikvisionCameraService {
}

@ -68,22 +68,23 @@ public class CornJobUtil {
if (new Date().compareTo(nextExecuteTime) < 0) {
continue;
}
// System.out.println("-----------------====================");
try {
if (StringUtils.isNotBlank(job.getDeviceId())) {
String[] ids = job.getDeviceId().split(",");
String[] nums = job.getHostSerialNumber().split(",");
// 布防
if (job.getType() == 1) {
for (String id : ids) {
String[] split = id.split("_");
Alarm.zibufang(job.getHostSerialNumber(), Integer.parseInt(split[split.length - 1]));
for (int i = 0; i < ids.length; i++) {
String[] split = ids[i].split("_");
Alarm.zibufang(nums[i], Integer.parseInt(split[split.length - 1]));
}
}
// 撤防
else if (job.getType() == 2) {
for (String id : ids) {
String[] split = id.split("_");
Alarm.zichefang(job.getHostSerialNumber(), Integer.parseInt(split[split.length - 1]));
for (int i = 0; i < ids.length; i++) {
String[] split = ids[i].split("_");
Alarm.zichefang(nums[i], Integer.parseInt(split[split.length - 1]));
}
}
// 修改下次执行时间
@ -102,7 +103,7 @@ public class CornJobUtil {
}
}
// @Async
// @Async
// @Scheduled(initialDelay = 7000, fixedRate = 3600000)
public void testWebSocket() {
// System.out.println("定时任务执行了3");

@ -5,11 +5,8 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.protobuf.ByteString;
import com.hisense.device.agent.grpc.Point;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.common.cache.ParamCache;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.tool.api.R;
@ -17,7 +14,6 @@ import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.hospital.agent.utils.DataTrans;
import org.springblade.hospital.agent.utils.QueueUtils;
import org.springblade.hospital.entity.KeyAndSecret;
import org.springblade.hospital.hik.NetSDKDemo.HCNetSDK;
import org.springblade.hospital.hik.alarm.Alarm;
import org.springblade.hospital.newalarm.communicationCom.HTTPClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
@ -30,7 +26,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Exchanger;
import java.util.stream.Collectors;
import static org.springblade.common.constant.CommonConstant.IOT_PLATFORM_URL;
@ -226,7 +221,7 @@ public class ExternalUtils {
Map zone = JSONObject.parseObject(zoneMap.get("Zone").toString(), Map.class);
// 防区布防状态 0-对应防区处于撤防状态,1-对应防区处于布防状态
int bySetupAlarmStatus = 0;
if ((boolean) zone.get("isArming")) {
if ((boolean) zone.get("armed")) {
bySetupAlarmStatus = 1;
}
@ -284,6 +279,12 @@ public class ExternalUtils {
// 物联网平台
bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), fqStatus);
for (Map mapData : mapList) {
if (map.get("id").equals(mapData.get("id"))) {
mapData.put("status", fqStatus);
break;
}
}
}
}
}
@ -390,7 +391,7 @@ public class ExternalUtils {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
headers.setBearerAuth(token);
Map map = new HashMap();
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("id", id);
map.put("status", status);
String content = JSON.toJSONString(map);

@ -0,0 +1,144 @@
package org.springblade.hospital.utils;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ImageBase64Util {
/**
* 将网络图片进行Base64位编码
* @param imageUrl 图片的url路径如http://.....xx.jpg
* @return
*/
public static String encodeImgageToBase64(String imageUrl) {
// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
ByteArrayOutputStream outputStream = null;
try {
String substring = imageUrl.substring(imageUrl.lastIndexOf(".") + 1);
BufferedImage bufferedImage = ImageIO.read(new URL(imageUrl));
outputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, substring, outputStream);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// 对字节数组Base64编码
BASE64Encoder encoder = new BASE64Encoder();
// 返回Base64编码过的字节数组字符串
return encoder.encode(outputStream.toByteArray());
}
/**
* 将本地图片进行Base64位编码
*/
public static String encodeImgageToBase64(File imageFile) {
// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
ByteArrayOutputStream outputStream = null;
try {
BufferedImage bufferedImage = ImageIO.read(imageFile);
outputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "jpg", outputStream);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// 对字节数组Base64编码
BASE64Encoder encoder = new BASE64Encoder();
// 返回Base64编码过的字节数组字符串
return encoder.encode(outputStream.toByteArray());
}
/**
* 将Base64位编码进行转本地图片
*/
public static void decodeBase64ToImage(String base64, String path, String imgName) {
BASE64Decoder decoder = new BASE64Decoder();
try {
FileOutputStream write = new FileOutputStream(new File(path
+ imgName));
byte[] decoderBytes = decoder.decodeBuffer(base64);
write.write(decoderBytes);
write.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getBase64(String imageUrl) {
File file = null;
String fileName = imageUrl.substring(imageUrl.lastIndexOf("."),imageUrl.length());
URL urlfile;
InputStream inputStream = null;
OutputStream outputStream= null;
try {
file = File.createTempFile("wx_image", fileName);
//下载
urlfile = new URL(imageUrl);
inputStream = urlfile.openStream();
outputStream= new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
if (null != outputStream) {
outputStream.close();
}
if (null != inputStream) {
inputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return getBase64ceshi(file);
}
public static String getBase64ceshi(File file) {
String base64Str = null;
FileInputStream inputStream = null;
try {
java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
inputStream = new FileInputStream(file);
int available = inputStream.available();
byte[] bytes = new byte[available];
inputStream.read(bytes);
base64Str = encoder.encodeToString(bytes);
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return replaceEnter(base64Str);
}
public static String replaceEnter(String str){
String reg ="[\n-\r]";
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(str);
return m.replaceAll("");
}
}

@ -32,6 +32,8 @@ import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.hospital.entity.HikvisionCamera;
import org.springblade.hospital.service.IHikvisionCameraService;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.service.IDictBizService;
import org.springblade.modules.system.vo.DictBizVO;
@ -58,6 +60,8 @@ public class DictBizController extends BladeController {
private final IDictBizService dictService;
private final IHikvisionCameraService hikvisionCameraService;
/**
* 详情
*/
@ -206,13 +210,13 @@ public class DictBizController extends BladeController {
@GetMapping("/getValues")
public R getValues(String keys) {
String[] keyArray = keys.split(",");
List<DictBiz> list = dictService.list(Wrappers.<DictBiz>lambdaQuery().eq(DictBiz::getCode, "camera_information").in(DictBiz::getDictKey, keyArray));
List<HikvisionCamera> list = hikvisionCameraService.list(Wrappers.<HikvisionCamera>lambdaQuery().select(HikvisionCamera::getCode, HikvisionCamera::getName).in(HikvisionCamera::getName, keyArray));
List<Map<String, String>> codes = new ArrayList<>();
if (CollectionUtils.isNotEmpty(list)) {
for (DictBiz dictBiz : list) {
for (HikvisionCamera hikvisionCamera : list) {
Map<String, String> map = new HashMap<>();
map.put("name", dictBiz.getDictKey());
map.put("code", dictBiz.getDictValue());
map.put("name", hikvisionCamera.getName());
map.put("code", hikvisionCamera.getCode());
codes.add(map);
}
}

Loading…
Cancel
Save