缓存枪状态字段处理逻辑完善
This commit is contained in:
parent
6aec7b24dd
commit
ec40bfde74
@ -23,7 +23,9 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMAT;
|
||||
@ -39,6 +41,7 @@ public class ChargingController {
|
||||
|
||||
@Autowired
|
||||
private PowerPileService powerPileService;
|
||||
private static List<String> etable = Arrays.asList((new String[]{"离线", "故障"}).clone());
|
||||
|
||||
@PostMapping("test/pile/charging/order")
|
||||
public R test(@Validated @RequestBody StartChargingData startChargingData) {
|
||||
@ -98,27 +101,23 @@ public class ChargingController {
|
||||
Long pileRateModelId = (Long) cachePile.get("rateModelId");
|
||||
cachePile.put("rateModelId", pileRateModelId);
|
||||
if (!stationRateModelId.equals(pileRateModelId)) {
|
||||
if (cachePile.get("status").toString().equals(REGISTERED)) {
|
||||
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString()));
|
||||
String rateModel = RateModelRequestLogic.translate(cacheRateModel);
|
||||
String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId());
|
||||
String skey = gunkey.concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
String rateModelMsg = "680E".concat(seq).concat("0058").concat(pileNo)
|
||||
.concat(String.format("%04X", stationRateModelId))
|
||||
.concat(rateModel);
|
||||
rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel));
|
||||
String response = HttpUtils.post(fmt(svcSrv).concat("/native/pile/".concat(pileNo).concat("/rateModel")), rateModelMsg);
|
||||
JSONObject responseJson = (JSONObject) JSON.parse(response);
|
||||
assert responseJson != null;
|
||||
int code = responseJson.getInteger("code");
|
||||
if (code != 200) {
|
||||
r = R.fail(code, responseJson.getString("msg"));
|
||||
} else {
|
||||
r = R.fail(responseJson.get("data"), responseJson.getString("msg"));
|
||||
}
|
||||
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString()));
|
||||
String rateModel = RateModelRequestLogic.translate(cacheRateModel);
|
||||
String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId());
|
||||
String skey = gunkey.concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
String rateModelMsg = "680E".concat(seq).concat("0058").concat(pileNo)
|
||||
.concat(String.format("%04X", stationRateModelId))
|
||||
.concat(rateModel);
|
||||
rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel));
|
||||
String response = HttpUtils.post(fmt(svcSrv).concat("/native/pile/".concat(pileNo).concat("/rateModel")), rateModelMsg);
|
||||
JSONObject responseJson = (JSONObject) JSON.parse(response);
|
||||
assert responseJson != null;
|
||||
int code = responseJson.getInteger("code");
|
||||
if (code != 200) {
|
||||
r = R.fail(code, responseJson.getString("msg"));
|
||||
} else {
|
||||
r = R.fail("充电桩离线,费率模型未更新或下发");
|
||||
r = R.fail(responseJson.get("data"), responseJson.getString("msg"));
|
||||
}
|
||||
} else {
|
||||
JSONObject json = (JSONObject) JSON.toJSON(startChargingData);
|
||||
@ -135,8 +134,8 @@ public class ChargingController {
|
||||
return R.fail("充电桩未注册");
|
||||
}
|
||||
String status = cachePile.get("status").toString();
|
||||
if (!REGISTERED.equals(status)) {
|
||||
return R.fail("充电桩离线");
|
||||
if (etable.contains(status)) {
|
||||
return R.fail("充电桩无法响应,状态:".concat(status));
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class RealtimeDataLogic implements ServiceLogic {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(RealtimeDataLogic.class);
|
||||
|
||||
public static final String[] stable = {"离线", "故障", "空闲", "充电"};
|
||||
public static final String[] stable = {"离线", "故障", "空闲", "充电中"};
|
||||
public static final String[] pvgstable = {"否", "是", "未知"};
|
||||
private static final String[] hftable = {"急停按钮动作故障", "无可用整流模块", "出风口温度过高", "交流防雷故障", "交直流模块DC20通信中断", "绝缘检测模块FC08通信中断", "电度表通信中断", "读卡器通信中断", "RC10通信中断", "风扇调速板故障", "直流熔断器故障", "高压接触器故障", "门打开"};
|
||||
|
||||
@ -77,7 +77,7 @@ public class RealtimeDataLogic implements ServiceLogic {
|
||||
String stationTermStatusKey = "stationTerminalStatus:".concat(cachePile.get("stationId").toString());
|
||||
String statusOrSOC;
|
||||
Integer socInt = Integer.parseInt(soc, 16);
|
||||
if (statusplain.equals("充电")) {
|
||||
if (statusplain.equals("充电中")) {
|
||||
statusOrSOC = socInt.toString();
|
||||
} else {
|
||||
statusOrSOC = statusplain;
|
||||
|
||||
@ -22,8 +22,8 @@ import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
@Component("RegisterLogic")
|
||||
public class RegisterLogic implements ServiceLogic {
|
||||
|
||||
public static final String DISCONNECTED = "Disconnected";
|
||||
public static final String REGISTERED = "Registered";
|
||||
public static final String DISCONNECTED = "离线";
|
||||
public static final String REGISTERED = "已注册";
|
||||
private static Logger log = LoggerFactory.getLogger(RegisterLogic.class);
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.xhpc.pp.server;
|
||||
|
||||
import com.xhpc.pp.logic.RegisterLogic;
|
||||
import org.quickserver.net.server.ClientEventHandler;
|
||||
import org.quickserver.net.server.ClientHandler;
|
||||
import org.slf4j.Logger;
|
||||
@ -10,6 +9,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.pp.logic.RegisterLogic.DISCONNECTED;
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
|
||||
@Lazy(false)
|
||||
@ -46,7 +46,7 @@ public class ChargingPileEventHandler implements ClientEventHandler {
|
||||
ChargingPileServer.removeHandler(pileNo);
|
||||
String pkey = "pile:".concat(pileNo);
|
||||
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
||||
cachePile.put("status", RegisterLogic.DISCONNECTED);
|
||||
cachePile.put("status", DISCONNECTED);
|
||||
REDIS.setCacheMap(pkey, cachePile);
|
||||
handler.closeConnection();
|
||||
log.info("-> ({}) - [{}] <- {}", pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||
|
||||
@ -95,7 +95,7 @@ public class ChargingPileServer {
|
||||
String gunkey = "gun:".concat(pileNo).concat(String.format("%02d", i));
|
||||
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
||||
if (cacheGun != null) {
|
||||
cacheGun.put("status", "离线");
|
||||
cacheGun.put("status", DISCONNECTED);
|
||||
REDIS.setCacheMap(gunkey, cacheGun);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user