jiazx0107@163.com
2023-12-12 a9098372191b3c51995d41ee28404d1b71244d98
提交网关心跳和设备状态2
已修改9个文件
133 ■■■■ 文件已修改
src/main/java/com/fzzy/api/service/ApiTriggerService.java 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/data/ConfigData.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/entity/GatewayDevice.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReportService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/HxGatewayRemoteServiceImpl.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/service/ApiTriggerService.java
@@ -9,11 +9,10 @@
import com.fzzy.api.utils.RedisConst;
import com.fzzy.api.utils.RedisUtil;
import com.fzzy.api.view.repository.ApiTriggerRep;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -34,10 +33,10 @@
    private String DEFAULT_MAP_KEY = "DEFAULT";
    @Autowired
    @Resource
    private RedisUtil redisUtil;
    @Autowired
    @Resource
    private ApiTriggerRep apiTriggerRep;
@@ -158,6 +157,21 @@
    /**
     * 在线或者不在线
     * <p>
     * ${dorado.getDataProvider("apiTriggerService#triggerOnline").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<ApiTrigger> triggerOnline() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(Constant.YN_N,"离线"));
        list.add(new ApiTrigger(Constant.YN_Y,"在线"));
        return list;
    }
    /**
     * 页面下拉框使用,根据父编码获取,父编码的定注意在 @See Constant
     * <p>
     * ${dorado.getDataProvider("apiTriggerService#trigger").getResult("PARENT_CODE")}
src/main/java/com/fzzy/data/ConfigData.java
@@ -24,6 +24,9 @@
    @Value("${igds.img-path}")
    private String imgPath;
    @Value("${igds.weather-url}")
    private String weatherUrl;
    @Value("${igds.weather-path}")
    private String weatherPath;
    @Value("${igds.city-id}")
    private String cityId;
}
src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
@@ -1,12 +1,7 @@
package com.fzzy.gateway;
import com.alibaba.fastjson.JSON;
import com.fzzy.api.data.ApiParam;
import com.fzzy.api.data.GatewayDeviceProtocol;
import com.fzzy.api.entity.ApiConfs;
import com.fzzy.api.service.*;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.utils.RedisUtil;
import com.fzzy.data.ConfigData;
import com.fzzy.gateway.api.GatewayRemoteManager;
import com.fzzy.gateway.data.BaseReqData;
@@ -15,17 +10,13 @@
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.service.GatewayConfService;
import com.fzzy.gateway.util.GatewayHttpUtil;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date;
import java.util.List;
/**
@@ -88,10 +79,19 @@
    public void doWeatherExe() {
        try {
            String url = configData.getWeatherUrl();
            String url = configData.getWeatherPath();
            url = url.replace("{appId}", DEFAULT_APP_ID).replace("{appsecret}", DEFAULT_APP_SECRET).replace("{cityid}", DEFAULT_CITYID);
            if (null == url) {
                url = DEFAULT_URL;
            }
            url = url.replace("{appId}", DEFAULT_APP_ID).replace("{appsecret}", DEFAULT_APP_SECRET);
            if (StringUtils.isNotEmpty(configData.getCityId())) {
                url = url.replace("{cityid}", configData.getCityId());
            } else {
                url = url.replace("{cityid}", DEFAULT_CITYID);
            }
            log.debug("------气象请求信息URL---{}", url);
            String result = GatewayHttpUtil.doGet(url);
src/main/java/com/fzzy/gateway/entity/GatewayDevice.java
@@ -119,9 +119,9 @@
    @PropertyDef(label = "筒仓层规则", description = "针对筒仓")
    private String cableCir;
    @Transient
    @PropertyDef(label = "设备在线状态")
    private String status = Constant.YN_N;
    @Column(name = "STATUS_", length = 2)
    @PropertyDef(label = "在线状态")
    private String status = Constant.YN_Y;
    @Transient
    @PropertyDef(label = "设备上线时间")
src/main/java/com/fzzy/gateway/hx2023/kafka/KafkaDeviceReportService.java
@@ -31,7 +31,7 @@
            // 消息在分区内的offset
            long offset = success.getRecordMetadata().offset();
            log.info("---推送至KAFKA成功--:{}-{}-{}-{}", topic, partition, offset, sendData);
            log.info("---推送至KAFKA成功--:{}-{}", topic, sendData);
        }, failure -> {
            log.info("---推送至KAFKA失败--:{}-{}-{}-{}", topic, sendData);
            rePublishWithTopic(sendData, topic);
src/main/java/com/fzzy/gateway/hx2023/service/HxGatewayRemoteServiceImpl.java
@@ -135,8 +135,6 @@
            String messageInfo = JSONObject.toJSONString(heartBeatData);
            log.info("---网关心跳推送--{}-{}", topic, messageInfo);
            kafkaDeviceReportService.publishWithTopic(messageInfo, topic);
@@ -145,40 +143,13 @@
        }
        //执行当前网关的设备状态推送
        log.info("------------定时设备状态执行---------{}", gatewayConf.getKqmc());
        pushDeviceStatus(gatewayConf);
    }
    @Override
    public void pushInfo(GatewayConf gatewayConf) {
        try {
            if (StringUtils.isEmpty(gatewayConf.getApiUrl())) {
                return;
            }
            gatewayConf = getCacheConf(gatewayConf.getKqdm());
            //网关心跳接口
            Map<String, String> params = new HashMap<>();
            params.put("token", gatewayConf.getAccessToken());
            params.put("gatewayId", gatewayConf.getGatewayId());
            params.put("gatewayIp", gatewayConf.getGatewayIp());
            params.put("gatewayMac", null == gatewayConf.getGatewayMac() ? "无" : gatewayConf.getGatewayMac());
            params.put("gatewayCPU", null == gatewayConf.getGatewayCPU() ? "无" : gatewayConf.getGatewayCPU());
            params.put("gatewayMem", null == gatewayConf.getGatewayMem() ? "无" : gatewayConf.getGatewayMem());
            params.put("gatewayHardDisk", null == gatewayConf.getGatewayHardDisk() ? "无" : gatewayConf.getGatewayHardDisk());
            params.put("timestamp", System.currentTimeMillis() + "");
            String sign = getSign(params, gatewayConf);
            params.put("sign", sign);
            String url = gatewayConf.getApiUrl() + "reserver/api/iot/equipment/heartbeat";
            String jsonStr = GatewayHttpUtil.doGet(url, params);
            log.info("---推送网关信息-返回---{}", jsonStr);
        } catch (Exception e) {
            log.error("------推送网关信息--执行失败-----{}", e);
        }
        //DO NOTHING
    }
src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
@@ -5,6 +5,7 @@
import com.bstek.dorado.annotation.Expose;
import com.fzzy.api.Constant;
import com.fzzy.api.data.ApiCommonDevice;
import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.entity.GatewayDevice;
@@ -42,15 +43,14 @@
        List<GatewayDevice> result = new ArrayList<>();
        GatewayDevice cacheDevice;
        ApiCommonDevice commonDevice;
        for (GatewayDevice device : list) {
            device.setStatus(Constant.YN_Y);
            cacheDevice = GatewayUtils.getCacheByDeviceId(device.getDeviceId());
            if (null != cacheDevice) {
                device.setIp(cacheDevice.getIp());
                device.setPort(cacheDevice.getPort());
                device.setStatus(cacheDevice.getStatus());
                device.setOnlineTime(cacheDevice.getOnlineTime());
            commonDevice = Constant.getCommonDeviceCache(device.getDeviceSn());
            if (null != commonDevice) {
                device.setIp(commonDevice.getIp());
                device.setPort(commonDevice.getPort());
                device.setStatus(commonDevice.getStatus());
                device.setOnlineTime(commonDevice.getOnlineTime());
            }
            result.add(device);
        }
@@ -66,6 +66,14 @@
    public void updateSave(GatewayDevice data) {
        GatewayDevice data2 = new GatewayDevice();
        BeanUtils.copyProperties(data, data2);
        if (null == data2.getStatus()) {
            data.setStatus(Constant.YN_Y);
            if (GatewayDeviceType.TYPE_07.equals(data2.getType())) {
                data.setStatus(Constant.YN_N);
            }
        }
        if (null == data2.getDeviceSn()) {
            if (null != data2.getIp()) {
@@ -142,9 +150,7 @@
        for (GatewayDevice device : list) {
            device.setIp(commonDevice.getIp());
            device.setPort(commonDevice.getPort());
            //device.setOnlineTime(new Date());
            device.setStatus(Constant.YN_N);
            GatewayUtils.add2Cache(device);
        }
    }
src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml
@@ -117,8 +117,13 @@
        <Property name="label">位置</Property>
      </PropertyDef>
      <PropertyDef name="status">
        <Property/>
        <Property></Property>
        <Property name="label">在线状态</Property>
        <Property name="mapping">
          <Property name="mapValues">${dorado.getDataProvider(&quot;apiTriggerService#triggerOnline&quot;).getResult()}</Property>
          <Property name="keyProperty">code</Property>
          <Property name="valueProperty">name</Property>
        </Property>
      </PropertyDef>
      <PropertyDef name="onlineTime">
        <Property name="dataType">DateTime</Property>
@@ -431,6 +436,11 @@
              <Property name="property">cableCir</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">status</Property>
              <Property name="property">status</Property>
              <Editor/>
            </AutoFormElement>
          </AutoForm>
        </Container>
      </Children>
src/main/resources/application.yml
@@ -42,4 +42,5 @@
    companyId: 5326
  file-path: C:/app/igds-api
  img-path: D:/IGDS/FILE/
  weather-url: https://v1.yiketianqi.com/api?unescape=1&version=v61&appid={appId}&appsecret={appsecret}&cityid={cityid}
  weather-path: https://v1.yiketianqi.com/api?unescape=1&version=v61&appid={appId}&appsecret={appsecret}&cityid={cityid}
  city-id: