From 46203ee88249d9a4046f3d453deb41edc562cf6c Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期二, 12 十二月 2023 12:36:53 +0800 Subject: [PATCH] 提交网关心跳和设备状态 --- src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java | 79 +++++++++++++++++++++++++++++---------- 1 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java index 2210aed..4f68178 100644 --- a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java +++ b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java @@ -3,20 +3,20 @@ import com.bstek.dorado.annotation.DataProvider; import com.bstek.dorado.annotation.DataResolver; import com.bstek.dorado.annotation.Expose; +import com.fzzy.api.Constant; +import com.fzzy.api.data.ApiCommonDevice; import com.fzzy.api.utils.ContextUtil; -import com.fzzy.async.fzzy40.Fzzy40CommonService; import com.fzzy.gateway.GatewayUtils; -import com.fzzy.gateway.api.GatewayRemoteManager; import com.fzzy.gateway.entity.GatewayDevice; import com.fzzy.gateway.service.repository.GatewayDeviceRep; -import com.fzzy.mqtt.MqttProviderConfig; -import com.fzzy.mqtt.MqttPublishService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Date; import java.util.List; @Slf4j @@ -34,24 +34,28 @@ @DataProvider public List<GatewayDevice> listAll() { Sort sort = new Sort(Sort.Direction.ASC, "deviceId"); - return gatewayDeviceRep.findAll(sort); - } -// /** -// * gatewayDeviceService#getQuery -// * -// * @return -// */ -// @DataProvider -// public GateWayTestParam getQuery() { -// GateWayTestParam param = new GateWayTestParam(); -// param.setDayTime(new Date()); -// param.setCarNumber("宸滱12345"); -// param.setEnd(new Date()); -// param.setStart(new Date()); -// param.setWeight(25000.00); -// return param; -// } + + List<GatewayDevice> list = gatewayDeviceRep.findAll(sort); + + if (null == list || list.isEmpty()) return list; + + List<GatewayDevice> result = new ArrayList<>(); + + GatewayDevice cacheDevice; + 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()); + } + result.add(device); + } + return result; + } /** * gatewayDeviceService#updateSave @@ -111,4 +115,37 @@ log.info("-----------test-------------------"); return "SUCCESS"; } + + /** + * 鏍规嵁瀹為檯閫氳鍒嗘満璁剧疆锛屽綋鍓嶅垎鏈哄湪绾� + * + * @param commonDevice 瀹為檯閫氳璁惧 + */ + public void onlineByCommonDevice(ApiCommonDevice commonDevice) { + List<GatewayDevice> list = GatewayUtils.getCacheByDeviceSn2(commonDevice.getSn()); + if (null == list || list.isEmpty()) return; + + for (GatewayDevice device : list) { + device.setIp(commonDevice.getIp()); + device.setPort(commonDevice.getPort()); + device.setOnlineTime(new Date()); + device.setStatus(Constant.YN_Y); + + GatewayUtils.add2Cache(device); + } + } + + public void OfflineByCommonDevice(ApiCommonDevice commonDevice) { + List<GatewayDevice> list = GatewayUtils.getCacheByDeviceSn2(commonDevice.getSn()); + if (null == list || list.isEmpty()) return; + + for (GatewayDevice device : list) { + device.setIp(commonDevice.getIp()); + device.setPort(commonDevice.getPort()); + //device.setOnlineTime(new Date()); + device.setStatus(Constant.YN_N); + + GatewayUtils.add2Cache(device); + } + } } -- Gitblit v1.9.3