From 8fdf204b408d92541bcf2bd0b380d2a4e948df78 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Tue, 20 Aug 2024 10:51:55 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E9=81=A5=E6=8E=A7=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A1=A8=E5=90=8D=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java index 3c0ea70..889b04a 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java @@ -3,6 +3,7 @@ package com.hnac.hzims.bigmodel.maintenance.entity; import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.annotation.SqlCondition; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -19,6 +20,7 @@ import java.io.Serializable; @Data @EqualsAndHashCode @ApiModel("设备控制实体类") +@TableName("data_yk") public class ControlEntity extends TenantEntity implements Serializable { @ApiModelProperty(value = "itemId",required = true) From 0d4e7fe74659b2900f2afae1c09142a63c396fa6 Mon Sep 17 00:00:00 2001 From: luyie Date: Tue, 20 Aug 2024 14:09:43 +0800 Subject: [PATCH 2/3] =?UTF-8?q?add:=E8=A7=86=E9=A2=91=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=EF=BC=8C=E6=88=AA=E5=9B=BE=E8=A7=86=E9=A2=91=E8=BD=AC=E5=AD=98?= =?UTF-8?q?minio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hnac/hzims/common/utils/FileUtil.java | 175 ++++++++++++++++++++- .../api/dto/BigModelAnalysisResponseDTO.java | 2 +- .../hydroelectric/vo/HydroelectricDeviceVo.java | 4 +- .../hydroelectric/vo/HydroelectricPowerRainVo.java | 4 +- .../zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java | 4 +- .../inspect/task/schedule/VideoTaskSchedule.java | 34 +++- 6 files changed, 211 insertions(+), 12 deletions(-) diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java index c6167b5..ce65fb3 100644 --- a/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java @@ -1,10 +1,14 @@ package com.hnac.hzims.common.utils; +import lombok.NonNull; +import lombok.Value; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.multipart.MultipartFile; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; +import java.io.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLDecoder; import java.util.Base64; /** @@ -35,6 +39,131 @@ public class FileUtil { return bytes; } + public static byte[] getUrlByte(URL url) { + InputStream inputStream = null; + ByteArrayOutputStream outputStream = null; + byte[] fileBytes = null; + try { + inputStream = url.openStream(); + outputStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + fileBytes = outputStream.toByteArray(); + } catch (Exception e) { + log.error("获取url文件失败", e); + } finally { + try { + if (null != inputStream) { + inputStream.close(); + } + if (null != outputStream) { + outputStream.close(); + } + } catch (Exception ignore) { + + } + } + return fileBytes; + } + + public static byte[] getUrlByte(String urlString) { + try { + return getUrlByte(new URL(urlString)); + } catch (MalformedURLException e) { + log.error("获取url文件失败", e); + } + return null; + } + + public static String getContentTypeFromUrl(String url) { + String result = ""; + String fileType = url.toLowerCase(); + if (fileType.indexOf(".png") >= 0) { + result = "image/png"; + } else if (fileType.indexOf(".gif") >= 0) { + result = "image/gif"; + } else if (fileType.indexOf(".jpg") >= 0 || fileType.indexOf(".jpeg") >= 0) { + result = "image/jpeg"; + } else if (fileType.indexOf(".svg") >= 0) { + result = "image/svg+xml"; + } else if (fileType.indexOf(".doc") >= 0) { + result = "application/msword"; + } else if (fileType.indexOf(".xls") >= 0) { + result = "application/x-excel"; + } else if (fileType.indexOf(".zip") >= 0) { + result = "application/zip"; + } else if (fileType.indexOf(".pdf") >= 0) { + result = "application/pdf"; + } else if (fileType.indexOf(".mpeg") >= 0) { //MP3 + result = "audio/mpeg"; + } else if (fileType.indexOf(".mp4") >= 0) { + result = "video/mp4"; + } else if (fileType.indexOf(".plain") >= 0) { + result = "text/plain"; + } else if (fileType.indexOf(".html") >= 0) { + result = "text/html"; + } else if (fileType.indexOf(".json") >= 0) { + result = "application/json"; + } else { + result = "application/octet-stream"; + } + return result; + } + + public static String getPureUrl(String url) { + String result = removeUrlParam(url); + try { + result = URLDecoder.decode(result, "utf-8"); + int index = result.lastIndexOf("http"); + if (index > 0) { + result = result.substring(index); + } + } catch (UnsupportedEncodingException e) { + log.error("解码url失败"); + } + return result; + } + + public static String getOriginalFilename(String path) { + String result = path; + int index = path.lastIndexOf("/"); + if (index > 0) { + result = path.substring(index + 1); + } + return result; + } + + public static String removeUrlParam(String url) { + int index = url.indexOf("&"); + if (index > 0) { + return url.substring(0, index); + } + return url; + } + + public static MultipartFile getMultipartFileFromUrl(String urlStr) { + String pureUrl = getPureUrl(urlStr); + return getMultipartFileFromPureUrl(pureUrl); + } + + public static MultipartFile getMultipartFileFromPureUrl(String pureUrlStr) { + MultipartFile result = null; + try { + URL url = new URL(pureUrlStr); + byte[] bytes = getUrlByte(url); + String name = url.getPath(); + String originalName = getOriginalFilename(name); + String contentType = getContentTypeFromUrl(originalName); + result = new ByteArrayMultipartFile(name, originalName, contentType, bytes); + } catch (Exception e) { + log.error("获取url文件失败", e); + } + return result; + } + public static String getBase64(byte[] bytes) { return Base64.getEncoder().encodeToString(bytes); } @@ -42,4 +171,44 @@ public class FileUtil { public static String getBase64(String filePath) { return getBase64(getFileBytes(filePath)); } + + @Value + public static class ByteArrayMultipartFile implements MultipartFile { + String name; + + String originalFilename; + + String contentType; + + @NonNull + byte[] bytes; + + @Override + public boolean isEmpty() { + return bytes.length == 0; + } + + @Override + public long getSize() { + return bytes.length; + } + + @Override + public InputStream getInputStream() { + return new ByteArrayInputStream(bytes); + } + + @Override + public void transferTo(File destination) throws IOException { + OutputStream outputStream = null; + try { + outputStream = new FileOutputStream(destination); + outputStream.write(bytes); + } finally { + if (outputStream != null) { + outputStream.close(); + } + } + } + } } diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/BigModelAnalysisResponseDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/BigModelAnalysisResponseDTO.java index 9869fe1..af4a12f 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/BigModelAnalysisResponseDTO.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/BigModelAnalysisResponseDTO.java @@ -51,6 +51,6 @@ public class BigModelAnalysisResponseDTO implements Serializable { } public Boolean getSuccess() { - return Optional.ofNullable(success).orElse(Boolean.FALSE); + return Optional.ofNullable(success).orElse(data != null); } } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricDeviceVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricDeviceVo.java index 4eb7c5b..f3ce2b7 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricDeviceVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricDeviceVo.java @@ -1,4 +1,4 @@ -package com.hnac.hzims.operational.homePage.hydroelectric.vo; +package com.hnac.hzims.operational.homePage.Hydroelectric.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -19,7 +19,7 @@ public class HydroelectricDeviceVo { @ApiModelProperty(value = "设备名称") private String deivceName; - @ApiModelProperty(value = "开关机状态 : 0 - 关机 1 - 开机") + @ApiModelProperty(value = "开关机状态: 0 - 关机 1 - 开机") private Boolean state; @ApiModelProperty(value = "总装机容量") diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricPowerRainVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricPowerRainVo.java index 22df4ec..a2aae0e 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricPowerRainVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricPowerRainVo.java @@ -1,4 +1,4 @@ -package com.hnac.hzims.operational.homePage.hydroelectric.vo; +package com.hnac.hzims.operational.homePage.Hydroelectric.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -8,7 +8,7 @@ import lombok.Data; * @author ysj */ @Data -@ApiModel(value = "站点首页 - 最近30日发电量/降雨量") +@ApiModel(value = "站点首页-最近30日发电量/降雨量") public class HydroelectricPowerRainVo { @ApiModelProperty(value = "日期") diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java index e56b0f3..7dae059 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java @@ -1,6 +1,6 @@ package com.hnac.hzims.bigmodel.zhipuai.handler; -import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; +import com.hnac.hzinfo.exception.HzServiceException; import com.zhipu.oapi.Constants; import com.zhipu.oapi.service.v4.model.ChatCompletionRequest; import com.zhipu.oapi.service.v4.model.ChatMessage; @@ -79,6 +79,8 @@ public class ZhipuAnalysisHandlerGlm4v extends AbstractZhipuAnalysisHandler { } catch (Exception e) { log.info("get data from response error", e); } + } else { + throw new HzServiceException(response.getMsg()); } return null; } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java index 1519e95..0de579a 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java @@ -5,7 +5,10 @@ import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.api.dto.BigModelAnalysisRequestDTO; +import com.hnac.hzims.bigmodel.api.dto.BigModelAnalysisResponseDTO; import com.hnac.hzims.bigmodel.api.feign.IBigModelAnalysisClient; +import com.hnac.hzims.common.utils.FileUtil; import com.hnac.hzinfo.datasearch.soe.ISoeClient; import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; import com.hnac.hzinfo.inspect.ai.entity.CameraInfoEntity; @@ -33,6 +36,8 @@ import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springblade.core.oss.model.BladeFile; +import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; @@ -42,10 +47,12 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Component; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import java.time.LocalDateTime; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import static com.hnac.hzinfo.inspect.task.schedule.XxlJobConstants.EXECUTE_VIDEO_TASK; @@ -173,6 +180,7 @@ public class VideoTaskSchedule { String picUrl = hikApiService.manualCapture(camera.getPointCode()); record.setFileUrl(picUrl); record.setCurrentValue(picUrl); + pictureHandle(picUrl, content.getContentId(), record); } } return record; @@ -225,15 +233,35 @@ public class VideoTaskSchedule { return null; } - private void pictureHandle(String url, Long contentId) { + private void pictureHandle(String url, Long contentId, EventRecordEntity record) { + MultipartFile multipartFile = FileUtil.getMultipartFileFromUrl(url); + R fileResponse = ossClient.putFile(multipartFile); + if (fileResponse.isSuccess()) { + record.setFileUrl(Optional.ofNullable(fileResponse.getData().getLink()).orElse(record.getFileUrl())); + } ContentEntity content = contentService.getById(contentId); if (StringUtil.isBlank(content.getMultiCheckTypeSon())) { return; } - String[] typeArray = content.getMultiCheckTypeSon().split(","); - List checkTypeSonList = Arrays.asList(typeArray); + + try { + String[] typeArray = content.getMultiCheckTypeSon().split(","); + List checkTypeSonList = Arrays.asList(typeArray); + String text = FileUtil.getBase64(multipartFile.getBytes()); + BigModelAnalysisRequestDTO analysisRequest = new BigModelAnalysisRequestDTO(); + analysisRequest.setCheckTypeSonList(checkTypeSonList); + analysisRequest.setUrl(text); + BigModelAnalysisResponseDTO analysisResponse = bigModelClient.analysis(analysisRequest); + if (!analysisResponse.getSuccess() || CollectionUtil.isEmpty(analysisResponse.getData())) { + return; + } + + } catch (Exception e) { + log.error("video task get big model analysis result fail", e); + } } + } From d7dfb9d957a6749b982c8bd00f9a1571953fde57 Mon Sep 17 00:00:00 2001 From: luyie Date: Tue, 20 Aug 2024 14:52:21 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/homePage/hydroelectric/vo/HydroelectricDeviceVo.java | 2 +- .../operational/homePage/hydroelectric/vo/HydroelectricPowerRainVo.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricDeviceVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricDeviceVo.java index f3ce2b7..ec21858 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricDeviceVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricDeviceVo.java @@ -1,4 +1,4 @@ -package com.hnac.hzims.operational.homePage.Hydroelectric.vo; +package com.hnac.hzims.operational.homePage.hydroelectric.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricPowerRainVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricPowerRainVo.java index a2aae0e..2fcb5e3 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricPowerRainVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/homePage/hydroelectric/vo/HydroelectricPowerRainVo.java @@ -1,4 +1,4 @@ -package com.hnac.hzims.operational.homePage.Hydroelectric.vo; +package com.hnac.hzims.operational.homePage.hydroelectric.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty;