|
|
@@ -0,0 +1,253 @@
|
|
|
+package com.zksy.visualization.controller;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.zksy.common.core.domain.Result;
|
|
|
+import com.zksy.visualization.config.IccConfigProperty;
|
|
|
+import com.zksy.visualization.domain.request.ParkingListRequest;
|
|
|
+import com.zksy.visualization.domain.response.*;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Administrator
|
|
|
+ * @version 1.0
|
|
|
+ * @project dh-server-micro
|
|
|
+ * @description 停车管理
|
|
|
+ * @date 2024/12/16 10:58:15
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@Api(tags = "停车管理", description = "停车管理")
|
|
|
+@RequestMapping("/parkingManage")
|
|
|
+@Slf4j
|
|
|
+public class ParkingManageController {
|
|
|
+ @Autowired
|
|
|
+ private OkHttpClient httpClient;
|
|
|
+ @Autowired
|
|
|
+ private IccConfigProperty iccConfigProperty;
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate<String,String> redisTemplate;
|
|
|
+
|
|
|
+ @ApiOperation(value = "停车场概览(用户总览/今日收款占比/今日泊位概况)")
|
|
|
+ @GetMapping("/parkingLot")
|
|
|
+ public Result parkingLot(){
|
|
|
+ String authorization = redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .get("Authorization:" + iccConfigProperty.getUsername());
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/ipms/parkSurvey/platformDetail?noKeepAlive=true")
|
|
|
+ .addHeader("Authorization", authorization)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ Response response = httpClient.newCall(request).execute();
|
|
|
+ if(!response.isSuccessful()){
|
|
|
+ return Result.error("查询停车场概览失败");
|
|
|
+ }
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String responseString = responseBody.string();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
+ JsonNode success = rootNode.path("success");
|
|
|
+ if(success.isBoolean() && success.asBoolean()) {
|
|
|
+ JsonNode dataNode = rootNode.path("data");
|
|
|
+ if (dataNode.isObject()) {
|
|
|
+ ParkingOverviewResponse parkingOverviewResponse = objectMapper.treeToValue(dataNode, ParkingOverviewResponse.class);
|
|
|
+ return Result.ok(parkingOverviewResponse);
|
|
|
+ } else {
|
|
|
+ return Result.ok(null);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ JsonNode errMsgNode = rootNode.path("errMsg");
|
|
|
+ String errMsg = errMsgNode.isTextual() ? errMsgNode.asText() : "未知错误";
|
|
|
+ return Result.error(errMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("error:{}", e);
|
|
|
+ }
|
|
|
+ return Result.error("查询停车场概览失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "收款统计")
|
|
|
+ @GetMapping("/collectionStatistics")
|
|
|
+ public Result collectionStatistics(){
|
|
|
+ String authorization = redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .get("Authorization:" + iccConfigProperty.getUsername());
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/ipms/parkSurvey/todaySurvey?type=0")
|
|
|
+ .addHeader("Authorization", authorization)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ Response response = httpClient.newCall(request).execute();
|
|
|
+ if(!response.isSuccessful()){
|
|
|
+ return Result.error("查询收款统计失败");
|
|
|
+ }
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String responseString = responseBody.string();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
+ JsonNode success = rootNode.path("success");
|
|
|
+ if(success.isBoolean() && success.asBoolean()) {
|
|
|
+ JsonNode dataNode = rootNode.path("data");
|
|
|
+ if (dataNode.isObject()) {
|
|
|
+ CollectionStatisticsResponse parkingOverviewResponse = objectMapper.treeToValue(dataNode, CollectionStatisticsResponse.class);
|
|
|
+ return Result.ok(parkingOverviewResponse);
|
|
|
+ } else {
|
|
|
+ return Result.ok(null);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ JsonNode errMsgNode = rootNode.path("errMsg");
|
|
|
+ String errMsg = errMsgNode.isTextual() ? errMsgNode.asText() : "未知错误";
|
|
|
+ return Result.error(errMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询收款统计失败:{}", e);
|
|
|
+ }
|
|
|
+ return Result.error("查询收款统计失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "车流统计")
|
|
|
+ @GetMapping("/trafficStatistics")
|
|
|
+ public Result TrafficStatistics(){
|
|
|
+ String authorization = redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .get("Authorization:" + iccConfigProperty.getUsername());
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/ipms/parkSurvey/carInOutSurvey?type=0")
|
|
|
+ .addHeader("Authorization", authorization)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ Response response = httpClient.newCall(request).execute();
|
|
|
+ if(!response.isSuccessful()){
|
|
|
+ return Result.error("查询车流统计失败");
|
|
|
+ }
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String responseString = responseBody.string();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
+ JsonNode success = rootNode.path("success");
|
|
|
+ if(success.isBoolean() && success.asBoolean()) {
|
|
|
+ JsonNode dataNode = rootNode.path("data");
|
|
|
+ if (dataNode.isObject()) {
|
|
|
+ TrafficStatisticsResponse parkingOverviewResponse = objectMapper.treeToValue(dataNode, TrafficStatisticsResponse.class);
|
|
|
+ return Result.ok(parkingOverviewResponse);
|
|
|
+ } else {
|
|
|
+ return Result.ok(null);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ JsonNode errMsgNode = rootNode.path("errMsg");
|
|
|
+ String errMsg = errMsgNode.isTextual() ? errMsgNode.asText() : "未知错误";
|
|
|
+ return Result.error(errMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询车流统计失败:{}", e);
|
|
|
+ }
|
|
|
+ return Result.error("查询车流统计失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询车场列表")
|
|
|
+ @GetMapping("/parkingList")
|
|
|
+ public Result ParkingList(ParkingListRequest parkingListRequest){
|
|
|
+ String authorization = redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .get("Authorization:" + iccConfigProperty.getUsername());
|
|
|
+ HttpUrl url = new HttpUrl.Builder()
|
|
|
+ .scheme("https")
|
|
|
+ .host(iccConfigProperty.getHost())
|
|
|
+ .addPathSegments("/evo-apigw/ipms/parkinglot/query")
|
|
|
+ .addQueryParameter("pageNum", String.valueOf(parkingListRequest.getPageNum()))
|
|
|
+ .addQueryParameter("pageSize",String.valueOf(parkingListRequest.getPageSize()))
|
|
|
+ .addQueryParameter("returnPage",String.valueOf(parkingListRequest.getReturnPage()))
|
|
|
+ .addQueryParameter("parkingLotFuzzy",parkingListRequest.getParkingLotFuzzy())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(url)
|
|
|
+ .addHeader("Authorization", authorization)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ Response response = httpClient.newCall(request).execute();
|
|
|
+ if(!response.isSuccessful()){
|
|
|
+ return Result.error("查询车场列表失败");
|
|
|
+ }
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String responseString = responseBody.string();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
+ JsonNode success = rootNode.path("success");
|
|
|
+ if(success.isBoolean() && success.asBoolean()) {
|
|
|
+ JsonNode dataNode = rootNode.path("data");
|
|
|
+ if (dataNode.isObject()) {
|
|
|
+ ParkingListResponse parkingListResponse = objectMapper.treeToValue(dataNode, ParkingListResponse.class);
|
|
|
+ return Result.ok(parkingListResponse);
|
|
|
+ } else {
|
|
|
+ return Result.ok(null);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ JsonNode errMsgNode = rootNode.path("errMsg");
|
|
|
+ String errMsg = errMsgNode.isTextual() ? errMsgNode.asText() : "未知错误";
|
|
|
+ return Result.error(errMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询车场列表失败:{}", e);
|
|
|
+ }
|
|
|
+ return Result.error("查询车场列表失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "车场余位信息")
|
|
|
+ @GetMapping("/parkingVacancy")
|
|
|
+ public Result ParkingVacancy(){
|
|
|
+ String authorization = redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .get("Authorization:" + iccConfigProperty.getUsername());
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/ipms/parkinglot/stat")
|
|
|
+ .addHeader("Authorization", authorization)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ Response response = httpClient.newCall(request).execute();
|
|
|
+ if(!response.isSuccessful()){
|
|
|
+ return Result.error("车场余位信息失败");
|
|
|
+ }
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String responseString = responseBody.string();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
+ JsonNode success = rootNode.path("success");
|
|
|
+ if(success.isBoolean() && success.asBoolean()) {
|
|
|
+ JsonNode dataNode = rootNode.path("data");
|
|
|
+ if (dataNode.isObject()) {
|
|
|
+ ParkingVacancyResponse parkingListResponse = objectMapper.treeToValue(dataNode, ParkingVacancyResponse.class);
|
|
|
+ return Result.ok(parkingListResponse);
|
|
|
+ } else {
|
|
|
+ return Result.ok(null);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ JsonNode errMsgNode = rootNode.path("errMsg");
|
|
|
+ String errMsg = errMsgNode.isTextual() ? errMsgNode.asText() : "未知错误";
|
|
|
+ return Result.error(errMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("车场余位信息失败:{}", e);
|
|
|
+ }
|
|
|
+ return Result.error("车场余位信息失败");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|