智能识别
This commit is contained in:
parent
a218d59449
commit
e78fb79d76
|
|
@ -1,12 +1,14 @@
|
||||||
package com.bonus.common.core.utils;
|
package com.bonus.common.core.utils;
|
||||||
|
|
||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import sun.misc.BASE64Decoder;
|
import sun.misc.BASE64Decoder;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author:cwchen
|
* @author:cwchen
|
||||||
* @date:2024-06-11 17:53-10:10
|
* @date:2024-06-11 17:53-10:10
|
||||||
|
|
@ -17,6 +19,7 @@ public class BASE64DecodedMultipartFile implements MultipartFile {
|
||||||
|
|
||||||
private final byte[] imgContent;
|
private final byte[] imgContent;
|
||||||
private final String header;
|
private final String header;
|
||||||
|
private final static String IMG_PREFIX = "data:image/jpeg;base64,";
|
||||||
|
|
||||||
public BASE64DecodedMultipartFile(byte[] imgContent, String header) {
|
public BASE64DecodedMultipartFile(byte[] imgContent, String header) {
|
||||||
this.imgContent = imgContent;
|
this.imgContent = imgContent;
|
||||||
|
|
@ -84,6 +87,42 @@ public class BASE64DecodedMultipartFile implements MultipartFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MultipartFile base64ToMultipart2(String base64) {
|
||||||
|
try {
|
||||||
|
if (StringUtils.isEmpty(base64)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String[] baseStrs = base64.split(",");
|
||||||
|
if (baseStrs.length == 1) {
|
||||||
|
BASE64Decoder decoder = new BASE64Decoder();
|
||||||
|
byte[] b = new byte[0];
|
||||||
|
b = decoder.decodeBuffer(baseStrs[0]);
|
||||||
|
|
||||||
|
for (int i = 0; i < b.length; ++i) {
|
||||||
|
if (b[i] < 0) {
|
||||||
|
b[i] += 256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new BASE64DecodedMultipartFile(b, IMG_PREFIX);
|
||||||
|
} else if (baseStrs.length == 2) {
|
||||||
|
BASE64Decoder decoder = new BASE64Decoder();
|
||||||
|
byte[] b = new byte[0];
|
||||||
|
b = decoder.decodeBuffer(baseStrs[1]);
|
||||||
|
|
||||||
|
for (int i = 0; i < b.length; ++i) {
|
||||||
|
if (b[i] < 0) {
|
||||||
|
b[i] += 256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new BASE64DecodedMultipartFile(b, baseStrs[0]);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getBase64(String path) {
|
public static String getBase64(String path) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import org.springframework.core.io.buffer.DataBufferFactory;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.server.RequestPath;
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -23,6 +24,8 @@ import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
|
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
|
||||||
|
|
||||||
|
|
@ -39,6 +42,13 @@ public class AecDecryptParamFilter extends AbstractGatewayFilterFactory {
|
||||||
|
|
||||||
public final static String HEARD_NAME="decrypt";
|
public final static String HEARD_NAME="decrypt";
|
||||||
|
|
||||||
|
/**忽略加密的参数的请求*/
|
||||||
|
public static List<String> ignoreUrls = new ArrayList<>();
|
||||||
|
|
||||||
|
{
|
||||||
|
ignoreUrls.add("/tcp/ball/xmlAnalysis");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GatewayFilter apply(Object config) {
|
public GatewayFilter apply(Object config) {
|
||||||
return (exchange, chain) -> {
|
return (exchange, chain) -> {
|
||||||
|
|
@ -47,6 +57,11 @@ public class AecDecryptParamFilter extends AbstractGatewayFilterFactory {
|
||||||
if(StringUtils.isNotEmpty(head)&& HEARD_NAME.equals(head)){
|
if(StringUtils.isNotEmpty(head)&& HEARD_NAME.equals(head)){
|
||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
}
|
}
|
||||||
|
String reqPath = serverHttpRequest.getURI().getPath();
|
||||||
|
boolean sf = ignoreUrls.contains(reqPath);
|
||||||
|
if(sf){
|
||||||
|
return chain.filter(exchange);
|
||||||
|
}
|
||||||
if(!jaData){
|
if(!jaData){
|
||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -47,13 +49,24 @@ public class ResponseEncryptFilter implements GlobalFilter, Ordered {
|
||||||
*/
|
*/
|
||||||
public final static String KEY_HEAD="decrypt";
|
public final static String KEY_HEAD="decrypt";
|
||||||
|
|
||||||
|
/**忽略加密的参数的请求*/
|
||||||
|
public static List<String> ignoreUrls = new ArrayList<>();
|
||||||
|
|
||||||
|
{
|
||||||
|
ignoreUrls.add("/tcp/ball/xmlAnalysis");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
log.info("============================ResponseEncryptFilter start===================================");
|
log.info("============================ResponseEncryptFilter start===================================");
|
||||||
|
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
URI uri = request.getURI();
|
URI uri = request.getURI();
|
||||||
|
String reqPath = request.getURI().getPath();
|
||||||
|
boolean sf = ignoreUrls.contains(reqPath);
|
||||||
|
if(sf){
|
||||||
|
return chain.filter(exchange);
|
||||||
|
}
|
||||||
HttpHeaders headers=request.getHeaders();
|
HttpHeaders headers=request.getHeaders();
|
||||||
if(headers!=null){
|
if(headers!=null){
|
||||||
Object object=headers.getFirst("Content-Type");
|
Object object=headers.getFirst("Content-Type");
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ public class SmartIdentifyController {
|
||||||
eventTime = DateTimeHelper.stampToDate(element.attributeValue("Time"));
|
eventTime = DateTimeHelper.stampToDate(element.attributeValue("Time"));
|
||||||
}
|
}
|
||||||
Iterator desc2Interator = element.elementIterator("Desc2");
|
Iterator desc2Interator = element.elementIterator("Desc2");
|
||||||
if(desc2Interator != null){
|
if (desc2Interator != null) {
|
||||||
Element idCardEle = (Element) desc2Interator.next();
|
Element idCardEle = (Element) desc2Interator.next();
|
||||||
idCard = idCardEle.attributeValue("IDCard");
|
idCard = idCardEle.attributeValue("IDCard");
|
||||||
}
|
}
|
||||||
|
|
@ -112,6 +112,7 @@ public class SmartIdentifyController {
|
||||||
// 十分钟内存在该事件,直接返回
|
// 十分钟内存在该事件,直接返回
|
||||||
Object cacheObject = redisService.getCacheObject(evenID + "_" + puid);
|
Object cacheObject = redisService.getCacheObject(evenID + "_" + puid);
|
||||||
if (Objects.nonNull(cacheObject)) {
|
if (Objects.nonNull(cacheObject)) {
|
||||||
|
log.info("十分钟内存在该事件");
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
Iterator resInterator = headEle.elementIterator("Res");
|
Iterator resInterator = headEle.elementIterator("Res");
|
||||||
|
|
@ -127,11 +128,11 @@ public class SmartIdentifyController {
|
||||||
}
|
}
|
||||||
//存在该设备
|
//存在该设备
|
||||||
if (existence) {
|
if (existence) {
|
||||||
switchEvent(evenID, element, eventTime, puid, ballName,idCard, devices);
|
switchEvent(evenID, element, eventTime, puid, ballName, idCard, devices);
|
||||||
// 事件推送成功后,设置缓存
|
// 事件推送成功后,设置缓存
|
||||||
String key = evenID + "_" + puid;
|
String key = evenID + "_" + puid;
|
||||||
log.info("redis-key:{}",key);
|
log.info("redis-key:{}", key);
|
||||||
redisService.setCacheObject(key, puid, 100L, TimeUnit.MILLISECONDS);
|
redisService.setCacheObject(key, puid, 10L, TimeUnit.MINUTES);
|
||||||
} else {
|
} else {
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
|
|
@ -156,42 +157,36 @@ public class SmartIdentifyController {
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchEvent(String eventId, Element element, String eventTime, String puid, String ballName,String idCard, List<DeviceUseVo> devices) {
|
private void switchEvent(String eventId, Element element, String eventTime, String puid, String ballName, String idCard, List<DeviceUseVo> devices) {
|
||||||
List<MultipartFile> files = null;
|
List<MultipartFile> files = null;
|
||||||
DeviceUseVo deviceUseVo = devices.get(0);
|
DeviceUseVo deviceUseVo = devices.get(0);
|
||||||
deviceUseVo.setWarnTime(eventTime);
|
deviceUseVo.setWarnTime(eventTime);
|
||||||
deviceUseVo.setIdCard(idCard);
|
deviceUseVo.setIdCard(idCard);
|
||||||
switch (eventId) {
|
switch (eventId) {
|
||||||
case "E_IVS_FaceRecognition":
|
|
||||||
log.info(puid + ":违章事件:人脸识别");
|
|
||||||
deviceUseVo.setWarnContent("未戴安全帽");
|
|
||||||
files = deviceVolEvenHandler(puid, eventTime, element);
|
|
||||||
// service.addEventData(deviceUseVo, files);
|
|
||||||
break;
|
|
||||||
case "E_IVS_HelmetNotWear":
|
case "E_IVS_HelmetNotWear":
|
||||||
log.info(puid + ":违章事件:未戴安全帽");
|
log.info(puid + ":违章事件:未戴安全帽");
|
||||||
deviceUseVo.setWarnContent("未戴安全帽");
|
deviceUseVo.setWarnContent("未戴安全帽");
|
||||||
files = deviceVolEvenHandler(puid, eventTime, element);
|
files = deviceVolEvenHandler(element);
|
||||||
// service.addEventData(deviceUseVo, files);
|
service.addEventData(deviceUseVo, files);
|
||||||
break;
|
break;
|
||||||
case "E_IVS_Smoking":
|
case "E_IVS_Smoking":
|
||||||
log.info(puid + ":违章事件:吸烟行为");
|
log.info(puid + ":违章事件:吸烟行为");
|
||||||
deviceUseVo.setWarnContent("吸烟行为");
|
deviceUseVo.setWarnContent("吸烟行为");
|
||||||
files = deviceVolEvenHandler(puid, eventTime, element);
|
files = deviceVolEvenHandler(element);
|
||||||
// service.addEventData(deviceUseVo, files);
|
service.addEventData(deviceUseVo, files);
|
||||||
break;
|
break;
|
||||||
case "E_IVS_NotWear3ColorVest":
|
case "E_IVS_NotWear3ColorVest":
|
||||||
log.info(puid + ":违章事件:未穿马甲");
|
log.info(puid + ":违章事件:未穿马甲");
|
||||||
deviceUseVo.setWarnContent("未穿马甲");
|
deviceUseVo.setWarnContent("未穿马甲");
|
||||||
files = deviceVolEvenHandler(puid, eventTime, element);
|
files = deviceVolEvenHandler(element);
|
||||||
// service.addEventData(deviceUseVo, files);
|
service.addEventData(deviceUseVo, files);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MultipartFile> deviceVolEvenHandler(String puid, String volTime, Element element) {
|
private List<MultipartFile> deviceVolEvenHandler(Element element) {
|
||||||
List<MultipartFile> multipartFiles = new ArrayList<>();
|
List<MultipartFile> multipartFiles = new ArrayList<>();
|
||||||
Iterator silcesInterator = element.elementIterator("Slices");
|
Iterator silcesInterator = element.elementIterator("Slices");
|
||||||
if (silcesInterator.hasNext()) {
|
if (silcesInterator.hasNext()) {
|
||||||
|
|
@ -206,8 +201,10 @@ public class SmartIdentifyController {
|
||||||
Element TestEle = (Element) snapshotInterator.next();
|
Element TestEle = (Element) snapshotInterator.next();
|
||||||
String photoBase64 = TestEle.getText();
|
String photoBase64 = TestEle.getText();
|
||||||
log.info("base64地址:{}", photoBase64);
|
log.info("base64地址:{}", photoBase64);
|
||||||
// MultipartFile multipartFile = BASE64DecodedMultipartFile.base64ToMultipart(photoBase64);
|
MultipartFile multipartFile = BASE64DecodedMultipartFile.base64ToMultipart2(photoBase64);
|
||||||
// multipartFiles.add(multipartFile);
|
if (multipartFile != null) {
|
||||||
|
multipartFiles.add(multipartFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ public class SmartIdentifyServiceImpl implements SmartIdentifyService {
|
||||||
R<Boolean> r = null;
|
R<Boolean> r = null;
|
||||||
try {
|
try {
|
||||||
r = remoteSourceService.addFileSource(fileVo, SecurityConstants.INNER);
|
r = remoteSourceService.addFileSource(fileVo, SecurityConstants.INNER);
|
||||||
if (!r.getData()) {
|
if (r.getData()) {
|
||||||
// 资源文件保存失败,删除文件
|
// 资源文件保存失败,删除文件
|
||||||
remoteFileService.delFile(item.getString("fileId"), SecurityConstants.INNER);
|
remoteFileService.delFile(item.getString("fileId"), SecurityConstants.INNER);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="userId != null">user_id,</if>
|
<if test="userId != null">user_id,</if>
|
||||||
<if test="warnContent != null and warnContent!=''">warn_content,</if>
|
<if test="warnContent != null and warnContent!=''">warn_content,</if>
|
||||||
<if test="warnTime != null and warnTime!=''">warn_time,</if>
|
<if test="warnTime != null and warnTime!=''">warn_time,</if>
|
||||||
|
<if test="warnType != null">warn_type,</if>
|
||||||
<if test="devType != null">dev_type,</if>
|
<if test="devType != null">dev_type,</if>
|
||||||
<if test="peopleType != null">people_type,</if>
|
<if test="peopleType != null">people_type,</if>
|
||||||
create_time,
|
create_time,
|
||||||
|
|
@ -26,6 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="userId != null">#{userId},</if>
|
<if test="userId != null">#{userId},</if>
|
||||||
<if test="warnContent != null and warnContent!=''">#{warnContent},</if>
|
<if test="warnContent != null and warnContent!=''">#{warnContent},</if>
|
||||||
<if test="warnTime != null and warnTime!=''">#{warnTime},</if>
|
<if test="warnTime != null and warnTime!=''">#{warnTime},</if>
|
||||||
|
<if test="warnType != null">#{warnType},</if>
|
||||||
<if test="devType != null">#{devType},</if>
|
<if test="devType != null">#{devType},</if>
|
||||||
<if test="peopleType != null">#{peopleType},</if>
|
<if test="peopleType != null">#{peopleType},</if>
|
||||||
#{createTime},
|
#{createTime},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue