rev:拍照
This commit is contained in:
@@ -2,7 +2,7 @@ package org.nl.common.domain.constant;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.nl.common.hikvision.HikvisionSnapshotUtil;
|
||||
import org.nl.common.hikvision.HikvisionIsapiDigestUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -10,13 +10,14 @@ import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* s
|
||||
*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/26 9:29 上午
|
||||
*/
|
||||
@Service
|
||||
@Data
|
||||
@ToString
|
||||
public class DictConstantPool {
|
||||
public class DictConstantPool {
|
||||
@Value("${hikvison.ins}")
|
||||
public String ins;
|
||||
@Value("${hikvison.path}")
|
||||
@@ -32,23 +33,21 @@ public class DictConstantPool {
|
||||
@Value("${hikvison.channelHttp}")
|
||||
public String channelHttp;
|
||||
@Value("${hikvison.channelSdk}")
|
||||
public Integer channel;
|
||||
|
||||
public String channel;
|
||||
|
||||
|
||||
public static final String DICT_SYS_CODE = "system_type";
|
||||
public static final String DICT_SYS_NAME = "所属系统";
|
||||
|
||||
@PostConstruct
|
||||
public void initHikvisonConfig(){
|
||||
System.out.println("初始化海康威视配置:"+ this);
|
||||
// HikvisionSnapshotUtil.ins = this.ins;
|
||||
// HikvisionSnapshotUtil.path = this.path;
|
||||
HikvisionSnapshotUtil.ip = this.ip;
|
||||
HikvisionSnapshotUtil.port = this.port;
|
||||
HikvisionSnapshotUtil.username = this.username;
|
||||
HikvisionSnapshotUtil.password = this.password;
|
||||
HikvisionSnapshotUtil.channelHttp = this.channelHttp;
|
||||
HikvisionSnapshotUtil.channel = this.channel;
|
||||
public void initHikvisonConfig() {
|
||||
System.out.println("初始化海康威视配置:" + this);
|
||||
HikvisionIsapiDigestUtil.path = this.path;
|
||||
HikvisionIsapiDigestUtil.ip = this.ip;
|
||||
HikvisionIsapiDigestUtil.port = this.port;
|
||||
HikvisionIsapiDigestUtil.username = this.username;
|
||||
HikvisionIsapiDigestUtil.password = this.password;
|
||||
HikvisionIsapiDigestUtil.channelHttp = this.channelHttp;
|
||||
HikvisionIsapiDigestUtil.channel = this.channel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package org.nl.common.hikvision;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 海康威视HTTP接口截图
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class HikvisionIsapiDigestUtil {
|
||||
//存储路径
|
||||
public static String path;
|
||||
//ip 10.22.10.192
|
||||
public static String ip;
|
||||
//端口号80
|
||||
public static Short port;
|
||||
//账号admin
|
||||
public static String username;
|
||||
//密码nl1314520
|
||||
public static String password;
|
||||
//默认
|
||||
public static String channelHttp;
|
||||
//默认1
|
||||
public static String channel;
|
||||
|
||||
/**
|
||||
* ISAPI 抓图
|
||||
*
|
||||
* @param imageName 图片名称
|
||||
* @param taskCode 任务编号
|
||||
* @return
|
||||
*/
|
||||
public boolean syncSnapByDigest(String imageName, String taskCode) {
|
||||
if (StringUtils.isEmpty(imageName)) {
|
||||
log.info("图片名称未定义,跳过截图");
|
||||
return false;
|
||||
}
|
||||
// 参数校验
|
||||
if (StringUtils.isBlank(ip) || port == null
|
||||
|| StringUtils.isBlank(username)
|
||||
|| StringUtils.isBlank(password)) {
|
||||
log.info("海康威视配置参数不完整,无法执行截图。ip={}, port={}, username={}, password={}",
|
||||
ip, port, username, password);
|
||||
return false;
|
||||
}
|
||||
//通道
|
||||
String channel = StringUtils.isNotBlank(channelHttp)
|
||||
? channelHttp
|
||||
: "1";
|
||||
//URL
|
||||
String isapiUrl = String.format("http://%s:%d/ISAPI/Streaming/channels/%s/picture",
|
||||
ip, port, channel);
|
||||
|
||||
log.info("开始截图,URL: {}, imageName={}, taskCode={}", isapiUrl, imageName, taskCode);
|
||||
// 保存路径
|
||||
LocalDate now = LocalDate.now();
|
||||
String datePath = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
String imagePath = path + File.separator + datePath;
|
||||
File dir = new File(imagePath);
|
||||
if (!dir.exists() && !dir.mkdirs()) {
|
||||
log.info("创建图片目录失败: {}", imagePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
String sFileUrl = imagePath + File.separator + taskCode + "_" + imageName + ".jpg";
|
||||
|
||||
//权限
|
||||
CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
credsProvider.setCredentials(AuthScope.ANY,
|
||||
new UsernamePasswordCredentials(username, password));
|
||||
try (CloseableHttpClient client = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider)
|
||||
.build()) {
|
||||
HttpGet get = new HttpGet(isapiUrl);
|
||||
try (CloseableHttpResponse response = client.execute(get)) {
|
||||
int status = response.getStatusLine().getStatusCode();
|
||||
if (status == 200) {
|
||||
byte[] data = EntityUtils.toByteArray(response.getEntity());
|
||||
if (data != null && data.length > 0) {
|
||||
try (FileOutputStream fos = new FileOutputStream(sFileUrl)) {
|
||||
fos.write(data);
|
||||
fos.flush();
|
||||
}
|
||||
log.info("抓图成功: {}, 图片大小: {} bytes", sFileUrl, data.length);
|
||||
return true;
|
||||
} else {
|
||||
log.info("抓图失败: 图片数据为空, URL: {}", isapiUrl);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log.info("抓图失败: HTTP状态码={}, URL={}, 响应: {}",
|
||||
status, isapiUrl, EntityUtils.toString(response.getEntity()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("[ISAPI-Digest] 抓图异常: {}, URL: {}", sFileUrl, isapiUrl, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.base.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.hikvision.HikvisionSnapshotUtil;
|
||||
import org.nl.common.hikvision.HikvisionIsapiDigestUtil;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.wms.basedata_manage.service.IBsrealStorattrService;
|
||||
import org.nl.wms.basedata_manage.service.dao.BsrealStorattr;
|
||||
@@ -90,7 +90,7 @@ public class BsrealStorattrController {
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> getFile(@PathVariable String filename) {
|
||||
try {
|
||||
String imagePath = HikvisionSnapshotUtil.path+ DateUtil.thisYear();
|
||||
String imagePath = HikvisionIsapiDigestUtil.path+ DateUtil.thisYear();
|
||||
//文件名称后缀是jpg,具体以实际为准。文件路径是:path+当前年份,在存储时也是一样
|
||||
//文件会存储两份:一个是载具编号.jpg,一个是载具编号_任务号.jpg,载具编号的图片会进行替换为最新的
|
||||
Path file = Paths.get(imagePath).resolve(filename+".jpg");
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.hikvision.HikvisionSnapshotUtil;
|
||||
import org.nl.common.hikvision.HikvisionIsapiDigestUtil;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
import org.nl.system.service.param.impl.SysParamServiceImpl;
|
||||
@@ -82,6 +82,9 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
@Autowired
|
||||
private IMdPbStoragevehicleinfoService iMdPbStoragevehicleinfoService;
|
||||
|
||||
@Autowired
|
||||
private HikvisionIsapiDigestUtil hikvisionIsapiDigestUtil;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@SneakyThrows
|
||||
@@ -198,7 +201,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
String taskCode = taskDao.getTask_code();
|
||||
log.info("[拍照] 开始异步调用海康拍照,vehicleCode={}, taskCode={}", vehicleCode, taskCode);
|
||||
try {
|
||||
HikvisionSnapshotUtil.syncSnap(vehicleCode, taskCode);
|
||||
hikvisionIsapiDigestUtil.syncSnapByDigest(vehicleCode, taskCode);
|
||||
log.info("[拍照] 海康拍照调用完成,vehicleCode={}, taskCode={}", vehicleCode, taskCode);
|
||||
} catch (Throwable e) {
|
||||
log.info("[拍照] 调用海康拍照失败,vehicleCode={}, taskCode={}", vehicleCode, taskCode, e);
|
||||
|
||||
@@ -7,7 +7,7 @@ nl:
|
||||
ip: 127.0.0.1
|
||||
port: 3306
|
||||
username: root
|
||||
password: 12356
|
||||
password: P@ssw0rd.
|
||||
database: wms
|
||||
redis:
|
||||
ip: 127.0.0.1
|
||||
@@ -28,3 +28,12 @@ nl:
|
||||
database: 马钢_RH
|
||||
logging-path: C:\log\wms
|
||||
dynamic-log-path: C:\log\lms
|
||||
hikvison:
|
||||
ins: C:\Users\Administrator\Desktop\库文件\HCNetSDK.dll
|
||||
path: C:\software\wms\images
|
||||
ip: 10.22.10.192
|
||||
port: 80
|
||||
username: admin
|
||||
password: nl1314520
|
||||
channelHttp: 101
|
||||
channelSdk: 1
|
||||
|
||||
@@ -4,7 +4,7 @@ server:
|
||||
relaxed-path-chars: [ '|','{','}','[',']' ] #字符问题: https://blog.csdn.net/weixin_41996632/article/details/90715118
|
||||
lucene:
|
||||
index:
|
||||
path: D:\lucene\index
|
||||
path: C:\wms\lucene\index
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
@@ -192,7 +192,7 @@ file:
|
||||
avatarMaxSize: 5
|
||||
logging:
|
||||
file:
|
||||
path: D:\log\XuGong\wms
|
||||
path: C:\log\XuGong\wms
|
||||
config: classpath:logback-spring.xml
|
||||
# sa-token白名单配置
|
||||
security:
|
||||
@@ -306,9 +306,9 @@ jetcache:
|
||||
port: ${nl.config.redis.port}
|
||||
hikvison:
|
||||
ins: C:\Users\Administrator\Desktop\库文件\HCNetSDK.dll
|
||||
path: E:\lms\2025\
|
||||
ip: 169.254.43.101
|
||||
port: 8000
|
||||
path: C:\software\wms\images
|
||||
ip: 10.22.10.192
|
||||
port: 80
|
||||
username: admin
|
||||
password: nl1314520
|
||||
channelHttp: 101
|
||||
|
||||
Reference in New Issue
Block a user