刷新余额;seq all real seq
This commit is contained in:
parent
9e6be0a359
commit
693ae9ca5d
@ -15,10 +15,13 @@ import java.util.Set;
|
||||
@FeignClient(contextId = "powerPileService", value = ServiceNameConstants.PILE_SERVICE, fallbackFactory = PowerPileFallbackFactory.class)
|
||||
public interface PowerPileService {
|
||||
|
||||
// @PreAuthorize(hasPermi = "user:privilege:add") todo
|
||||
// @PreAuthorize(hasPermi = "user:privilege:add") todo
|
||||
@PostMapping("/charging/start")
|
||||
R startCharging(@Validated @RequestBody StartChargingData startChargingData);
|
||||
|
||||
@PostMapping("/charging/balance/refresh")
|
||||
R refreshBalance(@Validated @RequestBody StartChargingData balanceRefreshData);
|
||||
|
||||
@PutMapping("charging/stop/{pileNo}/{gunId}/{version}")
|
||||
R stopCharging(@PathVariable("pileNo") String pileNo, @PathVariable("gunId") String gunId, @PathVariable("version") String version);
|
||||
|
||||
@ -28,9 +31,6 @@ public interface PowerPileService {
|
||||
@DeleteMapping("/pile/whitelist/delete/{stationId}")
|
||||
R deletePileWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet);
|
||||
|
||||
@GetMapping("terminal/{terminalSn}/status")
|
||||
R terminalStatus(@PathVariable("terminalSn")String terminalSn);
|
||||
|
||||
@PostMapping("/station/rateModel/{stationId}/{rateModelId}")
|
||||
R setStationRateModel(@PathVariable("stationId") @Param("stationId") Long stationId, @PathVariable("rateModelId") @Param("rateModelId") Long rateModelId, @RequestBody @Param("rateModel") CacheRateModel rateModel);
|
||||
|
||||
|
||||
@ -28,6 +28,12 @@ public class PowerPileFallbackFactory implements FallbackFactory<PowerPileServic
|
||||
return R.fail("启动充电失败:" + cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R refreshBalance(StartChargingData balanceRefreshData) {
|
||||
|
||||
return R.fail("刷新余额失败:" + cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R stopCharging(String pileNo, String gunId, String version) {
|
||||
|
||||
@ -46,12 +52,6 @@ public class PowerPileFallbackFactory implements FallbackFactory<PowerPileServic
|
||||
return R.fail("删除充电桩白名单失败:" + cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R terminalStatus(String terminalSn) {
|
||||
|
||||
return R.fail("查询终端状态失败:" + cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R setStationRateModel(Long stationId, Long rateModelId, CacheRateModel rateModel) {
|
||||
|
||||
|
||||
@ -13,8 +13,8 @@ public class StartChargingData {
|
||||
private String gunId; //枪号
|
||||
@Min(value = 5, message = "账户余额不能小于5")
|
||||
private Integer balance; //账户余额(精度:小数点后2位)=实际金额(元)×100
|
||||
private String logicCardNo = "0000000000000000"; //逻辑卡号
|
||||
private String physicCardNo = "0000000000000000"; //物理卡号
|
||||
private String logicCardNo = "0000000000000000"; //逻辑卡号 16进制,无需补零
|
||||
private String physicCardNo = "0000000000000000"; //物理卡号 同上
|
||||
private String version = "0A"; //协议版本号(0A)
|
||||
|
||||
public String getOrderNo() {
|
||||
|
||||
@ -83,10 +83,10 @@ public class HxpcChargeOrderServiceImpl implements IHxpcChargeOrderService {
|
||||
}
|
||||
//终端状态是否空闲
|
||||
//是否插枪
|
||||
R r = powerPileService.terminalStatus(serialNumber);
|
||||
if(r.getCode() !=200){
|
||||
return AjaxResult.error(r.getMsg());
|
||||
}
|
||||
// R r = powerPileService.terminalStatus(serialNumber);
|
||||
// if(r.getCode() !=200){
|
||||
// return AjaxResult.error(r.getMsg());
|
||||
// }
|
||||
//终端信息
|
||||
XhpcTerminal xhpcTerminal = hxpcChargeOrderMapper.getXhpcTerminalSerialNumber(serialNumber);
|
||||
if (xhpcTerminal == null || xhpcTerminal.getTerminalId() == null || xhpcTerminal.getChargingPileId() == null || xhpcTerminal.getPileSerialNumber() == null) {
|
||||
|
||||
@ -45,55 +45,24 @@ public class ChargingController {
|
||||
}
|
||||
|
||||
@PostMapping("charging/balance/refresh")
|
||||
public Object refreshBalance(@Validated @RequestBody StartChargingData startChargingData) {
|
||||
public Object refreshBalance(@Validated @RequestBody StartChargingData balanceRefreshData) {
|
||||
|
||||
String pileNo = startChargingData.getPileNo();
|
||||
String pileNo = balanceRefreshData.getPileNo();
|
||||
String pkey = "pile:".concat(pileNo);
|
||||
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
||||
R<Object> r = R.ok();
|
||||
if (cachePile == null) {
|
||||
return R.fail("充电桩未注册");
|
||||
}
|
||||
String status = cachePile.get("status").toString();
|
||||
if (!REGISTERED.equals(status)) {
|
||||
return R.fail("充电桩离线");
|
||||
}
|
||||
R<Object> r = checkPile(cachePile);
|
||||
if (r.getCode() == 200) {
|
||||
Long stationId = (Long) cachePile.get("stationId"); //todo
|
||||
ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(stationId.toString()));
|
||||
Long stationRateModelId = cacheStation.getRateModelId();
|
||||
Long pileRateModelId = (Long) cachePile.get("rateModelId");
|
||||
if (pileRateModelId == null) {
|
||||
pileRateModelId = stationRateModelId;
|
||||
}
|
||||
cachePile.put("rateModelId", pileRateModelId);
|
||||
if (!pileRateModelId.equals(stationRateModelId)) {
|
||||
if (cachePile.get("status").toString().equals(REGISTERED)) {
|
||||
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString()));
|
||||
String rateModel = RateModelRequestLogic.translate(cacheRateModel);
|
||||
String rateModelMsg = "680E0000000A".concat(pileNo)
|
||||
.concat(String.format("%04X", stationRateModelId))
|
||||
.concat(rateModel)
|
||||
.concat(ServiceResult.HEX_OK);
|
||||
rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel));
|
||||
ClientHandler handler = getHandler(pileNo);
|
||||
if (handler != null) {
|
||||
try {
|
||||
handler.sendClientBinary(HexUtils.toBytes(rateModelMsg));
|
||||
r = R.ok("余额更新已下发");
|
||||
} catch (IOException e) {
|
||||
r = R.fail("余额更新下发失败:".concat(e.getMessage()));
|
||||
}
|
||||
} else {
|
||||
r = R.fail("费率模型下发失败,充电桩离线");
|
||||
}
|
||||
} else {
|
||||
r = R.fail("充电桩离线,余额更新下发失败");
|
||||
}
|
||||
} else {
|
||||
String svcSrv = (String) cachePile.get("svcSrv");
|
||||
JSONObject json = (JSONObject) JSON.toJSON(startChargingData);
|
||||
String response = HttpUtils.post(fmt(svcSrv).concat("/native/charging/start"), json);
|
||||
JSONObject json = (JSONObject) JSON.toJSON(balanceRefreshData);
|
||||
String response = HttpUtils.post(fmt(svcSrv).concat("/native/charging/balance/refresh"), json);
|
||||
r = getRR(response);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private R<Object> getRR(String response) {
|
||||
|
||||
R<Object> r;
|
||||
JSONObject responseJson = (JSONObject) JSON.parse(response);
|
||||
int code = responseJson.getInteger("code");
|
||||
if (code != 200) {
|
||||
@ -101,8 +70,6 @@ public class ChargingController {
|
||||
} else {
|
||||
r = R.ok(responseJson.get("data"), responseJson.getString("msg"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -112,17 +79,10 @@ public class ChargingController {
|
||||
String pileNo = startChargingData.getPileNo();
|
||||
String pkey = "pile:".concat(pileNo);
|
||||
Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
|
||||
R<Object> r = R.ok();
|
||||
if (cachePile == null) {
|
||||
return R.fail("充电桩未注册");
|
||||
}
|
||||
String status = cachePile.get("status").toString();
|
||||
if (!REGISTERED.equals(status)) {
|
||||
return R.fail("充电桩离线");
|
||||
}
|
||||
R<Object> r = checkPile(cachePile);
|
||||
if (r.getCode() == 200) {
|
||||
String svcSrv = (String) cachePile.get("svcSrv");
|
||||
Long stationId = (Long) cachePile.get("stationId"); //todo
|
||||
Long stationId = (Long) cachePile.get("stationId");
|
||||
ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(stationId.toString()));
|
||||
Long stationRateModelId = cacheStation.getRateModelId();
|
||||
Long pileRateModelId = (Long) cachePile.get("rateModelId");
|
||||
@ -131,7 +91,10 @@ public class ChargingController {
|
||||
if (cachePile.get("status").toString().equals(REGISTERED)) {
|
||||
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString()));
|
||||
String rateModel = RateModelRequestLogic.translate(cacheRateModel);
|
||||
String rateModelMsg = "680E0000000A".concat(pileNo)
|
||||
String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId());
|
||||
String skey = gunkey.concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
String rateModelMsg = "680E".concat(seq).concat("000A").concat(pileNo)
|
||||
.concat(String.format("%04X", stationRateModelId))
|
||||
.concat(rateModel)
|
||||
.concat(ServiceResult.HEX_OK);
|
||||
@ -151,18 +114,24 @@ public class ChargingController {
|
||||
} else {
|
||||
JSONObject json = (JSONObject) JSON.toJSON(startChargingData);
|
||||
String response = HttpUtils.post(fmt(svcSrv).concat("/native/charging/start"), json);
|
||||
JSONObject responseJson = (JSONObject) JSON.parse(response);
|
||||
int code = responseJson.getInteger("code");
|
||||
if (code != 200) {
|
||||
r = R.fail(code, responseJson.getString("msg"));
|
||||
} else {
|
||||
r = R.ok(responseJson.get("data"), responseJson.getString("msg"));
|
||||
}
|
||||
r = getRR(response);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private R<Object> checkPile(Map<String, Object> cachePile) {
|
||||
|
||||
if (cachePile == null) {
|
||||
return R.fail("充电桩未注册");
|
||||
}
|
||||
String status = cachePile.get("status").toString();
|
||||
if (!REGISTERED.equals(status)) {
|
||||
return R.fail("充电桩离线");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PutMapping("charging/stop/{pileNo}/{gunId}/{version}")
|
||||
public Object stopCharging(@PathVariable("pileNo") String pileNo, @PathVariable("gunId") String gunId, @PathVariable("version") String version) {
|
||||
|
||||
@ -183,13 +152,7 @@ public class ChargingController {
|
||||
.concat(pileNo).concat("/")
|
||||
.concat(gunId).concat("/")
|
||||
.concat(version));
|
||||
JSONObject responseJson = (JSONObject) JSON.parse(response);
|
||||
int code = responseJson.getInteger("code");
|
||||
if (code != 200) {
|
||||
r = R.fail(code, responseJson.getString("msg"));
|
||||
} else {
|
||||
r = R.ok(responseJson.get("data"), responseJson.getString("msg"));
|
||||
}
|
||||
r = getRR(response);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@ -200,6 +163,32 @@ public class ChargingController {
|
||||
return "http://".concat(split[0]).concat(":").concat(split[1]);
|
||||
}
|
||||
|
||||
@PostMapping("native/charging/balance/refresh")
|
||||
public Object nativeRefreshBalance(@Validated @RequestBody StartChargingData refreshBalanceData) {
|
||||
|
||||
String pileNo = refreshBalanceData.getPileNo();
|
||||
String gunkey = "gun:".concat(pileNo).concat(refreshBalanceData.getGunId());
|
||||
String skey = gunkey.concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
String refreshBalanceMsg = "6817".concat(seq).concat("0042").concat(pileNo)
|
||||
.concat(refreshBalanceData.getPhysicCardNo())
|
||||
.concat(HexUtils.toHexInt(refreshBalanceData.getBalance()));
|
||||
refreshBalanceMsg = refreshBalanceMsg.concat(CRCCalculator.calcCrc(refreshBalanceMsg));
|
||||
ClientHandler handler = getHandler(pileNo);
|
||||
R<Object> r;
|
||||
if (handler != null) {
|
||||
try {
|
||||
handler.sendClientBinary(HexUtils.toBytes(refreshBalanceMsg));
|
||||
r = R.ok("余额更新已下发");
|
||||
} catch (IOException e) {
|
||||
r = R.fail("余额更新下发失败:".concat(e.getMessage()));
|
||||
}
|
||||
} else {
|
||||
r = R.fail("费率模型下发失败,充电桩离线");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@PostMapping("native/charging/start")
|
||||
public Object nativeStartCharging(@Validated @RequestBody StartChargingData startChargingData) {
|
||||
|
||||
@ -246,8 +235,8 @@ public class ChargingController {
|
||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getOrderNo()));
|
||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getPileNo()));
|
||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getGunId()));
|
||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getLogicCardNo()));
|
||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getPhysicCardNo()));
|
||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(String.format("%016X", Long.parseLong(startChargingData.getLogicCardNo(), 16))));
|
||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(String.format("%016X", Long.parseLong(startChargingData.getPhysicCardNo(), 16))));
|
||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(toHexInt(startChargingData.getBalance())));
|
||||
} else {
|
||||
// not defined or implemented yet
|
||||
@ -271,4 +260,5 @@ public class ChargingController {
|
||||
log.info("stop charging, send msg to terminal ({}{}) >>>> {}", pileNo, gunId, msg);
|
||||
return HexUtils.toBytes(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,7 +4,10 @@ import com.xhpc.common.api.dto.ChargingStationDto;
|
||||
import com.xhpc.common.core.domain.R;
|
||||
import com.xhpc.pp.utils.security.HexUtils;
|
||||
import org.quickserver.net.server.ClientHandler;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
@ -65,13 +68,6 @@ public class PileController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("terminal/{terminalSn}/status")
|
||||
public Object terminalStatus(@PathVariable("terminalSn") String terminalSn) {
|
||||
|
||||
// todo
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PostMapping("native/pile/{pileNo}/rateModel")
|
||||
public Object configRateModel(@PathVariable("pileNo") String pileNo, @RequestBody String msg) {
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.common.data.redis.SeqUtil.seqHex;
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
|
||||
@Lazy
|
||||
@ -32,7 +33,9 @@ public class HBLogic implements ServiceLogic {
|
||||
Map<String, Integer> cacheGun = REDIS.getCacheMap(gunkey);
|
||||
cacheGun.put("status", gunStatusInt);
|
||||
REDIS.setCacheMap(gunkey, cacheGun);
|
||||
String resultStr = "680D00000004".concat(pileNo).concat(gunId).concat(ServiceResult.HEX_OK);
|
||||
String skey = gunkey.concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
String resultStr = "680D".concat(seq).concat("0004").concat(pileNo).concat(gunId).concat(ServiceResult.HEX_OK);
|
||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.common.data.redis.SeqUtil.seqHex;
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
import static com.xhpc.pp.utils.security.CacheDataUtils.reflectTranslate;
|
||||
|
||||
@ -38,7 +39,10 @@ public class OrderDataLogic implements ServiceLogic {
|
||||
cacheOrder.put("status", "完成结算");
|
||||
cacheOrder.put("orderData", translate(orderData));
|
||||
REDIS.setCacheMap(orderkey, cacheOrder);
|
||||
String resultStr = "681500000040".concat(orderNo).concat(ServiceResult.HEX_OK);
|
||||
String gunkey = "gun:".concat(orderData.getPileNo()).concat(orderData.getGunId());
|
||||
String skey = gunkey.concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
String resultStr = "6815".concat(seq).concat("0040").concat(orderNo).concat(ServiceResult.HEX_OK);
|
||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.common.data.redis.SeqUtil.seqHex;
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
import static com.xhpc.pp.utils.security.HexUtils.toHexInt;
|
||||
|
||||
@ -42,7 +43,9 @@ public class RateModelRequestLogic implements ServiceLogic {
|
||||
}
|
||||
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(rateModelId.toString()));
|
||||
String rateModel = translate(cacheRateModel);
|
||||
String resultStr = "680E0000000A".concat(pileNo)
|
||||
String skey = "pile:".concat(pileNo).concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
String resultStr = "680E".concat(seq).concat("000A").concat(pileNo)
|
||||
.concat(String.format("%04X", rateModelId))
|
||||
.concat(rateModel)
|
||||
.concat(ServiceResult.HEX_OK);
|
||||
|
||||
@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.common.data.redis.SeqUtil.seqHex;
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
|
||||
@Lazy
|
||||
@ -37,7 +38,9 @@ public class RateModelValidateLogic implements ServiceLogic {
|
||||
hexCode = ServiceResult.HEX_FAIL;
|
||||
resultCode = ServiceResult.FAIL;
|
||||
}
|
||||
String resultStr = "680E00000006".concat(pileNo).concat(String.format("%04X", csRateModelId)).concat(hexCode);
|
||||
String skey = "pile:".concat(pileNo).concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
String resultStr = "680E".concat(seq).concat("0006").concat(pileNo).concat(String.format("%04X", csRateModelId)).concat(hexCode);
|
||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.xhpc.common.data.redis.SeqUtil.seqHex;
|
||||
import static com.xhpc.pp.config.EarlierBeanConf.getLocalIPAndPort;
|
||||
import static com.xhpc.pp.server.ChargingPileServer.REDIS;
|
||||
|
||||
@ -59,7 +60,9 @@ public class RegisterLogic implements ServiceLogic {
|
||||
cachePileGunSvcSrv(pileNo);
|
||||
log.info("pile (re)registered ({}) ", pileNo);
|
||||
}
|
||||
String resultStr = "680C00000002".concat(pileNo).concat(hexCode);
|
||||
String skey = "pile:".concat(pileNo).concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
String resultStr = "680C".concat(seq).concat("0002").concat(pileNo).concat(hexCode);
|
||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ public class HexUtils {
|
||||
*/
|
||||
private static final char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
public static String toHexInt(Integer dec) {
|
||||
public static String toHexInt(long dec) {
|
||||
|
||||
return toHex(toIntBytes(String.format("%08d", dec), 8));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user