guoshilong
2024-04-26 741821101cae1142c809df12b49137032d17e6b6
skjcmanager/skjcmanager-service/skjcmanager-nky/src/main/java/cn/gistack/nky/service/impl/NkyServiceImpl.java
@@ -4,13 +4,16 @@
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.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;
@@ -28,7 +31,7 @@
@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/";
@@ -50,12 +53,40 @@
   @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);
   }
@@ -92,6 +123,21 @@
   @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);
   }