vince
2024-04-26 b1c572949997a5d82d9b609163ff280a1c49627d
src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
@@ -5,6 +5,8 @@
import com.bstek.dorado.annotation.Expose;
import com.fzzy.api.Constant;
import com.fzzy.api.data.ApiCommonDevice;
import com.fzzy.api.data.DepotType;
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 +44,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);
        }
@@ -67,12 +68,26 @@
        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()) {
                data.setDeviceSn(data2.getIp());
            } else {
                data.setDeviceSn(data2.getDeviceId());
            }
        }
        if (null == data2.getDepotType()) {
            data2.setDepotType(DepotType.TYPE_01.getCode());
        }
        if (null == data2.getId()) {
@@ -83,6 +98,15 @@
        }
        flushCache();
    }
    public void updateData(GatewayDevice device) {
        device.setStatus(Constant.YN_Y);
        gatewayDeviceRep.save(device);
        flushCacheOne(device);
    }
    /**
     * gatewayDeviceService#delData
@@ -109,6 +133,10 @@
        }
    }
    private void flushCacheOne(GatewayDevice device) {
        GatewayUtils.add2Cache(device);
    }
    @Expose
    public String test() {
@@ -130,7 +158,7 @@
            device.setPort(commonDevice.getPort());
            device.setOnlineTime(new Date());
            device.setStatus(Constant.YN_Y);
            device.setDeviceSn(commonDevice.getSn());
            GatewayUtils.add2Cache(device);
        }
    }
@@ -142,10 +170,10 @@
        for (GatewayDevice device : list) {
            device.setIp(commonDevice.getIp());
            device.setPort(commonDevice.getPort());
            //device.setOnlineTime(new Date());
            device.setStatus(Constant.YN_N);
            GatewayUtils.add2Cache(device);
        }
    }
}