新增算法分析调用逻辑
This commit is contained in:
		
							parent
							
								
									14e10b9a59
								
							
						
					
					
						commit
						548f66b281
					
				| @ -1,10 +1,8 @@ | |||||||
| package com.yfd.platform.modules.algorithm.controller; | package com.yfd.platform.modules.algorithm.controller; | ||||||
| 
 | 
 | ||||||
| import cn.hutool.core.util.StrUtil; | import cn.hutool.core.util.StrUtil; | ||||||
| import cn.hutool.json.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||||
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |  | ||||||
| import com.yfd.platform.config.ResponseResult; | 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.domain.AlgorithmParams; | ||||||
| import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService; | import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService; | ||||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||||
| @ -94,8 +92,8 @@ public class AlgorithmParamsController { | |||||||
|     @PostMapping("/callAlgorithmAnalyse") |     @PostMapping("/callAlgorithmAnalyse") | ||||||
|     @ApiOperation("调用算法分析") |     @ApiOperation("调用算法分析") | ||||||
|     public ResponseResult callAlgorithmAnalyse(String id,String componentId) { |     public ResponseResult callAlgorithmAnalyse(String id,String componentId) { | ||||||
|         if (StrUtil.isBlank(id)) { |         if (StrUtil.isBlank(id)|| StrUtil.isBlank(componentId)) { | ||||||
|             return ResponseResult.error("算法分类id为空"); |             return ResponseResult.error("算法参数为空"); | ||||||
|         } |         } | ||||||
|         JSONObject data = algorithmParamsService.callAlgorithmAnalyse(id, componentId); |         JSONObject data = algorithmParamsService.callAlgorithmAnalyse(id, componentId); | ||||||
|         return ResponseResult.successData(data); |         return ResponseResult.successData(data); | ||||||
|  | |||||||
| @ -19,4 +19,7 @@ public interface AlgorithmParamsMapper extends BaseMapper<AlgorithmParams> { | |||||||
|     List<Map<String, Object>> getAlgorithmParamsList(String algorithmId,String componentId); |     List<Map<String, Object>> getAlgorithmParamsList(String algorithmId,String componentId); | ||||||
| 
 | 
 | ||||||
|     List<Map<String, Object>> getAlgorithmParamsNameList(String algorithmId,String componentId); |     List<Map<String, Object>> getAlgorithmParamsNameList(String algorithmId,String componentId); | ||||||
|  | 
 | ||||||
|  |     List<Map<String, String>> getAnalyseParams(String id, String componentId); | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,9 +1,8 @@ | |||||||
| package com.yfd.platform.modules.algorithm.service; | package com.yfd.platform.modules.algorithm.service; | ||||||
| 
 | 
 | ||||||
| import cn.hutool.json.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||||
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |  | ||||||
| import com.yfd.platform.modules.algorithm.domain.AlgorithmParams; |  | ||||||
| import com.baomidou.mybatisplus.extension.service.IService; | import com.baomidou.mybatisplus.extension.service.IService; | ||||||
|  | import com.yfd.platform.modules.algorithm.domain.AlgorithmParams; | ||||||
| 
 | 
 | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  | |||||||
| @ -1,14 +1,17 @@ | |||||||
| package com.yfd.platform.modules.algorithm.service.impl; | 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.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.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.mapper.AlgorithmParamsMapper; | ||||||
| import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService; | import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService; | ||||||
|  | import com.yfd.platform.utils.HttpRESTfulUtils; | ||||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||||
| 
 | 
 | ||||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||||
|  | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| 
 | 
 | ||||||
| @ -26,7 +29,9 @@ public class AlgorithmParamsServiceImpl extends ServiceImpl<AlgorithmParamsMappe | |||||||
|     @Resource |     @Resource | ||||||
|     private AlgorithmParamsMapper algorithmParamsMapper; |     private AlgorithmParamsMapper algorithmParamsMapper; | ||||||
|     @Resource |     @Resource | ||||||
|     private AlgorithmDeviceMapper algorithmDeviceMapper; |     private AlgorithmClassMapper algorithmClassMapper; | ||||||
|  |     @Resource | ||||||
|  |     private HttpRESTfulUtils httpRESTfulUtils; | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public List<Map<String, Object>> getAlgorithmParamsList(String algorithmId, String componentId) { |     public List<Map<String, Object>> getAlgorithmParamsList(String algorithmId, String componentId) { | ||||||
| @ -60,7 +65,24 @@ public class AlgorithmParamsServiceImpl extends ServiceImpl<AlgorithmParamsMappe | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public JSONObject callAlgorithmAnalyse(String id, String componentId) { |     public JSONObject callAlgorithmAnalyse(String id, String componentId) { | ||||||
| 
 |         AlgorithmClass algorithmClass = algorithmClassMapper.selectById(id); | ||||||
|  |         if (algorithmClass == null) { | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|  |         // 固定参数就是固定参数,点位数据是默认最新点位,信号也是找最新数据 | ||||||
|  |         List<Map<String, String>> mapList = algorithmParamsMapper.getAnalyseParams(id, componentId); | ||||||
|  |         if (mapList.size() <= 0) { | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |         Map<String, Object> senData = new HashMap<>(); | ||||||
|  |         for (Map<String, String> map : mapList) { | ||||||
|  |             senData.put(map.get("paramName"), map.get("paramValue")); | ||||||
|  |         } | ||||||
|  |         Map<String, Object> param = new HashMap<>(); | ||||||
|  |         param.put("param", senData); | ||||||
|  |         JSONObject jsonObject = httpRESTfulUtils.sendHttpUrlPost("json", | ||||||
|  |                 algorithmClass.getServiceAddress(), "", param, null); | ||||||
|  |         jsonObject.put("mapList", mapList); | ||||||
|  |         return jsonObject; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -49,12 +49,12 @@ public class DeviceSignalController { | |||||||
|      ***********************************/ |      ***********************************/ | ||||||
|     @GetMapping("/page") |     @GetMapping("/page") | ||||||
|     @ApiOperation("分页查询变电站辅控设备信号") |     @ApiOperation("分页查询变电站辅控设备信号") | ||||||
|     public ResponseResult getDeviceSignalPage(String mainDeviceId, String mainComponentId, String signalName, Page<DeviceSignal> page) { |     public ResponseResult getDeviceSignalPage(String systemcode,String meterDeviceId,String mainDeviceId, String mainComponentId, String signalName, Page<DeviceSignal> page) { | ||||||
|         //参数校验  辅控设备ID不能为空 |         //参数校验  辅控设备ID不能为空 | ||||||
|         if (StrUtil.isBlank(mainComponentId)) { |         if (StrUtil.isBlank(mainComponentId)) { | ||||||
|             return ResponseResult.error("参数为空"); |             return ResponseResult.error("参数为空"); | ||||||
|         } |         } | ||||||
|         Page<DeviceSignal> deviceSignalPage = deviceSignalService.getDeviceSignalPage(mainDeviceId,mainComponentId, signalName, page); |         Page<DeviceSignal> deviceSignalPage = deviceSignalService.getDeviceSignalPage(systemcode,meterDeviceId,mainDeviceId,mainComponentId, signalName, page); | ||||||
|         return ResponseResult.successData(deviceSignalPage); |         return ResponseResult.successData(deviceSignalPage); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -52,7 +52,7 @@ public interface IDeviceSignalService extends IService<DeviceSignal> { | |||||||
|     * 参数说明 page |     * 参数说明 page | ||||||
|     * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.yfd.platform.modules.auxcontrol.domain.DeviceSignal> |     * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.yfd.platform.modules.auxcontrol.domain.DeviceSignal> | ||||||
|     ***********************************/ |     ***********************************/ | ||||||
|     Page<DeviceSignal> getDeviceSignalPage(String mainDeviceId, String componentId, String signalName, Page<DeviceSignal> page); |     Page<DeviceSignal> getDeviceSignalPage(String systemcode,String meterDeviceId,String mainDeviceId, String componentId, String signalName, Page<DeviceSignal> page); | ||||||
| 
 | 
 | ||||||
|     /********************************** |     /********************************** | ||||||
|      * 用途说明: 获取信号集合 |      * 用途说明: 获取信号集合 | ||||||
|  | |||||||
| @ -161,9 +161,16 @@ public class DeviceSignalServiceImpl extends ServiceImpl<DeviceSignalMapper, Dev | |||||||
|      * .DeviceSignal> |      * .DeviceSignal> | ||||||
|      ***********************************/ |      ***********************************/ | ||||||
|     @Override |     @Override | ||||||
|     public Page<DeviceSignal> getDeviceSignalPage(String mainDeviceId, String componentId, String signalName, |     public Page<DeviceSignal> getDeviceSignalPage(String systemcode,String meterDeviceId,String mainDeviceId, String componentId, String signalName, | ||||||
|                                                   Page<DeviceSignal> page) { |                                                   Page<DeviceSignal> page) { | ||||||
|         LambdaQueryWrapper<DeviceSignal> queryWrapper = new LambdaQueryWrapper<>(); |         LambdaQueryWrapper<DeviceSignal> queryWrapper = new LambdaQueryWrapper<>(); | ||||||
|  |         if (StrUtil.isNotBlank(systemcode)) { | ||||||
|  |             //查询条件拼接模糊 | ||||||
|  |             queryWrapper.like(DeviceSignal::getSystemcode, systemcode); | ||||||
|  |         } | ||||||
|  |         if (StrUtil.isNotBlank(meterDeviceId)) { | ||||||
|  |             queryWrapper.eq(DeviceSignal::getMeterDeviceId, meterDeviceId); | ||||||
|  |         } | ||||||
|         //如果信号名称signalName不为空 模糊搜索 |         //如果信号名称signalName不为空 模糊搜索 | ||||||
|         if (StrUtil.isNotBlank(signalName)) { |         if (StrUtil.isNotBlank(signalName)) { | ||||||
|             //查询条件拼接模糊 |             //查询条件拼接模糊 | ||||||
|  | |||||||
| @ -266,6 +266,102 @@ public class HttpRESTfulUtils { | |||||||
|         return responseJSON; |         return responseJSON; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |     public JSONObject sendHttpUrlPost(String posttype,String url,  String secret, Map<String, Object> 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<String, Object> param, RequestCallback callback) { |     public JSONObject sendHttpPostStr(String ip, String port, String api, Map<String, Object> param, RequestCallback callback) { | ||||||
|         OkHttpClient client = getClient(); |         OkHttpClient client = getClient(); | ||||||
|         String url = String.format("http://%s:%s/%s", ip, port, api); |         String url = String.format("http://%s:%s/%s", ip, port, api); | ||||||
|  | |||||||
| @ -18,7 +18,8 @@ | |||||||
|         ad.source_type, |         ad.source_type, | ||||||
|         ad.device_id, |         ad.device_id, | ||||||
|         ad.device_name, |         ad.device_name, | ||||||
|         ap.id |         ap.id paramId, | ||||||
|  |         ad.id | ||||||
|         FROM |         FROM | ||||||
|         iis_algorithm_params ap |         iis_algorithm_params ap | ||||||
|         LEFT JOIN iis_algorithm_device ad |         LEFT JOIN iis_algorithm_device ad | ||||||
| @ -50,4 +51,43 @@ | |||||||
|             AND ap.algorithm_id = #{algorithmId} |             AND ap.algorithm_id = #{algorithmId} | ||||||
|         </if> |         </if> | ||||||
|     </select> |     </select> | ||||||
|  |     <select id="getAnalyseParams" resultType="java.util.Map"> | ||||||
|  |     SELECT | ||||||
|  |     ap.id paramId, | ||||||
|  | 		ad.device_id, | ||||||
|  |     ap.param_unit, | ||||||
|  |     ap.param_name, | ||||||
|  |     CASE | ||||||
|  |         WHEN ap.param_fixed = '1' THEN ad.param_value | ||||||
|  |         ELSE | ||||||
|  |             CASE ad.source_type | ||||||
|  |                 WHEN '1' THEN ( | ||||||
|  |                     SELECT tr.value | ||||||
|  |                     FROM iis_task_result tr | ||||||
|  |                     WHERE tr.device_id = ad.device_id | ||||||
|  |                     ORDER BY tr.patroldevice_date DESC | ||||||
|  |                     LIMIT 1 | ||||||
|  |                 ) | ||||||
|  |                 WHEN '2' THEN ( | ||||||
|  |                     SELECT dwd.value | ||||||
|  |                     FROM fk_device_work_data dwd | ||||||
|  |                     WHERE dwd.signal_id = ad.device_id | ||||||
|  | 										ORDER BY dwd.start_time DESC | ||||||
|  |                     LIMIT 1 | ||||||
|  |                 ) | ||||||
|  |                 ELSE NULL | ||||||
|  |             END | ||||||
|  |     END AS param_value, | ||||||
|  |     ap.algorithm_id, | ||||||
|  |     ad.component_id, | ||||||
|  |     ap.param_fixed | ||||||
|  | FROM | ||||||
|  |     iis_algorithm_params ap | ||||||
|  | LEFT JOIN iis_algorithm_device ad | ||||||
|  |     ON ap.id = ad.param_id | ||||||
|  |     AND ad.component_id = #{componentId} | ||||||
|  | WHERE | ||||||
|  | 
 | ||||||
|  |      ap.algorithm_id = #{id}; | ||||||
|  |     </select> | ||||||
| </mapper> | </mapper> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 weitang
						weitang