Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
wangsixiang 8 months ago
parent
commit
181743df6f
  1. 171
      ruoyi-common/src/test/java/OkhttpTest.java
  2. 24
      zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java
  3. 262
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  4. 4
      zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java
  5. 3
      zc-business/src/main/java/com/zc/business/service/impl/DcNoStakeWarningTableServiceImpl.java
  6. 247
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

171
ruoyi-common/src/test/java/OkhttpTest.java

@ -1,4 +1,7 @@
import com.ruoyi.common.utils.uuid.IdUtils; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zc.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.OkHttp;
import com.zc.common.core.httpclient.exception.HttpException; import com.zc.common.core.httpclient.exception.HttpException;
import com.zc.common.core.httpclient.request.RequestParams; import com.zc.common.core.httpclient.request.RequestParams;
@ -7,8 +10,18 @@ import okhttp3.Callback;
import okhttp3.Response; import okhttp3.Response;
import org.junit.Test; import org.junit.Test;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -19,6 +32,7 @@ public class OkhttpTest {
/** /**
* get 同步请求 * get 同步请求
*
* @throws HttpException * @throws HttpException
* @throws IOException * @throws IOException
*/ */
@ -47,6 +61,7 @@ public class OkhttpTest {
/** /**
* get 异步请求 * get 异步请求
*
* @throws HttpException * @throws HttpException
* @throws IOException * @throws IOException
*/ */
@ -56,21 +71,25 @@ public class OkhttpTest {
OkHttp okHttp = new OkHttp(); OkHttp okHttp = new OkHttp();
okHttp.url("https://www.baidu.com/") // 请求地址 okHttp.url("https://www.baidu.com/") // 请求地址
.data(new RequestParams("java", "okhttp")) // 请求参数 .data(new RequestParams("java", "okhttp")) // 请求参数
.get(new Callback() { .get(new Callback() {
// 请求失败回调 // 请求失败回调
@Override @Override
public void onFailure(Call call, IOException e) { } public void onFailure(Call call, IOException e) {
}
// 请求成功回调 // 请求成功回调
@Override @Override
public void onResponse(Call call, Response response) throws IOException { } public void onResponse(Call call, Response response) throws IOException {
}); // 请求方法 }
}); // 请求方法
} }
/** /**
* post 同步请求 * post 同步请求
*
* @throws HttpException * @throws HttpException
* @throws IOException * @throws IOException
*/ */
@ -98,6 +117,7 @@ public class OkhttpTest {
/** /**
* 文件 post 异步请求 * 文件 post 异步请求
*
* @throws HttpException * @throws HttpException
* @throws IOException * @throws IOException
*/ */
@ -111,20 +131,24 @@ public class OkhttpTest {
requestParams.put("data", data); requestParams.put("data", data);
okHttp.url("https://www.baidu.com/") // 请求地址 okHttp.url("https://www.baidu.com/") // 请求地址
.data(requestParams) // 请求参数 .data(requestParams) // 请求参数
.post(new Callback() { .post(new Callback() {
// 请求失败回调 // 请求失败回调
@Override @Override
public void onFailure(Call call, IOException e) { } public void onFailure(Call call, IOException e) {
}
// 请求成功回调
@Override // 请求成功回调
public void onResponse(Call call, Response response) throws IOException { } @Override
}); // 请求方法 public void onResponse(Call call, Response response) throws IOException {
}
}); // 请求方法
} }
/** /**
* 文件 post 同步请求 * 文件 post 同步请求
*
* @throws HttpException * @throws HttpException
* @throws IOException * @throws IOException
*/ */
@ -149,6 +173,7 @@ public class OkhttpTest {
/** /**
* post 异步请求 * post 异步请求
*
* @throws HttpException * @throws HttpException
* @throws IOException * @throws IOException
*/ */
@ -161,22 +186,102 @@ public class OkhttpTest {
requestParams.put("文件1", new File("/file1")); requestParams.put("文件1", new File("/file1"));
requestParams.put("文件2", new File("/file2")); requestParams.put("文件2", new File("/file2"));
okHttp.url("https://www.baidu.com/") // 请求地址 okHttp.url("https://www.baidu.com/") // 请求地址
.data(requestParams) // 请求参数 .data(requestParams) // 请求参数
.filePost(new Callback() { .filePost(new Callback() {
// 请求失败回调 // 请求失败回调
@Override @Override
public void onFailure(Call call, IOException e) { } public void onFailure(Call call, IOException e) {
}
// 请求成功回调
@Override
public void onResponse(Call call, Response response) throws IOException {
}
}); // 请求方法
// 请求成功回调 }
@Override
public void onResponse(Call call, Response response) throws IOException { }
}); // 请求方法
@Test
public void aaa() {
try {
String apiKey = "00b26cbc2cb242283452ac5c842e81d1"; // 替换为你的API密钥
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 获取当前年份
int currentYear = currentDate.getYear();
String urlString = "https://apis.tianapi.com/jiejiari/index?key=" + apiKey + "&date=" + currentYear + "&type=1";
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/json");
if (connection.getResponseCode() != 200) {
throw new RuntimeException("HTTP错误码:" + connection.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((connection.getInputStream())));
String output;
StringBuilder response = new StringBuilder();
while ((output = br.readLine()) != null) {
response.append(output);
}
connection.disconnect();
JSONObject jsonResponse = JSONObject.parseObject(response.toString());
// 计算当前日期加上七天的日期
LocalDate dateAfterSevenDays = currentDate.plusDays(7);
String formatter = String.valueOf(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
// 检查响应状态是否成功
if (jsonResponse.getInteger("code") == 200) {
// 获取result对象
JSONObject resultObj = jsonResponse.getJSONObject("result");
// 获取节假日列表JSONArray
JSONArray listArray = resultObj.getJSONArray("list");
// 遍历节假日列表
for (int i = 0; i < listArray.size(); i++) {
JSONObject holidayObj = listArray.getJSONObject(i);
String vacation = holidayObj.getString("vacation");
String name = holidayObj.getString("name");
String wage = holidayObj.getString("wage");
// Map<String, String> dateMap = splitDateString(vacation);
if (wage.equals(formatter)) {
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 分割日期字符串并构造Map
*
* @param dateStr 原始日期字符串 "|" 分隔
* @return 一个Map其中第一个日期为键剩余日期为值
*/
public static Map<String, String> splitDateString(String dateStr) {
String[] dates = dateStr.split("\\|");
if (dates.length > 0) {
Map<String, String> map = new HashMap<>();
String key = dates[0]; // 第一个日期作为键
map.put(key, dateStr);
return map;
} else {
return Collections.emptyMap(); // 如果原始字符串为空或只有分隔符,则返回空Map
}
} }
@Test @Test
public void aaa(){ public void ddd(){
String uuid = IdUtils.fastSimpleUUID(); // 获取当前季度
System.out.println(uuid.length()); System.out.println();
System.out.println(uuid);
} }
} }

24
zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java

@ -266,11 +266,11 @@ public class DCPerceivedEventsWarningController extends BaseController {
*/ */
@ApiOperation(value = "导出感知事件多发时段",tags = {"ECharts导出"}) @ApiOperation(value = "导出感知事件多发时段",tags = {"ECharts导出"})
@GetMapping("/exportManyTimesInterval") @GetMapping("/exportManyTimesInterval")
public AjaxResult exportManyTimesInterval(HttpServletResponse response,DcWarning dcWarning){ public void exportManyTimesInterval(HttpServletResponse response,DcWarning dcWarning){
if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null
||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark()) ||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark())
||StringUtils.isBlank(dcWarning.getDirection())){ ||StringUtils.isBlank(dcWarning.getDirection())){
return AjaxResult.error("参数错误"); return ;
} }
HashMap<String,Object> map = perceivedEventsWarningService.selectManyTimesInterval(dcWarning); HashMap<String,Object> map = perceivedEventsWarningService.selectManyTimesInterval(dcWarning);
List<ManyTimesInterval> list = new ArrayList<>(); List<ManyTimesInterval> list = new ArrayList<>();
@ -289,7 +289,6 @@ public class DCPerceivedEventsWarningController extends BaseController {
ExcelUtil<ManyTimesInterval> util = new ExcelUtil<>(ManyTimesInterval.class); ExcelUtil<ManyTimesInterval> util = new ExcelUtil<>(ManyTimesInterval.class);
util.exportExcel(response, list, "感知事件多发时段"); util.exportExcel(response, list, "感知事件多发时段");
return AjaxResult.success("导出感知事件多发时段成功");
} }
//新-感知事件类型分析 //新-感知事件类型分析
@ -304,11 +303,11 @@ public class DCPerceivedEventsWarningController extends BaseController {
} }
@ApiOperation(value = "导出感知事件类型分析",tags = {"ECharts导出"}) @ApiOperation(value = "导出感知事件类型分析",tags = {"ECharts导出"})
@GetMapping("/exportSelectWarningType") @GetMapping("/exportSelectWarningType")
public AjaxResult exportSelectWarningType(HttpServletResponse response,DcWarning dcWarning){ public void exportSelectWarningType(HttpServletResponse response,DcWarning dcWarning){
if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null
||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark()) ||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark())
||StringUtils.isBlank(dcWarning.getDirection())){ ||StringUtils.isBlank(dcWarning.getDirection())){
return AjaxResult.error("参数错误"); return;
} }
HashMap<String,Object> map = perceivedEventsWarningService.newSelectWarningType(dcWarning); HashMap<String,Object> map = perceivedEventsWarningService.newSelectWarningType(dcWarning);
List<SelectWarningType> list = new ArrayList<>(); List<SelectWarningType> list = new ArrayList<>();
@ -330,7 +329,6 @@ public class DCPerceivedEventsWarningController extends BaseController {
ExcelUtil<SelectWarningType> util = new ExcelUtil<>(SelectWarningType.class); ExcelUtil<SelectWarningType> util = new ExcelUtil<>(SelectWarningType.class);
util.exportExcel(response, list, "感知事件类型分析"); util.exportExcel(response, list, "感知事件类型分析");
return AjaxResult.success("导出感知事件类型分析成功");
} }
//新-感知事件桩号范围内事件分析 //新-感知事件桩号范围内事件分析
@PostMapping("/selectSection") @PostMapping("/selectSection")
@ -345,11 +343,11 @@ public class DCPerceivedEventsWarningController extends BaseController {
@ApiOperation(value = "导出桩号范围内事件分析",tags = {"ECharts导出"}) @ApiOperation(value = "导出桩号范围内事件分析",tags = {"ECharts导出"})
@GetMapping("/exportSelectSection") @GetMapping("/exportSelectSection")
public AjaxResult exportSelectSection(HttpServletResponse response,DcWarning dcWarning){ public void exportSelectSection(HttpServletResponse response,DcWarning dcWarning){
if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null
||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark()) ||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark())
||StringUtils.isBlank(dcWarning.getDirection())){ ||StringUtils.isBlank(dcWarning.getDirection())){
return AjaxResult.error("参数错误"); return;
} }
HashMap<String,Object> map = perceivedEventsWarningService.newSelectSection(dcWarning); HashMap<String,Object> map = perceivedEventsWarningService.newSelectSection(dcWarning);
List<SelectSection> list = new ArrayList<>(); List<SelectSection> list = new ArrayList<>();
@ -376,7 +374,6 @@ public class DCPerceivedEventsWarningController extends BaseController {
ExcelUtil<SelectSection> util = new ExcelUtil<>(SelectSection.class); ExcelUtil<SelectSection> util = new ExcelUtil<>(SelectSection.class);
util.exportExcel(response, list, "桩号范围内事件分析"); util.exportExcel(response, list, "桩号范围内事件分析");
return AjaxResult.success("导出桩号范围内事件分析成功");
} }
//新-感知事件路段处置类型分析 //新-感知事件路段处置类型分析
@PostMapping("/selectStateType") @PostMapping("/selectStateType")
@ -388,9 +385,9 @@ public class DCPerceivedEventsWarningController extends BaseController {
} }
@ApiOperation(value = "导出感知事件路段分析",tags = {"ECharts导出"}) @ApiOperation(value = "导出感知事件路段分析",tags = {"ECharts导出"})
@GetMapping("/exportSelectStateType") @GetMapping("/exportSelectStateType")
public AjaxResult exportSelectStateType(HttpServletResponse response, DcWarning dcWarning){ public void exportSelectStateType(HttpServletResponse response, DcWarning dcWarning){
if (dcWarning==null||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null){ if (dcWarning==null||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null){
return AjaxResult.error("参数错误"); return;
} }
List<SelectStateType> list = new ArrayList<>(); List<SelectStateType> list = new ArrayList<>();
@ -443,7 +440,6 @@ public class DCPerceivedEventsWarningController extends BaseController {
ExcelUtil<SelectStateType> util = new ExcelUtil<>(SelectStateType.class); ExcelUtil<SelectStateType> util = new ExcelUtil<>(SelectStateType.class);
util.exportExcel(response, list, "感知事件路段分析"); util.exportExcel(response, list, "感知事件路段分析");
return AjaxResult.success("导出感知事件路段分析成功");
} }
//查询感知数量按照路段数量进行排名 //查询感知数量按照路段数量进行排名
@PostMapping("/sectionPerceivedList") @PostMapping("/sectionPerceivedList")
@ -453,7 +449,7 @@ public class DCPerceivedEventsWarningController extends BaseController {
@ApiOperation(value = "导出感知事件路段排名",tags = {"ECharts导出"}) @ApiOperation(value = "导出感知事件路段排名",tags = {"ECharts导出"})
@GetMapping("/exportSectionPerceivedList") @GetMapping("/exportSectionPerceivedList")
public AjaxResult exportSectionPerceivedList(HttpServletResponse response){ public void exportSectionPerceivedList(HttpServletResponse response){
List<HashMap<String,Object>> dataList = perceivedEventsWarningService.selectSectionPerceivedEventsList(); List<HashMap<String,Object>> dataList = perceivedEventsWarningService.selectSectionPerceivedEventsList();
List<SectionPerceivedList> list = new ArrayList<>(); List<SectionPerceivedList> list = new ArrayList<>();
if (dataList != null && dataList.size() > 0){ if (dataList != null && dataList.size() > 0){
@ -467,7 +463,5 @@ public class DCPerceivedEventsWarningController extends BaseController {
} }
ExcelUtil<SectionPerceivedList> util = new ExcelUtil<>(SectionPerceivedList.class); ExcelUtil<SectionPerceivedList> util = new ExcelUtil<>(SectionPerceivedList.class);
util.exportExcel(response, list, "感知事件路段排名"); util.exportExcel(response, list, "感知事件路段排名");
return AjaxResult.success("导出感知事件路段排名成功");
} }
} }

262
zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java

@ -24,6 +24,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -222,9 +223,9 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
*/ */
@ApiOperation(value="导出全路段车流量状况分析",tags = {"ECharts导出"}) @ApiOperation(value="导出全路段车流量状况分析",tags = {"ECharts导出"})
@GetMapping("/history/exportRealTimeTrafficFlow") @GetMapping("/history/exportRealTimeTrafficFlow")
public AjaxResult exportRealTimeTrafficFlow(HttpServletResponse response,String startDate, String direction,String periodType ){ public void exportRealTimeTrafficFlow(HttpServletResponse response,String startDate, String direction,String periodType ){
if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)){ if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)){
return AjaxResult.error("参数错误"); return;
} }
String endDate = ""; String endDate = "";
if ("4".equals(periodType)){ if ("4".equals(periodType)){
@ -280,7 +281,6 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
ExcelUtil<RealTimeTrafficFlow> util = new ExcelUtil<>(RealTimeTrafficFlow.class); ExcelUtil<RealTimeTrafficFlow> util = new ExcelUtil<>(RealTimeTrafficFlow.class);
util.exportExcel(response, list, "全路段双向实时车流量"); util.exportExcel(response, list, "全路段双向实时车流量");
// 将查询结果封装为成功响应并返回 // 将查询结果封装为成功响应并返回
return AjaxResult.success("导出成功");
} }
/** /**
* 车流量时段分析 * 车流量时段分析
@ -304,9 +304,9 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
*/ */
@ApiOperation(value="导出车流量时段分析",tags = {"ECharts导出"}) @ApiOperation(value="导出车流量时段分析",tags = {"ECharts导出"})
@GetMapping("/history/exportTrafficPeriodAnalysis") @GetMapping("/history/exportTrafficPeriodAnalysis")
public AjaxResult exportTrafficPeriodAnalysis(HttpServletResponse response,String startDate, String direction,String periodType ){ public void exportTrafficPeriodAnalysis(HttpServletResponse response,String startDate, String direction,String periodType ){
if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)){ if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(direction) || StringUtils.isEmpty(periodType)){
return AjaxResult.error("参数错误"); return;
} }
String endDate = ""; String endDate = "";
if ("4".equals(periodType)){ if ("4".equals(periodType)){
@ -361,8 +361,6 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
ExcelUtil<TrafficPeriodAnalysis> util = new ExcelUtil<>(TrafficPeriodAnalysis.class); ExcelUtil<TrafficPeriodAnalysis> util = new ExcelUtil<>(TrafficPeriodAnalysis.class);
util.exportExcel(response, list, "车流量时段分析"); util.exportExcel(response, list, "车流量时段分析");
// 将查询结果封装为成功响应并返回
return AjaxResult.success("导出成功");
} }
@ApiOperation("断面车流量排名") @ApiOperation("断面车流量排名")
@ -383,7 +381,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
*/ */
@ApiOperation(value="导出断面车流量排名",tags = {"ECharts导出"}) @ApiOperation(value="导出断面车流量排名",tags = {"ECharts导出"})
@GetMapping("/history/exportSectionTrafficRanking") @GetMapping("/history/exportSectionTrafficRanking")
public AjaxResult exportSectionTrafficRanking(HttpServletResponse response,String startDate, String direction,String periodType ){ public void exportSectionTrafficRanking(HttpServletResponse response,String startDate, String direction,String periodType ){
List<SectionTrafficRanking> list = new ArrayList<>(); List<SectionTrafficRanking> list = new ArrayList<>();
List<Map<String, String>> dcStatisticsData = dcGantryStatisticsDataService.sectionTrafficRanking(startDate,direction,periodType); List<Map<String, String>> dcStatisticsData = dcGantryStatisticsDataService.sectionTrafficRanking(startDate,direction,periodType);
for (int i = 0; i < dcStatisticsData.size(); i++) { for (int i = 0; i < dcStatisticsData.size(); i++) {
@ -396,8 +394,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
ExcelUtil<SectionTrafficRanking> util = new ExcelUtil<>(SectionTrafficRanking.class); ExcelUtil<SectionTrafficRanking> util = new ExcelUtil<>(SectionTrafficRanking.class);
util.exportExcel(response, list, "断面车流量排名"); util.exportExcel(response, list, "断面车流量排名");
// 将查询结果封装为成功响应并返回
return AjaxResult.success("导出成功");
} }
/** /**
@ -418,7 +415,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
@ApiOperation(value="导出路段交通指标分析",tags = {"ECharts导出"}) @ApiOperation(value="导出路段交通指标分析",tags = {"ECharts导出"})
@GetMapping("/history/exportSectionTrafficIndexAnalysis") @GetMapping("/history/exportSectionTrafficIndexAnalysis")
public AjaxResult exportSectionTrafficIndexAnalysis(HttpServletResponse response,String startDate, String direction,String periodType,Long ranking){ public void exportSectionTrafficIndexAnalysis(HttpServletResponse response,String startDate, String direction,String periodType,Long ranking){
List<SectionTrafficIndexAnalysis> list = new ArrayList<>(); List<SectionTrafficIndexAnalysis> list = new ArrayList<>();
String endDate = ""; String endDate = "";
@ -482,7 +479,6 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String
ExcelUtil<SectionTrafficIndexAnalysis> util = new ExcelUtil<>(SectionTrafficIndexAnalysis.class); ExcelUtil<SectionTrafficIndexAnalysis> util = new ExcelUtil<>(SectionTrafficIndexAnalysis.class);
util.exportExcel(response, list, "路段交通指标分析"); util.exportExcel(response, list, "路段交通指标分析");
// 将查询结果封装为成功响应并返回 // 将查询结果封装为成功响应并返回
return AjaxResult.success("导出成功");
} }
@ApiOperation("通指标时间分布") @ApiOperation("通指标时间分布")
@ -641,8 +637,15 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD
*/ */
@ApiOperation("全路段双向实时车流量") @ApiOperation("全路段双向实时车流量")
@GetMapping("/history/realTimeTrafficFlowHour") @GetMapping("/history/realTimeTrafficFlowHour")
public AjaxResult realTimeTrafficFlowHour(String startDate,Long direction) throws HttpException, IOException{ public AjaxResult realTimeTrafficFlowHour() throws HttpException, IOException{
List<Map<String,Object>> mapList = dcTrafficStatisticsService.realTimeTrafficFlowHour(startDate,direction); Map<String,List<Map<String, Object>>> mapList = dcTrafficStatisticsService.realTimeTrafficFlowHour();
// 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList);
}
@ApiOperation("按照桩号查询门架数据 ")
@GetMapping("/history/queryTheGantryDataByPileNumber")
public AjaxResult queryTheGantryDataByPileNumber(String startDate,String stakeMark) throws HttpException, IOException{
List<Map<String,Object>> mapList = dcTrafficStatisticsService.queryTheGantryDataByPileNumber(startDate,stakeMark);
// 将查询结果封装为成功响应并返回 // 将查询结果封装为成功响应并返回
return AjaxResult.success(mapList); return AjaxResult.success(mapList);
} }
@ -665,7 +668,13 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD
*/ */
@ApiOperation(value = "导出全路段双向实时车流量",tags = {"ECharts导出"}) @ApiOperation(value = "导出全路段双向实时车流量",tags = {"ECharts导出"})
@GetMapping("/history/exportRealTimeTrafficFlowHour") @GetMapping("/history/exportRealTimeTrafficFlowHour")
public AjaxResult exportRealTimeTrafficFlowHour(HttpServletResponse response) throws IOException, HttpException { public void exportRealTimeTrafficFlowHour(HttpServletResponse response) throws IOException, HttpException {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
String fileName = "全路段双向实时车流量.xlsx";
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
@ -675,121 +684,122 @@ public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endD
LocalDate oneYearAgo = currentDate.minusYears(1); LocalDate oneYearAgo = currentDate.minusYears(1);
String lastYear = oneYearAgo.format(formatter); String lastYear = oneYearAgo.format(formatter);
List<Map<String,Object>> thisYearHZ = dcTrafficStatisticsService.realTimeTrafficFlowHour(now,1L); Map<String,List<Map<String,Object>>> map = dcTrafficStatisticsService.realTimeTrafficFlowHour();
List<Map<String,Object>> thisYearJN = dcTrafficStatisticsService.realTimeTrafficFlowHour(now,3L); if (map != null){
List<Map<String,Object>> lastYearHZ = dcTrafficStatisticsService.realTimeTrafficFlowHour(lastYear,1L); List<Map<String,Object>> thisYearHZ = map.get("1");
List<Map<String,Object>> lastYearJN = dcTrafficStatisticsService.realTimeTrafficFlowHour(lastYear,3L); List<Map<String,Object>> thisYearJN = map.get("2");
List<Map<String,Object>> lastYearHZ = map.get("3");
Workbook workbook = new XSSFWorkbook(); // 创建工作簿 List<Map<String,Object>> lastYearJN = map.get("4");
Sheet sheet = workbook.createSheet("全路段双向实时车流量"); // 创建工作表
XSSFWorkbook workbook = new XSSFWorkbook(); // 创建工作簿
// 创建数据行样式 Sheet sheet = workbook.createSheet("全路段双向实时车流量"); // 创建工作表
CellStyle dataStyle = workbook.createCellStyle();
dataStyle.setAlignment(HorizontalAlignment.CENTER); // 创建数据行样式
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); CellStyle dataStyle = workbook.createCellStyle();
dataStyle.setBorderRight(BorderStyle.THIN); dataStyle.setAlignment(HorizontalAlignment.CENTER);
dataStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); dataStyle.setVerticalAlignment(VerticalAlignment.CENTER);
dataStyle.setBorderLeft(BorderStyle.THIN); dataStyle.setBorderRight(BorderStyle.THIN);
dataStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); dataStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
dataStyle.setBorderTop(BorderStyle.THIN); dataStyle.setBorderLeft(BorderStyle.THIN);
dataStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); dataStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
dataStyle.setBorderBottom(BorderStyle.THIN); dataStyle.setBorderTop(BorderStyle.THIN);
dataStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); dataStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = workbook.createFont(); dataStyle.setBorderBottom(BorderStyle.THIN);
dataFont.setFontName("Arial"); dataStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
dataFont.setFontHeightInPoints((short) 10); Font dataFont = workbook.createFont();
dataStyle.setFont(dataFont); dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10);
// 创建表头样式 dataStyle.setFont(dataFont);
CellStyle headerStyle = workbook.createCellStyle();
headerStyle.cloneStyleFrom(dataStyle); // 创建表头样式
headerStyle.setAlignment(HorizontalAlignment.CENTER); CellStyle headerStyle = workbook.createCellStyle();
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); headerStyle.cloneStyleFrom(dataStyle);
headerStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
Font headerFont = workbook.createFont(); headerStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
headerFont.setFontName("Arial"); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
headerFont.setFontHeightInPoints((short) 10); Font headerFont = workbook.createFont();
headerFont.setBold(true); headerFont.setFontName("Arial");
headerFont.setColor(IndexedColors.WHITE.getIndex()); headerFont.setFontHeightInPoints((short) 10);
headerStyle.setFont(headerFont); headerFont.setBold(true);
headerFont.setColor(IndexedColors.WHITE.getIndex());
// 添加第一层级表头 headerStyle.setFont(headerFont);
Row row = sheet.createRow(0);
Cell cell = row.createCell(0); // 添加第一层级表头
cell.setCellValue("路段名称"); Row row = sheet.createRow(0);
cell.setCellStyle(headerStyle); Cell cell = row.createCell(0);
cell = row.createCell(1); cell.setCellValue("路段名称");
cell.setCellValue("济南方向"); cell.setCellStyle(headerStyle);
cell.setCellStyle(headerStyle); cell = row.createCell(1);
cell = row.createCell(2); cell.setCellValue("济南方向");
cell.setCellValue(""); cell.setCellStyle(headerStyle);
cell.setCellStyle(headerStyle);; cell = row.createCell(2);
cell = row.createCell(3); cell.setCellValue("");
cell.setCellValue("菏泽方向"); cell.setCellStyle(headerStyle);;
cell.setCellStyle(headerStyle); cell = row.createCell(3);
cell = row.createCell(4); cell.setCellValue("菏泽方向");
cell.setCellValue(""); cell.setCellStyle(headerStyle);
cell.setCellStyle(headerStyle); cell = row.createCell(4);
cell.setCellValue("");
// 添加第二层级表头(与第一层级对齐) cell.setCellStyle(headerStyle);
Row subHeaderRow1 = sheet.createRow(1);
cell = subHeaderRow1.createCell(0); // 添加第二层级表头(与第一层级对齐)
cell.setCellValue(""); Row subHeaderRow1 = sheet.createRow(1);
cell.setCellStyle(headerStyle); cell = subHeaderRow1.createCell(0);
cell = subHeaderRow1.createCell(1); cell.setCellValue("");
cell.setCellValue("本期车流量"); cell.setCellStyle(headerStyle);
cell.setCellStyle(headerStyle); cell = subHeaderRow1.createCell(1);
cell.setCellValue("本期车流量");
cell = subHeaderRow1.createCell(2); cell.setCellStyle(headerStyle);
cell.setCellValue("去年同期");
cell.setCellStyle(headerStyle); cell = subHeaderRow1.createCell(2);
cell = subHeaderRow1.createCell(3); cell.setCellValue("去年同期");
cell.setCellValue("本期车流量"); cell.setCellStyle(headerStyle);
cell.setCellStyle(headerStyle); cell = subHeaderRow1.createCell(3);
cell.setCellValue("本期车流量");
cell = subHeaderRow1.createCell(4); cell.setCellStyle(headerStyle);
cell.setCellValue("去年同期");
cell.setCellStyle(headerStyle); cell = subHeaderRow1.createCell(4);
cell.setCellValue("去年同期");
//合并单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始) cell.setCellStyle(headerStyle);
//路段名称
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0)); //合并单元格,参数依次为起始行,结束行,起始列,结束列 (从0开始)
//济南方向 //路段名称
sheet.addMergedRegion(new CellRangeAddress(0, 0, 1, 2)); sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
//菏泽方向 //济南方向
sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 4)); sheet.addMergedRegion(new CellRangeAddress(0, 0, 1, 2));
//菏泽方向
for (int i = 0; i < thisYearHZ.size(); i++) { sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 4));
Row subHeaderRow = sheet.createRow(i+2);
cell = subHeaderRow.createCell(0); for (int i = 0; i < thisYearHZ.size(); i++) {
cell.setCellValue(thisYearJN.get(i).get("name").toString()); Row subHeaderRow = sheet.createRow(i+2);
cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(0);
cell = subHeaderRow.createCell(1); cell.setCellValue(thisYearJN.get(i).get("name").toString());
cell.setCellValue(thisYearJN.get(i).get("totalFlow").toString()); cell.setCellStyle(dataStyle);
cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(1);
cell = subHeaderRow.createCell(2); cell.setCellValue(thisYearJN.get(i).get("totalFlow").toString());
cell.setCellValue(lastYearJN.get(i).get("totalFlow").toString()); cell.setCellStyle(dataStyle);
cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(2);
cell = subHeaderRow.createCell(3); cell.setCellValue(lastYearJN.get(i).get("totalFlow").toString());
cell.setCellValue(thisYearHZ.get(i).get("totalFlow").toString()); cell.setCellStyle(dataStyle);
cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(3);
cell = subHeaderRow.createCell(4); cell.setCellValue(thisYearHZ.get(i).get("totalFlow").toString());
cell.setCellValue(lastYearHZ.get(i).get("totalFlow").toString()); cell.setCellStyle(dataStyle);
cell.setCellStyle(dataStyle); cell = subHeaderRow.createCell(4);
} cell.setCellValue(lastYearHZ.get(i).get("totalFlow").toString());
cell.setCellStyle(dataStyle);
}
// 写入文件
try (ServletOutputStream outputStream = response.getOutputStream()){
workbook.write(outputStream);
} finally {
workbook.close();
}
// 写入文件
try {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
workbook.write(response.getOutputStream());
} finally {
workbook.close();
} }
return AjaxResult.success("导出感知事件多发时段成功");
} }
} }

