| | |
| | | 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; |
| | |
| | | @AllArgsConstructor |
| | | @Slf4j |
| | | public class NkyServiceImpl implements INkyService { |
| | | |
| | | private final IRequestRecordService requestRecordService; |
| | | |
| | | private static final String API_PREFIX = "http://10.42.7.146:9503/"; |
| | | private static final String LOCAL_API_PREFIX = "https://sk.hubeishuiyi.cn/warnIp/"; |
| | |
| | | //判定异常 |
| | | 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); |
| | | } |
| | | |
| | |
| | | JSONObject jsonObject = requestNkyApi(ALARM_GET,JSON.toJSONString(alarmGetPo)); |
| | | AlarmGet alarmGet = jsonObject.toJavaObject(AlarmGet.class); |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | JSONObject jsonObject = JSONObject.parseObject(resultStr); |
| | | return jsonObject; |
| | | } |
| | | |
| | | |
| | | |
| | | } |