Accomplising the query_station_status.

This commit is contained in:
little-cat-sweet 2021-10-28 11:09:04 +08:00
parent c2e084016b
commit 17846ec1c9
2 changed files with 59 additions and 7 deletions

View File

@ -46,7 +46,7 @@ public class QueryStartChargeController {
startChargeResponse.setStartChargeSeqStat(5);
resp.setMsg("This 3rd has no token");
} 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);
startChargeResponse.setStartChargeSeq(startChargeSeq);
startChargeResponse.setConnectorID(connectorID);

View File

@ -1,26 +1,78 @@
package com.xhpc.evcs.api;
import com.xhpc.evcs.dto.*;
import com.xhpc.evcs.jpa.XhpcTerminalRepository;
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.RequestBody;
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
public class QueryStationStatusController extends CoreDispatcher {
@Autowired
private XhpcTerminalRepository xhpcTerminalRepository;
@PostMapping("/v1/query_station_status")
public CommonResponse queryStationsInfo(@RequestBody CommonRequest<StationStatusRequest> commonRequest) throws Exception {
StationStatusRequest stationStatusRequest = JSONUtil.readParams(commonRequest.getData(), StationStatusRequest.class);
String stationIDs[] = stationStatusRequest.getStationIds();
String data = "";
List<StationStatusInfo> stationStatusInfo = JSONUtil.readParamsList(data, StationStatusInfo.class);
String[] stationIDs = stationStatusRequest.getStationIds();
List<StationStatusInfo> stationStatusInfos = new ArrayList<>();
//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();
stationStatusInfoWrappers.setTotal(stationStatusInfo.size());
stationStatusInfoWrappers.setStationStatusInfos(stationStatusInfo);
stationStatusInfoWrappers.setTotal(stationStatusInfos.size());
if (stationStatusInfos.size() != 0) {
stationStatusInfoWrappers.setStationStatusInfos(stationStatusInfos);
}
CommonResponse resp = new CommonResponse();
resp.setRet("0");
resp.setMsg("");