From 20fa685dd1fe1fdfa0cd49ddde6d189fbb807173 Mon Sep 17 00:00:00 2001 From: xiepufeng <1072271977@qq.com> Date: Sun, 7 Apr 2024 17:12:11 +0800 Subject: [PATCH 01/10] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0setPeriodType?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=AF=BC=E8=87=B4@Data=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=E4=B8=8D=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4setPeriodType?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=A0=E6=B3=95=E6=98=A0=E5=B0=84=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=202.=E8=8E=B7=E5=8F=96=E5=8E=86=E5=8F=B2=E4=BA=A4?= =?UTF-8?q?=E9=80=9A=E6=88=AA=E9=9D=A2=E6=95=B0=E6=8D=AE=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=BC=80=E5=A7=8B=E6=97=B6=E9=97=B4=E5=92=8C?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E6=97=B6=E9=97=B4=E6=B7=BB=E5=8A=A0=20=20@Da?= =?UTF-8?q?teTimeFormat(pattern=20=3D=20"yyyy-MM-dd=20HH:mm:ss")=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E4=BB=A5=E6=94=AF=E6=8C=81=E5=AF=B9=E5=BA=94=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F=203.?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=8E=86=E5=8F=B2=E4=BA=A4=E9=80=9A=E6=88=AA?= =?UTF-8?q?=E9=9D=A2=E6=95=B0=E6=8D=AE=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E4=B8=BAnull=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zc/business/domain/DcTrafficSectionData.java | 6 ++++++ .../request/DcTrafficSectionDataRequest.java | 3 +++ .../impl/DcTrafficStatisticsServiceImpl.java | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/domain/DcTrafficSectionData.java b/zc-business/src/main/java/com/zc/business/domain/DcTrafficSectionData.java index 860bcf6a..5ac4e709 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcTrafficSectionData.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcTrafficSectionData.java @@ -47,12 +47,14 @@ public class DcTrafficSectionData { /** * 统计时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") private Date statisticalDate; /** * 上报时间 */ @TableField(exist = false) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") private Date reportTime; /** @@ -87,6 +89,10 @@ public class DcTrafficSectionData { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") private Date updateTime; + public void setPeriodType(Byte periodType) { + this.periodType = periodType; + } + /** * 设置交通数据的统计周期类型。 * @param periodType 统计周期类型的枚举值。 diff --git a/zc-business/src/main/java/com/zc/business/request/DcTrafficSectionDataRequest.java b/zc-business/src/main/java/com/zc/business/request/DcTrafficSectionDataRequest.java index 5c9540ff..e99f04f3 100644 --- a/zc-business/src/main/java/com/zc/business/request/DcTrafficSectionDataRequest.java +++ b/zc-business/src/main/java/com/zc/business/request/DcTrafficSectionDataRequest.java @@ -1,6 +1,7 @@ package com.zc.business.request; import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; @@ -25,11 +26,13 @@ public class DcTrafficSectionDataRequest { /** * 开始时间 */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date startTime; /** * 结束时间 */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date endTime; /** 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 e92bce6b..5924c2b6 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 @@ -123,9 +123,18 @@ public class DcTrafficStatisticsServiceImpl LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.between(DcTrafficSectionData::getStatisticalDate, request.getStartTime(), request.getEndTime()); queryWrapper.eq(DcTrafficSectionData::getPeriodType, request.getPeriodType()); - queryWrapper.eq(DcTrafficSectionData::getDirection, request.getDirection()); - queryWrapper.eq(DcTrafficSectionData::getDeviceType, request.getDeviceType()); - queryWrapper.eq(DcTrafficSectionData::getDeviceId, request.getDeviceId()); + + if (request.getDirection() != null) { + queryWrapper.eq(DcTrafficSectionData::getDirection, request.getDirection()); + } + + if (request.getDeviceType() != null) { + queryWrapper.eq(DcTrafficSectionData::getDeviceType, request.getDeviceType()); + } + + if (request.getDeviceId() != null) { + queryWrapper.eq(DcTrafficSectionData::getDeviceId, request.getDeviceId()); + } return list(queryWrapper); } From c24faf3d8ad3ae400a9bf3c8d5c59c3bf82c8efa Mon Sep 17 00:00:00 2001 From: "Mr.Wang" Date: Mon, 8 Apr 2024 11:23:40 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=A4=E8=B0=83?= =?UTF-8?q?=E8=BD=A6=E6=B5=81=E9=87=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/zc/business/controller/DcDeviceController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index bc99bd59..9a4b4312 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -248,7 +248,7 @@ public class DcDeviceController extends BaseController { JSONObject formatValue = JSON.parseObject(jsonObject.get("formatValue").toString()); map.put("1", formatValue.get("1")); map.put("3", formatValue.get("3")); - map.put("timestamp", formatValue.get("equipmentReportingTime") == null? "":formatValue.get("equipmentReportingTime")); + map.put("timestamp", formatValue.get("equipmentReportingTime") == null? "":Long.valueOf(formatValue.get("equipmentReportingTime").toString())); list.add(map); }); List> newList = list.stream() From 4d9bc0583f1111b92b66ffb76669b07c9576b85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Mon, 8 Apr 2024 11:28:30 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=A9=E6=B0=94?= =?UTF-8?q?=E7=AD=89=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/src/main/resources/application-druid.yml | 10 ++++++---- ruoyi-admin/src/main/resources/application.yml | 12 ++++++------ .../com/ruoyi/framework/config/SecurityConfig.java | 6 +++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml index b66131c4..53280b64 100644 --- a/ruoyi-admin/src/main/resources/application-druid.yml +++ b/ruoyi-admin/src/main/resources/application-druid.yml @@ -8,10 +8,12 @@ spring: master: # 公司数据库地址 # url: jdbc:mysql://10.168.3.169:3306/athena?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 - url: jdbc:mysql://10.168.56.204:3306/jihe-dc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true - username: root -# password: Platform123!@# - password: Platform123!@# +# url: jdbc:mysql://127.0.0.1:3308/event_iot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true +# url: jdbc:mysql://127.0.0.1:3308/jihe-dc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true + url: jdbc:mysql://10.168.56.204:3306/jihe-dc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 + username: root + # password: root + password: Platform123!@# # 从库数据源 slave: # 从数据源开关/默认关闭 diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index f0180661..ae61f5d9 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -67,9 +67,9 @@ spring: # 端口,默认为6379 port: 6379 # 数据库索引 - database: 0 + database: 1 # 密码 - password: Redis123!@# + password: # 连接超时时间 timeout: 10s lettuce: @@ -156,7 +156,7 @@ aj: iot: # 物联平台地址 - address: http://127.0.0.1:8080 + address: https://10.0.81.202:8081 # redis 配置 redis: # 地址 @@ -164,9 +164,9 @@ iot: # 端口,默认为6379 port: 6379 # 数据库索引 - database: 10 + database: 0 # 密码 - password: Redis123!@# + password: # 连接超时时间 timeout: 10s lettuce: @@ -183,4 +183,4 @@ iot: # 允许访问的ip地址 allowed: - ips: 10.0.81.202,10.168.73.54,10.168.71.194 + ips: 10.0.81.202,10.168.73.54,10.168.71.194, diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 046648e7..f76628c4 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -116,7 +116,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { // 过滤请求 .authorizeRequests() // 对于登录login 注册register 验证码captchaImage 允许匿名访问 - .antMatchers("/login", "/register", "/captchaImage").anonymous() + .antMatchers("/login", "/register", "/captchaImage","/dc/**").anonymous() .antMatchers( HttpMethod.GET, "/", @@ -126,8 +126,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { "/**/*.js", "/profile/**" ).permitAll() -// .antMatchers("/swagger-ui.html").anonymous() -// .antMatchers("/swagger-resources/**").anonymous() + .antMatchers("/swagger-ui.html").anonymous() + .antMatchers("/swagger-resources/**").anonymous() .antMatchers("/webjars/**").anonymous() .antMatchers("/*/api-docs").anonymous() .antMatchers("/druid/**").anonymous() From 30b5b8ce373303ff8ed687fb3f897cd7a6c29a73 Mon Sep 17 00:00:00 2001 From: lau572 <1010031226@qq.com> Date: Mon, 8 Apr 2024 16:52:18 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E8=A7=86=E9=A2=91=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E8=A1=8C=E5=88=97=E8=A1=A8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/config/SecurityConfig.java | 6 +++--- .../business/controller/VideoController.java | 21 +++++++------------ .../service/impl/DcBoardServiceImpl.java | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index f76628c4..ead83dcd 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -116,7 +116,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { // 过滤请求 .authorizeRequests() // 对于登录login 注册register 验证码captchaImage 允许匿名访问 - .antMatchers("/login", "/register", "/captchaImage","/dc/**").anonymous() + .antMatchers("/login", "/register", "/captchaImage").anonymous() .antMatchers( HttpMethod.GET, "/", @@ -126,8 +126,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { "/**/*.js", "/profile/**" ).permitAll() - .antMatchers("/swagger-ui.html").anonymous() - .antMatchers("/swagger-resources/**").anonymous() +// .antMatchers("/swagger-ui.html").anonymous() +// .antMatchers("/swagger-resources/**").anonymous() .antMatchers("/webjars/**").anonymous() .antMatchers("/*/api-docs").anonymous() .antMatchers("/druid/**").anonymous() diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index 2021f8a4..7c374ad6 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -412,35 +412,30 @@ public class VideoController extends BaseController { Integer pileNumDistance = pileNumTransformMetre(pileNum); Map result = new HashMap<>(); - //上行列表 + //上行列表(包含双向) List> upCameraList = datalist.stream() - .filter(item -> "0".equals(item.get("camOrientation"))) .map(item->{ item.put("distance",Math.abs(pileNumTransformMetre(item.get("pileNum").toString()) - pileNumDistance)); return item; }) + .filter(item -> + ("0".equals(item.get("camOrientation")) || "2".equals(item.get("camOrientation"))) + && Integer.parseInt(item.get("distance").toString()) < 2000) .sorted(comparing(item -> Integer.parseInt(item.get("distance").toString()))) .collect(Collectors.toList()); - if (upCameraList.size() > 0 && Integer.parseInt(upCameraList.get(0).get("distance").toString()) < 2000){ - result.put("upCamera",upCameraList.get(0)); - } else { - result.put("upCamera",new HashMap<>()); - } + result.put("upCamera",upCameraList); + //下行列表 List> downCameraList = datalist.stream() - .filter(item -> "1".equals(item.get("camOrientation"))) .map(item->{ item.put("distance",Math.abs(pileNumTransformMetre(item.get("pileNum").toString()) - pileNumDistance)); return item; }) + .filter(item -> "1".equals(item.get("camOrientation")) && Integer.parseInt(item.get("distance").toString()) < 2000) .sorted(comparing(item -> Integer.parseInt(item.get("distance").toString()))) .collect(Collectors.toList()); - if (downCameraList.size() > 0 && Integer.parseInt(downCameraList.get(0).get("distance").toString()) < 2000){ - result.put("downCamera",downCameraList.get(0)); - } else { - result.put("downCamera",new HashMap<>()); - } + result.put("downCamera",downCameraList); return AjaxResult.success(result); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcBoardServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcBoardServiceImpl.java index 8a2c0a1f..a8c06783 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcBoardServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcBoardServiceImpl.java @@ -260,7 +260,7 @@ public class DcBoardServiceImpl implements IDcBoardService { result.add(map); }else { status = "0"; - map.put("code",status); + map.put("code",status); map.put("msg",ajaxResult13.get("msg").toString()); result.add(map); } From fd7e87457d50aad05904d8041786b31ad6569f63 Mon Sep 17 00:00:00 2001 From: xiepufeng <1072271977@qq.com> Date: Mon, 8 Apr 2024 17:10:40 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=A4=E9=80=9A?= =?UTF-8?q?=E7=89=B9=E5=BE=81=E6=8C=87=E6=A0=87=E6=8E=A5=E5=8F=A3=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/domain/DcTrafficMetricsData.java | 2 + .../enums/ChannelCongestionLevelEnum.java | 2 +- .../request/DcTrafficMetricsDataRequest.java | 3 ++ .../impl/DcTrafficStatisticsServiceImpl.java | 40 ++++++++++++++++++- .../statistics/handler/TrafficAnalysis.java | 15 ++++--- 5 files changed, 55 insertions(+), 7 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/domain/DcTrafficMetricsData.java b/zc-business/src/main/java/com/zc/business/domain/DcTrafficMetricsData.java index 3fee49b5..09297c7c 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcTrafficMetricsData.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcTrafficMetricsData.java @@ -1,5 +1,6 @@ package com.zc.business.domain; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.util.Date; @@ -39,6 +40,7 @@ public class DcTrafficMetricsData { /** * 统计时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") private Date statisticalDate; /** diff --git a/zc-business/src/main/java/com/zc/business/enums/ChannelCongestionLevelEnum.java b/zc-business/src/main/java/com/zc/business/enums/ChannelCongestionLevelEnum.java index 24922754..770b96ad 100644 --- a/zc-business/src/main/java/com/zc/business/enums/ChannelCongestionLevelEnum.java +++ b/zc-business/src/main/java/com/zc/business/enums/ChannelCongestionLevelEnum.java @@ -69,7 +69,7 @@ public enum ChannelCongestionLevelEnum { */ public static ChannelCongestionLevelEnum fromSpeed(int speed) { for (ChannelCongestionLevelEnum level : values()) { - if (speed > level.speedThreshold) { + if (speed >= level.speedThreshold) { return level; } } diff --git a/zc-business/src/main/java/com/zc/business/request/DcTrafficMetricsDataRequest.java b/zc-business/src/main/java/com/zc/business/request/DcTrafficMetricsDataRequest.java index 0e60621e..d5030b8d 100644 --- a/zc-business/src/main/java/com/zc/business/request/DcTrafficMetricsDataRequest.java +++ b/zc-business/src/main/java/com/zc/business/request/DcTrafficMetricsDataRequest.java @@ -1,6 +1,7 @@ package com.zc.business.request; import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; @@ -30,11 +31,13 @@ public class DcTrafficMetricsDataRequest { /** * 开始时间 */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date startTime; /** * 结束时间 */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date endTime; /** 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 5924c2b6..1caca7d6 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 @@ -30,6 +30,8 @@ import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.io.IOException; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.Collectors; @@ -152,6 +154,9 @@ public class DcTrafficStatisticsServiceImpl // 从Redis缓存中获取指定方向的交通路段数据列表 List dcTrafficSectionDataCaches = getDcTrafficSectionDataRedisCache(request.getDirection()); + // 过滤掉时间错误的交通数据 + processStaleTrafficSectionData(dcTrafficSectionDataCaches); + // 根据请求过滤交通数据 List trafficSectionDataList = filterTrafficDataByRequest(request, dcTrafficSectionDataCaches); @@ -189,7 +194,10 @@ public class DcTrafficStatisticsServiceImpl LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.between(DcTrafficSectionData::getStatisticalDate, request.getStartTime(), request.getEndTime()); queryWrapper.eq(DcTrafficSectionData::getPeriodType, request.getPeriodType()); - queryWrapper.eq(DcTrafficSectionData::getDirection, request.getDirection()); + + if (request.getDirection() != null) { + queryWrapper.eq(DcTrafficSectionData::getDirection, request.getDirection()); + } // 根据请求获取所属路段ID,并进一步筛选路段范围内的数据 Long roadSectionId = request.getRoadSectionId(); @@ -329,6 +337,36 @@ public class DcTrafficStatisticsServiceImpl return new ArrayList<>(dcTrafficSectionDataMap.values()); } + /** + * 过滤掉时间错误的交通路段数据,并更新数据的统计时间为当前时间。 + * 该方法会遍历交通路段数据列表,移除统计时间早于20分钟前的数据,并将其它数据的统计时间更新为当前时间。 + * + * @param dcTrafficSectionDataList 交通路段数据列表,列表中每一项包含一个交通路段的统计数据。 + */ + public void processStaleTrafficSectionData(List dcTrafficSectionDataList) { + // 计算20分钟前的时间戳 + Instant twentyMinutesAgo = Instant.now().minus(20, ChronoUnit.MINUTES); + // 获取当前时间 + Instant currentTime = Instant.now(); + + // 遍历交通路段数据列表 + dcTrafficSectionDataList.removeIf(data -> { + // 获取数据的统计时间 + Instant dataStatisticalTime = data.getStatisticalDate().toInstant(); + + // 如果数据的统计时间早于20分钟前,则移除该数据,并记录日志 + if (dataStatisticalTime.isBefore(twentyMinutesAgo)) { + logger.error("过滤掉时间错误的交通路段数据,已移除:" + data); + return true; // 移除该元素 + } + + // 更新数据的统计时间为当前时间 + data.setStatisticalDate(Date.from(currentTime)); // 直接使用Instant对象 + return false; // 保留该元素 + }); + } + + /** * 根据方向获取交通数据 * diff --git a/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java b/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java index 1be1f17c..7ce8ddc1 100644 --- a/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java +++ b/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java @@ -303,9 +303,6 @@ public class TrafficAnalysis { return (int) Math.round(averageSaturationDegree); } - - - /** * 计算路段饱和度 * @@ -423,14 +420,16 @@ public class TrafficAnalysis { // 遍历排序后的路段数据,计算每个路段的拥堵里程,并累加到总拥堵里程中 for (DcTrafficSectionData dcTrafficSectionData : sortedList) { + int averageSpeed = dcTrafficSectionData.getAverageSpeed(); int stakeMark = dcTrafficSectionData.getStakeMark(); // 对于不拥堵的路段,累加之前计算的默认拥堵距离 - if (!ChannelCongestionLevelEnum.isMediumOrSevereCongestion(averageSpeed)) { + if (!ChannelCongestionLevelEnum.isMediumOrSevereCongestion(averageSpeed) || dcTrafficSectionData.getTrafficVolume() == 0) { totalCongestionDistance.addAndGet(defaultCongestionDistance); previousStakeMark = stakeMark; defaultCongestionDistance = 0; + previousAverageSpeed = 0; continue; } @@ -447,12 +446,18 @@ public class TrafficAnalysis { // 如果当前路段被计算过,则累加拥堵路段数量 congestedSectionQuantity.addAndGet(1); } + } else { + // 如果之前没有计算过任何路段,则直接累加默认拥堵距离 + totalCongestionDistance.addAndGet(defaultCongestionDistance); + // 累加拥堵路段数量 + congestedSectionQuantity.addAndGet(1); } // 更新辅助变量以备后续计算 previousStakeMark = stakeMark; previousAverageSpeed = averageSpeed; } + }); // 计算并返回路网整体的拥堵指数 @@ -624,7 +629,7 @@ public class TrafficAnalysis { // 如果找到对应的路段,则将交通数据添加到该路段的数据列表中。 if (index > -1) { DcRoadSection dcRoadSection = sortedRoadSections.get(index); - List dcTrafficSectionList = sectionDataMap.putIfAbsent(dcRoadSection.getId(), new ArrayList<>()); + List dcTrafficSectionList = sectionDataMap.computeIfAbsent(dcRoadSection.getId(), k -> new ArrayList<>()); dcTrafficSectionList.add(trafficSectionData); } } From e94db979cf3d72f252bd91221bce4e5a9c893af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Mon, 8 Apr 2024 18:14:27 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=20=E4=BA=8B=E4=BB=B6id=20=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=AF=A6=E6=83=85=20=E6=B5=81=E7=A8=8B=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/zc/business/controller/DcEventController.java | 2 -- zc-business/src/main/java/com/zc/business/domain/DcEvent.java | 3 +++ .../java/com/zc/business/service/impl/DcEventServiceImpl.java | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcEventController.java b/zc-business/src/main/java/com/zc/business/controller/DcEventController.java index f7dcbe6d..6d5d060b 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcEventController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcEventController.java @@ -46,10 +46,8 @@ public class DcEventController extends BaseController @GetMapping("/list") public TableDataInfo list(DcEvent dcEvent) { - startPage(); List list = dcEventService.selectDcEventList(dcEvent); - return getDataTable(list); } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcEvent.java b/zc-business/src/main/java/com/zc/business/domain/DcEvent.java index 5740e0d4..172107f8 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcEvent.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcEvent.java @@ -279,6 +279,9 @@ public class DcEvent { @ApiModelProperty("事件类型名称") @TableField(exist = false) private String eventName; + @ApiModelProperty("流程节点") + @TableField(exist = false) + private String processNode; diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java index 80be2290..53846d7b 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java @@ -603,6 +603,8 @@ public class DcEventServiceImpl extends ServiceImpl impl public DcEvent selectEventSubclassById(int eventType, String id) { //todo DcEvent dcEvent = dcEventMapper.selectDcEventById(id); + List processConfigList = dcProcessConfigMapper.selectDcProcessConfigByEventType(Math.toIntExact(dcEvent.getEventType())); + dcEvent.setProcessConfigList(processConfigList); switch (eventType) { //交通事故 case 1: From a9820f478b39c2a1f8dc252e9de4f8407ab00c74 Mon Sep 17 00:00:00 2001 From: "Mr.Wang" Date: Mon, 8 Apr 2024 18:37:30 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=84=E6=A1=88?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DcEmergencyPlansController.java | 8 ++-- .../zc/business/domain/DcEmergencyPlans.java | 6 --- .../zc/business/domain/DcExecuteAction.java | 18 ++++----- .../impl/DcEmergencyPlansServiceImpl.java | 37 ++++++++++--------- .../business/DcEmergencyPlansMapper.xml | 24 +++++------- .../mapper/business/DcExecuteActionMapper.xml | 28 +++++++------- 6 files changed, 56 insertions(+), 65 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcEmergencyPlansController.java b/zc-business/src/main/java/com/zc/business/controller/DcEmergencyPlansController.java index d6b84c89..f260969a 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcEmergencyPlansController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcEmergencyPlansController.java @@ -34,7 +34,7 @@ public class DcEmergencyPlansController extends BaseController { * 查询事件预案列表 */ @ApiOperation("查询事件预案列表") - @PreAuthorize("@ss.hasPermi('business:plans:list')") +// @PreAuthorize("@ss.hasPermi('business:plans:list')") @GetMapping("/list") public TableDataInfo list(DcEmergencyPlans dcEmergencyPlans) { startPage(); @@ -46,7 +46,7 @@ public class DcEmergencyPlansController extends BaseController { * 根据事件预案id查询事件预案列表 */ @ApiOperation("根据事件预案id查询事件预案列表") - @PreAuthorize("@ss.hasPermi('business:plans:list')") +// @PreAuthorize("@ss.hasPermi('business:plans:list')") @GetMapping("/list/{id}") public AjaxResult list(@PathVariable @ApiParam(name = "id", value = "事件预案id", required = true) Integer id) { @@ -149,7 +149,7 @@ public class DcEmergencyPlansController extends BaseController { * 新增事件预案 */ @ApiOperation("新增预案") - @PreAuthorize("@ss.hasPermi('business:plans:add')") +// @PreAuthorize("@ss.hasPermi('business:plans:add')") @PostMapping public AjaxResult add(@RequestBody DcEmergencyPlans dcEmergencyPlans) { return toAjax(dcEmergencyPlansService.insertDcEmergencyPlans(dcEmergencyPlans)); @@ -159,7 +159,7 @@ public class DcEmergencyPlansController extends BaseController { * 修改事件预案 */ @ApiOperation("修改预案") - @PreAuthorize("@ss.hasPermi('business:plans:edit')") +// @PreAuthorize("@ss.hasPermi('business:plans:edit')") @PutMapping public AjaxResult update(@RequestBody DcEmergencyPlans dcEmergencyPlans) { return toAjax(dcEmergencyPlansService.updateDcEmergencyPlans(dcEmergencyPlans)); diff --git a/zc-business/src/main/java/com/zc/business/domain/DcEmergencyPlans.java b/zc-business/src/main/java/com/zc/business/domain/DcEmergencyPlans.java index a7bcad9e..67fc4156 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcEmergencyPlans.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcEmergencyPlans.java @@ -81,12 +81,6 @@ public class DcEmergencyPlans { @ApiModelProperty("控制指令") private String controlCommand; - /** - * 事件分类 - */ - @ApiModelProperty("事件分类") - private int eventCategory; - /** * 执行操作列表 */ diff --git a/zc-business/src/main/java/com/zc/business/domain/DcExecuteAction.java b/zc-business/src/main/java/com/zc/business/domain/DcExecuteAction.java index 1ef52211..c43224bd 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcExecuteAction.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcExecuteAction.java @@ -39,12 +39,6 @@ public class DcExecuteAction{ @ApiModelProperty("设备类型") private int deviceType; - /** - * 操作类型 - */ - @ApiModelProperty("操作类型") - private int actionType; - @ApiModelProperty("创建时间") private Date createTime; @ApiModelProperty("修改时间") @@ -69,10 +63,16 @@ public class DcExecuteAction{ private String deviceList; /** - * 其他配置 + * 执行操作配置 + */ + @ApiModelProperty("执行操作配置") + private String executeConfig; + + /** + * 恢复操作配置 */ - @ApiModelProperty("其他配置") - private String otherConfig; + @ApiModelProperty("恢复操作配置") + private String recoverConfig; diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java index e837c5ea..c373152e 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java @@ -301,7 +301,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { // 指定设备资源 // 根据设备id,获取设备集合 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - JSONObject otherConfig = JSON.parseObject(dcExecuteAction.getOtherConfig()); + JSONObject otherConfig = JSON.parseObject(dcExecuteAction.getExecuteConfig()); List deviceList = (List) otherConfig.get("deviceList"); queryWrapper.in(DcDevice::getIotDeviceId, deviceList); dcDevices = dcDeviceService.list(queryWrapper); @@ -576,7 +576,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { invokedFunction( dcEventAnDcEmergencyPlans.getOperationType(), dcDevices, - JSON.parseObject(dcExecuteAction.getOtherConfig()), + JSON.parseObject(dcExecuteAction.getExecuteConfig()), resultArray); // 记录操作过的设备id @@ -828,7 +828,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { dcEmergencyPlansMapper.updateDcEmergencyPlans(dcEmergencyPlans); // 修改执行操作表数据 dcExecuteActionList.forEach(dcExecuteAction -> dcExecuteAction.setUpdateTime(DateUtils.getNowDate())); - // 过滤出删除掉的执行操作和恢复操作 + // 过滤出删除掉的操作 String dcExecuteActionId = dcExecuteActionList.stream() .filter(dcExecuteAction -> dcExecuteAction.getId() != null) .map(DcExecuteAction::getEmergencyPlansId) @@ -839,17 +839,16 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { .filter(dcExecuteAction -> dcExecuteAction.getId() != null) .map(DcExecuteAction::getId) .collect(Collectors.toList()); - // 查询出事件预案关联的执行操作和恢复操作 + // 查询出事件预案关联的操作 List dcExecuteActionIdList = dcExecuteActionService.selectDcExecuteActionByEmergencyPlansId(dcExecuteActionId); List commonIds = new ArrayList<>(ids); commonIds.retainAll(dcExecuteActionIdList); - // 删除后的执行操作id和恢复操作id + // 删除后的操作id List idsNotInDcExecuteActionIdList = new ArrayList<>(dcExecuteActionIdList); idsNotInDcExecuteActionIdList.removeAll(commonIds); - // 根据执行操作id和恢复操作id,进行删除操作 + // 根据操作id,进行删除操作 if (idsNotInDcExecuteActionIdList.size() > 0) { - System.out.println("存在需要删除的数据"); dcExecuteActionService.deleteDcExecuteAction(idsNotInDcExecuteActionIdList); } @@ -907,14 +906,10 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { * 数据处理 */ public static List dataProcessing(DcEmergencyPlans dcEmergencyPlans) { - // 过滤出执行操作数据 - List dcExecuteActionOperationList = dcEmergencyPlans.getDcExecuteAction() - .stream() - .filter(dcExecuteAction -> dcExecuteAction.getActionType() == 1) - .collect(Collectors.toList()); + List dcExecuteActionList = dcEmergencyPlans.getDcExecuteAction(); // 设备类型 数据处理 - String deviceType = dcExecuteActionOperationList.stream() + String deviceType = dcExecuteActionList.stream() .map(DcExecuteAction::getDeviceType) .distinct() .map(type -> Arrays.stream(DeviceTypeEnum.values()) @@ -926,7 +921,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { .collect(Collectors.joining(",")); dcEmergencyPlans.setDeviceType(deviceType); // 可控设备 数据处理 - List dcExecuteActionNewList = dcExecuteActionOperationList.stream() + List dcExecuteActionNewList = dcExecuteActionList.stream() .filter(dcExecuteAction -> dcExecuteAction.getSearchRule() == 1) .collect(Collectors.toList()); String controllableDevice = dcExecuteActionNewList.stream() @@ -934,11 +929,12 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { .collect(Collectors.joining("、")); dcEmergencyPlans.setControllableDevice(controllableDevice); // 控制指令 数据处理 - List otherConfigList = dcExecuteActionOperationList.stream() + List otherConfigList = dcExecuteActionList.stream() .map(dcExecuteAction -> { JSONObject config = new JSONObject(); - String otherConfig = dcExecuteAction.getOtherConfig(); - JSONObject jsonObject = JSON.parseObject(otherConfig); + // 执行操作配置 + String executeConfig = dcExecuteAction.getExecuteConfig(); + JSONObject jsonObject = JSON.parseObject(executeConfig); if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.DRIVING_GUIDANCE) { // 行车诱导 config.put("controlModelName",jsonObject.get("controlModelName")); @@ -950,7 +946,12 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { }else if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.VARIABLE_INFORMATION_FLAG || dcExecuteAction.getDeviceType() == DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING) { // 情报板/语音广播 - config.put("content",jsonObject.get("content")); + if (jsonObject.get("operationType").equals("1")) { + config.put("content",jsonObject.get("content")); + }else { + config.put("operationType","智能发布"); + } + } else if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.LASER_FATIGUE_AWAKENING) { // 激光疲劳唤醒 diff --git a/zc-business/src/main/resources/mapper/business/DcEmergencyPlansMapper.xml b/zc-business/src/main/resources/mapper/business/DcEmergencyPlansMapper.xml index a1e7e6f5..bb15469d 100644 --- a/zc-business/src/main/resources/mapper/business/DcEmergencyPlansMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcEmergencyPlansMapper.xml @@ -15,18 +15,17 @@ - - - + + @@ -43,7 +42,6 @@ triggering_condition, controllable_device, control_command, - event_category, #{planName}, @@ -55,7 +53,6 @@ #{triggeringCondition}, #{controllableDevice}, #{controlCommand}, - #{eventCategory}, @@ -68,8 +65,7 @@ device_type = #{deviceType}, triggering_condition = #{triggeringCondition}, controllable_device = #{controllableDevice}, - control_command = #{controlCommand}, - event_category = #{eventCategory} + control_command = #{controlCommand} where id = #{id} @@ -90,16 +86,16 @@ t1.triggering_condition, t1.controllable_device, t1.control_command, - t1.event_category, t2.id as action_id, t2.emergency_plans_id as action_emergency_plans_id, t2.device_type as action_device_type, - t2.action_type as action_action_type, t2.create_time as action_create_time, + t2.update_time as action_update_time, t2.search_rule as action_search_rule, t2.`number` as action_number, t2.device_list as action_device_list, - t2.other_config as action_other_config + t2.execute_config as action_execute_config, + t2.recover_config as action_recover_config from dc_emergency_plans t1 left join dc_execute_action t2 on t1.id = t2.emergency_plans_id @@ -115,13 +111,11 @@ t1.device_type, t1.triggering_condition, t1.controllable_device, - t1.control_command, - t1.event_category + t1.control_command from dc_emergency_plans t1 and plan_name like concat('%', #{planName}, '%') and event_type = #{eventType} - and event_category = #{eventCategory} order by t1.id desc @@ -133,12 +127,12 @@ diff --git a/zc-business/src/main/resources/mapper/business/DcExecuteActionMapper.xml b/zc-business/src/main/resources/mapper/business/DcExecuteActionMapper.xml index 2d975ec5..98c710ce 100644 --- a/zc-business/src/main/resources/mapper/business/DcExecuteActionMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcExecuteActionMapper.xml @@ -10,24 +10,26 @@ (emergency_plans_id, device_type, - action_type, create_time, search_rule, `number`, device_list, - other_config + execute_config, + recover_config ) values - (#{item.emergencyPlansId}, + ( + #{item.emergencyPlansId}, #{item.deviceType}, - #{item.actionType}, #{item.createTime}, #{item.searchRule}, #{item.number}, #{item.deviceList}, - #{item.otherConfig}) + #{item.executeConfig}, + #{item.recoverConfig} + ) @@ -47,12 +49,6 @@ then #{item.deviceType} - - - when id=#{item.id} - then #{item.actionType} - - when id=#{item.id} @@ -77,10 +73,16 @@ then #{item.deviceList} - + + + when id=#{item.id} + then #{item.executeConfig} + + + when id=#{item.id} - then #{item.otherConfig} + then #{item.recoverConfig} From adf4a9600f39be699cb66e8e013590466ebea1d8 Mon Sep 17 00:00:00 2001 From: "Mr.Wang" Date: Mon, 8 Apr 2024 19:45:45 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E5=92=8C=E9=A2=84=E6=A1=88=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DcEmergencyPlansServiceImpl.java | 177 ++++++++++-------- 1 file changed, 101 insertions(+), 76 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java index c373152e..bf54a4b8 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java @@ -196,7 +196,8 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { markArray[1] = String.format("%0" + 3 + "d", markArray[1]); } DcExecuteAction executeAction = dcEventAnDcEmergencyPlans.getDcEmergencyPlans().getExecuteAction(); - List dcDevices = ruleFiltering(executeAction, markArray, direction); + Integer operationType = dcEventAnDcEmergencyPlans.getOperationType(); + List dcDevices = ruleFiltering(executeAction, markArray, direction, operationType); return getBoardTemplate(dcDevices); } @@ -217,7 +218,8 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { markArray[1] = String.format("%0" + 3 + "d", markArray[1]); } DcExecuteAction executeAction = dcEventAnDcEmergencyPlans.getDcEmergencyPlans().getExecuteAction(); - List dcDevices = ruleFiltering(executeAction, markArray, direction); + Integer operationType = dcEventAnDcEmergencyPlans.getOperationType(); + List dcDevices = ruleFiltering(executeAction, markArray, direction, operationType); return getBoardTemplate(dcDevices); } @@ -287,9 +289,12 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { * @param direction * @return */ - public List ruleFiltering(DcExecuteAction dcExecuteAction, String[] markArray, String direction) { + public List ruleFiltering(DcExecuteAction dcExecuteAction, String[] markArray, String direction, Integer operationType) { Integer searchRule = dcExecuteAction.getSearchRule(); + // 区分执行操作还是恢复操作 + JSONObject otherConfig = operationType.equals(1)? + JSON.parseObject(dcExecuteAction.getExecuteConfig()): JSON.parseObject(dcExecuteAction.getRecoverConfig()); List start = new ArrayList<>(); List end = new ArrayList<>(); // 设备列表 @@ -301,7 +306,6 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { // 指定设备资源 // 根据设备id,获取设备集合 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - JSONObject otherConfig = JSON.parseObject(dcExecuteAction.getExecuteConfig()); List deviceList = (List) otherConfig.get("deviceList"); queryWrapper.in(DcDevice::getIotDeviceId, deviceList); dcDevices = dcDeviceService.list(queryWrapper); @@ -564,19 +568,21 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { // 获取事件预案数据 DcEmergencyPlans dcEmergencyPlans = dcEventAnDcEmergencyPlans.getDcEmergencyPlans(); + Integer operationType = dcEventAnDcEmergencyPlans.getOperationType(); - //获取事件预案中的 执行操作配置 + //获取事件预案中的操作配置 dcEmergencyPlans.getDcExecuteAction() .forEach(dcExecuteAction -> { - List dcDevices = ruleFiltering(dcExecuteAction, markArray, direction); - + List dcDevices = ruleFiltering(dcExecuteAction, markArray, direction, operationType); + JSONObject otherConfig = operationType.equals(1)? + JSON.parseObject(dcExecuteAction.getExecuteConfig()): JSON.parseObject(dcExecuteAction.getRecoverConfig()); try { // 根据不通设备类型,执行不通的功能操作 invokedFunction( dcEventAnDcEmergencyPlans.getOperationType(), dcDevices, - JSON.parseObject(dcExecuteAction.getExecuteConfig()), + otherConfig, resultArray); // 记录操作过的设备id @@ -666,81 +672,31 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { } else if (device.getDeviceType().equals(DeviceTypeConstants.VARIABLE_INFORMATION_FLAG.toString())) { if (operationType == 1) { - - // 执行操作 - // 可变信息标志 分三步 - // 1:执行11功能码 - functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_11; - props.put("fileName", "play011.lst"); - props.put("size", "65535"); - AjaxResult ajaxResult11; - ajaxResult11 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props); - if (ajaxResult11.get("code").equals(200)) { - // 2:执行13功能码 - HashMap props11 = new HashMap<>(); - functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_13; - List> list = new ArrayList<>(); - Map parameters = new HashMap<>(); - DcInfoBoardTemplate dcInfoBoardTemplate = JSON.parseObject( - JSON.toJSONString(otherConfig.get("dcInfoBoardTemplate")), - DcInfoBoardTemplate.class); - // stopTime - parameters.put("STAY", dcInfoBoardTemplate.getStopTime()); - // inScreenMode - parameters.put("ACTION", dcInfoBoardTemplate.getInScreenMode()); - // fontSpacing - parameters.put("SPEED", dcInfoBoardTemplate.getFontSpacing()); - // fontColor - parameters.put("COLOR", dcInfoBoardTemplate.getFontColor()); - // fontType - parameters.put("FONT", dcInfoBoardTemplate.getFontType()); - // fontSize - parameters.put("FONT_SIZE", dcInfoBoardTemplate.getFontSize()); - // content - parameters.put("CONTENT", dcInfoBoardTemplate.getContent()); - // screenSize 768*64 宽度和高度 - parameters.put("width", dcInfoBoardTemplate.getScreenSize().split("\\*")[0]); - parameters.put("height", dcInfoBoardTemplate.getScreenSize().split("\\*")[1]); - // formatStyle - parameters.put("formatStyle", dcInfoBoardTemplate.getFormatStyle()); - list.add(parameters); - props11.put("parameters", list); - AjaxResult ajaxResult13 = null; - ajaxResult13 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props11); - JSONObject result = new JSONObject(); - if (ajaxResult13.get("code").equals(200)) { - HashMap props1B = new HashMap<>(); - // 3: 执行1B功能码 - functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B; - props1B.put("fileId", "11"); - AjaxResult ajaxResult1B = dcDeviceController.invokedFunction(iotDeviceId, functionId, props1B); - result.put("device", device.getId()); - result.put("result", ajaxResult1B); - resultArray.add(result); - - } else { - result.put("device", device.getId()); - result.put("result", ajaxResult13); - resultArray.add(result); - } - } - + // 情报板发布全流程 + boardReleaseProcess(props, iotDeviceId, otherConfig, device, resultArray); } else { // 恢复操作 - props.put("fileId", "10"); - functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B; - AjaxResult ajaxResult1B; + if (otherConfig.get("operationType").equals("2")) { + // 还原上次 + props.put("fileId", "10"); + functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B; + AjaxResult ajaxResult1B; - ajaxResult1B = dcDeviceController.invokedFunction(iotDeviceId, functionId, props); + ajaxResult1B = dcDeviceController.invokedFunction(iotDeviceId, functionId, props); - JSONObject result = new JSONObject(); - result.put("device", device.getId()); - result.put("result", ajaxResult1B); - resultArray.add(result); + JSONObject result = new JSONObject(); + result.put("device", device.getId()); + result.put("result", ajaxResult1B); + resultArray.add(result); + }else { + // 播放自定义 + boardReleaseProcess(props, iotDeviceId, otherConfig, device, resultArray); + } } } - else if (device.getDeviceType().equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING.toString())) { + else if (device.getDeviceType().equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING.toString()) + && operationType.equals(1)) { // 路段广播 JSONObject params = new JSONObject(); params.put("name", "task-event"); @@ -793,6 +749,75 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { } + /** + * 情报板发布全流程 + */ + public void boardReleaseProcess(HashMap props, + String iotDeviceId, + JSONObject otherConfig, + DcDevice device, + JSONArray resultArray + ) throws HttpException, IOException { + String functionId = ""; + // 执行操作 + // 可变信息标志 分三步 + // 1:执行11功能码 + functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_11; + props.put("fileName", "play011.lst"); + props.put("size", "65535"); + AjaxResult ajaxResult11; + ajaxResult11 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props); + if (ajaxResult11.get("code").equals(200)) { + // 2:执行13功能码 + HashMap props11 = new HashMap<>(); + functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_13; + List> list = new ArrayList<>(); + Map parameters = new HashMap<>(); + DcInfoBoardTemplate dcInfoBoardTemplate = JSON.parseObject( + JSON.toJSONString(otherConfig.get("dcInfoBoardTemplate")), + DcInfoBoardTemplate.class); + // stopTime + parameters.put("STAY", dcInfoBoardTemplate.getStopTime()); + // inScreenMode + parameters.put("ACTION", dcInfoBoardTemplate.getInScreenMode()); + // fontSpacing + parameters.put("SPEED", dcInfoBoardTemplate.getFontSpacing()); + // fontColor + parameters.put("COLOR", dcInfoBoardTemplate.getFontColor()); + // fontType + parameters.put("FONT", dcInfoBoardTemplate.getFontType()); + // fontSize + parameters.put("FONT_SIZE", dcInfoBoardTemplate.getFontSize()); + // content + parameters.put("CONTENT", dcInfoBoardTemplate.getContent()); + // screenSize 768*64 宽度和高度 + parameters.put("width", dcInfoBoardTemplate.getScreenSize().split("\\*")[0]); + parameters.put("height", dcInfoBoardTemplate.getScreenSize().split("\\*")[1]); + // formatStyle + parameters.put("formatStyle", dcInfoBoardTemplate.getFormatStyle()); + list.add(parameters); + props11.put("parameters", list); + AjaxResult ajaxResult13 = null; + ajaxResult13 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props11); + JSONObject result = new JSONObject(); + if (ajaxResult13.get("code").equals(200)) { + HashMap props1B = new HashMap<>(); + // 3: 执行1B功能码 + functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B; + props1B.put("fileId", "11"); + AjaxResult ajaxResult1B = dcDeviceController.invokedFunction(iotDeviceId, functionId, props1B); + result.put("device", device.getId()); + result.put("result", ajaxResult1B); + resultArray.add(result); + + } else { + result.put("device", device.getId()); + result.put("result", ajaxResult13); + resultArray.add(result); + } + } + } + /** * 新增事件预案 From dc8c7a05c53c8d5258f8f9a33963f7e91cd683b0 Mon Sep 17 00:00:00 2001 From: xiepufeng <1072271977@qq.com> Date: Tue, 9 Apr 2024 11:48:03 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=8B=A5=E5=A0=B5=E8=B7=AF=E6=AE=B5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/constant/StakeMarkConstant.java | 2 +- .../DcTrafficStatisticsController.java | 16 ++ .../domain/DcCongestedSectionData.java | 31 ++++ .../enums/ChannelCongestionLevelEnum.java | 69 +++++++++ .../service/DcTrafficStatisticsService.java | 9 ++ .../impl/DcTrafficStatisticsServiceImpl.java | 25 ++++ .../statistics/handler/TrafficAnalysis.java | 137 +++++++++++++++++- 7 files changed, 281 insertions(+), 8 deletions(-) create mode 100644 zc-business/src/main/java/com/zc/business/domain/DcCongestedSectionData.java diff --git a/zc-business/src/main/java/com/zc/business/constant/StakeMarkConstant.java b/zc-business/src/main/java/com/zc/business/constant/StakeMarkConstant.java index 45d5e654..d3f65f5c 100644 --- a/zc-business/src/main/java/com/zc/business/constant/StakeMarkConstant.java +++ b/zc-business/src/main/java/com/zc/business/constant/StakeMarkConstant.java @@ -13,7 +13,7 @@ public class StakeMarkConstant { // 定义最小桩号常量 public static final int MIN_STAKE_MARK = 54394; - // 定义毫米波雷达最大测量间隔 + // 定义毫米波雷达最大间隔 public static final int MAX_INTERVAL_MILLIMETER_WAVE_RADAR = 12030; /** 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 eb1224cc..0f799cf9 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 @@ -1,6 +1,7 @@ package com.zc.business.controller; import com.ruoyi.common.core.domain.AjaxResult; +import com.zc.business.domain.DcCongestedSectionData; import com.zc.business.domain.DcTrafficMetricsData; import com.zc.business.domain.DcTrafficSectionData; import com.zc.business.request.DcTrafficMetricsDataRequest; @@ -88,4 +89,19 @@ public class DcTrafficStatisticsController { return AjaxResult.success(dcTrafficMetricsDataList); } + /** + * 获取当前拥堵路段 + * + * @param direction 交通方向,指定查询哪个方向的拥堵路段。具体方向的定义根据实际业务而定。 + * @return 返回一个AjaxResult对象,其中包含了查询结果。如果查询成功,则结果中封装了当前拥堵路段的数据列表。 + */ + @ApiOperation("获取当前拥堵路段") + @GetMapping("/current/congested") + public AjaxResult currentCongestedSection(Byte direction){ + // 调用服务层方法,获取当前交通指标数据 + List dcTrafficMetricsData = dcTrafficStatisticsService.currentCongestedSection(direction); + // 将获取到的交通指标数据封装为成功的结果并返回 + return AjaxResult.success(dcTrafficMetricsData); + } + } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcCongestedSectionData.java b/zc-business/src/main/java/com/zc/business/domain/DcCongestedSectionData.java new file mode 100644 index 00000000..d89bc720 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcCongestedSectionData.java @@ -0,0 +1,31 @@ +package com.zc.business.domain; + +import lombok.Data; + +/** + * 交通拥堵路段数据定义 + * @author xiepufeng + */ +@Data +public class DcCongestedSectionData { + + /** + * 开始桩号 + */ + private Integer startStakeMark; + + /** + * 结束桩号 + */ + private Integer endStakeMark; + + /** + * 道路方向 + */ + private Byte direction; + + /** + * 平均车速 + */ + private Integer averageSpeed; +} diff --git a/zc-business/src/main/java/com/zc/business/enums/ChannelCongestionLevelEnum.java b/zc-business/src/main/java/com/zc/business/enums/ChannelCongestionLevelEnum.java index 770b96ad..67e3e584 100644 --- a/zc-business/src/main/java/com/zc/business/enums/ChannelCongestionLevelEnum.java +++ b/zc-business/src/main/java/com/zc/business/enums/ChannelCongestionLevelEnum.java @@ -76,6 +76,27 @@ public enum ChannelCongestionLevelEnum { return SEVERE_CONGESTION; // 若速度小于等于所有等级阈值,则视为严重拥堵 } + /** + * 根据给定速度,返回对应的通道拥挤度等级。 + * + * @param speed 速度(单位:km/h) + * @param trafficVolume 车流量 + * @return 对应的通道拥挤度等级 + */ + public static ChannelCongestionLevelEnum fromSpeed(int speed, int trafficVolume) { + + if (trafficVolume == 0) { + return FLOWING; + } + + for (ChannelCongestionLevelEnum level : values()) { + if (speed >= level.speedThreshold) { + return level; + } + } + return SEVERE_CONGESTION; // 若速度小于等于所有等级阈值,则视为严重拥堵 + } + /** * 判断速度是否是是中度拥堵或者严重拥堵 */ @@ -84,6 +105,53 @@ public enum ChannelCongestionLevelEnum { return level == MEDIUM_CONGESTION || level == SEVERE_CONGESTION; } + + /** + * 判断当前交通状况是否为中度或严重拥堵。 + * + * @param speed 当前道路的车速,单位为任意测量单位,取决于具体应用。 + * @param trafficVolume 当前道路的交通流量,单位为任意测量单位,取决于具体应用。 + * @return boolean 返回 true 如果当前交通状况被判断为中度或严重拥堵,否则返回 false。 + */ + public static boolean isMediumOrSevereCongestion(int speed, int trafficVolume) { + + // 当交通流量为0时,不考虑拥堵问题,直接返回false + if (trafficVolume == 0) { + return false; + } + + // 根据车速判断拥堵级别 + ChannelCongestionLevelEnum level = fromSpeed(speed); + // 判断拥堵级别是否为中度或严重拥堵 + return level == MEDIUM_CONGESTION || level == SEVERE_CONGESTION; + } + + /** + * 判断给定速度是否属于拥堵状态。 + * + * @param speed 速度(单位:km/h) + * @param trafficVolume 车流量 + * @return 如果速度小于等于基本畅通的阈值,则返回true;否则返回false。 + */ + public static boolean isCongestion(int speed, int trafficVolume) { + + if (trafficVolume == 0) { + return false; + } + + return speed < BASIC_FLOWING.getSpeedThreshold(); + } + + /** + * 判断给定速度是否属于拥堵状态。 + * + * @param speed 速度(单位:km/h) + * @return 如果速度小于等于基本畅通的阈值,则返回true;否则返回false。 + */ + public static boolean isCongestion(int speed) { + return speed < BASIC_FLOWING.getSpeedThreshold(); + } + /** * 判断给定速度是否属于指定的拥挤度等级。 * @@ -92,6 +160,7 @@ public enum ChannelCongestionLevelEnum { * @return 如果速度属于该等级,返回true;否则返回false。 */ public static boolean isWithinLevel(int speed, ChannelCongestionLevelEnum level) { + if (level == null) return false; ChannelCongestionLevelEnum currentLevel = fromSpeed(speed); return currentLevel == level; } diff --git a/zc-business/src/main/java/com/zc/business/service/DcTrafficStatisticsService.java b/zc-business/src/main/java/com/zc/business/service/DcTrafficStatisticsService.java index 45611fec..1fddc4ba 100644 --- a/zc-business/src/main/java/com/zc/business/service/DcTrafficStatisticsService.java +++ b/zc-business/src/main/java/com/zc/business/service/DcTrafficStatisticsService.java @@ -2,6 +2,7 @@ package com.zc.business.service; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.IService; +import com.zc.business.domain.DcCongestedSectionData; import com.zc.business.domain.DcTrafficMetricsData; import com.zc.business.domain.DcTrafficSectionData; import com.zc.business.request.DcTrafficMetricsDataRequest; @@ -50,4 +51,12 @@ public interface DcTrafficStatisticsService extends IService historyTrafficMetrics(DcTrafficMetricsDataRequest request); + + /** + * 获取当前拥堵路段列表。 + * + * @param direction 交通方向,指定查询哪个方向的拥堵路段。具体方向的定义根据实际业务而定。 + * @return 返回当前拥堵路段列表。 + */ + List currentCongestedSection(Byte direction); } 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 1caca7d6..de1c91fc 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 @@ -10,6 +10,7 @@ import com.ruoyi.common.exception.ServiceException; import com.zc.business.constant.DeviceTypeConstants; import com.zc.business.constant.RedisKeyConstants; import com.zc.business.controller.DcDeviceController; +import com.zc.business.domain.DcCongestedSectionData; import com.zc.business.domain.DcRoadSection; import com.zc.business.domain.DcTrafficMetricsData; import com.zc.business.domain.DcTrafficSectionData; @@ -228,6 +229,30 @@ public class DcTrafficStatisticsServiceImpl } + /** + * 获取当前拥堵的路段数据列表。 + * + * @param direction 指定的方向,用于筛选交通数据。 + * @return 返回一个包含当前拥堵路段数据的列表。 + */ + @Override + public List currentCongestedSection(Byte direction) { + + // 从Redis缓存中获取指定方向的交通路段数据列表 + List dcTrafficSectionDataCaches = getDcTrafficSectionDataRedisCache(direction); + + // 过滤掉时间错误的交通数据 + processStaleTrafficSectionData(dcTrafficSectionDataCaches); + + // 移除非毫米波雷达设备类型的交通数据 + dcTrafficSectionDataCaches.removeIf(data -> !Objects.equals(data.getDeviceType(), DeviceTypeConstants.MILLIMETER_WAVE_RADAR)); + + // 分析交通数据,计算出当前拥堵的路段列表并返回 + return trafficAnalysis.calculateCongestedSection(dcTrafficSectionDataCaches); + } + + + /** * 恢复每日缓存的函数。 * 该方法尝试从物联平台获取所有设备信息,并对这些信息进行处理。 diff --git a/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java b/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java index 7ce8ddc1..41e441b8 100644 --- a/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java +++ b/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java @@ -5,10 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.common.core.redis.RedisCache; import com.zc.business.constant.RedisKeyConstants; import com.zc.business.constant.StakeMarkConstant; -import com.zc.business.domain.DcRoadSection; -import com.zc.business.domain.DcTrafficMetricsData; -import com.zc.business.domain.DcTrafficSectionData; -import com.zc.business.domain.DcTrafficVolumeForecast; +import com.zc.business.domain.*; import com.zc.business.enums.*; import com.zc.business.request.DcTrafficMetricsDataRequest; import com.zc.business.service.DcTrafficVolumeForecastService; @@ -425,7 +422,7 @@ public class TrafficAnalysis { int stakeMark = dcTrafficSectionData.getStakeMark(); // 对于不拥堵的路段,累加之前计算的默认拥堵距离 - if (!ChannelCongestionLevelEnum.isMediumOrSevereCongestion(averageSpeed) || dcTrafficSectionData.getTrafficVolume() == 0) { + if (!ChannelCongestionLevelEnum.isMediumOrSevereCongestion(averageSpeed, dcTrafficSectionData.getTrafficVolume())) { totalCongestionDistance.addAndGet(defaultCongestionDistance); previousStakeMark = stakeMark; defaultCongestionDistance = 0; @@ -441,6 +438,7 @@ public class TrafficAnalysis { int congestionDistance = Math.abs(stakeMark - previousStakeMark); if (congestionDistance > StakeMarkConstant.MAX_INTERVAL_MILLIMETER_WAVE_RADAR) { totalCongestionDistance.addAndGet(defaultCongestionDistance); + defaultCongestionDistance = 0; } else { totalCongestionDistance.addAndGet(congestionDistance); // 如果当前路段被计算过,则累加拥堵路段数量 @@ -458,6 +456,10 @@ public class TrafficAnalysis { previousAverageSpeed = averageSpeed; } + if (defaultCongestionDistance != 0) { + totalCongestionDistance.addAndGet(defaultCongestionDistance); + } + }); // 计算并返回路网整体的拥堵指数 @@ -470,8 +472,6 @@ public class TrafficAnalysis { return metricsData; } - - /** * 计算路段交通量 * @@ -638,4 +638,127 @@ public class TrafficAnalysis { } + /** + * 计算拥堵路段数据。 + * + * @param trafficSectionDataList 交通路段数据列表,包含各个路段的平均速度、交通量和行驶方向等信息。 + * @return 拥堵路段数据列表,详细记录了每个拥堵路段的起始桩号、结束桩号、平均速度和行驶方向等信息。 + */ + public List calculateCongestedSection(List trafficSectionDataList) { + + if (trafficSectionDataList == null || trafficSectionDataList.isEmpty()) { + return Collections.emptyList(); + } + + // 根据行驶方向对交通数据进行分组 + Map> groupedByDirection = trafficSectionDataList.stream() + .collect(Collectors.groupingBy(DcTrafficSectionData::getDirection)); + + List dcCongestedSectionDataList = new ArrayList<>(); + + groupedByDirection.forEach((directionData, trafficSectionList) -> { + + List sortedList; + + // 根据行驶方向,对交通路段数据进行排序,上行方向逆序,下行方向正序 + if (directionData.equals(LaneDirectionEnum.UPWARD.getValue())) { + sortedList = trafficSectionList.stream() + .sorted(Comparator.comparing(DcTrafficSectionData::getStakeMark).reversed()) + .collect(Collectors.toList()); + } else { + sortedList = trafficSectionList.stream() + .sorted(Comparator.comparing(DcTrafficSectionData::getStakeMark)) + .collect(Collectors.toList()); + } + + int previousStakeMark = 0; + int previousAverageSpeed = 0; + int defaultCongestionDistance = 0; + int trafficVolume = 0; + ChannelCongestionLevelEnum previousCongestionLevel = null; + DcCongestedSectionData congestedSectionData = null; + + // 遍历排序后的路段数据,计算每个路段的拥堵里程,并累加到总拥堵里程中 + for (DcTrafficSectionData dcTrafficSectionData : sortedList) { + + int averageSpeed = dcTrafficSectionData.getAverageSpeed(); + int stakeMark = dcTrafficSectionData.getStakeMark(); + trafficVolume = dcTrafficSectionData.getTrafficVolume(); + + boolean isCongestion = ChannelCongestionLevelEnum.isCongestion(averageSpeed, trafficVolume); + + // 判断当前路段是否拥堵,如果不是拥堵路段且前一个路段是拥堵的,则更新拥堵里程并创建新的拥堵路段数据 + if (!isCongestion && previousAverageSpeed != 0) { + int congestionDistance = Math.abs(stakeMark - previousStakeMark); + if (congestionDistance > defaultCongestionDistance) { + if (directionData.equals(LaneDirectionEnum.UPWARD.getValue())) { + previousStakeMark -= defaultCongestionDistance; + } else { + previousStakeMark += defaultCongestionDistance; + } + congestedSectionData.setEndStakeMark(previousStakeMark); + } else { + previousStakeMark = stakeMark; + congestedSectionData.setEndStakeMark(stakeMark); + } + + congestedSectionData.setEndStakeMark(previousStakeMark); + previousCongestionLevel = ChannelCongestionLevelEnum.fromSpeed(averageSpeed, trafficVolume); + previousAverageSpeed = 0; + defaultCongestionDistance = 0; + continue; + } + + if (!isCongestion) { + continue; + } + + // 处理同等级别拥堵的路段,计算拥堵距离,更新拥堵路段的结束桩号 + if (ChannelCongestionLevelEnum.isWithinLevel(averageSpeed, previousCongestionLevel)) { + int congestionDistance = Math.abs(stakeMark - previousStakeMark); + // 对于超出最大间隔的拥堵路段,更新拥堵里程 + if (congestionDistance > StakeMarkConstant.MAX_INTERVAL_MILLIMETER_WAVE_RADAR) { + if (directionData.equals(LaneDirectionEnum.UPWARD.getValue())) { + previousStakeMark -= defaultCongestionDistance; + } else { + previousStakeMark += defaultCongestionDistance; + } + congestedSectionData.setEndStakeMark(previousStakeMark); + } else { + previousStakeMark = stakeMark; + congestedSectionData.setEndStakeMark(stakeMark); + } + } else { + // 如果当前路段拥堵级别改变,创建新的拥堵路段数据,并更新起始桩号和默认拥堵距离 + congestedSectionData = new DcCongestedSectionData(); + congestedSectionData.setAverageSpeed(averageSpeed); + congestedSectionData.setDirection(directionData); + congestedSectionData.setStartStakeMark(stakeMark); + + dcCongestedSectionDataList.add(congestedSectionData); + + previousStakeMark = stakeMark; + defaultCongestionDistance = ChannelCongestionLevelEnum.fromSpeed(averageSpeed).getDefaultCongestionDistance(); + } + + previousAverageSpeed = averageSpeed; + previousCongestionLevel = ChannelCongestionLevelEnum.fromSpeed(averageSpeed); + } + + // 处理遍历完所有路段后的拥堵状态,确保最后一个拥堵路段也被记录 + boolean isCongestion = ChannelCongestionLevelEnum.isCongestion(previousAverageSpeed, trafficVolume); + + if (isCongestion && congestedSectionData != null) { + // 根据行驶方向更新拥堵里程 + if (directionData.equals(LaneDirectionEnum.UPWARD.getValue())) { + previousStakeMark -= defaultCongestionDistance; + } else { + previousStakeMark += defaultCongestionDistance; + } + congestedSectionData.setEndStakeMark(previousStakeMark); + } + }); + + return dcCongestedSectionDataList; + } } From 6286be72bd3190c3eaf93a214cb000ee0eb2dd0b Mon Sep 17 00:00:00 2001 From: xiepufeng <1072271977@qq.com> Date: Tue, 9 Apr 2024 16:53:31 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B7=AF=E7=BD=91?= =?UTF-8?q?=E6=95=B4=E4=BD=93=E6=8B=A5=E5=A0=B5=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zc/business/statistics/handler/TrafficAnalysis.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java b/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java index 41e441b8..7c94fa24 100644 --- a/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java +++ b/zc-business/src/main/java/com/zc/business/statistics/handler/TrafficAnalysis.java @@ -423,7 +423,8 @@ public class TrafficAnalysis { // 对于不拥堵的路段,累加之前计算的默认拥堵距离 if (!ChannelCongestionLevelEnum.isMediumOrSevereCongestion(averageSpeed, dcTrafficSectionData.getTrafficVolume())) { - totalCongestionDistance.addAndGet(defaultCongestionDistance); + int congestionDistance = Math.abs(stakeMark - previousStakeMark); + totalCongestionDistance.addAndGet(Math.min(congestionDistance, defaultCongestionDistance)); previousStakeMark = stakeMark; defaultCongestionDistance = 0; previousAverageSpeed = 0; @@ -445,8 +446,6 @@ public class TrafficAnalysis { congestedSectionQuantity.addAndGet(1); } } else { - // 如果之前没有计算过任何路段,则直接累加默认拥堵距离 - totalCongestionDistance.addAndGet(defaultCongestionDistance); // 累加拥堵路段数量 congestedSectionQuantity.addAndGet(1); }