完善费率下发逻辑

This commit is contained in:
ZZ 2021-09-08 19:55:26 +08:00
parent fb7f3426ff
commit 39bd95ded6
3 changed files with 26 additions and 9 deletions

View File

@ -80,8 +80,10 @@ public class ChargingController {
} else {
int code = responseJson.getInteger("code");
if (code != 200) {
log.error("1");
r = R.fail(code, responseJson.getString("msg"));
} else {
log.error("2");
r = R.ok(responseJson.get("data"), responseJson.getString("msg"));
}
}
@ -102,7 +104,6 @@ public class ChargingController {
ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(stationId.toString()));
Long stationRateModelId = cacheStation.getRateModelId();
Long pileRateModelId = (Long) cachePile.get("rateModelId");
cachePile.put("rateModelId", pileRateModelId);
if (!stationRateModelId.equals(pileRateModelId)) {
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString()));
String rateModel = RateModelRequestLogic.translate(cacheRateModel);
@ -117,10 +118,11 @@ public class ChargingController {
JSONObject responseJson = (JSONObject) JSON.parse(response);
assert responseJson != null;
int code = responseJson.getInteger("code");
log.error(response);
if (code != 200) {
r = R.fail(code, responseJson.getString("msg"));
} else {
r = R.fail(responseJson.get("data"), responseJson.getString("msg"));
r = R.fail(responseJson.getString("msg"));
}
} else {
JSONObject json = (JSONObject) JSON.toJSON(startChargingData);

View File

@ -3,6 +3,7 @@ package com.xhpc.pp.controller;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.common.core.domain.R;
import com.xhpc.pp.utils.security.HexUtils;
import lombok.extern.slf4j.Slf4j;
import org.quickserver.net.server.ClientHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@ -17,6 +18,7 @@ import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
import static com.xhpc.pp.server.ChargingPileServer.getHandler;
@RestController
@Slf4j
public class PileController {
@PostMapping("pile/whitelist/add/{stationId}")
@ -65,9 +67,11 @@ public class PileController {
R r;
if (handler != null) {
try {
log.info("server send msg >>>> ({}) |{}|", pileNo, msg);
handler.sendClientBinary(HexUtils.toBytes(msg));
r = R.ok("费率模型已下发,请再次启动充电");
r = R.ok(null, "费率模型已下发,请再次启动充电");
} catch (IOException e) {
log.error("send message failed. " + e.getMessage(), e);
r = R.fail("费率模型下发失败:".concat(e.getMessage()).concat(".无法启动充电"));
}
} else {

View File

@ -3,8 +3,10 @@ package com.xhpc.pp.server;
import cn.hutool.core.date.DateUtil;
import com.alibaba.nacos.api.exception.NacosException;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.common.data.redis.CacheRateModel;
import com.xhpc.pp.domain.ServiceField;
import com.xhpc.pp.logic.FieldLogic;
import com.xhpc.pp.logic.RateModelRequestLogic;
import com.xhpc.pp.logic.ServiceMainLogic;
import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult;
@ -100,8 +102,6 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
cachePile.put("tcfg", false);
REDIS.setCacheMap(pilekey, cachePile);
regHandler(handler, pileNo, req);
} else if (SERVICE_RMCR.equals(serviceName) && OK.equals(resultCode)) {
setCachePileRM(pilekey);
}
if (result.getBinary() != null) {
String gunId = (String) req.get("gunId");
@ -110,14 +110,13 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
}
log.info("server send msg >>>> ({}) |{}|", pileNo, toHex(result.getBinary()));
handler.sendClientBinary(result.getBinary());
if (SERVICE_RMR.equals(serviceName) && OK.equals(resultCode)) {
setCachePileRM(pilekey);
} else if (SERVICE_HB.equals(serviceName) && OK.equals(resultCode)) {
if (SERVICE_HB.equals(serviceName) && OK.equals(resultCode)) {
Boolean tcfg = (Boolean) cachePile.get("tcfg");
if (!tcfg) {
String skey = pilekey.concat(".seqhex");
Thread.sleep(500);
Date date = Calendar.getInstance().getTime();
String timebin = getTimeBin(seqHex(pilekey.concat("seqhex")), pileNo, date);
String timebin = getTimeBin(seqHex(skey), pileNo, date);
cachePile.put("configTime", DateUtil.format(date, NORM_DATETIME_FORMAT));
REDIS.setCacheMap(pilekey, cachePile);
log.info("server send time config msg >>>> ({}) |{}|", pileNo, timebin);
@ -127,6 +126,18 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
}
cachePile.put("tcfg", true);
REDIS.setCacheMap(pilekey, cachePile);
Thread.sleep(500);
Long stationId = (Long) cachePile.get("stationId");
ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(stationId.toString()));
Long stationRateModelId = cacheStation.getRateModelId();
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString()));
String rateModel = RateModelRequestLogic.translate(cacheRateModel);
String rateModelMsg = "685E".concat(seqHex(skey)).concat("0058").concat(pileNo)
.concat(String.format("%04X", stationRateModelId))
.concat(rateModel);
rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel));
log.info("server send msg >>>> ({}) |{}|", pileNo, rateModelMsg);
handler.sendClientBinary(HexUtils.toBytes(rateModelMsg));
}
}
}