From 1a110afcf8a87106b76c194431c77e8bb5b0be69 Mon Sep 17 00:00:00 2001 From: weitang Date: Fri, 6 Jun 2025 17:53:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=AE=97=E6=B3=95=E5=B8=83?= =?UTF-8?q?=E7=82=B9=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yfd/platform/config/HttpServerConfig.java | 6 + .../yfd/platform/config/SwaggerConfig.java | 19 +++ .../com/yfd/platform/config/WebConfig.java | 9 +- .../AlgorithmArrangeController.java | 49 ++++++- .../domain/AlgorithmArrangeDevice.java | 18 +-- .../mapper/AlgorithmArrangeDeviceMapper.java | 5 + .../IAlgorithmArrangeDeviceService.java | 5 + .../service/IAlgorithmArrangeService.java | 14 ++ .../AlgorithmArrangeDeviceServiceImpl.java | 17 ++- .../impl/AlgorithmArrangeServiceImpl.java | 131 ++++++++++++++++- .../yfd/platform/utils/HttpRESTfulUtils.java | 133 +++++++++++++++--- .../src/main/resources/application-dev.yml | 1 + .../src/main/resources/application-prod.yml | 1 + .../AlgorithmArrangeDeviceMapper.xml | 14 +- 14 files changed, 375 insertions(+), 47 deletions(-) diff --git a/riis-system/src/main/java/com/yfd/platform/config/HttpServerConfig.java b/riis-system/src/main/java/com/yfd/platform/config/HttpServerConfig.java index 558cb31..66e63d3 100644 --- a/riis-system/src/main/java/com/yfd/platform/config/HttpServerConfig.java +++ b/riis-system/src/main/java/com/yfd/platform/config/HttpServerConfig.java @@ -114,6 +114,8 @@ public class HttpServerConfig { @Value("${httpserver.patrolserver.maindevicefilepath}") private String mainDeviceFilepath; + @Value("${httpserver.patrolserver.planfilepath}") + private String planFilePath; @Value("${httpserver.patrolserver.tempfilepath}") private String tempFilePath; @@ -263,6 +265,10 @@ public class HttpServerConfig { return mainDeviceFilepath; } + public String getPlanFilePath() { + return planFilePath; + } + public String getTempFilePath() { return tempFilePath; } diff --git a/riis-system/src/main/java/com/yfd/platform/config/SwaggerConfig.java b/riis-system/src/main/java/com/yfd/platform/config/SwaggerConfig.java index 17407b7..fe146ac 100644 --- a/riis-system/src/main/java/com/yfd/platform/config/SwaggerConfig.java +++ b/riis-system/src/main/java/com/yfd/platform/config/SwaggerConfig.java @@ -1,15 +1,21 @@ package com.yfd.platform.config; +import io.swagger.models.auth.In; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.builders.RequestParameterBuilder; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; +import springfox.documentation.service.RequestParameter; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; +import java.util.ArrayList; +import java.util.List; + /** * swagger配置 */ @@ -159,4 +165,17 @@ public class SwaggerConfig { .version("3.0") .build(); } + + /** + * 获取通用的全局参数 + * + * @return 全局参数列表 + */ + private List generateRequestParameters(){ + RequestParameterBuilder token = new RequestParameterBuilder(); + List parameters = new ArrayList<>(); + token.name("token").description("token").in(In.HEADER.toValue()).required(true).build(); + parameters.add(token.build()); + return parameters; + } } diff --git a/riis-system/src/main/java/com/yfd/platform/config/WebConfig.java b/riis-system/src/main/java/com/yfd/platform/config/WebConfig.java index cc8d3a2..ed3b5e4 100644 --- a/riis-system/src/main/java/com/yfd/platform/config/WebConfig.java +++ b/riis-system/src/main/java/com/yfd/platform/config/WebConfig.java @@ -37,6 +37,9 @@ public class WebConfig implements WebMvcConfigurer { @Value("${httpserver.patrolserver.maindevicefilepath}") private String mainDeviceFilepath; + @Value("${httpserver.patrolserver.planfilepath}") + private String planFilePath; + @Resource private ISubstationDeviceService substationDeviceService; @@ -99,9 +102,13 @@ public class WebConfig implements WebMvcConfigurer { String alarmUrl = "file:" + alarmFilePath; registry.addResourceHandler("/alarm/**").addResourceLocations(alarmUrl).setCachePeriod(0); - // 告警图片 + // 主设备图片 String mainDeviceUrl = "file:" + mainDeviceFilepath; registry.addResourceHandler("/mainDevice/**").addResourceLocations(mainDeviceUrl).setCachePeriod(0); + + // 变电站平面图地址 + String planUrl = "file:" + planFilePath; + registry.addResourceHandler("/plan/**").addResourceLocations(planUrl).setCachePeriod(0); } } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmArrangeController.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmArrangeController.java index 5bf69f1..f5f4b81 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmArrangeController.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmArrangeController.java @@ -10,7 +10,11 @@ import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeService; import com.yfd.platform.utils.SecurityUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.time.LocalDateTime; @@ -45,15 +49,32 @@ public class AlgorithmArrangeController { Page arrangePage = algorithmArrangeService.page(page, queryWrapper); return ResponseResult.successData(arrangePage); } + @GetMapping("/getAlgorithmArrangeById") + @ApiOperation("根据Id查询算法布点") + public ResponseResult getAlgorithmArrangeById (String id){ + AlgorithmArrange algorithmArrange = algorithmArrangeService.getById(id); + return ResponseResult.successData(algorithmArrange); + } @PostMapping("/saveAlgorithmArrange") @ApiOperation("新增算法布点") - public ResponseResult saveAlgorithmArrange(@RequestBody AlgorithmArrange algorithmArrange) { - algorithmArrange.setLastmodifier(SecurityUtils.getCurrentUsername()); + public ResponseResult saveAlgorithmArrange(AlgorithmArrange algorithmArrange, MultipartFile file) { + algorithmArrange.setLastmodifier("admin"); algorithmArrange.setLastmodifydate(LocalDateTime.now()); algorithmArrange.setDatastatus("1"); String id = IdUtil.fastSimpleUUID(); algorithmArrange.setId(id); + // 文件上传逻辑 + if (file != null && !file.isEmpty()) { + try { + // 上传文件 + String fileUrl = algorithmArrangeService.uploadImage(file); + algorithmArrange.setImageUrl(fileUrl); + algorithmArrange.setIsImageFlag("1"); + } catch (Exception e) { + return ResponseResult.error("文件上传失败:" + e.getMessage()); + } + } boolean save = algorithmArrangeService.save(algorithmArrange); if (!save) { return ResponseResult.error(); @@ -63,13 +84,33 @@ public class AlgorithmArrangeController { @PostMapping("/updateAlgorithmArrange") @ApiOperation("修改算法布点") - public ResponseResult updateAlgorithmArrange(@RequestBody AlgorithmArrange algorithmArrange) { + public ResponseResult updateAlgorithmArrange(AlgorithmArrange algorithmArrange, MultipartFile file) { algorithmArrange.setLastmodifier(SecurityUtils.getCurrentUsername()); algorithmArrange.setLastmodifydate(LocalDateTime.now()); + // 文件上传逻辑 + if (file != null && !file.isEmpty()) { + try { + // 调用服务层方法 + String fileUrl = algorithmArrangeService.uploadImage(file); + algorithmArrange.setImageUrl(fileUrl); + algorithmArrange.setIsImageFlag("1"); + } catch (Exception e) { + return ResponseResult.error("文件上传失败:" + e.getMessage()); + } + } boolean save = algorithmArrangeService.updateById(algorithmArrange); if (!save) { return ResponseResult.error(); } return ResponseResult.success(); } + + @PostMapping("/callAlgorithmArrange") + @ApiOperation("调用算法布点API") + public ResponseResult callAlgorithmArrange(String id) { + AlgorithmArrange algorithmArrange=algorithmArrangeService.callAlgorithmArrange(id); + return ResponseResult.successData(algorithmArrange); + } + + } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/domain/AlgorithmArrangeDevice.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/domain/AlgorithmArrangeDevice.java index b11ecb5..6d8747d 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/domain/AlgorithmArrangeDevice.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/domain/AlgorithmArrangeDevice.java @@ -1,13 +1,15 @@ package com.yfd.platform.modules.algorithm.domain; import com.baomidou.mybatisplus.annotation.TableName; + import java.io.Serializable; + import lombok.Data; import lombok.EqualsAndHashCode; /** *

- * + * *

* * @author zhengsl @@ -31,19 +33,14 @@ public class AlgorithmArrangeDevice implements Serializable { private String arrangeId; /** - * 主设备id + * 区域id */ - private String mainDeviceId; + private String areaId; /** - * 主设备类型 + * 区域名称 */ - private String deviceType; - - /** - * 主设备名称 - */ - private String mainDeviceName; + private String areaName; /** * 设备类型;1:摄像机;2:声纹传感器;3:局放传感器;4:温湿度传感器 @@ -60,5 +57,4 @@ public class AlgorithmArrangeDevice implements Serializable { */ private String patroldeviceDes; - } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/mapper/AlgorithmArrangeDeviceMapper.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/mapper/AlgorithmArrangeDeviceMapper.java index 288a8b0..53d5b73 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/mapper/AlgorithmArrangeDeviceMapper.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/mapper/AlgorithmArrangeDeviceMapper.java @@ -16,5 +16,10 @@ import java.util.Map; */ public interface AlgorithmArrangeDeviceMapper extends BaseMapper { + /*********************************** + * 用途说明: 查询当前布点的主设备数量 + * 参数说明 arrangeId 算法布点ID + * 返回值说明: java.util.List> + ***********************************/ List> getArrangeDeviceInfo(String arrangeId); } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmArrangeDeviceService.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmArrangeDeviceService.java index 0974b81..882a38f 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmArrangeDeviceService.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmArrangeDeviceService.java @@ -16,5 +16,10 @@ import java.util.Map; */ public interface IAlgorithmArrangeDeviceService extends IService { + /*********************************** + * 用途说明: 查询当前布点的主设备数量 + * 参数说明 arrangeId 算法布点ID + * 返回值说明: java.util.List> + ***********************************/ List> getArrangeDeviceInfo(String arrangeId); } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmArrangeService.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmArrangeService.java index 16f50d3..43e556d 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmArrangeService.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmArrangeService.java @@ -2,6 +2,7 @@ package com.yfd.platform.modules.algorithm.service; import com.yfd.platform.modules.algorithm.domain.AlgorithmArrange; import com.baomidou.mybatisplus.extension.service.IService; +import org.springframework.web.multipart.MultipartFile; /** *

@@ -13,4 +14,17 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface IAlgorithmArrangeService extends IService { + /*********************************** + * 用途说明: 调用算法布点API + * 参数说明 id : 算法布点ID + * 返回值说明: com.yfd.platform.modules.algorithm.domain.AlgorithmArrange + ***********************************/ + AlgorithmArrange callAlgorithmArrange(String id); + + /*********************************** + * 用途说明: 上传文件 + * 参数说明 file 文件域 + * 返回值说明: java.lang.String + ***********************************/ + String uploadImage(MultipartFile file); } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmArrangeDeviceServiceImpl.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmArrangeDeviceServiceImpl.java index b124115..84c76e4 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmArrangeDeviceServiceImpl.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmArrangeDeviceServiceImpl.java @@ -24,6 +24,11 @@ public class AlgorithmArrangeDeviceServiceImpl extends ServiceImpl> + ***********************************/ @Override public List> getArrangeDeviceInfo(String arrangeId) { List> rawData = algorithmArrangeDeviceMapper.getArrangeDeviceInfo(arrangeId); @@ -32,19 +37,19 @@ public class AlgorithmArrangeDeviceServiceImpl extends ServiceImpl> groupedData = new HashMap<>(); for (Map row : rawData) { - String mainDeviceId = (String) row.get("mainDeviceId"); - String mainDeviceName = (String) row.get("mainDeviceName"); + String areaId = (String) row.get("areaId"); + String areaName = (String) row.get("areaName"); String deviceTypeCode = (String) row.get("deviceTypeCode"); Long count = (Long) row.get("deviceTypeCount"); - groupedData.computeIfAbsent(mainDeviceId, k -> { + groupedData.computeIfAbsent(areaId, k -> { Map newRow = new HashMap<>(); - newRow.put("mainDeviceId", mainDeviceId); - newRow.put("mainDeviceName", mainDeviceName); + newRow.put("areaId", areaId); + newRow.put("areaName", areaName); return newRow; }); // 设置具体类型的数量 - groupedData.get(mainDeviceId).put(deviceTypeCode, count); + groupedData.get(areaId).put(deviceTypeCode, count); } return new ArrayList<>(groupedData.values()); diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmArrangeServiceImpl.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmArrangeServiceImpl.java index 5af0c2d..b0e57d7 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmArrangeServiceImpl.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmArrangeServiceImpl.java @@ -1,20 +1,149 @@ package com.yfd.platform.modules.algorithm.service.impl; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.yfd.platform.config.HttpServerConfig; import com.yfd.platform.modules.algorithm.domain.AlgorithmArrange; +import com.yfd.platform.modules.algorithm.domain.AlgorithmArrangeDevice; import com.yfd.platform.modules.algorithm.mapper.AlgorithmArrangeMapper; +import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeDeviceService; import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.yfd.platform.modules.basedata.domain.SubstationMaindevice; +import com.yfd.platform.modules.basedata.service.ISubstationMaindeviceService; +import com.yfd.platform.utils.FileUtil; +import com.yfd.platform.utils.HttpRESTfulUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; /** *

- * 服务实现类 + * 服务实现类 *

* * @author zhengsl * @since 2025-06-06 */ @Service +@Slf4j public class AlgorithmArrangeServiceImpl extends ServiceImpl implements IAlgorithmArrangeService { + @Resource + private HttpRESTfulUtils httpRESTfulUtils; + + @Resource + private ISubstationMaindeviceService substationMaindeviceService; + @Resource + private IAlgorithmArrangeDeviceService algorithmArrangeDeviceService; + @Resource + private HttpServerConfig httpServerConfig; + + /*********************************** + * 用途说明: 调用算法布点API + * 参数说明 id : 算法布点ID + * 返回值说明: com.yfd.platform.modules.algorithm.domain.AlgorithmArrange + ***********************************/ + @Override + public AlgorithmArrange callAlgorithmArrange(String id) { + // 查询算法布点信息 + AlgorithmArrange algorithmArrange = this.getById(id); + if (algorithmArrange == null) { + return null; + } + if ("0".equals(algorithmArrange.getIsImageFlag())) { + return algorithmArrange; + } + JSONObject param = new JSONObject(); + param.put("arrange_id", algorithmArrange.getId()); + param.put("station_name", algorithmArrange.getStationName()); + param.put("station_type", algorithmArrange.getStationType()); + param.put("volt_level", algorithmArrange.getVoltLevel()); + param.put("business_type", algorithmArrange.getBusinessType()); + String deviceTypeList = algorithmArrange.getDeviceTypeList(); + List typeList = StrUtil.split(deviceTypeList, ","); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(SubstationMaindevice::getDeviceType, typeList).select(SubstationMaindevice::getMainDeviceId, + SubstationMaindevice::getMainDeviceName, SubstationMaindevice::getDeviceType, + SubstationMaindevice::getAreaId, SubstationMaindevice::getAreaName); + List> maps = substationMaindeviceService.listMaps(queryWrapper); + List> mainDeviceList = renameKeysWithStream(maps); + param.put("main_device_list", mainDeviceList); + File file = new File("D:\\riis\\video\\test0.jpg"); + JSONObject arrange = httpRESTfulUtils.uploadJsonWithImageFileWithDataWrapper("192.168.1.173", "20014", + "arrange", param, file + , null); + if (!"200".equals(arrange.getString("code"))) { + throw new RuntimeException("调用失败!"); + } + String arrangeId = arrange.getString("arrange_id"); + JSONArray resultsList = arrange.getJSONArray("results_list"); + List algorithmArrangeDeviceList = new java.util.ArrayList<>(); + for (int i = 0; i < resultsList.size(); i++) { + JSONObject result = resultsList.getJSONObject(i); + String areaId = result.getString("area_id"); + String areaName = result.getString("area_name"); + JSONArray patroldeviceList = result.getJSONArray("patroldevice_list"); + for (int j = 0; j < patroldeviceList.size(); j++) { + AlgorithmArrangeDevice algorithmArrangeDevice = new AlgorithmArrangeDevice(); + JSONObject patroldevice = patroldeviceList.getJSONObject(j); + String patroldeviceType = patroldevice.getString("patroldevice_type"); + String patroldevicePos = patroldevice.getString("patroldevice_pos"); + algorithmArrangeDevice.setArrangeId(arrangeId); + algorithmArrangeDevice.setAreaId(areaId); + algorithmArrangeDevice.setAreaName(areaName); + algorithmArrangeDevice.setPatroldeviceType(patroldeviceType); + algorithmArrangeDevice.setPatroldevicePos(patroldevicePos); + algorithmArrangeDeviceList.add(algorithmArrangeDevice); + } + } + algorithmArrangeDeviceService.saveBatch(algorithmArrangeDeviceList); + return algorithmArrange; + + } + + /*********************************** + * 用途说明: 上传文件 + * 参数说明 file 文件域 + * 返回值说明: java.lang.String + ***********************************/ + @Override + public String uploadImage(MultipartFile file) { + + // 文件存储地址 + String fileName = + IdUtil.fastSimpleUUID() + "." + FileUtil.getExtensionName(file.getOriginalFilename()); + // 上传文件 + String name = + Objects.requireNonNull(FileUtil.upload(file, httpServerConfig.getPlanFilePath(), fileName)).getName(); + return name; + } + + /*********************************** + * 用途说明: 转换方法 + * 参数说明 originalList 原始列表 + * 返回值说明: java.util.List> + ***********************************/ + private List> renameKeysWithStream(List> originalList) { + return originalList.stream().map(originalMap -> { + Map newMap = new HashMap<>(); + newMap.put("main_device_id", originalMap.get("mainDeviceId")); + newMap.put("main_device_name", originalMap.get("mainDeviceName")); + newMap.put("device_type", originalMap.get("deviceType")); + newMap.put("area_id", originalMap.get("areaId")); + newMap.put("area_name", originalMap.get("areaName")); + return newMap; + }).collect(Collectors.toList()); + } } diff --git a/riis-system/src/main/java/com/yfd/platform/utils/HttpRESTfulUtils.java b/riis-system/src/main/java/com/yfd/platform/utils/HttpRESTfulUtils.java index edb0626..88f53d0 100644 --- a/riis-system/src/main/java/com/yfd/platform/utils/HttpRESTfulUtils.java +++ b/riis-system/src/main/java/com/yfd/platform/utils/HttpRESTfulUtils.java @@ -169,6 +169,99 @@ public class HttpRESTfulUtils { return responseJSON; } + /** + * 发送 multipart/form-data 请求,其中 JSON 数据包装在 { "data": ... } 中,并附带一张图片 + * + * @param ip 目标服务器 IP 地址 + * @param port 目标服务器端口 + * @param api 接口路径(如 /api/callAlgorithmArrange) + * @param jsonData JSON 数据内容(即 data 字段的值) + * @param imageFile 要上传的图片文件 + * @param callback 回调函数(null 表示同步) + * @return 响应结果 + */ + public JSONObject uploadJsonWithImageFileWithDataWrapper(String ip, String port, String api, + JSONObject jsonData, + File imageFile, + RequestCallback callback) { + OkHttpClient client = getClient(); + String url = String.format("http://%s:%s/%s", ip, port, api); + JSONObject responseJSON = new JSONObject(); + responseJSON.put("code", -2); + responseJSON.put("msg", "http请求调用失败!"); + + MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM); + + // 添加 JSON 数据(包装为 { "data": ... } 格式) + if (jsonData != null && !jsonData.isEmpty()) { + builder.addFormDataPart("data", jsonData.toJSONString()); + } + + // 添加图片文件 + if (imageFile != null && imageFile.exists()) { + RequestBody fileBody = RequestBody.create(MediaType.parse("image/*"), imageFile); + builder.addFormDataPart("image_file", imageFile.getName(), fileBody); + } + + Request request = new Request.Builder() + .url(url) + .post(builder.build()) + .build(); + + if (callback == null) { + try { + Response response = client.newCall(request).execute(); + if (response.isSuccessful()) { + ResponseBody responseBody = response.body(); + if (responseBody != null) { + String responseStr = responseBody.string(); + responseJSON = JSON.parseObject(responseStr); + } + } else { + if (response.body() != null) { + response.body().close(); + } + } + } catch (IOException e) { + logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage())); + if (e instanceof SocketTimeoutException) { + throw new RuntimeException(String.format("读取Http服务器数据失败: %s, %s", url, e.getMessage())); + } + if (e instanceof ConnectException) { + throw new RuntimeException(String.format("连接Http服务器失败: %s, %s", url, e.getMessage())); + } + throw new RuntimeException(String.format("访问Http服务器失败: %s, %s", url, e.getMessage())); + } + } else { + client.newCall(request).enqueue(new Callback() { + @Override + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { + if (response.isSuccessful()) { + String responseStr = Objects.requireNonNull(response.body()).string(); + callback.run(JSON.parseObject(responseStr)); + } else { + response.close(); + Objects.requireNonNull(response.body()).close(); + } + } + + @Override + public void onFailure(@NotNull Call call, @NotNull IOException e) { + logger.error(String.format("连接Http服务器失败: %s, %s", call.request().toString(), e.getMessage())); + if (e instanceof SocketTimeoutException) { + logger.error(String.format("读取Http服务器数据失败: %s, %s", call.request().toString(), e.getMessage())); + } + if (e instanceof ConnectException) { + logger.error(String.format("连接Http服务器失败: %s, %s", call.request().toString(), e.getMessage())); + } + } + }); + } + + return responseJSON; + } + + public JSONObject sendHttpPost(String posttype, String ip, String port, String secret, String api, Map param, RequestCallback callback) { OkHttpClient client = getClient(); @@ -266,8 +359,8 @@ public class HttpRESTfulUtils { return responseJSON; } - - public JSONObject sendHttpUrlPost(String posttype,String url, String secret, Map param, RequestCallback callback) { + public JSONObject sendHttpUrlPost(String posttype, String url, String secret, Map param, + RequestCallback callback) { OkHttpClient client = getClient(); JSONObject responseJSON = new JSONObject(); //-2自定义流媒体 调用错误码 @@ -362,7 +455,8 @@ public class HttpRESTfulUtils { return responseJSON; } - public JSONObject sendHttpPostStr(String ip, String port, String api, Map param, RequestCallback callback) { + public JSONObject sendHttpPostStr(String ip, String port, String api, Map param, + RequestCallback callback) { OkHttpClient client = getClient(); String url = String.format("http://%s:%s/%s", ip, port, api); JSONObject responseJSON = new JSONObject(); @@ -597,7 +691,8 @@ public class HttpRESTfulUtils { public JSONObject callDevicePos(String devicecode, String channelcode, String poscode, RequestCallback callback) { String api = String.format("api/ptz/front_end_command/%s/%s", devicecode, channelcode); if (StrUtil.isNotEmpty(Config.getMonitorAppname())) { - api = String.format("%s/api/ptz/front_end_command/%s/%s", Config.getMonitorAppname(), devicecode, channelcode); + api = String.format("%s/api/ptz/front_end_command/%s/%s", Config.getMonitorAppname(), devicecode, + channelcode); } logger.info(api); Map param = new HashMap<>(); @@ -649,7 +744,8 @@ public class HttpRESTfulUtils { } //调用智能分析主机图像算法识别 - public JSONObject callPicAnalyse(String requestId, String objectId, String typeList, String customParams, String filename) throws Exception { + public JSONObject callPicAnalyse(String requestId, String objectId, String typeList, String customParams, + String filename) throws Exception { String api = "picAnalyse"; Map param = new HashMap<>(); param.put("requestHostIp", Config.getPatrolIp()); //巡视主机IP @@ -673,15 +769,15 @@ public class HttpRESTfulUtils { methodname = "playAudioFile"; } // if ("3".equals(Config.getFilefromtype())) { -// imageurl = filename; -// } else { -// imageurl = String.format("http://%s:%s/%s?filename=%s", Config.getPatrolIp(), -// Config.getPatrolPort(), methodname, filename); -// if (StrUtil.isNotEmpty(Config.getPatrolAppname())) { -// imageurl = String.format("http://%s:%s/%s/%s?filename=%s", Config.getPatrolIp(), -// Config.getPatrolPort(), Config.getPatrolAppname(), methodname, filename); -// } -// } + // imageurl = filename; + // } else { + // imageurl = String.format("http://%s:%s/%s?filename=%s", Config.getPatrolIp(), + // Config.getPatrolPort(), methodname, filename); + // if (StrUtil.isNotEmpty(Config.getPatrolAppname())) { + // imageurl = String.format("http://%s:%s/%s/%s?filename=%s", Config.getPatrolIp(), + // Config.getPatrolPort(), Config.getPatrolAppname(), methodname, filename); + // } + // } imageUrlArray.add(filename); jsonObject.put("imagePathList", imageUrlArray); @@ -710,7 +806,8 @@ public class HttpRESTfulUtils { logger.info("===================调用分析===============" + jsonObject1.toString()); return sendHttpPost("json", analyseIp, analysePort, "", api, param, null); } catch (Exception e) { - logger.error(e.getMessage());; + logger.error(e.getMessage()); + ; logger.error("===================调用分析出错==============="); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("code", "-2"); @@ -719,7 +816,8 @@ public class HttpRESTfulUtils { } //调用智能分析主机图像算法识别 - public JSONObject callPicAnalyse(String requestId,String objectId,String typeList,String customParams,String filename,String manId) throws Exception { + public JSONObject callPicAnalyse(String requestId, String objectId, String typeList, String customParams, + String filename, String manId) throws Exception { String api = "picAnalyse"; Map param = new HashMap<>(); param.put("requestHostIp", Config.getPatrolIp()); //巡视主机IP @@ -779,7 +877,8 @@ public class HttpRESTfulUtils { logger.info("===================调用分析===============" + jsonObject1.toString()); return sendHttpPost("json", analyseIp, analysePort, "", api, param, null); } catch (Exception e) { - logger.error(e.getMessage());; + logger.error(e.getMessage()); + ; logger.error("===================调用分析出错==============="); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("code", "-2"); diff --git a/riis-system/src/main/resources/application-dev.yml b/riis-system/src/main/resources/application-dev.yml index 9ab76fa..9d66546 100644 --- a/riis-system/src/main/resources/application-dev.yml +++ b/riis-system/src/main/resources/application-dev.yml @@ -149,6 +149,7 @@ httpserver: #配置http请求访问的地址 snapfilepath: d:\riis\video\ #视频截图文件路径 alarmfilepath: d:\riis\alarm\ #报警图片存储路径 maindevicefilepath: d:\riis\maindevice\ #主设备文件存储地址 + planfilepath: d:\riis\plan\ #变电站平面原图地址 tempfilepath: d:\riis\temp\ #模板图片路径 ffmpegpath: E:\ffmpeg\bin\ #ffmpeg截图命名路径 modelpath: d:\riis\model\ diff --git a/riis-system/src/main/resources/application-prod.yml b/riis-system/src/main/resources/application-prod.yml index 0c56afc..45aa7ba 100644 --- a/riis-system/src/main/resources/application-prod.yml +++ b/riis-system/src/main/resources/application-prod.yml @@ -149,6 +149,7 @@ httpserver: #配置http请求访问的地址 snapfilepath: d:\riis\video\ #视频截图文件路径 alarmfilepath: d:\riis\alarm\ #报警图片存储路径 maindevicefilepath: d:\riis\maindevice\ #主设备文件存储地址 + planfilepath: d:\riis\plan\ #变电站平面原图地址 tempfilepath: d:\riis\temp\ #模板图片路径 ffmpegpath: E:\ffmpeg\bin\ #ffmpeg截图命名路径 modelpath: d:\riis\model\ diff --git a/riis-system/src/main/resources/mapper/algorithm/AlgorithmArrangeDeviceMapper.xml b/riis-system/src/main/resources/mapper/algorithm/AlgorithmArrangeDeviceMapper.xml index 0704a48..105b7c2 100644 --- a/riis-system/src/main/resources/mapper/algorithm/AlgorithmArrangeDeviceMapper.xml +++ b/riis-system/src/main/resources/mapper/algorithm/AlgorithmArrangeDeviceMapper.xml @@ -4,13 +4,13 @@