From a6e9dd8810d9cba3e339fced913c848bc7c0b062 Mon Sep 17 00:00:00 2001 From: wangsixiang <2970484253@qq.com> Date: Wed, 12 Jun 2024 08:28:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=84=9F=E7=9F=A5=E4=BA=8B=E4=BB=B6=E7=9B=91?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DCPerceivedEventsWarningController.java | 50 ++++++- .../com/zc/business/domain/DcWarning.java | 23 +++ .../DcPerceivedEventsWarningMapper.java | 16 ++ .../IDCPerceivedEventsWarningService.java | 8 + .../DcPerceivedEventsWarningServiceImpl.java | 101 +++++++++++++ .../service/impl/DcWarningServiceImpl.java | 36 +++-- .../DcPerceivedEventsWarningMapper.xml | 140 +++++++++++++++++- 7 files changed, 355 insertions(+), 19 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java b/zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java index cd2b47a6..0cb175de 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DCPerceivedEventsWarningController.java @@ -72,11 +72,7 @@ public class DCPerceivedEventsWarningController extends BaseController { startPage(); return getDataTable(perceivedEventsWarningService.selectWarningList(dcWarning)); } - //查询感知数量按照路段数量进行排名 - @PostMapping("/sectionPerceivedList") - public AjaxResult getSectionPerceivedEventsList(){ - return AjaxResult.success(perceivedEventsWarningService.selectSectionPerceivedEventsList()); - } + //查询感知数量按照路段进行区分 @PostMapping("/sectionPerceivedNumber") public AjaxResult getSectionPerceivedNumber(){ @@ -246,4 +242,48 @@ public class DCPerceivedEventsWarningController extends BaseController { } return AjaxResult.success(perceivedEventsWarningService.selectNonAutomaticWarningFacility(dcWarning)); } + + //新-感知事件多发时段 + @PostMapping("/manyTimesInterval") + public AjaxResult manyTimesInterval(@RequestBody DcWarning dcWarning){ + if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null + ||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark()) + ||StringUtils.isBlank(dcWarning.getDirection())){ + return AjaxResult.error("参数错误"); + } + return AjaxResult.success(perceivedEventsWarningService.selectManyTimesInterval(dcWarning)); + } + //新-感知事件类型分析 + @PostMapping("/selectWarningType") + public AjaxResult selectWarningType(@RequestBody DcWarning dcWarning){ + if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null + ||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark()) + ||StringUtils.isBlank(dcWarning.getDirection())){ + return AjaxResult.error("参数错误"); + } + return AjaxResult.success(perceivedEventsWarningService.newSelectWarningType(dcWarning)); + } + //新-感知事件桩号范围内事件分析 + @PostMapping("/selectSection") + public AjaxResult selectSection(@RequestBody DcWarning dcWarning){ + if (dcWarning==null||StringUtils.isBlank(dcWarning.getType())||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null + ||StringUtils.isBlank(dcWarning.getStartStakeMark())||StringUtils.isBlank(dcWarning.getEndStakeMark()) + ||StringUtils.isBlank(dcWarning.getDirection())){ + return AjaxResult.error("参数错误"); + } + return AjaxResult.success(perceivedEventsWarningService.newSelectSection(dcWarning)); + } + //新-感知事件路段处置类型分析 + @PostMapping("/selectStateType") + public AjaxResult selectStateType(@RequestBody DcWarning dcWarning){ + if (dcWarning==null||dcWarning.getCurrently()==null||dcWarning.getLastYear()==null){ + return AjaxResult.error("参数错误"); + } + return AjaxResult.success(perceivedEventsWarningService.newSelectStateType(dcWarning)); + } + //查询感知数量按照路段数量进行排名 + @PostMapping("/sectionPerceivedList") + public AjaxResult getSectionPerceivedEventsList(){ + return AjaxResult.success(perceivedEventsWarningService.selectSectionPerceivedEventsList()); + } } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcWarning.java b/zc-business/src/main/java/com/zc/business/domain/DcWarning.java index 11a16c40..10627b66 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcWarning.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcWarning.java @@ -120,6 +120,29 @@ public class DcWarning extends BaseEntity //收费站 private String facilityName; + //去年同期时间参数 + @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8") + private Date lastYear; + //当下时间参数 + @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8") + private Date currently; + + public Date getCurrently() { + return currently; + } + + public void setCurrently(Date currently) { + this.currently = currently; + } + + public Date getLastYear() { + return lastYear; + } + + public void setLastYear(Date lastYear) { + this.lastYear = lastYear; + } + public String getRelieveReason() { return relieveReason; } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcPerceivedEventsWarningMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcPerceivedEventsWarningMapper.java index 6a7d5368..dcfd6986 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcPerceivedEventsWarningMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcPerceivedEventsWarningMapper.java @@ -100,4 +100,20 @@ public interface DcPerceivedEventsWarningMapper { List> selectNonAutomaticWarningFacilityMonth(DcWarning dcWarning); //查询非机预警数据按照年和收费站分组 List> selectNonAutomaticWarningFacilityYear(DcWarning dcWarning); + + //新-感知事件按照路段查询小时分组-日 + List> newSelectSectionDay(DcWarning dcWarning); + //新-感知事件按照路段查询小时分组-月 + List> newSelectSectionMonth(DcWarning dcWarning); + //新-感知事件按照路段查询小时分组-年 + List> newSelectSectionYear(DcWarning dcWarning); + //新-感知事件按照类型查询数量-日/月/年 + List> newSelectWarningType(DcWarning dcWarning); + //新-感知事件桩号范围内事件分析 + List> newSelectSection(DcWarning dcWarning); + //新-感知事件路段处置类型分析 + List> newSelectStateType(DcWarning dcWarning); + //新-感知事件路段处置类型分析-平均处置时长 + List> newStateDuration(DcWarning dcWarning); + } diff --git a/zc-business/src/main/java/com/zc/business/service/IDCPerceivedEventsWarningService.java b/zc-business/src/main/java/com/zc/business/service/IDCPerceivedEventsWarningService.java index f13ca069..ae338ab0 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDCPerceivedEventsWarningService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDCPerceivedEventsWarningService.java @@ -61,4 +61,12 @@ public interface IDCPerceivedEventsWarningService { //查询非机预警数据按照日和收费站分组 List> selectNonAutomaticWarningFacility(DcWarning dcWarning); + //新-感知时间多发时段 + HashMap selectManyTimesInterval(DcWarning dcWarning); + //新-感知事件按照类型查询数量-日/月/年 + HashMap newSelectWarningType(DcWarning dcWarning); + //新-感知事件桩号范围内事件分析 + HashMap newSelectSection(DcWarning dcWarning); + //新-感知事件路段处置类型分析 + HashMap newSelectStateType(DcWarning dcWarning); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcPerceivedEventsWarningServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcPerceivedEventsWarningServiceImpl.java index beb4384d..cbe2c196 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcPerceivedEventsWarningServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcPerceivedEventsWarningServiceImpl.java @@ -11,9 +11,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @author 王思祥 @@ -310,6 +314,103 @@ public class DcPerceivedEventsWarningServiceImpl implements IDCPerceivedEventsWa } return null; } + //新-感知时间多发时段 + @Override + public HashMap selectManyTimesInterval(DcWarning dcWarning) { + + String startStakeMark = StakeMarkUtils.formatMetre(dcWarning.getStartStakeMark()); + dcWarning.setStartStakeMark(startStakeMark); + String endStakeMark = StakeMarkUtils.formatMetre(dcWarning.getEndStakeMark()); + dcWarning.setEndStakeMark(endStakeMark); + String type = dcWarning.getType(); + HashMap hashMap = new HashMap<>(); + switch (type){ + case "day": + hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectSectionDay(dcWarning)); + break; + case "month": + hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectSectionMonth(dcWarning)); + break; + case "year": + hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectSectionYear(dcWarning)); + break; + } + + dcWarning.setCurrently(dcWarning.getLastYear());//把传入的去年的时间参数,转为当下时间作为查询参数(因为mapper中的查询提交参数是当下时间) + switch (type) { + case "day": + hashMap.put("lastYearMap", perceivedEventsWarningMapper.newSelectSectionDay(dcWarning)); + break; + case "month": + hashMap.put("lastYearMap", perceivedEventsWarningMapper.newSelectSectionMonth(dcWarning)); + break; + case "year": + hashMap.put("lastYearMap", perceivedEventsWarningMapper.newSelectSectionYear(dcWarning)); + break; + } + return hashMap; + } + //新-感知事件按照类型查询数量-日/月/年 + @Override + public HashMap newSelectWarningType(DcWarning dcWarning) { + String startStakeMark = StakeMarkUtils.formatMetre(dcWarning.getStartStakeMark()); + dcWarning.setStartStakeMark(startStakeMark); + String endStakeMark = StakeMarkUtils.formatMetre(dcWarning.getEndStakeMark()); + dcWarning.setEndStakeMark(endStakeMark); + HashMap hashMap = new HashMap<>(); + hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectWarningType(dcWarning)); + dcWarning.setCurrently(dcWarning.getLastYear()); + hashMap.put("lastYearMap", perceivedEventsWarningMapper.newSelectWarningType(dcWarning)); + + return hashMap; + } + //新-感知事件桩号范围内事件分析 + @Override + public HashMap newSelectSection(DcWarning dcWarning) { + HashMap hashMap = new HashMap<>(); + String startStakeMark = StakeMarkUtils.formatMetre(dcWarning.getStartStakeMark()); + dcWarning.setStartStakeMark(startStakeMark); + String endStakeMark = StakeMarkUtils.formatMetre(dcWarning.getEndStakeMark()); + dcWarning.setEndStakeMark(endStakeMark); + hashMap.put("currentlyMap", selectSectionUtils(dcWarning)); + dcWarning.setCurrently(dcWarning.getLastYear());//时间参数转换,把去年的时间替换为查询时间参数 + hashMap.put("lastYearMap", selectSectionUtils(dcWarning)); + return hashMap; + } + + public Map selectSectionUtils(DcWarning dcWarning){ + //数据 + List> mapList = perceivedEventsWarningMapper.newSelectSection(dcWarning); + // 用于存储结果的Map,key为stakeMark,value为对应的number总和 + Map stakeMarkToNumberSum = new HashMap<>(); + // 遍历mapList + for (Map map : mapList) { + String stakeMarkValue =map.get("stakeMark").toString(); + String stakeMark = stakeMarkValue.substring(0, stakeMarkValue.indexOf("+")); + Integer number = Integer.valueOf(map.get("number").toString()); + // 如果stakeMarkToNumberSum中还没有这个stakeMark的条目,则添加并初始化为0 + stakeMarkToNumberSum.putIfAbsent(stakeMark, 0); + // 将当前map的number加到对应stakeMark的总和中 + Integer currentSum = stakeMarkToNumberSum.get(stakeMark); + stakeMarkToNumberSum.put(stakeMark, currentSum + number); + } + // 打印结果 +// for (Map.Entry entry : stakeMarkToNumberSum.entrySet()) { +// System.out.println("stakeMark: " + entry.getKey() + ", number sum: " + entry.getValue()); +// } + return stakeMarkToNumberSum; + } + //新-感知事件路段处置类型分析- + @Override + public HashMap newSelectStateType(DcWarning dcWarning) { + HashMap hashMap = new HashMap<>(); + hashMap.put("stateDuration", perceivedEventsWarningMapper.newStateDuration(dcWarning)); + hashMap.put("currentlyMap", perceivedEventsWarningMapper.newSelectStateType(dcWarning)); + dcWarning.setCurrently(dcWarning.getLastYear()); + hashMap.put("lastYearMap", perceivedEventsWarningMapper.newSelectStateType(dcWarning)); + return hashMap; + } + } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java index 5f272186..eef40aa8 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java @@ -1,13 +1,19 @@ package com.zc.business.service.impl; - import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.uuid.IdUtils; -import com.zc.business.domain.*; +import com.zc.business.domain.DcDispatch; +import com.zc.business.domain.DcDispatchResource; +import com.zc.business.domain.DcEvent; +import com.zc.business.domain.DcEventProcess; +import com.zc.business.domain.DcTrafficPolice; +import com.zc.business.domain.DcWaringStrategy; +import com.zc.business.domain.DcWarning; +import com.zc.business.domain.DcWarningBatchConvert; import com.zc.business.enums.ValueConverter; import com.zc.business.enums.WarningSubclassEnum; import com.zc.business.mapper.DcEventMapper; @@ -22,21 +28,18 @@ import com.zc.common.core.websocket.constant.WebSocketEvent; import org.apache.commons.lang3.StringUtils; import org.json.JSONArray; import org.json.JSONObject; -import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.lang.reflect.Array; -import java.rmi.MarshalledObject; -import java.util.Objects; -import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -629,6 +632,10 @@ public class DcWarningServiceImpl implements IDcWarningService public AjaxResult commandAndDispatch(DcWarning dcWarning) { Map mapAll = new HashMap<>(); HashMap dcDispatch = dcWarningMapper.selectDcDispatch(dcWarning.getId());//查询是否存在调度记录 + if (dcDispatch==null){ + mapAll.put("existence",0); + return AjaxResult.success(mapAll); + } //逻辑,调用全部的机构信息,计算传入的桩号与机构桩号的距离作为排序使用,使用机构的id调出车辆,人员,值班等信息 List> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称 ArrayList> hashMaps = new ArrayList<>(); @@ -662,10 +669,7 @@ public class DcWarningServiceImpl implements IDcWarningService DcTrafficPolice dcTrafficPolice = dcTrafficPoliceService.selectEvent(dcWarning.getStakeMark()); mapAll.put("trafficPolice",dcTrafficPolice); } - if (dcDispatch==null){ - mapAll.put("existence",0); - return AjaxResult.success(mapAll); - } + mapAll.put("dispatchId",dcDispatch.get("id")); mapAll.put("existence",1); HashMap map = dcWarningMapper.selectDcDispatch(dcWarning.getId());//获取机构id与资源id @@ -776,6 +780,10 @@ public class DcWarningServiceImpl implements IDcWarningService dcDispatch.setStartTime(DateUtils.getNowDate()); dcDispatch.setDispatchStatus(2L);//进行中状态 dcDispatch.setRemark(remark); + HashMap dispatch = dcWarningMapper.selectDcDispatch(eventId);//查询是否存在调度记录 + if (dispatch!=null){ //不为空说明已经存在处置记录,不在新增 + return AjaxResult.success("已经存在记录"); + } Integer integer = dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录 if (integer==0){ return AjaxResult.error(); @@ -810,7 +818,7 @@ public class DcWarningServiceImpl implements IDcWarningService } return dcWarningMapper.updateDcDispatch(dcDispatch); } - + //4.新增指挥调度资源记录 @Override @Transactional(rollbackFor = Exception.class) public Integer insertDispatchSource(HashMap map) { @@ -823,6 +831,10 @@ public class DcWarningServiceImpl implements IDcWarningService dcDispatch.setStartTime(DateUtils.getNowDate()); dcDispatch.setDispatchStatus(2L);//进行中状态 dcDispatch.setRemark(remark); + HashMap dispatch = dcWarningMapper.selectDcDispatch(eventId);//查询是否存在调度记录 + if (dispatch!=null){ //不为空说明已经存在处置记录,不在新增 + return 1; + } dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录 Long dispatchId = dcDispatch.getId(); dcWarningMapper.deleteDispatchResource(dispatchId);//删除全部属于该调度记录下的全部资源 diff --git a/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml b/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml index b2a01e7c..1e914102 100644 --- a/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml @@ -119,7 +119,7 @@ order by warning.warning_time desc + SELECT + DATE_FORMAT(#{currently} + INTERVAL a.a HOUR, '%Y-%m-%d %H') AS time, + IFNULL(SUM(CASE WHEN dw.warning_source != 6 AND + CAST(SUBSTRING(SUBSTRING_INDEX(dw.stake_mark,'+',1),2)AS UNSIGNED)*1000 + + CAST(SUBSTRING_INDEX(dw.stake_mark, '+', -1) AS UNSIGNED)>#{startStakeMark} AND + CAST(SUBSTRING(SUBSTRING_INDEX(dw.stake_mark,'+',1),2)AS UNSIGNED)*1000 + + CAST(SUBSTRING_INDEX(dw.stake_mark, '+', -1) AS UNSIGNED)<#{endStakeMark} + THEN 1 ELSE 0 END), 0) AS number + FROM ( + SELECT 0 AS a + UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 + UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 + UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 + UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 + UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL SELECT 15 + UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 + UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21 + UNION ALL SELECT 22 UNION ALL SELECT 23 + ) AS a + LEFT JOIN dc_warning dw ON DATE_FORMAT(dw.warning_time, '%Y-%m-%d %H') + = DATE_FORMAT(#{currently} + INTERVAL a.a HOUR, '%Y-%m-%d %H') and dw.warning_source!=6 + and dw.direction=#{direction} + GROUP BY time + ORDER BY time; + + + + + + +