| | |
| | | package cn.gistack.nky.service.impl; |
| | | |
| | | import cn.gistack.common.utils.SpringContextUtil; |
| | | import cn.gistack.nky.entity.AlarmGet; |
| | | import cn.gistack.nky.entity.ArimaPredict; |
| | | import cn.gistack.nky.entity.HstPredict; |
| | | import cn.gistack.nky.entity.RequestRecord; |
| | | import cn.gistack.nky.requestpojo.*; |
| | | import cn.gistack.nky.resultpojo.NkyBindDetailResult; |
| | | import cn.gistack.nky.service.INkyService; |
| | | import cn.gistack.nky.service.IRequestRecordService; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springframework.http.*; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | @Slf4j |
| | | public class NkyServiceImpl implements INkyService { |
| | | private final IRequestRecordService requestRecordService; |
| | | |
| | | |
| | | private static final String API_PREFIX = "https://sk.hubeishuiyi.cn/warnIp/"; |
| | | private static final String API_PREFIX = "http://10.42.7.146:9503/"; |
| | | private static final String LOCAL_API_PREFIX = "https://sk.hubeishuiyi.cn/warnIp/"; |
| | | // ARIMA预测接口URL |
| | | private static final String ARIMA_PREDICT = API_PREFIX + "predict/arimaPredict"; |
| | | private static final String ARIMA_PREDICT = "predict/arimaPredict"; |
| | | // ARIMA预测结果接口 |
| | | private static final String ARIMA_QUERY = API_PREFIX+"predict/arimaQuery"; |
| | | private static final String ARIMA_QUERY = "predict/arimaQuery"; |
| | | // HST预测接口URL |
| | | private static final String HST_PREDICT =API_PREFIX+ "predict/hstPredict"; |
| | | private static final String HST_PREDICT = "predict/hstPredict"; |
| | | // HST预测结果接口 |
| | | private static final String HST_QUERY =API_PREFIX+ "predict/hstQuery"; |
| | | private static final String HST_QUERY = "predict/hstQuery"; |
| | | |
| | | //按库传输数据接口 |
| | | private static final String ORIGIN_BATCHDATA = API_PREFIX + "origin/batchData"; |
| | | private static final String ORIGIN_BATCHDATA = "origin/batchData"; |
| | | |
| | | //判定异常 |
| | | private static final String ALARM_GET = API_PREFIX+"alarm/get"; |
| | | private static final String ALARM_GET = "alarm/get"; |
| | | |
| | | private static final String BIND_DETAIL = "bind/detail"; |
| | | private static final String BIND_ENABLE = "bind/enable"; |
| | | private static final String BIND_PARAM = "bind/param"; |
| | | |
| | | @Override |
| | | public Boolean arimaPredict(ArimaPredictReqPo po) { |
| | | JSONObject jsonObject = requestNkyApi(ARIMA_PREDICT, JSON.toJSONString(po)); |
| | | RequestRecord requestRecord = new RequestRecord(); |
| | | |
| | | try { |
| | | requestRecord.setRequestUrl(ARIMA_PREDICT); |
| | | requestRecord.setResGuid(po.getDamId()); |
| | | requestRecord.setPointId(po.getPointId()); |
| | | requestRecord.setSendParams(JSON.toJSONString(po)); |
| | | requestRecord.setResult(JSON.toJSONString(jsonObject)); |
| | | requestRecord.setCreateTime(DateUtil.now()); |
| | | requestRecord.setType(po.getType()); |
| | | }catch (Exception e){ |
| | | requestRecord.setErrorDesc(e.toString()); |
| | | } |
| | | requestRecordService.save(requestRecord); |
| | | return jsonObject.get("status").equals(200); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean hstPredict(HstPredictReqPo po) { |
| | | JSONObject jsonObject = requestNkyApi(HST_PREDICT, JSON.toJSONString(po)); |
| | | RequestRecord requestRecord = new RequestRecord(); |
| | | |
| | | try { |
| | | requestRecord.setRequestUrl(HST_PREDICT); |
| | | requestRecord.setResGuid(po.getDamId()); |
| | | requestRecord.setPointId(po.getPointId()); |
| | | requestRecord.setSendParams(JSON.toJSONString(po)); |
| | | requestRecord.setResult(JSON.toJSONString(jsonObject)); |
| | | requestRecord.setCreateTime(DateUtil.now()); |
| | | requestRecord.setType(po.getType()); |
| | | }catch (Exception e){ |
| | | requestRecord.setErrorDesc(e.toString()); |
| | | } |
| | | requestRecordService.save(requestRecord); |
| | | return jsonObject.get("status").equals(200); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public Boolean batchData(BatchDataPo po) { |
| | | JSONObject jsonObject = requestNkyApi(ORIGIN_BATCHDATA, JSON.toJSONString(po)); |
| | | RequestRecord requestRecord = new RequestRecord(); |
| | | try { |
| | | requestRecord.setRequestUrl(ORIGIN_BATCHDATA); |
| | | if (po.getDatas().size()>0){ |
| | | requestRecord.setResGuid(po.getDatas().get(0).getDamId()); |
| | | requestRecord.setType(po.getDatas().get(0).getType()); |
| | | } |
| | | requestRecord.setSendParams(JSON.toJSONString(po)); |
| | | requestRecord.setResult(JSON.toJSONString(jsonObject)); |
| | | requestRecord.setCreateTime(DateUtil.now()); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | requestRecord.setErrorDesc(e.toString()); |
| | | } |
| | | requestRecordService.save(requestRecord); |
| | | return jsonObject.get("status").equals(200); |
| | | } |
| | | |
| | |
| | | return alarmGet; |
| | | } |
| | | |
| | | @Override |
| | | public List<NkyBindDetailResult> getBindDetail(String resCd, String cd, String type) { |
| | | |
| | | JSONObject params = new JSONObject(); |
| | | params.put("damId",resCd); |
| | | params.put("pointId",cd); |
| | | params.put("type",type); |
| | | |
| | | JSONObject result = requestNkyApi(BIND_DETAIL, JSON.toJSONString(params)); |
| | | |
| | | JSONArray dataList = result.getJSONArray("data"); |
| | | List<NkyBindDetailResult> nkyBindDetailResultList = dataList.toJavaList(NkyBindDetailResult.class); |
| | | return nkyBindDetailResultList; |
| | | } |
| | | |
| | | @Override |
| | | public boolean bindEnable(JSONObject params) { |
| | | JSONObject jsonObject = requestNkyApi(BIND_ENABLE, JSON.toJSONString(params)); |
| | | |
| | | if (jsonObject.get("status").equals("200")) { |
| | | return true; |
| | | }else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean bindParam(JSONObject bindParamParams) { |
| | | JSONObject jsonObject = requestNkyApi(BIND_PARAM, JSON.toJSONString(bindParamParams)); |
| | | |
| | | if (jsonObject.get("status").equals("200")) { |
| | | return true; |
| | | }else { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 请求南科院接口 |
| | | * @param url |
| | | * @param jsonparams |
| | | * @return |
| | | */ |
| | | private JSONObject requestNkyApi(String url, String jsonparams) { |
| | | private synchronized JSONObject requestNkyApi(String url, String jsonparams) { |
| | | // 获取环境 |
| | | String activeProfile = SpringContextUtil.getActiveProfile(); |
| | | if (activeProfile.equals("dev")) { |
| | | url = LOCAL_API_PREFIX+ url ; |
| | | } |
| | | if (activeProfile.equals("prod")) { |
| | | url = API_PREFIX+ url ; |
| | | } |
| | | if (activeProfile.equals("test")) { |
| | | url = API_PREFIX + url; |
| | | } |
| | | |
| | | // 声明一个header变量 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | // 设置为json格式 |
| | |
| | | headers.add("Accept", MediaType.APPLICATION_JSON.toString()); |
| | | |
| | | HttpEntity<String> httpEntity = new HttpEntity(jsonparams, headers); |
| | | System.out.println("请求参数:"+ jsonparams); |
| | | log.info("请求地址:"+ url); |
| | | log.info("请求参数:"+ jsonparams); |
| | | RestTemplate template = new RestTemplate(); |
| | | String resultStr = template.postForObject(url, httpEntity, String.class); |
| | | System.out.println(resultStr); |
| | | log.info("请求结果:"+ resultStr); |
| | | JSONObject jsonObject = JSONObject.parseObject(resultStr); |
| | | return jsonObject; |
| | | } |
| | | |
| | | |
| | | |
| | | } |