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()); ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
@@ -94,12 +94,12 @@ @ApiOperation(value = "根据钉钉授权码获取token") @GetMapping("/dingLogin") public CommonResult<Map> dingLogin(@RequestParam String code) { log.info("一键登录参数code--------------->{}",code); log.info("一键登录参数code--------------->{}", code); HashMap<String, Object> map = new HashMap<>(); //获取用户信息 DingUserInfo dingUser = dingCommon.getDingUserInfo(code); //按ding登录 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); //媒体文件类型,分别有图片(image)、语音(voice)、普通文件(file) oapiMediaUploadRequest.setType("file"); //orm-data中媒体文件标识,有filename、filelength、content-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]; 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(); 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(); 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 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 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