diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmParamsController.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmParamsController.java index 8bb0505..938ee33 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmParamsController.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmParamsController.java @@ -1,10 +1,8 @@ package com.yfd.platform.modules.algorithm.controller; import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONObject; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.alibaba.fastjson.JSONObject; import com.yfd.platform.config.ResponseResult; -import com.yfd.platform.modules.algorithm.domain.AlgorithmClass; import com.yfd.platform.modules.algorithm.domain.AlgorithmParams; import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService; import io.swagger.annotations.Api; @@ -94,8 +92,8 @@ public class AlgorithmParamsController { @PostMapping("/callAlgorithmAnalyse") @ApiOperation("调用算法分析") public ResponseResult callAlgorithmAnalyse(String id,String componentId) { - if (StrUtil.isBlank(id)) { - return ResponseResult.error("算法分类id为空"); + if (StrUtil.isBlank(id)|| StrUtil.isBlank(componentId)) { + return ResponseResult.error("算法参数为空"); } JSONObject data = algorithmParamsService.callAlgorithmAnalyse(id, componentId); return ResponseResult.successData(data); diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/mapper/AlgorithmParamsMapper.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/mapper/AlgorithmParamsMapper.java index 79a3061..8a1346a 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/mapper/AlgorithmParamsMapper.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/mapper/AlgorithmParamsMapper.java @@ -19,4 +19,7 @@ public interface AlgorithmParamsMapper extends BaseMapper { List> getAlgorithmParamsList(String algorithmId,String componentId); List> getAlgorithmParamsNameList(String algorithmId,String componentId); + + List> getAnalyseParams(String id, String componentId); + } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmParamsService.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmParamsService.java index 406d699..5fb174e 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmParamsService.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/IAlgorithmParamsService.java @@ -1,9 +1,8 @@ package com.yfd.platform.modules.algorithm.service; -import cn.hutool.json.JSONObject; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.yfd.platform.modules.algorithm.domain.AlgorithmParams; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.IService; +import com.yfd.platform.modules.algorithm.domain.AlgorithmParams; import java.util.List; import java.util.Map; diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmParamsServiceImpl.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmParamsServiceImpl.java index d3ff05d..47b3692 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmParamsServiceImpl.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmParamsServiceImpl.java @@ -1,14 +1,17 @@ package com.yfd.platform.modules.algorithm.service.impl; -import cn.hutool.json.JSONObject; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.yfd.platform.modules.algorithm.domain.AlgorithmClass; import com.yfd.platform.modules.algorithm.domain.AlgorithmParams; -import com.yfd.platform.modules.algorithm.mapper.AlgorithmDeviceMapper; +import com.yfd.platform.modules.algorithm.mapper.AlgorithmClassMapper; import com.yfd.platform.modules.algorithm.mapper.AlgorithmParamsMapper; import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService; +import com.yfd.platform.utils.HttpRESTfulUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,7 +29,9 @@ public class AlgorithmParamsServiceImpl extends ServiceImpl> getAlgorithmParamsList(String algorithmId, String componentId) { @@ -60,7 +65,24 @@ public class AlgorithmParamsServiceImpl extends ServiceImpl> mapList = algorithmParamsMapper.getAnalyseParams(id, componentId); + if (mapList.size() <= 0) { + return null; + } + Map senData = new HashMap<>(); + for (Map map : mapList) { + senData.put(map.get("paramName"), map.get("paramValue")); + } + Map param = new HashMap<>(); + param.put("param", senData); + JSONObject jsonObject = httpRESTfulUtils.sendHttpUrlPost("json", + algorithmClass.getServiceAddress(), "", param, null); + jsonObject.put("mapList", mapList); + return jsonObject; } } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/controller/DeviceSignalController.java b/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/controller/DeviceSignalController.java index 9a7ae31..e63b04c 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/controller/DeviceSignalController.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/controller/DeviceSignalController.java @@ -49,12 +49,12 @@ public class DeviceSignalController { ***********************************/ @GetMapping("/page") @ApiOperation("分页查询变电站辅控设备信号") - public ResponseResult getDeviceSignalPage(String mainDeviceId, String mainComponentId, String signalName, Page page) { + public ResponseResult getDeviceSignalPage(String systemcode,String meterDeviceId,String mainDeviceId, String mainComponentId, String signalName, Page page) { //参数校验 辅控设备ID不能为空 if (StrUtil.isBlank(mainComponentId)) { return ResponseResult.error("参数为空"); } - Page deviceSignalPage = deviceSignalService.getDeviceSignalPage(mainDeviceId,mainComponentId, signalName, page); + Page deviceSignalPage = deviceSignalService.getDeviceSignalPage(systemcode,meterDeviceId,mainDeviceId,mainComponentId, signalName, page); return ResponseResult.successData(deviceSignalPage); } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/service/IDeviceSignalService.java b/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/service/IDeviceSignalService.java index 86efefb..4903577 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/service/IDeviceSignalService.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/service/IDeviceSignalService.java @@ -52,7 +52,7 @@ public interface IDeviceSignalService extends IService { * 参数说明 page * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page ***********************************/ - Page getDeviceSignalPage(String mainDeviceId, String componentId, String signalName, Page page); + Page getDeviceSignalPage(String systemcode,String meterDeviceId,String mainDeviceId, String componentId, String signalName, Page page); /********************************** * 用途说明: 获取信号集合 diff --git a/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/service/impl/DeviceSignalServiceImpl.java b/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/service/impl/DeviceSignalServiceImpl.java index 290b6bc..eb9692a 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/service/impl/DeviceSignalServiceImpl.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/service/impl/DeviceSignalServiceImpl.java @@ -161,9 +161,16 @@ public class DeviceSignalServiceImpl extends ServiceImpl ***********************************/ @Override - public Page getDeviceSignalPage(String mainDeviceId, String componentId, String signalName, + public Page getDeviceSignalPage(String systemcode,String meterDeviceId,String mainDeviceId, String componentId, String signalName, Page page) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (StrUtil.isNotBlank(systemcode)) { + //查询条件拼接模糊 + queryWrapper.like(DeviceSignal::getSystemcode, systemcode); + } + if (StrUtil.isNotBlank(meterDeviceId)) { + queryWrapper.eq(DeviceSignal::getMeterDeviceId, meterDeviceId); + } //如果信号名称signalName不为空 模糊搜索 if (StrUtil.isNotBlank(signalName)) { //查询条件拼接模糊 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 67c2d84..edb0626 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 @@ -266,6 +266,102 @@ public class HttpRESTfulUtils { return responseJSON; } + + public JSONObject sendHttpUrlPost(String posttype,String url, String secret, Map param, RequestCallback callback) { + OkHttpClient client = getClient(); + JSONObject responseJSON = new JSONObject(); + //-2自定义流媒体 调用错误码 + responseJSON.put("code", -2); + responseJSON.put("msg", "http请求调用失败!"); + + RequestBody body = null; + if (posttype.equals("json")) { + body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), JSON.toJSONString(param)); + } else { + FormBody.Builder builder = new FormBody.Builder(); + builder.add("secret", secret); + if (param != null && param.keySet().size() > 0) { + for (String key : param.keySet()) { + if (param.get(key) != null) { + builder.add(key, param.get(key).toString()); + } + } + } + body = builder.build(); + } + Request request = new Request.Builder() + .post(body) + .url(url) + .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 { + response.close(); + Objects.requireNonNull(response.body()).close(); + } + } catch (IOException e) { + logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage())); + //throw new RuntimeException(String.format("[ %s ]请求失败: %s", url, e.getMessage())); + if (e instanceof SocketTimeoutException) { + //读取超时超时异常 + //logger.error(String.format("读取Http服务器数据失败: %s, %s", url, e.getMessage())); + throw new RuntimeException(String.format("读取Http服务器数据失败: %s, %s", url, e.getMessage())); + } + if (e instanceof ConnectException) { + //判断连接异常,我这里是报Failed to connect to 10.7.5.144 + logger.error(String.format("连接Http服务器失败: %s, %s", url, e.getMessage())); + throw new RuntimeException(String.format("连接Http服务器失败: %s, %s", url, e.getMessage())); + } + + } catch (Exception e) { + logger.error(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) { + if (response.isSuccessful()) { + try { + String responseStr = Objects.requireNonNull(response.body()).string(); + callback.run(JSON.parseObject(responseStr)); + } catch (IOException e) { + logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage())); + } + + } 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) { + //判断连接异常,我这里是报Failed to connect to 10.7.5.144 + logger.error(String.format("连接Http服务器失败: %s, %s", call.request().toString(), e.getMessage())); + } + } + }); + } + + return responseJSON; + } + 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); diff --git a/riis-system/src/main/resources/mapper/algorithm/AlgorithmParamsMapper.xml b/riis-system/src/main/resources/mapper/algorithm/AlgorithmParamsMapper.xml index c978880..99f1d37 100644 --- a/riis-system/src/main/resources/mapper/algorithm/AlgorithmParamsMapper.xml +++ b/riis-system/src/main/resources/mapper/algorithm/AlgorithmParamsMapper.xml @@ -18,7 +18,8 @@ ad.source_type, ad.device_id, ad.device_name, - ap.id + ap.id paramId, + ad.id FROM iis_algorithm_params ap LEFT JOIN iis_algorithm_device ad @@ -50,4 +51,43 @@ AND ap.algorithm_id = #{algorithmId} +