完善费率下发逻辑
This commit is contained in:
parent
fb7f3426ff
commit
39bd95ded6
@ -80,8 +80,10 @@ public class ChargingController {
|
|||||||
} else {
|
} else {
|
||||||
int code = responseJson.getInteger("code");
|
int code = responseJson.getInteger("code");
|
||||||
if (code != 200) {
|
if (code != 200) {
|
||||||
|
log.error("1");
|
||||||
r = R.fail(code, responseJson.getString("msg"));
|
r = R.fail(code, responseJson.getString("msg"));
|
||||||
} else {
|
} else {
|
||||||
|
log.error("2");
|
||||||
r = R.ok(responseJson.get("data"), responseJson.getString("msg"));
|
r = R.ok(responseJson.get("data"), responseJson.getString("msg"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +104,6 @@ public class ChargingController {
|
|||||||
ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(stationId.toString()));
|
ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(stationId.toString()));
|
||||||
Long stationRateModelId = cacheStation.getRateModelId();
|
Long stationRateModelId = cacheStation.getRateModelId();
|
||||||
Long pileRateModelId = (Long) cachePile.get("rateModelId");
|
Long pileRateModelId = (Long) cachePile.get("rateModelId");
|
||||||
cachePile.put("rateModelId", pileRateModelId);
|
|
||||||
if (!stationRateModelId.equals(pileRateModelId)) {
|
if (!stationRateModelId.equals(pileRateModelId)) {
|
||||||
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString()));
|
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString()));
|
||||||
String rateModel = RateModelRequestLogic.translate(cacheRateModel);
|
String rateModel = RateModelRequestLogic.translate(cacheRateModel);
|
||||||
@ -117,10 +118,11 @@ public class ChargingController {
|
|||||||
JSONObject responseJson = (JSONObject) JSON.parse(response);
|
JSONObject responseJson = (JSONObject) JSON.parse(response);
|
||||||
assert responseJson != null;
|
assert responseJson != null;
|
||||||
int code = responseJson.getInteger("code");
|
int code = responseJson.getInteger("code");
|
||||||
|
log.error(response);
|
||||||
if (code != 200) {
|
if (code != 200) {
|
||||||
r = R.fail(code, responseJson.getString("msg"));
|
r = R.fail(code, responseJson.getString("msg"));
|
||||||
} else {
|
} else {
|
||||||
r = R.fail(responseJson.get("data"), responseJson.getString("msg"));
|
r = R.fail(responseJson.getString("msg"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JSONObject json = (JSONObject) JSON.toJSON(startChargingData);
|
JSONObject json = (JSONObject) JSON.toJSON(startChargingData);
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.xhpc.pp.controller;
|
|||||||
import com.xhpc.common.api.dto.ChargingStationDto;
|
import com.xhpc.common.api.dto.ChargingStationDto;
|
||||||
import com.xhpc.common.core.domain.R;
|
import com.xhpc.common.core.domain.R;
|
||||||
import com.xhpc.pp.utils.security.HexUtils;
|
import com.xhpc.pp.utils.security.HexUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.quickserver.net.server.ClientHandler;
|
import org.quickserver.net.server.ClientHandler;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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;
|
import static com.xhpc.pp.server.ChargingPileServer.getHandler;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@Slf4j
|
||||||
public class PileController {
|
public class PileController {
|
||||||
|
|
||||||
@PostMapping("pile/whitelist/add/{stationId}")
|
@PostMapping("pile/whitelist/add/{stationId}")
|
||||||
@ -65,9 +67,11 @@ public class PileController {
|
|||||||
R r;
|
R r;
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
try {
|
try {
|
||||||
|
log.info("server send msg >>>> ({}) |{}|", pileNo, msg);
|
||||||
handler.sendClientBinary(HexUtils.toBytes(msg));
|
handler.sendClientBinary(HexUtils.toBytes(msg));
|
||||||
r = R.ok("费率模型已下发,请再次启动充电");
|
r = R.ok(null, "费率模型已下发,请再次启动充电");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
log.error("send message failed. " + e.getMessage(), e);
|
||||||
r = R.fail("费率模型下发失败:".concat(e.getMessage()).concat(".无法启动充电"));
|
r = R.fail("费率模型下发失败:".concat(e.getMessage()).concat(".无法启动充电"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -3,8 +3,10 @@ package com.xhpc.pp.server;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.xhpc.common.api.dto.ChargingStationDto;
|
import com.xhpc.common.api.dto.ChargingStationDto;
|
||||||
|
import com.xhpc.common.data.redis.CacheRateModel;
|
||||||
import com.xhpc.pp.domain.ServiceField;
|
import com.xhpc.pp.domain.ServiceField;
|
||||||
import com.xhpc.pp.logic.FieldLogic;
|
import com.xhpc.pp.logic.FieldLogic;
|
||||||
|
import com.xhpc.pp.logic.RateModelRequestLogic;
|
||||||
import com.xhpc.pp.logic.ServiceMainLogic;
|
import com.xhpc.pp.logic.ServiceMainLogic;
|
||||||
import com.xhpc.pp.tx.ServiceParameter;
|
import com.xhpc.pp.tx.ServiceParameter;
|
||||||
import com.xhpc.pp.tx.ServiceResult;
|
import com.xhpc.pp.tx.ServiceResult;
|
||||||
@ -100,8 +102,6 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
|||||||
cachePile.put("tcfg", false);
|
cachePile.put("tcfg", false);
|
||||||
REDIS.setCacheMap(pilekey, cachePile);
|
REDIS.setCacheMap(pilekey, cachePile);
|
||||||
regHandler(handler, pileNo, req);
|
regHandler(handler, pileNo, req);
|
||||||
} else if (SERVICE_RMCR.equals(serviceName) && OK.equals(resultCode)) {
|
|
||||||
setCachePileRM(pilekey);
|
|
||||||
}
|
}
|
||||||
if (result.getBinary() != null) {
|
if (result.getBinary() != null) {
|
||||||
String gunId = (String) req.get("gunId");
|
String gunId = (String) req.get("gunId");
|
||||||
@ -110,14 +110,13 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
|||||||
}
|
}
|
||||||
log.info("server send msg >>>> ({}) |{}|", pileNo, toHex(result.getBinary()));
|
log.info("server send msg >>>> ({}) |{}|", pileNo, toHex(result.getBinary()));
|
||||||
handler.sendClientBinary(result.getBinary());
|
handler.sendClientBinary(result.getBinary());
|
||||||
if (SERVICE_RMR.equals(serviceName) && OK.equals(resultCode)) {
|
if (SERVICE_HB.equals(serviceName) && OK.equals(resultCode)) {
|
||||||
setCachePileRM(pilekey);
|
|
||||||
} else if (SERVICE_HB.equals(serviceName) && OK.equals(resultCode)) {
|
|
||||||
Boolean tcfg = (Boolean) cachePile.get("tcfg");
|
Boolean tcfg = (Boolean) cachePile.get("tcfg");
|
||||||
if (!tcfg) {
|
if (!tcfg) {
|
||||||
|
String skey = pilekey.concat(".seqhex");
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
Date date = Calendar.getInstance().getTime();
|
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));
|
cachePile.put("configTime", DateUtil.format(date, NORM_DATETIME_FORMAT));
|
||||||
REDIS.setCacheMap(pilekey, cachePile);
|
REDIS.setCacheMap(pilekey, cachePile);
|
||||||
log.info("server send time config msg >>>> ({}) |{}|", pileNo, timebin);
|
log.info("server send time config msg >>>> ({}) |{}|", pileNo, timebin);
|
||||||
@ -127,6 +126,18 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
|||||||
}
|
}
|
||||||
cachePile.put("tcfg", true);
|
cachePile.put("tcfg", true);
|
||||||
REDIS.setCacheMap(pilekey, cachePile);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user