manual config time n rate model
This commit is contained in:
parent
843c74b175
commit
75b6fbd078
@ -40,4 +40,7 @@ public interface PowerPileService {
|
|||||||
@PathVariable("rateModelId") @Param("rateModelId") Long rateModelId,
|
@PathVariable("rateModelId") @Param("rateModelId") Long rateModelId,
|
||||||
@RequestBody @Param("rateModel") CacheRateModel rateModel);
|
@RequestBody @Param("rateModel") CacheRateModel rateModel);
|
||||||
|
|
||||||
|
@PostMapping("/pile/{pileNo}/timeNRateModel")
|
||||||
|
R configTimeNRateModel(@PathVariable("pileNo") String pileNo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,12 @@ public class PowerPileFallbackFactory implements FallbackFactory<PowerPileServic
|
|||||||
|
|
||||||
return R.fail("设置电站费率模型失败:" + cause.getMessage());
|
return R.fail("设置电站费率模型失败:" + cause.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R configTimeNRateModel(String pileNo) {
|
||||||
|
|
||||||
|
return R.fail("校时校费失败:" + cause.getMessage());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -77,12 +77,12 @@ public class ChargingController {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private R<Object> getRR(String response) {
|
public static R<Object> getRR(String response) {
|
||||||
|
|
||||||
R<Object> r;
|
R<Object> r;
|
||||||
JSONObject responseJson = (JSONObject) JSON.parse(response);
|
JSONObject responseJson = (JSONObject) JSON.parse(response);
|
||||||
if (responseJson == null) {
|
if (responseJson == null) {
|
||||||
r = R.fail("Native服务调用失败");
|
r = R.fail("原生服务调用失败");
|
||||||
} else {
|
} else {
|
||||||
int code = responseJson.getInteger("code");
|
int code = responseJson.getInteger("code");
|
||||||
log.debug(response);
|
log.debug(response);
|
||||||
@ -133,7 +133,7 @@ public class ChargingController {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private R<Object> checkPile(Map<String, Object> cachePile) {
|
public static R<Object> checkPile(Map<String, Object> cachePile) {
|
||||||
|
|
||||||
if (cachePile == null) {
|
if (cachePile == null) {
|
||||||
return R.fail("充电桩未注册");
|
return R.fail("充电桩未注册");
|
||||||
@ -186,7 +186,7 @@ public class ChargingController {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String fmt(String svcSrv) {
|
public static String fmt(String svcSrv) {
|
||||||
|
|
||||||
String[] split = svcSrv.split("#");
|
String[] split = svcSrv.split("#");
|
||||||
return "http://".concat(split[0]).concat(":").concat(split[1]);
|
return "http://".concat(split[0]).concat(":").concat(split[1]);
|
||||||
|
|||||||
@ -1,17 +1,24 @@
|
|||||||
package com.xhpc.pp.controller;
|
package com.xhpc.pp.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
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.common.core.utils.HttpUtils;
|
||||||
|
import com.xhpc.pp.logic.RateModelRequestLogic;
|
||||||
import com.xhpc.pp.utils.HexUtils;
|
import com.xhpc.pp.utils.HexUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.quickserver.net.server.ClientHandler;
|
import org.quickserver.net.server.ClientHandler;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
|
import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMAT;
|
||||||
|
import static cn.hutool.core.util.NumberUtil.isInteger;
|
||||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
|
import static com.xhpc.common.data.redis.StaticBeanUtil.seqHex;
|
||||||
|
import static com.xhpc.pp.controller.ChargingController.*;
|
||||||
|
import static com.xhpc.pp.server.ChargingPileBinaryHandler.getTimeBin;
|
||||||
import static com.xhpc.pp.server.ChargingPileServer.getHandler;
|
import static com.xhpc.pp.server.ChargingPileServer.getHandler;
|
||||||
import static com.xhpc.pp.server.ChargingPileServer.removeHandler;
|
import static com.xhpc.pp.server.ChargingPileServer.removeHandler;
|
||||||
|
|
||||||
@ -47,47 +54,96 @@ public class PileController {
|
|||||||
cachePile.put("version", version);
|
cachePile.put("version", version);
|
||||||
REDIS.setCacheMap(pkey, cachePile);
|
REDIS.setCacheMap(pkey, cachePile);
|
||||||
}
|
}
|
||||||
|
log.info("station [{}] pile whitelist add: [{}]", stationId, Arrays.toString(pileNoSet.toArray()));
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("pile/whitelist/delete/{stationId}")
|
@DeleteMapping("pile/whitelist/delete/{stationId}")
|
||||||
public Object deleteWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet) {
|
public Object deleteWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet) {
|
||||||
|
|
||||||
// System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
||||||
// System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
||||||
REDIS.deleteSetVal("PILE_WHITELIST", pileNoSet.toArray());
|
REDIS.deleteSetVal("PILE_WHITELIST", pileNoSet.toArray());
|
||||||
String stationKey = "station:".concat(stationId.toString());
|
String stationKey = "station:".concat(stationId.toString());
|
||||||
// System.out.println(">>>>>>>>>>>>>>>>>>pileNoSet.toArray()>>>>>>>>>>>>>>>>"+stationKey);
|
|
||||||
ChargingStationDto cacheStation = REDIS.getCacheObject(stationKey);
|
ChargingStationDto cacheStation = REDIS.getCacheObject(stationKey);
|
||||||
cacheStation.getPiles().removeAll(pileNoSet);
|
cacheStation.getPiles().removeAll(pileNoSet);
|
||||||
REDIS.setCacheObject(stationKey, cacheStation);
|
REDIS.setCacheObject(stationKey, cacheStation);
|
||||||
|
log.info("station [{}] pile whitelist delete: [{}]", stationId, Arrays.toString(pileNoSet.toArray()));
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("native/pile/{pileNo}/rateModel")
|
|
||||||
public Object configRateModel(@PathVariable("pileNo") String pileNo, @RequestBody String msg) {
|
@PostMapping("pile/{pileNo}/timeNRateModel")
|
||||||
|
public R configTimeNRateModel(@PathVariable("pileNo") String pileNo) {
|
||||||
|
|
||||||
|
String pkey = "pile:".concat(pileNo);
|
||||||
|
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
||||||
|
R<Object> r = checkPile(cachePile);
|
||||||
|
if (r.getCode() == 200) {
|
||||||
|
String svcSrv = (String) cachePile.get("svcSrv");
|
||||||
|
String response = HttpUtils.post(fmt(svcSrv).concat("/native/pile/").concat(pileNo).concat("/timeNRateModel"));
|
||||||
|
r = getRR(response);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("native/pile/{pileNo}/timeNRateModel")
|
||||||
|
public R nativeConfigTimeNRateModel(@PathVariable("pileNo") String pileNo) {
|
||||||
|
|
||||||
ClientHandler handler = getHandler(pileNo);
|
ClientHandler handler = getHandler(pileNo);
|
||||||
R r;
|
R r = R.fail("校时校费下发失败,充电桩未注册.");
|
||||||
if (handler != null && handler.isOpen()) {
|
if (handler != null && handler.isOpen()) {
|
||||||
if (!handler.isOpen()) {
|
if (!handler.isOpen()) {
|
||||||
log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo);
|
log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo);
|
||||||
removeHandler(pileNo);
|
removeHandler(pileNo);
|
||||||
r = R.fail("充电桩连接已断开,请稍后再试");
|
r = R.fail("充电桩连接已断开,请稍后再试.");
|
||||||
} else {
|
} else {
|
||||||
try {
|
Collection<String> stationKeys = REDIS.keys("station:*");
|
||||||
log.debug("[{}] - server send msg >>>> ({}) |{}|", handler.getName(), pileNo, msg);
|
for (String stationKey : stationKeys) {
|
||||||
handler.sendClientBinary(HexUtils.toBytes(msg));
|
ChargingStationDto stationDto = REDIS.getCacheObject(stationKey);
|
||||||
r = R.ok(null, "网络延迟,请重试");
|
Long rateModelIdStation = stationDto.getRateModelId();
|
||||||
} catch (IOException e) {
|
if (rateModelIdStation != null) {
|
||||||
log.error("费率模型下发失败[{}]:".concat(e.getMessage()).concat(".无法启动充电"), pileNo);
|
Set<String> pns = stationDto.getPiles();
|
||||||
removeHandler(pileNo);
|
if (pns != null) for (String pn : pns) {
|
||||||
r = R.fail("电桩网络通信失败,请重试");
|
if (pn.equals(pileNo)) {
|
||||||
|
String pk = "pile:".concat(pileNo);
|
||||||
|
Long rateModelIdPile = REDIS.getCacheMapValue(pk, "rateModelId");
|
||||||
|
if (!rateModelIdStation.equals(rateModelIdPile)) {
|
||||||
|
String gkPattern = ("gun:").concat(pileNo).concat("*");
|
||||||
|
Collection<String> gks = REDIS.keys(gkPattern);
|
||||||
|
boolean charging = false;
|
||||||
|
for (String gk : gks) {
|
||||||
|
if (gk.length() == 20 && isInteger(REDIS.getCacheMapValue(gk, "status"))) {
|
||||||
|
charging = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!charging) {
|
||||||
|
String rsmsg = RateModelRequestLogic.translate(pileNo, rateModelIdStation, "0058",
|
||||||
|
REDIS.getCacheMapValue(pk, "version"));
|
||||||
|
try {
|
||||||
|
handler.sendClientBinary(HexUtils.toBytes(rsmsg));
|
||||||
|
log.info("pile[{}] rate model[{}] sent ⚪ {}", pileNo, rateModelIdStation, rsmsg);
|
||||||
|
String skey = pk.concat(".seqhex");
|
||||||
|
Thread.sleep(500);
|
||||||
|
Date date = Calendar.getInstance().getTime();
|
||||||
|
String timebin = getTimeBin(seqHex(skey), pileNo, date);
|
||||||
|
handler.sendClientBinary(HexUtils.toBytes(timebin));
|
||||||
|
REDIS.setCacheMapValue(pk, "manConfTime", DateUtil.format(date,
|
||||||
|
NORM_DATETIME_FORMAT));
|
||||||
|
r = R.fail("校时校费下发成功.");
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
r = R.fail("校时|校费下发失败,请重试.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
r = R.fail("校时校费下发失败,充电桩在充电中.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.error("费率模型下发失败[{}].无法启动充电", pileNo);
|
|
||||||
r = R.fail("启动失败,请稍后重试");
|
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public class PileTimeConfigReplyDataLogic implements ServiceLogic {
|
|||||||
String pk = "pile:".concat(pileNo);
|
String pk = "pile:".concat(pileNo);
|
||||||
String configTime = DateUtil.format(cp56toDate(pileTimeConfigReplyData.getSetTime()), NORM_DATETIME_FORMAT);
|
String configTime = DateUtil.format(cp56toDate(pileTimeConfigReplyData.getSetTime()), NORM_DATETIME_FORMAT);
|
||||||
Map<String, Object> cachePile = REDIS.getCacheMap(pk);
|
Map<String, Object> cachePile = REDIS.getCacheMap(pk);
|
||||||
cachePile.put("configTime", configTime);
|
cachePile.put("configTimeReply", configTime);
|
||||||
REDIS.setCacheMap(pk, cachePile);
|
REDIS.setCacheMap(pk, cachePile);
|
||||||
log.debug("({}) set time success√: [{}]", pileNo, configTime);
|
log.debug("({}) set time success√: [{}]", pileNo, configTime);
|
||||||
String remark = "充电桩同步时钟";
|
String remark = "充电桩同步时钟";
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.xhpc.pp.logic;
|
package com.xhpc.pp.logic;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.xhpc.common.api.dto.ChargingStationDto;
|
import com.xhpc.common.api.dto.ChargingStationDto;
|
||||||
import com.xhpc.common.data.up.PileConfigReplyData;
|
import com.xhpc.common.data.up.PileConfigReplyData;
|
||||||
@ -15,8 +16,10 @@ import org.springframework.context.annotation.Lazy;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMAT;
|
||||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
import static com.xhpc.pp.tx.ServiceResult.*;
|
import static com.xhpc.pp.tx.ServiceResult.*;
|
||||||
|
|
||||||
@ -53,6 +56,8 @@ public class RateModelConfigReplyDataLogic implements ServiceLogic {
|
|||||||
cachePile.put("rateModelId", cacheStation.getRateModelId());
|
cachePile.put("rateModelId", cacheStation.getRateModelId());
|
||||||
result = OK;
|
result = OK;
|
||||||
}
|
}
|
||||||
|
String configTime = DateUtil.format(Calendar.getInstance().getTime(), NORM_DATETIME_FORMAT);
|
||||||
|
cachePile.put("configRmReply", configTime);
|
||||||
REDIS.setCacheMap(pkey, cachePile);
|
REDIS.setCacheMap(pkey, cachePile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMAT;
|
import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMAT;
|
||||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
@ -132,13 +133,14 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
|||||||
if (SERVICE_HB.equals(serviceName)) {
|
if (SERVICE_HB.equals(serviceName)) {
|
||||||
if (OK.equals(resultCode)) {
|
if (OK.equals(resultCode)) {
|
||||||
pileNo = ChargingPileServer.getPileNo(handler);
|
pileNo = ChargingPileServer.getPileNo(handler);
|
||||||
Boolean tcfg = (Boolean) cachePile.get("tcfg");
|
String tcfgkey = "pile:".concat(pileNo).concat(".tcfg");
|
||||||
|
Boolean tcfg = REDIS.getCacheObject(tcfgkey);
|
||||||
if (tcfg == null || !tcfg) {
|
if (tcfg == null || !tcfg) {
|
||||||
String skey = pilekey.concat(".seqhex");
|
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(skey), pileNo, date);
|
String timebin = getTimeBin(seqHex(skey), pileNo, date);
|
||||||
cachePile.put("configTime", DateUtil.format(date, NORM_DATETIME_FORMAT));
|
cachePile.put("hbConfTime", DateUtil.format(date, NORM_DATETIME_FORMAT));
|
||||||
REDIS.setCacheMap(pilekey, cachePile);
|
REDIS.setCacheMap(pilekey, cachePile);
|
||||||
log.debug("server send time config msg >>>> ({}) |{}|", pileNo, timebin);
|
log.debug("server send time config msg >>>> ({}) |{}|", pileNo, timebin);
|
||||||
if (!handler.isOpen()) {
|
if (!handler.isOpen()) {
|
||||||
@ -149,8 +151,7 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
|||||||
if (gunId != null) {
|
if (gunId != null) {
|
||||||
hori2(pileNo, gunId);
|
hori2(pileNo, gunId);
|
||||||
}
|
}
|
||||||
cachePile.put("tcfg", true);
|
REDIS.setCacheObject(tcfgkey, true, 1L, TimeUnit.DAYS);
|
||||||
REDIS.setCacheMap(pilekey, cachePile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -161,7 +162,7 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTimeBin(String seqhex, String pileNo, Date date) {
|
public static String getTimeBin(String seqhex, String pileNo, Date date) {
|
||||||
|
|
||||||
String timebin = "6812".concat(seqhex).concat("0056").concat(pileNo).concat(toCp56Hex(date));
|
String timebin = "6812".concat(seqhex).concat("0056").concat(pileNo).concat(toCp56Hex(date));
|
||||||
timebin = timebin.concat(CRCCalculator.calcCrc(timebin));
|
timebin = timebin.concat(CRCCalculator.calcCrc(timebin));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user