4
zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java

@ -52,7 +52,7 @@ public interface IDcTrafficStatisticsService {
JSONArray trafficFlowAtTollStationEntranceHour(String startDate, String endDate, String stationType)throws HttpException, IOException; JSONArray trafficFlowAtTollStationEntranceHour(String startDate, String endDate, String stationType)throws HttpException, IOException;
List<Map<String, Object>> realTimeTrafficFlowHour(String startDate,Long direction) throws HttpException, IOException; Map<String,List<Map<String, Object>>> realTimeTrafficFlowHour() throws HttpException, IOException;
// JSONArray realTimeTrafficFlowHour2(String startDate,Long direction) throws HttpException, IOException; List<Map<String,Object>> queryTheGantryDataByPileNumber(String startDate,String stakeMark) throws HttpException, IOException;
} }

3
zc-business/src/main/java/com/zc/business/service/impl/DcNoStakeWarningTableServiceImpl.java

@ -54,6 +54,9 @@ public class DcNoStakeWarningTableServiceImpl extends ServiceImpl<DcNoStakeWarni
if (endTime != null && startTime != null) { if (endTime != null && startTime != null) {
queryWrapper.between(DcNoStakeWarningTable::getWarningTime, startTime, endTime); queryWrapper.between(DcNoStakeWarningTable::getWarningTime, startTime, endTime);
} }
queryWrapper.orderByDesc(DcNoStakeWarningTable::getWarningTime);
// 木桩 // 木桩
return queryWrapper; return queryWrapper;
} }

