diff --git a/zc-business/src/main/java/com/zc/business/controller/DcExternalPlatformHeartbeatController.java b/zc-business/src/main/java/com/zc/business/controller/DcExternalPlatformHeartbeatController.java index 50d2b6d3..42757f02 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcExternalPlatformHeartbeatController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcExternalPlatformHeartbeatController.java @@ -1,12 +1,22 @@ package com.zc.business.controller; +import java.io.IOException; +import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.IpUtils; import com.zc.business.domain.DcExternalPlatformHeartbeat; +import com.zc.business.enums.UniversalEnum; import com.zc.business.service.IDcExternalPlatformHeartbeatService; +import com.zc.common.core.httpclient.OkHttp; +import com.zc.common.core.httpclient.exception.HttpException; +import okhttp3.Response; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -95,4 +105,27 @@ public class DcExternalPlatformHeartbeatController extends BaseController { return toAjax(dcExternalPlatformHeartbeatService.deleteDcExternalPlatformHeartbeatByIds(ids)); } + + /** + * 桥梁监测心跳 + */ + @Scheduled(cron = "0 */5 * * * ?") + public void bridgeMonitoringHeartbeat() throws HttpException, IOException { + OkHttp okHttp = new OkHttp(); + Response response // 请求响应 + = okHttp + .url("http://iot.sdhscloud.com/web/healthz") // 请求地址 + .get(); // 请求方法 + if (response.body() != null) { + String result = response.body().string(); + if (StringUtils.isNotEmpty(result) && result.equals("ok")){ + DcExternalPlatformHeartbeat dcExternalPlatformHeartbeat = new DcExternalPlatformHeartbeat(); + dcExternalPlatformHeartbeat.setType("4"); + dcExternalPlatformHeartbeat.setCreateTime(new Date()); + dcExternalPlatformHeartbeat.setIp(IpUtils.getHostIp()); + dcExternalPlatformHeartbeatService.insertDcExternalPlatformHeartbeat(dcExternalPlatformHeartbeat); + } + } + + } }