diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java index 0a6daecd..6d021c32 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java @@ -809,9 +809,18 @@ public AjaxResult trafficFlowAtTollStationEntranceHour(String startDate, String */ @ApiOperation("收费站日累计车流辆") @GetMapping("/history/trafficFlowAtToll") - public AjaxResult trafficFlowAtToll() throws HttpException, IOException { + public AjaxResult trafficFlowAtToll(String startDate) throws HttpException, IOException { // 调用服务层方法,获取当前交通指标数据 - int a = dcTrafficStatisticsService.trafficFlowAtToll(); + int a = dcTrafficStatisticsService.trafficFlowAtToll(startDate); + // 将获取到的交通指标数据封装为成功的结果并返回 + return AjaxResult.success(a); + } + + @ApiOperation("收费站昨日累计车流辆") + @GetMapping("/history/yesterdayTrafficFlowAtToll") + public AjaxResult yesterdayTrafficFlowAtToll(String startDate) throws HttpException, IOException { + // 调用服务层方法,获取当前交通指标数据 + int a = dcTrafficStatisticsService.yesterdayTrafficFlowAtToll(startDate); // 将获取到的交通指标数据封装为成功的结果并返回 return AjaxResult.success(a); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java b/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java index 70e828c3..32b6fe4a 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java @@ -62,6 +62,7 @@ public interface IDcTrafficStatisticsService { * 各收费站日累计车流辆 * @return */ - int trafficFlowAtToll()throws HttpException, IOException; + int trafficFlowAtToll(String startDate)throws HttpException, IOException; + int yesterdayTrafficFlowAtToll(String startDate)throws HttpException, IOException; } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java index 0700524d..1bedb46e 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java @@ -1248,10 +1248,8 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi * @return */ @Override - public int trafficFlowAtToll() throws HttpException, IOException { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue()); - LocalDate currentDate = LocalDate.now(); - String startDate = currentDate.format(formatter); + public int trafficFlowAtToll(String startDate) throws HttpException, IOException { + try { Response response = getResponseTrafficFlowAtToll(startDate, UniversalEnum.ONE.getValue()); Response responseTwo = getResponseTrafficFlowAtToll(startDate, UniversalEnum.TWO.getValue()); @@ -1290,6 +1288,52 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi } + /** + * 昨日车流量 + * @param startDate + * @return + * @throws HttpException + * @throws IOException + */ + @Override + public int yesterdayTrafficFlowAtToll(String startDate) throws HttpException, IOException { + try { + Response response = getResponseTrafficFlowAtToll(startDate, UniversalEnum.ONE.getValue()); + Response responseTwo = getResponseTrafficFlowAtToll(startDate, UniversalEnum.TWO.getValue()); + ResponseBody body = response.body(); + ResponseBody bodyTwo = responseTwo.body(); + Integer totalFlow1 = UniversalEnum.ZERO.getNumber(); + Integer totalFlow2 = UniversalEnum.ZERO.getNumber(); + if (body != null) { + String jsonString = body.string(); + if (JSON.isValidArray(jsonString)) { + JSONArray jsonArray = JSON.parseArray(jsonString); + for (Object item : jsonArray) { + JSONObject jsonObject = (JSONObject) item; + totalFlow1 = totalFlow1 + jsonObject.getInteger("total_flow"); + } + } + } + if (bodyTwo != null) { + String jsonString = bodyTwo.string(); + if (JSON.isValidArray(jsonString)) { + JSONArray jsonArray = JSON.parseArray(jsonString); + for (Object item : jsonArray) { + JSONObject jsonObject = (JSONObject) item; + totalFlow2 = totalFlow2 + jsonObject.getInteger("total_flow"); + } + } + } + + return totalFlow1 + totalFlow2; + } catch (IOException e) { + // 处理异常 + e.printStackTrace(); + return UniversalEnum.ZERO.getNumber(); + } + + } + private Response getResponseTrafficFlowAtToll(String startDate, String stationType) throws HttpException, IOException { // 创建OkHttpClient.Builder实例 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();