247
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

@ -31,7 +31,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -632,35 +634,27 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
ResponseBody body = response.body(); ResponseBody body = response.body();
if (body != null) { if (body != null) {
JSONArray jsonArray = JSON.parseArray(body.string()); JSONArray jsonArray = JSON.parseArray(body.string());
Map<String, Integer> sumByName = new LinkedHashMap<>();
// 使用HashMap来分组并求和
Map<String, Integer> sumByName = new HashMap<>();
List<Map<String, String>> list = new ArrayList(); List<Map<String, String>> list = new ArrayList();
for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object
JSONObject jsonObject = (JSONObject) item; JSONObject jsonObject = (JSONObject) item;
// 获取当前时间 // 获取当前时间
LocalTime now = LocalTime.now(); LocalTime now = LocalTime.now();
// 获取当前小时数(24小时制) // 获取当前小时数(24小时制)
int currentHour = now.getHour(); int currentHour = now.getHour();
if (jsonObject.getInteger("data_hour") == currentHour) { if (jsonObject.getInteger("data_hour") == currentHour) {
String name = jsonObject.getString("ts_name"); // 更安全的取值方式 String name = jsonObject.getString("ts_name"); // 更安全的取值方式
int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型 int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型
sumByName.put(name, totalFlow); sumByName.put(name, totalFlow);
// sumByName.put(name, sumByName.getOrDefault(name, 0) + totalFlow);
} }
} }
// 输出结果
// 输出结果
// 正确创建新的映射对象并添加到list中 // 正确创建新的映射对象并添加到list中
for (Map.Entry<String, Integer> entry : sumByName.entrySet()) { for (Map.Entry<String, Integer> entry : sumByName.entrySet()) {
Map<String, String> singleResult = new HashMap<>(); // 每次循环都创建一个新的映射 Map<String, String> singleResult = new LinkedHashMap<>(); // 每次循环都创建一个新的映射
singleResult.put("name", entry.getKey()); singleResult.put("name", entry.getKey());
singleResult.put("value", entry.getValue().toString()); singleResult.put("value", entry.getValue().toString());
list.add(singleResult); list.add(singleResult);
//System.out.println(entry.getKey() + " 的 total_flow 总和为: " + entry.getValue());
} }
return list; return list;
} }
@ -705,22 +699,107 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
} }
@Override @Override
public List<Map<String, Object>> realTimeTrafficFlowHour(String startDate, Long direction) throws HttpException, IOException { public Map<String,List<Map<String, Object>>> realTimeTrafficFlowHour() throws HttpException, IOException {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate currentDate = LocalDate.now();
String nowYear = currentDate.format(formatter);
//String nowYear =startDate;
// 获取一年前的日期
LocalDate oneYearAgo = currentDate.minusYears(1);
String lastYear = oneYearAgo.format(formatter);
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("sysid", sysid); requestParams.put("sysid", sysid);
//求情地址 startDate 时间
JSONArray body = getResponseBody(nowYear, requestParams, okHttp);
JSONArray bodylast = getResponseBody(lastYear, requestParams, okHttp);
Map<String,List<Map<String, Object>>> map = new HashMap<>();
if (body != null) {
List<Map<String, Object>> mapList = getMaps("1", body);
map.put("1",mapList);
List<Map<String, Object>> mapList2 = getMaps("3", body);
map.put("2",mapList2);
}
if (bodylast != null) {
List<Map<String, Object>> mapList = getMaps("1", bodylast);
map.put("3",mapList);
List<Map<String, Object>> mapList2 = getMaps("3", bodylast);
map.put("4",mapList2);
}
return map;
}
//处理 接口响应数据
private List<Map<String, Object>> getMaps(String direction, JSONArray jsonArray) throws IOException {
// 获取当前时间
LocalTime now = LocalTime.now();
// 获取当前小时数(24小时制)
int currentHour = now.getHour();
// 初始化计数器和描述映射
Map<Integer, Integer> flowCounts = new HashMap<>();
Map<Integer, String> descriptions = new HashMap<>();
for (int i = 1; i <= 14; i++) {
flowCounts.put(i, 0);
descriptions.put(i, "");
}
for (Object item : jsonArray) {
JSONObject jsonObject = (JSONObject) item;
if (jsonObject.getInteger("data_hour") == currentHour) {
int totalFlow = jsonObject.getInteger("total_flow");
String gantryId = jsonObject.getString("gantry_id");
DcFacility dcFacilityAll = new DcFacility();
dcFacilityAll.setFacilityType(10);
dcFacilityAll.setDirection(direction);
List<DcFacility> dcFacilityList = facilityService.listFacility(dcFacilityAll);
DcFacility dcFacility2 = facilityService.getfacilityCode(gantryId);
if (dcFacility2 != null) {
String stakeMark = dcFacility2.getStakeMark();
boolean exists = dcFacilityList.stream()
.anyMatch(dcFacility -> dcFacility.getId().equals(dcFacility2.getId()));
if (exists) {
int extractedNumber = Integer.parseInt(extract(stakeMark));
int identification = Arrays.stream(StakeMarkRange.values())
.filter(smRange -> extractedNumber >= smRange.getStakeMark() && extractedNumber <= smRange.getEndMark())
.mapToInt(StakeMarkRange::getIdentification)
.findFirst()
.orElse(0);
String description = getDescriptionByIdentification(identification);
descriptions.put(identification, description);
flowCounts.put(identification, flowCounts.get(identification) + totalFlow);
}
}
}
}
// 构建结果列表
List<Map<String, Object>> mapList = new ArrayList<>();
for (int i = 1; i <= 14; i++) {
Map<String, Object> map = new HashMap<>();
map.put("name", getDescriptionByIdentification(i));
map.put("totalFlow", flowCounts.get(i));
mapList.add(map);
}
return mapList;
}
// 获取车流量接口 返回 jsonArray
private JSONArray getResponseBody(String startDate, RequestParams requestParams, OkHttp okHttp) throws HttpException, IOException {
JSONObject parameters = new JSONObject() { JSONObject parameters = new JSONObject() {
{ {
put("start_date", startDate); put("start_date", startDate);
put("end_date", startDate); put("end_date", startDate);
} }
}; };
requestParams.put("parameters", parameters.toJSONString()); requestParams.put("parameters", parameters.toJSONString());
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("Authorization", getAccessToken()); headers.put("Authorization", getAccessToken());
@ -731,65 +810,8 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
.data(requestParams) // 请求参数 .data(requestParams) // 请求参数
.post(); // 请求方法 .post(); // 请求方法
ResponseBody body = response.body(); ResponseBody body = response.body();
if (body != null) { JSONArray jsonArray = JSON.parseArray(body.string());
return jsonArray;
JSONArray jsonArray = JSON.parseArray(body.string());
// 获取当前时间
LocalTime now = LocalTime.now();
// 获取当前小时数(24小时制)
int currentHour = now.getHour();
// 初始化计数器和描述映射
Map<Integer, Integer> flowCounts = new HashMap<>();
Map<Integer, String> descriptions = new HashMap<>();
for (int i = 1; i <= 14; i++) {
flowCounts.put(i, 0);
descriptions.put(i, "");
}
for (Object item : jsonArray) {
JSONObject jsonObject = (JSONObject) item;
if (jsonObject.getInteger("data_hour") == currentHour) {
int totalFlow = jsonObject.getInteger("total_flow");
String gantryId = jsonObject.getString("gantry_id");
DcFacility dcFacilityAll = new DcFacility();
dcFacilityAll.setFacilityType(10);
dcFacilityAll.setDirection(String.valueOf(direction));
List<DcFacility> dcFacilityList = facilityService.listFacility(dcFacilityAll);
DcFacility dcFacility2 = facilityService.getfacilityCode(gantryId);
if (dcFacility2 != null) {
String stakeMark = dcFacility2.getStakeMark();
boolean exists = dcFacilityList.stream()
.anyMatch(dcFacility -> dcFacility.getId().equals(dcFacility2.getId()));
if (exists) {
int extractedNumber = Integer.parseInt(extract(stakeMark));
int identification = Arrays.stream(StakeMarkRange.values())
.filter(smRange -> extractedNumber >= smRange.getStakeMark() && extractedNumber <= smRange.getEndMark())
.mapToInt(StakeMarkRange::getIdentification)
.findFirst()
.orElse(0);
String description = getDescriptionByIdentification(identification);
descriptions.put(identification, description);
flowCounts.put(identification, flowCounts.get(identification) + totalFlow);
}
}
}
}
// 构建结果列表
List<Map<String, Object>> mapList = new ArrayList<>();
for (int i = 1; i <= 14; i++) {
Map<String, Object> map = new HashMap<>();
map.put("name", getDescriptionByIdentification(i));
map.put("totalFlow", flowCounts.get(i));
mapList.add(map);
}
return mapList;
}
return null;
} }
@ -815,8 +837,19 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
} }
return ""; return "";
} }
/*
public JSONArray realTimeTrafficFlowHour2(String startDate,Long direction) throws HttpException, IOException { public List<Map<String,Object>> queryTheGantryDataByPileNumber(String startDate,String stakeMark) throws HttpException, IOException {
if (stakeMark != null) {
//处理URl地址栏获取参数+号消失
stakeMark= stakeMark.replace(" ", "+");
}
List<Map<String,Object>> mapList =new ArrayList<>();
DcFacility dcFacilityAll = new DcFacility();
dcFacilityAll.setFacilityType(10);
List<DcFacility> dcFacilityList = facilityService.listFacility(dcFacilityAll);
DcFacility nearestFacility = findNearestFacility(dcFacilityList,stakeMark);
OkHttp okHttp = new OkHttp(); OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams(); RequestParams requestParams = new RequestParams();
@ -845,41 +878,51 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
ResponseBody body = response.body(); ResponseBody body = response.body();
if (body != null) { if (body != null) {
JSONArray jsonArray = JSON.parseArray(body.string()); JSONArray jsonArray = JSON.parseArray(body.string());
System.out.println(jsonArray);
// 使用HashMap来分组并求和 for (Object item : jsonArray) {
List<Map<String, Object>> list = new ArrayList();
for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object
JSONObject jsonObject = (JSONObject) item; JSONObject jsonObject = (JSONObject) item;
// 获取当前时间 if (jsonObject.getString("gantry_id").equals(nearestFacility.getFacilityCode())) {
LocalTime now = LocalTime.now(); Map<String, Object> map = new HashMap<>();
int totalFlow = jsonObject.getInteger("total_flow");
// 获取当前小时数(24小时制) int data_hour = jsonObject.getInteger("data_hour");
int currentHour = now.getHour(); map.put("hour",data_hour);
if (jsonObject.getInteger("data_hour") == 16) { map.put("totalFlow",totalFlow);
mapList.add(map);
Map<String,Object> sumByName = new HashMap<>();
String name = jsonObject.getString("gantry_name"); // 更安全的取值方式
int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型
String gantryId = jsonObject.getString("gantry_id"); // 专门针对Integer类型
String data_hour = jsonObject.getString("data_hour"); // 专门针对Integer类型
sumByName.put("naame", name);
sumByName.put("gantryId", gantryId);
sumByName.put("totalFlow", totalFlow);
sumByName.put("data_hour", data_hour);
list.add(sumByName);
} }
} }
// 输出结果 // 输出结果
return jsonArray; return mapList;
} }
return null; return null;
} }
*/ public DcFacility findNearestFacility(List<DcFacility> dcFacilityList, String stakeMarkCode) {
// 将目标桩号转换为整数,以便比较
int targetCodeAsInt = Integer.parseInt(extract(stakeMarkCode));
DcFacility nearestFacility = null;
int minDistance = Integer.MAX_VALUE; // 初始化为最大整数值,确保任何实际距离都会小于这个值
for (DcFacility facility : dcFacilityList) {
// 假设每个DcFacility对象中有一个方法或直接字段可以获取处理后的桩号字符串
String stakeMark = facility.getStakeMark(); // 请替换为实际的getter方法名
// 将当前设施的桩号转换为整数
int currentCodeAsInt = Integer.parseInt(extract(stakeMark));
// 计算与目标桩号的距离(差值的绝对值)
int distance = Math.abs(targetCodeAsInt - currentCodeAsInt);
// 如果当前桩号比之前记录的最近桩号更近,则更新最近桩号
if (distance < minDistance) {
minDistance = distance;
nearestFacility = facility;
}
}
return nearestFacility; // 返回最近的桩号信息
}
} }

Loading…
Cancel
Save