diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java index fd214510..0213feda 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStartChargeController.java @@ -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); diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationStatusController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationStatusController.java index 70998213..08930d52 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationStatusController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationStatusController.java @@ -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 commonRequest) throws Exception { StationStatusRequest stationStatusRequest = JSONUtil.readParams(commonRequest.getData(), StationStatusRequest.class); - String stationIDs[] = stationStatusRequest.getStationIds(); - String data = ""; - List stationStatusInfo = JSONUtil.readParamsList(data, StationStatusInfo.class); + String[] stationIDs = stationStatusRequest.getStationIds(); + List stationStatusInfos = new ArrayList<>(); + //Loading data through redis at first. + Collection guns = REDIS.keys("gun:*"); + List gunsNewList = new ArrayList<>(); + for (String value : guns) { + gunsNewList.add(value.substring(4)); + } + List gunsIds = new ArrayList<>(); + for (String value : gunsNewList) { + if (value.length() == 16) { + gunsIds.add(value); + } + } + Map 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 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("");