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