Accomplising the query_station_status.
This commit is contained in:
parent
c2e084016b
commit
17846ec1c9
@ -46,7 +46,7 @@ public class QueryStartChargeController {
|
|||||||
startChargeResponse.setStartChargeSeqStat(5);
|
startChargeResponse.setStartChargeSeqStat(5);
|
||||||
resp.setMsg("This 3rd has no token");
|
resp.setMsg("This 3rd has no token");
|
||||||
} else {
|
} else {
|
||||||
//todo invoke a order making interface(finished);
|
// invoke a order making interface(finished);
|
||||||
R res = pileOrderService.pileStartUpBy3rd(startChargeSeq, startChargeRequest.getDriverId(), startChargeRequest.getChargingAmt(), startChargeRequest.getPlateNum(), 0, connectorID);
|
R res = pileOrderService.pileStartUpBy3rd(startChargeSeq, startChargeRequest.getDriverId(), startChargeRequest.getChargingAmt(), startChargeRequest.getPlateNum(), 0, connectorID);
|
||||||
startChargeResponse.setStartChargeSeq(startChargeSeq);
|
startChargeResponse.setStartChargeSeq(startChargeSeq);
|
||||||
startChargeResponse.setConnectorID(connectorID);
|
startChargeResponse.setConnectorID(connectorID);
|
||||||
|
|||||||
@ -1,26 +1,78 @@
|
|||||||
package com.xhpc.evcs.api;
|
package com.xhpc.evcs.api;
|
||||||
|
|
||||||
import com.xhpc.evcs.dto.*;
|
import com.xhpc.evcs.dto.*;
|
||||||
|
import com.xhpc.evcs.jpa.XhpcTerminalRepository;
|
||||||
import com.xhpc.evcs.utils.JSONUtil;
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static cn.hutool.core.util.NumberUtil.isInteger;
|
||||||
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class QueryStationStatusController extends CoreDispatcher {
|
public class QueryStationStatusController extends CoreDispatcher {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private XhpcTerminalRepository xhpcTerminalRepository;
|
||||||
|
|
||||||
@PostMapping("/v1/query_station_status")
|
@PostMapping("/v1/query_station_status")
|
||||||
public CommonResponse queryStationsInfo(@RequestBody CommonRequest<StationStatusRequest> commonRequest) throws Exception {
|
public CommonResponse queryStationsInfo(@RequestBody CommonRequest<StationStatusRequest> commonRequest) throws Exception {
|
||||||
|
|
||||||
StationStatusRequest stationStatusRequest = JSONUtil.readParams(commonRequest.getData(), StationStatusRequest.class);
|
StationStatusRequest stationStatusRequest = JSONUtil.readParams(commonRequest.getData(), StationStatusRequest.class);
|
||||||
String stationIDs[] = stationStatusRequest.getStationIds();
|
String[] stationIDs = stationStatusRequest.getStationIds();
|
||||||
String data = "";
|
List<StationStatusInfo> stationStatusInfos = new ArrayList<>();
|
||||||
List<StationStatusInfo> stationStatusInfo = JSONUtil.readParamsList(data, StationStatusInfo.class);
|
//Loading data through redis at first.
|
||||||
|
Collection<String> guns = REDIS.keys("gun:*");
|
||||||
|
List<String> gunsNewList = new ArrayList<>();
|
||||||
|
for (String value : guns) {
|
||||||
|
gunsNewList.add(value.substring(4));
|
||||||
|
}
|
||||||
|
List<String> gunsIds = new ArrayList<>();
|
||||||
|
for (String value : gunsNewList) {
|
||||||
|
if (value.length() == 16) {
|
||||||
|
gunsIds.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String, Integer> statusMap = new HashMap<>();
|
||||||
|
String[] keys = {"离线", "空闲", "故障"};
|
||||||
|
Integer[] values = {0, 1, 255};
|
||||||
|
for (int i = 0; i < keys.length; i++) {
|
||||||
|
statusMap.put(keys[i], values[i]);
|
||||||
|
}
|
||||||
|
for (String stationID : stationIDs) {
|
||||||
|
boolean existsGun = false;
|
||||||
|
List<ConnectorStatusInfo> connectorStatusInfos = new ArrayList<>();
|
||||||
|
for (String value : gunsIds) {
|
||||||
|
if (stationID.equals(value.substring(0, 12))) {
|
||||||
|
existsGun = true;
|
||||||
|
ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo();
|
||||||
|
Object status = REDIS.getCacheMapValue("gun:" + value, "status");
|
||||||
|
if (isInteger(status.toString())) {
|
||||||
|
connectorStatusInfo.setStatus(3);
|
||||||
|
} else {
|
||||||
|
connectorStatusInfo.setStatus(statusMap.get(status));
|
||||||
|
}
|
||||||
|
connectorStatusInfo.setConnectorID(value);
|
||||||
|
connectorStatusInfos.add(connectorStatusInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (existsGun) {
|
||||||
|
StationStatusInfo stationStatusInfo = new StationStatusInfo();
|
||||||
|
stationStatusInfo.setStationID(stationID);
|
||||||
|
stationStatusInfo.setConnectorStatusInfos(connectorStatusInfos);
|
||||||
|
stationStatusInfos.add(stationStatusInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StationStatusInfoWrapper stationStatusInfoWrappers = new StationStatusInfoWrapper();
|
StationStatusInfoWrapper stationStatusInfoWrappers = new StationStatusInfoWrapper();
|
||||||
stationStatusInfoWrappers.setTotal(stationStatusInfo.size());
|
stationStatusInfoWrappers.setTotal(stationStatusInfos.size());
|
||||||
stationStatusInfoWrappers.setStationStatusInfos(stationStatusInfo);
|
if (stationStatusInfos.size() != 0) {
|
||||||
|
stationStatusInfoWrappers.setStationStatusInfos(stationStatusInfos);
|
||||||
|
}
|
||||||
CommonResponse resp = new CommonResponse();
|
CommonResponse resp = new CommonResponse();
|
||||||
resp.setRet("0");
|
resp.setRet("0");
|
||||||
resp.setMsg("");
|
resp.setMsg("");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user