From 0fe078a6f1c598f77316dc7c002fe069a27c54e9 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期一, 25 三月 2024 21:43:31 +0800
Subject: [PATCH] bug修改
---
ycl-platform/src/main/resources/application-prod.yml | 4
ycl-common/src/main/java/com/ycl/service/oss/impl/OssServiceImpl.java | 14 ++--
ycl-platform/src/main/resources/application-online.yml | 4
ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java | 50 +++++++++++++++-
ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java | 14 ++--
ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java | 37 ++----------
ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java | 24 +++++++
7 files changed, 95 insertions(+), 52 deletions(-)
diff --git a/ycl-common/src/main/java/com/ycl/service/oss/impl/OssServiceImpl.java b/ycl-common/src/main/java/com/ycl/service/oss/impl/OssServiceImpl.java
index 3a24a08..183c739 100644
--- a/ycl-common/src/main/java/com/ycl/service/oss/impl/OssServiceImpl.java
+++ b/ycl-common/src/main/java/com/ycl/service/oss/impl/OssServiceImpl.java
@@ -43,10 +43,12 @@
// 涓婁紶鏂囦欢娴�
try {
// 鑾峰彇鏂囦欢鐨勫悕绉�
- String fileName = "sczf/" + file.getOriginalFilename();
+ String strDate2 = dtf2.format(LocalDateTime.now());
byte[] newImg = file.getBytes();
String originalFilename = file.getOriginalFilename();
String fileType = originalFilename.substring(originalFilename.lastIndexOf("."));
+
+ String fileName = "sczf/" + strDate2 + RandomUtils.generateRandomInt(4) + "." + fileType;
if (".png".equalsIgnoreCase(fileType) || ".jpg".equalsIgnoreCase(fileType) || ".jpeg".equalsIgnoreCase(fileType)) {
if (file.getSize() > 2097152) {
newImg = compressUnderSize(file.getBytes(), 2097152);
@@ -65,7 +67,7 @@
Date expiration = new Date(System.currentTimeMillis() + (long) 946080000 * 1000);
String url = ossClient.generatePresignedUrl(bucketName, fileName, expiration).toString();
- System.out.println("涓婁紶缁撴潫--" + dtf2.format(LocalDateTime.now()));
+ System.out.println("涓婁紶缁撴潫--" + url + "------" + dtf2.format(LocalDateTime.now()));
return url;
} catch (Exception e) {
System.out.println("uploadImages涓婁紶鍥剧墖澶辫触锛�");
@@ -171,7 +173,7 @@
DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- System.out.println("鍑嗗涓婁紶--" + dtf2.format(LocalDateTime.now()));
+// System.out.println("鍑嗗涓婁紶--" + dtf2.format(LocalDateTime.now()));
// 鍒涘缓OSSClient瀹炰緥銆�
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
// 涓婁紶鏂囦欢娴�
@@ -179,12 +181,12 @@
// 鑾峰彇鏂囦欢鐨勫悕绉�
LocalDate date = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
- String fileName = "sczf/" + date.format(formatter) + RandomUtils.generateRandomInt(8) + "." + ext;
+ String fileName = "sczf/" + date.format(formatter) + RandomUtils.generateRandomInt(8) + ext;
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType(getcontentType(ext));
- System.out.println("寮�濮嬩笂浼�--" + dtf2.format(LocalDateTime.now()));
+// System.out.println("寮�濮嬩笂浼�--" + dtf2.format(LocalDateTime.now()));
ossClient.putObject(bucketName, fileName, inputStream, objectMetadata);
ossClient.shutdown();
@@ -194,7 +196,7 @@
String url = ossClient.generatePresignedUrl(bucketName, fileName, expiration).toString();
// System.out.println("oss涓婁紶鎴愬姛锛�" + url);
- System.out.println("涓婁紶瀹屾垚--" + dtf2.format(LocalDateTime.now()));
+// System.out.println("涓婁紶瀹屾垚--" + dtf2.format(LocalDateTime.now()));
return url;
} catch (Exception e) {
System.out.println("oss寮傚父锛�" + e.getMessage());
diff --git a/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java b/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
index e96e969..fcb1d8b 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
@@ -94,12 +94,12 @@
@ApiOperation(value = "鏍规嵁閽夐拤鎺堟潈鐮佽幏鍙杢oken")
@GetMapping("/dingLogin")
public CommonResult<Map> dingLogin(@RequestParam String code) {
- log.info("涓�閿櫥褰曞弬鏁癱ode--------------->{}",code);
+ log.info("涓�閿櫥褰曞弬鏁癱ode--------------->{}", code);
HashMap<String, Object> map = new HashMap<>();
//鑾峰彇鐢ㄦ埛淇℃伅
DingUserInfo dingUser = dingCommon.getDingUserInfo(code);
//鎸塪ing鐧诲綍
- log.info("鐢ㄦ埛淇℃伅------------------->{}",dingUser);
+ log.info("鐢ㄦ埛淇℃伅------------------->{}", dingUser);
String token = authService.dingLogin(dingUser);
map.put("token", token);
map.put("tokenHead", tokenHead);
@@ -221,7 +221,7 @@
// MultipartFile file = getMultipartFile(is, fileName);
- String url = ossService.uploadImages(is,dto.getExtension());
+ String url = ossService.uploadImages(is, dto.getExtension());
return CommonResult.success(url);
} catch (Exception e) {
e.printStackTrace();
@@ -246,21 +246,6 @@
public CommonResult<String> getVideo(@PathVariable String mediaId) {
String accessToken = getToken();
-
- //executableClient淇濊瘉鍗曚緥
- IntelligentPostClient intelligentPostClient = executableClient.newIntelligentPostClient("/media/upload");
- OapiMediaUploadRequest oapiMediaUploadRequest = new OapiMediaUploadRequest();
- //璋冪敤鎺ュ彛鍑瘉
- oapiMediaUploadRequest.setAccess_token(accessToken);
- //濯掍綋鏂囦欢绫诲瀷锛屽垎鍒湁鍥剧墖锛坕mage锛夈�佽闊筹紙voice锛夈�佹櫘閫氭枃浠�(file)
- oapiMediaUploadRequest.setType("file");
- //orm-data涓獟浣撴枃浠舵爣璇嗭紝鏈塮ilename銆乫ilelength銆乧ontent-type绛変俊鎭�
- oapiMediaUploadRequest.setMedia("filename");
- intelligentPostClient.addFile(new File("F:\\瑙嗛\\7鏈�29鏃�.mp4"));
- //鑾峰彇缁撴灉
- OapiMediaUploadResponse apiResult = intelligentPostClient.post(oapiMediaUploadRequest);
-
-
MultipartFile file = getDownload(accessToken, mediaId);
String url = ossService.uploadImages(file);
return CommonResult.success(url);
@@ -279,17 +264,7 @@
response = getClient.getB();
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
-// File voice = new File("D:/IMG_4401.MOV");
-// OutputStream fos = new FileOutputStream(voice);
-// int cache = 10 * 1024;
-// byte[] buffer = new byte[cache];
-// int ch = 0;
-// while ((ch = is.read(buffer)) != -1) {
-// fos.write(buffer, 0, ch);
-// }
-// is.close();
-// fos.flush();
-// fos.close();
+
DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
String strDate2 = dtf2.format(LocalDateTime.now());
@@ -334,7 +309,9 @@
*/
public FileItem createFileItem(InputStream inputStream, String fileName) {
FileItemFactory factory = new DiskFileItemFactory(16, null);
- String textFieldName = "file";
+ DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ String strDate2 = dtf2.format(LocalDateTime.now());
+ String textFieldName = strDate2 + RandomUtils.generateRandomInt(4);
FileItem item = factory.createItem(textFieldName, MediaType.MULTIPART_FORM_DATA_VALUE, true, fileName);
int bytesRead = 0;
byte[] buffer = new byte[8192];
diff --git a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java
index 2be50d9..863e7f6 100644
--- a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java
+++ b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java
@@ -264,13 +264,15 @@
baseCase.setViolationsVO(violationsVO);
} else {
IllegalBuilding illegalBuilding = illegalBuildingMapper.selectById(baseCase.getId());
- LambdaQueryWrapper<DataDictionary> dict = new LambdaQueryWrapper<>();
- dict.eq(DataDictionary::getId, illegalBuilding.getCategoryId());
- DataDictionary dictionary = dataDictionaryMapper.selectOne(dict);
- if (dictionary != null) {
- illegalBuilding.setCategoryText(dictionary.getName());
+ if(illegalBuilding!=null) {
+ LambdaQueryWrapper<DataDictionary> dict = new LambdaQueryWrapper<>();
+ dict.eq(DataDictionary::getId, illegalBuilding.getCategoryId());
+ DataDictionary dictionary = dataDictionaryMapper.selectOne(dict);
+ if (dictionary != null) {
+ illegalBuilding.setCategoryText(dictionary.getName());
+ }
+ baseCase.setIllegalBuilding(illegalBuilding);
}
- baseCase.setIllegalBuilding(illegalBuilding);
}
//鑾峰彇璋冨害淇℃伅
Map mapD = new HashMap();
diff --git a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java
index b97fd39..9f4c791 100644
--- a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java
+++ b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.hikvision.artemis.sdk.util.HttpUtils;
import com.ycl.common.util.UtilNumber;
import com.ycl.dto.video.HKAlarmParam;
import com.ycl.entity.caseHandler.BaseCase;
@@ -21,15 +22,23 @@
import com.ycl.service.caseHandler.IBaseCaseService;
import com.ycl.service.caseHandler.IViolationsService;
import com.ycl.service.dict.IDataDictionaryService;
+import com.ycl.service.oss.OssService;
import com.ycl.service.region.ISccgRegionService;
import com.ycl.service.resources.IImageResourcesService;
import com.ycl.service.video.IVideoAlarmReportService;
import com.ycl.service.video.impl.IVideoPointService;
import com.ycl.vo.cockpit.enforcementEvents.VideoAndAreaVO;
+import net.coobird.thumbnailator.Thumbnails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -54,6 +63,8 @@
private IImageResourcesService imageResourcesService;
private ISccgRegionService regionService;
private IVideoAlarmReportService videoAlarmReportService;
+ @Autowired
+ private OssService ossService;
@Resource
BaseCaseMapper baseCaseMapper;
@@ -128,7 +139,7 @@
imageResources.setCreateTime(LocalDateTime.now());
ImageResources imageResources1 = new ImageResources();
- BeanUtil.copyProperties(imageResources,imageResources1);
+ BeanUtil.copyProperties(imageResources, imageResources1);
imageResources1.setType("01");
imageResourcesService.save(imageResources1);
@@ -180,8 +191,10 @@
VideoAlarmReport videoAlarmReport = new VideoAlarmReport();
videoAlarmReport.setPlatResourceId(alarmParam.getEventNumber());
+ String img0 = "";
if (imgs.length > 0) {
- videoAlarmReport.setPicData(imgs[0]);
+ img0 = saveOSS(imgs[0]);
+ videoAlarmReport.setPicData(img0);
}
videoAlarmReport.setAlarmTime(alarmTime);
videoAlarmReport.setAlarmId(alarmParam.getEventId());
@@ -197,11 +210,11 @@
ImageResources imageResources = new ImageResources();
imageResources.setType("04");
imageResources.setBelongToId(baseCase.getId());
- imageResources.setUrl(imgs[i]);
+ imageResources.setUrl(i == 0 ? img0 : saveOSS(imgs[i]));
imageResources.setCreateTime(LocalDateTime.now());
ImageResources imageResources1 = new ImageResources();
- BeanUtil.copyProperties(imageResources,imageResources1);
+ BeanUtil.copyProperties(imageResources, imageResources1);
imageResources1.setType("01");
imageResourcesService.save(imageResources1);
@@ -213,6 +226,35 @@
}
+ private String saveOSS(String hkUrl) {
+ InputStream inputStream = getImageStream(hkUrl);
+ if (inputStream != null) {
+ String picData = ossService.uploadImages(inputStream, ".png");
+ return picData;
+ } else return "";
+ }
+
+ private InputStream getImageStream(String url) {
+ try {
+ HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
+ connection.setReadTimeout(5000);
+ connection.setConnectTimeout(5000);
+ connection.setRequestMethod("GET");
+ if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
+ InputStream inputStream = connection.getInputStream();
+ ByteArrayOutputStream outs = new ByteArrayOutputStream();
+ Thumbnails.of(inputStream).scale(0.6).outputQuality(1).toOutputStream(outs);
+ InputStream ins = new ByteArrayInputStream(outs.toByteArray());
+ return ins;
+ }
+ } catch (IOException e) {
+ System.out.println("鑾峰彇缃戠粶鍥剧墖鍑虹幇寮傚父锛屽浘鐗囪矾寰勪负锛�" + url);
+
+ e.printStackTrace();
+ }
+ return null;
+ }
+
@Override
public List<VideoAndAreaVO> selectType() {
return baseCaseMapper.selectType();
diff --git a/ycl-platform/src/main/resources/application-online.yml b/ycl-platform/src/main/resources/application-online.yml
index 983c90c..6ed6fdc 100644
--- a/ycl-platform/src/main/resources/application-online.yml
+++ b/ycl-platform/src/main/resources/application-online.yml
@@ -67,8 +67,8 @@
videoPoint:
url: http://172.28.194.180:7901
- web_url: https://172.28.194.185:8282
- # web_url: http://172.28.194.185:8281
+# web_url: https://172.28.194.185:8282
+ web_url: http://172.28.194.185:8281
port: 7901
userName: suichang
passWord: a12345677
diff --git a/ycl-platform/src/main/resources/application-prod.yml b/ycl-platform/src/main/resources/application-prod.yml
index ce662ad..e12f014 100644
--- a/ycl-platform/src/main/resources/application-prod.yml
+++ b/ycl-platform/src/main/resources/application-prod.yml
@@ -67,8 +67,8 @@
videoPoint:
url: http://172.28.194.180:7901
- web_url: https://172.28.194.185:8282
-# web_url: http://172.28.194.185:8281
+# web_url: https://172.28.194.185:8282
+ web_url: http://172.28.194.185:8281
port: 7901
userName: suichang
passWord: a12345677
diff --git a/ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java b/ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java
index b1678d3..1d0d5a5 100644
--- a/ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java
+++ b/ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java
@@ -5,6 +5,7 @@
import com.ycl.entity.user.UmsAdmin;
import com.ycl.mapper.unlawful.UnlawfulMapper;
import com.ycl.service.oss.OssService;
+import net.coobird.thumbnailator.Thumbnails;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -12,6 +13,8 @@
import javax.annotation.Resource;
import javax.xml.bind.DatatypeConverter;
import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.util.*;
@SpringBootTest
@@ -29,8 +32,25 @@
void test() {
// List<CategoryDto> data = unlawfuldao.getDataByType(0, 5,"2022-12-14 17:19:01", "2022-12-14 17:19:03");
// System.out.println(data);
- System.out.println(utilNumber.createShopCode());
- System.out.println(utilNumber.createCaseCode());
+ String url = "http://test.xshcs.com/10%E6%9C%88%E6%8E%92%E6%9C%9F.jpg";
+ try {
+ HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
+ connection.setReadTimeout(5000);
+ connection.setConnectTimeout(5000);
+ connection.setRequestMethod("GET");
+ if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
+ InputStream in = connection.getInputStream();
+ ByteArrayOutputStream outs = new ByteArrayOutputStream();
+ Thumbnails.of(in).scale(0.6).outputQuality(1).toOutputStream(outs);
+ InputStream ins = new ByteArrayInputStream(outs.toByteArray());
+ String picData = ossService.uploadImages(ins, ".png");
+ System.out.println(picData);
+ }
+ } catch (IOException e) {
+ System.out.println("鑾峰彇缃戠粶鍥剧墖鍑虹幇寮傚父锛屽浘鐗囪矾寰勪负锛�" + url);
+
+ e.printStackTrace();
+ }
}
// @Test
--
Gitblit v1.8.0