增加平台远程重启桩协议
This commit is contained in:
parent
9c60a1a5a5
commit
a11070cd04
@ -186,6 +186,21 @@ public class XhpcChargingPileController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
// 远程重启桩
|
||||
@GetMapping("/restart")
|
||||
public AjaxResult pileRestart(String serialNumber) {
|
||||
|
||||
if(serialNumber==null || "".equals(serialNumber)){
|
||||
return AjaxResult.error("桩号为空");
|
||||
}
|
||||
R r = powerPileService.pileRestart(serialNumber);
|
||||
if(r.getCode() !=200){
|
||||
return AjaxResult.error(r.getMsg());
|
||||
}
|
||||
return AjaxResult.success(r.getMsg());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/configRmReplyMessage")
|
||||
public AjaxResult configRmReplyMessage(String serialNumber) {
|
||||
if(serialNumber==null || "".equals(serialNumber)){
|
||||
|
||||
@ -46,4 +46,8 @@ public interface PowerPileService {
|
||||
|
||||
@PostMapping("/pile/{pileNo}/softwareUpgrade")
|
||||
R pileSoftwareUpgrade(@PathVariable("pileNo") String pileNo);
|
||||
|
||||
|
||||
@PostMapping("/pile/{pileNo}/restart")
|
||||
R pileRestart(@PathVariable("pileNo") String pileNo);
|
||||
}
|
||||
|
||||
@ -69,6 +69,12 @@ public class PowerPileFallbackFactory implements FallbackFactory<PowerPileServic
|
||||
|
||||
return R.fail("更新桩程序失败:" + cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R pileRestart(String pileNo) {
|
||||
|
||||
return R.fail("重启桩程序失败:" + cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import com.xhpc.common.core.utils.HttpUtils;
|
||||
import com.xhpc.common.enums.StationDeviceEnum;
|
||||
import com.xhpc.pp.domain.XhpcDeviceMessage;
|
||||
import com.xhpc.pp.logic.RateModelRequestLogic;
|
||||
import com.xhpc.pp.logic.RemoteRestartDataLogic;
|
||||
import com.xhpc.pp.logic.RemoteUpgradeDataLogic;
|
||||
import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
|
||||
import com.xhpc.pp.utils.HexUtils;
|
||||
@ -204,6 +205,68 @@ public class PileController {
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("pile/{pileNo}/restart")
|
||||
public R pileRestart(@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("/restart"));
|
||||
r = getRR(response);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("native/pile/{pileNo}/restart")
|
||||
public R nativePileRestart(@PathVariable("pileNo") String pileNo) {
|
||||
|
||||
ClientHandler handler = getHandler(pileNo);
|
||||
|
||||
R r = R.fail("充电桩重启失败,充电桩未注册.");
|
||||
if (handler != null && handler.isOpen()) {
|
||||
if (!handler.isOpen()) {
|
||||
log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo);
|
||||
removeHandler(pileNo);
|
||||
r = R.fail("充电桩连接已断开,请稍后再试.");
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
int runFlag = charging ? 2: 1;
|
||||
try {
|
||||
String rsmsg = RemoteRestartDataLogic.translate(pileNo, runFlag);
|
||||
|
||||
handler.sendClientBinary(HexUtils.toBytes(rsmsg));
|
||||
r = R.ok("充电桩重启下发成功.");
|
||||
|
||||
XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage();
|
||||
deviceMessage.setType(StationDeviceEnum.PILE.getCode());
|
||||
deviceMessage.setSerialNumber(pileNo);
|
||||
deviceMessage.setRemark("充电桩主动下发远程重启");
|
||||
deviceMessage.setStatus(0);
|
||||
deviceMessage.setContent(rsmsg);
|
||||
deviceMessageMapper.insertByDomain(deviceMessage);
|
||||
|
||||
} catch (Exception e) {
|
||||
r = R.fail("充电桩重启下发失败,请重试.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("pile/{pileNo}/softwareUpgrade")
|
||||
public R pileSoftwareUpgrade(@PathVariable("pileNo") String pileNo) {
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
|
||||
import com.xhpc.pp.tx.ServiceParameter;
|
||||
import com.xhpc.pp.tx.ServiceResult;
|
||||
import com.xhpc.pp.tx.logic.ServiceLogic;
|
||||
import com.xhpc.pp.utils.HexUtils;
|
||||
import com.xhpc.pp.utils.security.CRCCalculator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -106,4 +105,10 @@ public class RegisterLogic implements ServiceLogic {
|
||||
REDIS.setCacheSet(svcSrvKey, svcPileGuns);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String version = new String(toBytes("332E340000000000"));
|
||||
|
||||
System.out.println("version: " + version);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
package com.xhpc.pp.logic;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.xhpc.common.enums.StationDeviceEnum;
|
||||
import com.xhpc.pp.domain.XhpcDeviceMessage;
|
||||
import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
|
||||
import com.xhpc.pp.tx.ServiceParameter;
|
||||
import com.xhpc.pp.tx.ServiceResult;
|
||||
import com.xhpc.pp.tx.logic.ServiceLogic;
|
||||
import com.xhpc.pp.utils.HexUtils;
|
||||
import com.xhpc.pp.utils.security.CRCCalculator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||
import static com.xhpc.common.data.redis.StaticBeanUtil.seqHex;
|
||||
|
||||
@Lazy
|
||||
@Component("RemoteRestartDataLogic")
|
||||
public class RemoteRestartDataLogic implements ServiceLogic {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteRestartDataLogic.class);
|
||||
|
||||
@Resource
|
||||
XhpcDeviceMessageMapper deviceMessageMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public ServiceResult service(ServiceParameter sp) throws Exception {
|
||||
Map<String, Object> req = sp.getParameters();
|
||||
String pileNo = (String) req.get("pileNo");
|
||||
Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileNo));
|
||||
if(!"已注册".equals(cachePile.get("status").toString())){
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectNode json = mapper.createObjectNode();
|
||||
json.put("error", "桩未注册");
|
||||
return new ServiceResult(null, ServiceResult.FAIL, json);
|
||||
}
|
||||
|
||||
String resultStr = translate(pileNo, 2);
|
||||
|
||||
String remark = "充电桩主动下发远程重启";
|
||||
XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage();
|
||||
deviceMessage.setType(StationDeviceEnum.PILE.getCode());
|
||||
deviceMessage.setSerialNumber(sp.getPileNo());
|
||||
deviceMessage.setRemark(remark);
|
||||
deviceMessage.setStatus(0);
|
||||
deviceMessage.setContent(resultStr);
|
||||
deviceMessageMapper.insertByDomain(deviceMessage);
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
|
||||
}
|
||||
|
||||
public static String translate(String pileNo, int runFlag) {
|
||||
|
||||
String skey = "pile:".concat(pileNo).concat(".seqhex");
|
||||
|
||||
String resultStr = "680C".concat(seqHex(skey)).concat("0092")
|
||||
.concat(pileNo).concat(String.format("%02x", runFlag));
|
||||
|
||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user