1分钟内下发新费率

This commit is contained in:
ZZ 2021-11-29 15:09:39 +08:00
parent a2dde3133d
commit 74329a4903

View File

@ -0,0 +1,61 @@
package com.xhpc.pp.server;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.pp.logic.RateModelRequestLogic;
import com.xhpc.pp.utils.HexUtils;
import lombok.extern.slf4j.Slf4j;
import org.quickserver.net.server.ClientHandler;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;
import static cn.hutool.core.util.NumberUtil.isInteger;
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
import static com.xhpc.pp.server.ChargingPileServer.getHandler;
@Slf4j
@Component
public class RateModelTask {
@Scheduled(fixedRate = 60000)
protected void run() {
Collection<String> stationKeys = REDIS.keys("station:*");
for (String stationKey : stationKeys) {
ChargingStationDto stationDto = REDIS.getCacheObject(stationKey);
Long rateModelIdStation = stationDto.getRateModelId();
if (rateModelIdStation != null) {
Set<String> pks = stationDto.getPiles();
if (pks != null) for (String pk : pks) {
Long rateModelIdPile = REDIS.getCacheMapValue(pk, "rateModelId");
if (rateModelIdPile == null || !rateModelIdStation.equals(rateModelIdPile)) {
String gkPattern = ("gun:").concat(pk).concat("*");
Collection<String> gks = REDIS.keys(gkPattern);
boolean charging = false;
for (String gk : gks) {
if (isInteger(REDIS.getCacheMapValue(gk, "status"))) {
charging = true;
break;
}
}
if (!charging) {
ClientHandler handler = getHandler(pk.substring(5));
if (handler != null && handler.isOpen()) {
String rsmsg = RateModelRequestLogic.translate(pk.substring(5), rateModelIdStation, "0058");
try {
handler.sendClientBinary(HexUtils.toBytes(rsmsg));
} catch (IOException e) {
log.error("{} rate model not sent.", pk);
}
}
}
}
}
}
}
}
}