From ca5d33a1a8b4447ee4fc07019d1d3956e8a76fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Tue, 2 Jul 2024 10:14:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E8=B7=AF=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DcTrafficStatisticsController.java | 5 ++- .../impl/DcTrafficStatisticsServiceImpl.java | 40 +++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) 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 957a3c72..c47d18eb 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 @@ -24,6 +24,8 @@ import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.*; import javax.servlet.ServletOutputStream; @@ -42,6 +44,7 @@ import java.util.stream.Collectors; * * @author xiepufeng */ +//@Component @Api(tags = "交通数据统计") @RestController @RequestMapping("/business/traffic-statistics") @@ -704,7 +707,7 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String // 将获取到的交通指标数据封装为成功的结果并返回 return AjaxResult.success(jsonArray); } - + // @Scheduled(cron = "0/30 * * * * ?") @ApiOperation("获取当前拥堵路段") @GetMapping("/current/getTheCurrentCongestedSection") public AjaxResult getTheCurrentCongestedSection() 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 12ce6a3a..88a2798c 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 @@ -933,44 +933,52 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi for (Object object : jsonArray) { JSONObject jsonObject = (JSONObject) object; Integer asOneRoad = jsonObject.getInteger("as_one_road"); - double endPileNo = jsonObject.getDouble("end_pile_no"); + if (jsonObject.getDouble("end_pile_no")!=null){ + double endPileNo = jsonObject.getDouble("end_pile_no"); + String endMark = formatNumber(endPileNo); + jsonObject.put("endMark", endMark);//结束桩号 + } double startPileNo = jsonObject.getDouble("start_pile_no"); String stakeMark = formatNumber(startPileNo); - String endMark = formatNumber(endPileNo); - jsonObject.put("stakeMark", stakeMark);//当前拥堵距离 - jsonObject.put("endMark", endMark);//当前拥堵距离 + jsonObject.put("stakeMark", stakeMark);// //as_one_road //是否为同一条路,1-是,0-否 - if (asOneRoad == UniversalEnum.ZERO.getNumber()) { + if (asOneRoad == UniversalEnum.ZERO.getNumber()) { String string = jsonObject.getString("list_link_info"); JSONArray jsonlist = JSON.parseArray(string); - JSONObject o = (JSONObject) jsonlist.get(0); + JSONObject o = (JSONObject) jsonlist.get(UniversalEnum.ZERO.getNumber()); String string1 = o.getString("firstPoint"); String string2 = o.getString("lastPoint"); String lngLats = o.getString("lngLats"); String[] lngLatsString = lngLats.split(";"); - double s = Double.parseDouble(lngLatsString[0].split(",")[0]); - double s2 = Double.parseDouble(lngLatsString[0].split(",")[1]); - double s3 = Double.parseDouble(lngLatsString[lngLatsString.length - 1].split(",")[0]); - double s4 = Double.parseDouble(lngLatsString[lngLatsString.length - 1].split(",")[1]); - double distanceM = calculateDistance(s2, s, s4, s3) * 1000; + double s = Double.parseDouble(lngLatsString[UniversalEnum.ZERO.getNumber()].split(",")[UniversalEnum.ZERO.getNumber()]); + double s2 = Double.parseDouble(lngLatsString[UniversalEnum.ZERO.getNumber()].split(",")[UniversalEnum.ONE.getNumber()]); + double s3 = Double.parseDouble(lngLatsString[lngLatsString.length - UniversalEnum.ONE.getNumber()].split(",")[UniversalEnum.ZERO.getNumber()]); + double s4 = Double.parseDouble(lngLatsString[lngLatsString.length - UniversalEnum.ONE.getNumber()].split(",")[UniversalEnum.ONE.getNumber()]); + double distanceM = calculateDistance(s2, s, s4, s3); // System.out.printf("最大距离为: %.2f 米%n", distanceM); jsonObject.put("max_jam_dist", distanceM);//最大拥堵距离 + double endMake = startPileNo +Double.parseDouble(String.format("%.3f", distanceM)); + + String endmark = formatNumber(endMake); + jsonObject.put("endMark", endmark);//结束桩号 + + String[] split = string1.split(","); - double firstLon = Double.parseDouble(split[0]); - double firstLat = Double.parseDouble(split[1]); + double firstLon = Double.parseDouble(split[UniversalEnum.ZERO.getNumber()]); + double firstLat = Double.parseDouble(split[UniversalEnum.ONE.getNumber()]); String[] split2 = string2.split(","); - double lastLon = Double.parseDouble(split2[0]); - double lastLat = Double.parseDouble(split2[1]); + double lastLon = Double.parseDouble(split2[UniversalEnum.ZERO.getNumber()]); + double lastLat = Double.parseDouble(split2[UniversalEnum.ONE.getNumber()]); //double firstLat = 35.38524527319016; // double firstLon = 118.39808642864227; //double lastLat = 35.386351346969604; // double lastLon = 118.4038907289505; double distanceKm = calculateDistance(firstLat, firstLon, lastLat, lastLon); - double distanceMeters = distanceKm * 1000; // 将距离转换为米 + double distanceMeters = distanceKm * UniversalEnum.THOUSAND.getNumber(); // 将距离转换为米 //System.out.printf("两点之间的距离为: %.2f 米%n", distanceMeters); jsonObject.put("jam_dist", distanceMeters);//当前拥堵距离