1
zhang
6 小时以前 547da9acb9683a683c4f6aebd55eee8aa3980220
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/ChargeService.java
@@ -1,6 +1,7 @@
package com.zy.acs.manager.core.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.xingshuangs.iot.protocol.modbus.service.ModbusRtuOverTcp;
import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
import com.github.xingshuangs.iot.utils.HexUtil;
import com.zy.acs.framework.common.Cools;
@@ -25,7 +26,7 @@
    @Autowired
    private FuncStaService funcStaService;
    private final Map<String, ModbusTcp> CHARGE_CACHE = new ConcurrentHashMap<>();
    private final Map<String, ModbusRtuOverTcp> CHARGE_CACHE = new ConcurrentHashMap<>();
    @PostConstruct
@@ -33,7 +34,7 @@
        List<FuncSta> list = funcStaService.list(new LambdaQueryWrapper<FuncSta>()
                .eq(FuncSta::getType, FuncStaType.CHARGE.toString()));
        for (FuncSta funcSta : list) {
            if (Cools.isEmpty(funcSta.getProtocol()) && funcSta.getProtocol().equalsIgnoreCase(ProtocolType.MODBUS.toString())) {
            if (!Cools.isEmpty(funcSta.getProtocol()) && funcSta.getProtocol().equalsIgnoreCase(ProtocolType.MODBUS.toString())) {
                if (!Cools.isEmpty(funcSta.getIp()) && !Cools.isEmpty(funcSta.getPort()))
                    add(funcSta);
            }
@@ -42,7 +43,7 @@
    public void add(FuncSta funcSta) {
        ModbusTcp modbusTcp = new ModbusTcp(funcSta.getIp(), funcSta.getPort());
        ModbusRtuOverTcp modbusTcp = new ModbusRtuOverTcp(funcSta.getIp(), funcSta.getPort());
        modbusTcp.setComCallback((tag, bytes) -> log.info("%s[%d] %s%n", tag, bytes.length, HexUtil.toHexString(bytes)));
        CHARGE_CACHE.put(funcSta.getUuid(), modbusTcp);
    }
@@ -51,14 +52,15 @@
        CHARGE_CACHE.remove(chargePointId);
    }
    public ModbusTcp get(String chargePointId) {
        ModbusTcp modbusTcp = CHARGE_CACHE.get(chargePointId);
    public ModbusRtuOverTcp get(String chargePointId) {
        ModbusRtuOverTcp modbusTcp = CHARGE_CACHE.get(chargePointId);
        if (modbusTcp != null) {
            return modbusTcp;
        }
        FuncSta funcSta = funcStaService.getOne(new LambdaQueryWrapper<FuncSta>().eq(FuncSta::getUuid, chargePointId));
        modbusTcp = new ModbusTcp(funcSta.getIp(), funcSta.getPort());
        modbusTcp = new ModbusRtuOverTcp(funcSta.getIp(), funcSta.getPort());
        modbusTcp.setComCallback((tag, bytes) -> log.info("%s[%d] %s%n", tag, bytes.length, HexUtil.toHexString(bytes)));
        CHARGE_CACHE.put(chargePointId, modbusTcp);
        return modbusTcp;
    }