| | |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); |
| | | String oneHour = oneHourAgo.format(formatter) + ":00"; |
| | | String nowHour = now.format(formatter) + ":00"; |
| | | |
| | | // 调用中台接口获取实时测点数据 |
| | | JSONArray ztData = getZtData("", |
| | | ZtConfigConstant.url_prefix + DamEnum.ofType(type).getApiUrl() + "?start_tm=" + oneHour + "&end_tm=" + nowHour + ""); |
| | |
| | | JSONObject jsonObject = ztData.getJSONObject(i); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | // 水库信息设置 |
| | | flag = waterInfoSet(jsonObject, map,flag); |
| | | flag = waterInfoSet(jsonObject, map); |
| | | if (flag) { |
| | | // 测点信息设置 |
| | | flag = pointValueInfoSet(jsonObject, map, type,flag); |
| | |
| | | if (flag) { |
| | | map.put("batchId",UUID.randomUUID()); |
| | | map.put("serialNo",getSerialNo()); |
| | | log.info("发送数据:{}",map); |
| | | // 发送请求 |
| | | String response = sendPostJsonRequest(OpenApiConstant.POINT_VALUE_INLET_URL, map); |
| | | JSONObject parseObject = JSON.parseObject(response); |
| | |
| | | * @param jsonObject |
| | | * @param map |
| | | */ |
| | | private boolean waterInfoSet(JSONObject jsonObject, Map<String, Object> map,boolean flag) { |
| | | private boolean waterInfoSet(JSONObject jsonObject, Map<String, Object> map) { |
| | | String rz = jsonObject.getString("rz"); |
| | | flag = false; |
| | | if (!Strings.isBlank(rz)) { |
| | | flag = true; |
| | | String res_cd = replaceSpecialStr(jsonObject.getString("res_cd")); |
| | | List<Map<String, Object>> waterLevelInfoList = new ArrayList<>(); |
| | | Map<String, Object> waterLevelInfoMap = new HashMap<>(); |
| | | waterLevelInfoMap.put("damCode", res_cd); |
| | | waterLevelInfoMap.put("waterLevel", jsonObject.getString("rz")); |
| | | waterLevelInfoMap.put("waterLevelTime", jsonObject.getString("rz_tm")); |
| | | waterLevelInfoMap.put("rainCondition", jsonObject.getString("drp")); |
| | | waterLevelInfoMap.put("rainConditionTime", jsonObject.getString("drp_tm")); |
| | | waterLevelInfoList.add(waterLevelInfoMap); |
| | | map.put("waterLevelInfo", waterLevelInfoList); |
| | | if(Strings.isBlank(rz)){ |
| | | return false; |
| | | } |
| | | return flag; |
| | | // 需要过滤2022高标准水库才发送 |
| | | String res_cd = replaceSpecialStr(jsonObject.getString("res_cd")); |
| | | String flag = openApiMapper.getResInfoBy2022(res_cd); |
| | | if (Strings.isBlank(flag)){ |
| | | return false; |
| | | } |
| | | List<Map<String, Object>> waterLevelInfoList = new ArrayList<>(); |
| | | Map<String, Object> waterLevelInfoMap = new HashMap<>(); |
| | | waterLevelInfoMap.put("damCode", res_cd); |
| | | waterLevelInfoMap.put("waterLevel", jsonObject.getString("rz")); |
| | | waterLevelInfoMap.put("waterLevelTime", jsonObject.getString("rz_tm")); |
| | | waterLevelInfoMap.put("rainCondition", jsonObject.getString("drp")); |
| | | waterLevelInfoMap.put("rainConditionTime", jsonObject.getString("drp_tm")); |
| | | waterLevelInfoList.add(waterLevelInfoMap); |
| | | map.put("waterLevelInfo", waterLevelInfoList); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public JSONArray getZtData(String params, String url) { |
| | | log.info("实时测点请求中台接口:{}",url); |
| | | //设置请求头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add(ZtConfigConstant.header_key, ZtConfigConstant.header_value); |
| | |
| | | formEntity, |
| | | String.class); |
| | | JSONObject jsonObject = JSON.parseObject(responseEntity.getBody()); |
| | | log.info("实时测点请求中台接口结果数据:{}",jsonObject); |
| | | // 返回 |
| | | return JSONArray.parseArray(jsonObject.get("data").toString()); |
| | | } catch (Exception e) { |
| | |
| | | for (int i = 0; i < dataJsonArray.size(); i++) { |
| | | DamAlarmRecord damAlarmRecord = new DamAlarmRecord(); |
| | | JSONObject alarmRecordJSONObject = dataJsonArray.getJSONObject(i); |
| | | damAlarmRecord.setPointId(alarmRecordJSONObject.getString("pointId")); |
| | | // 设置测点信息,类型、测点编号 |
| | | setPointInfo(damAlarmRecord,alarmRecordJSONObject.getString("pointId")); |
| | | // 设置其他信息 |
| | | damAlarmRecord.setResGuid(alarmRecordJSONObject.getString("RS_CODE")); |
| | | damAlarmRecord.setCollecTime(alarmRecordJSONObject.getDate("collecTime")); |
| | | damAlarmRecord.setPointValue(alarmRecordJSONObject.getString("ponitValue")); |
| | | JSONObject generalInfo = alarmRecordJSONObject.getJSONObject("generalInfo"); |
| | | damAlarmRecord.setPointWarnLevel(generalInfo.getInteger("pointWarnLevel")); |
| | | damAlarmRecord.setPointWarnInfo(generalInfo.getString("pointWarnInfo")); |
| | | damAlarmRecord.setCreateTime(new Date()); |
| | | // 保存 |
| | | // 获取回调类型:1:告警规则法 2: 预测法 3:待补充 |
| | | Integer callbackType = alarmRecordJSONObject.getInteger("callbackType"); |
| | | damAlarmRecord.setCallbackType(callbackType); |
| | | if (callbackType==1){ |
| | | JSONObject generalInfo = alarmRecordJSONObject.getJSONObject("generalInfo"); |
| | | damAlarmRecord.setPointWarnLevel(generalInfo.getInteger("pointWarnLevel")); |
| | | damAlarmRecord.setPointWarnInfo(generalInfo.getString("pointWarnInfo")); |
| | | } |
| | | if (callbackType==2){ |
| | | damAlarmRecord.setValue(alarmRecordJSONObject.getString("value")); |
| | | damAlarmRecord.setTimeValue(alarmRecordJSONObject.getString("timeValue")); |
| | | } |
| | | // 保存详情,预测没有详情 |
| | | flag = damAlarmRecordService.save(damAlarmRecord); |
| | | if (flag){ |
| | | if (callbackType==1 && flag){ |
| | | flag = saveDamAlarmRecordDetail(alarmRecordJSONObject.getJSONArray("detailInfo"),damAlarmRecord); |
| | | } |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 设置测点信息 |
| | | * @param pointId |
| | | */ |
| | | private void setPointInfo(DamAlarmRecord damAlarmRecord,String pointId) { |
| | | damAlarmRecord.setPointId(pointId); |
| | | // 测点值解析赋值 |
| | | String[] point = pointId.split("_"); |
| | | // 渗压、渗流 |
| | | if (point.length==3) { |
| | | // 设置测点id |
| | | damAlarmRecord.setStationId(point[1]); |
| | | String typeName = point[2]; |
| | | // 设置 大坝安全监测类型 |
| | | damAlarmRecord.setType(Integer.parseInt(DamEnum.ofName(typeName).getKey())); |
| | | } |
| | | // 位移 |
| | | if (point.length==4) { |
| | | // 设置测点id |
| | | damAlarmRecord.setStationId(point[1]); |
| | | String typeName = point[2] + "_" + point[3]; |
| | | // 设置 大坝安全监测类型 |
| | | damAlarmRecord.setType(Integer.parseInt(DamEnum.ofName(typeName).getKey())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveDamAlarmRecordDetail(JSONArray detailInfo,DamAlarmRecord damAlarmRecord) { |
| | | boolean flag = false; |
| | | List<DamAlarmRecordDetail> list = new ArrayList<>(); |
| | | for (int i = 0; i < detailInfo.size(); i++) { |
| | | DamAlarmRecordDetail damAlarmRecordDetail = new DamAlarmRecordDetail(); |
| | | JSONObject jsonObject = detailInfo.getJSONObject(i); |
| | | damAlarmRecordDetail.setDamAlarmRecordId(damAlarmRecord.getId()); |
| | | damAlarmRecordDetail.setAlgorithmName(jsonObject.getString("algorithmName")); |
| | | damAlarmRecordDetail.setAlgorithmWarnLevel(jsonObject.getInteger("algorithmWarnLevel")); |
| | | damAlarmRecordDetail.setAlgorithmWarnInfo(jsonObject.getString("algorithmWarnInfo")); |
| | | damAlarmRecordDetail.setAlgorithmWarnExplain(jsonObject.getString("algorithmWarnExplain")); |
| | | damAlarmRecordDetail.setCreateTime(new Date()); |
| | | // 加入集合 |
| | | list.add(damAlarmRecordDetail); |
| | | } |
| | | // 保存 |
| | | if (list.size()>0) { |
| | | flag = damAlarmRecordDetailService.saveBatch(list); |
| | | }else { |
| | | flag = true; |
| | | if (null!=detailInfo) { |
| | | List<DamAlarmRecordDetail> list = new ArrayList<>(); |
| | | for (int i = 0; i < detailInfo.size(); i++) { |
| | | DamAlarmRecordDetail damAlarmRecordDetail = new DamAlarmRecordDetail(); |
| | | JSONObject jsonObject = detailInfo.getJSONObject(i); |
| | | damAlarmRecordDetail.setDamAlarmRecordId(damAlarmRecord.getId()); |
| | | damAlarmRecordDetail.setAlgorithmName(jsonObject.getString("algorithmName")); |
| | | damAlarmRecordDetail.setAlgorithmWarnLevel(jsonObject.getInteger("algorithmWarnLevel")); |
| | | damAlarmRecordDetail.setAlgorithmWarnInfo(jsonObject.getString("algorithmWarnInfo")); |
| | | damAlarmRecordDetail.setAlgorithmWarnExplain(jsonObject.getString("algorithmWarnExplain")); |
| | | damAlarmRecordDetail.setCreateTime(new Date()); |
| | | // 加入集合 |
| | | list.add(damAlarmRecordDetail); |
| | | } |
| | | // 保存 |
| | | if (list.size() > 0) { |
| | | flag = damAlarmRecordDetailService.saveBatch(list); |
| | | } else { |
| | | flag = true; |
| | | } |
| | | } |
| | | return flag; |
| | | } |