|
|
@ -2,6 +2,7 @@ package com.zc.business.service.impl; |
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
import com.ruoyi.common.utils.StakeMarkUtils; |
|
|
|
import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.zc.business.domain.DcEvent; |
|
|
|
import com.zc.business.domain.DcEventType; |
|
|
|
import com.zc.business.mapper.DcTrafficIncidentsMapper; |
|
|
@ -15,6 +16,7 @@ import java.math.RoundingMode; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.Year; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 交通事件统计Service业务层处理 |
|
|
@ -352,111 +354,129 @@ public class DcTrafficIncidentsServiceImpl implements IDcTrafficIncidentsService |
|
|
|
* @Description 路网管控-事件管控分析-收费站统计分析table |
|
|
|
* @return com.ruoyi.common.core.domain.AjaxResult |
|
|
|
* @author liuwenge |
|
|
|
* @param searchType 查询条件 |
|
|
|
* @param facilityIdList 站点id |
|
|
|
* @param controlType 类型(1:封闭,2:限行) |
|
|
|
* @param startTime 开始时间 |
|
|
|
* @param endTime 结束时间 |
|
|
|
* @date 2024/1/15 17:31 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public AjaxResult selectTollStationAnalysis(String controlType,String startTime,String endTime){ |
|
|
|
|
|
|
|
//目标时段
|
|
|
|
List<Map<String,Object>> list = trafficIncidentsMapper.selectTollStationAnalysis(controlType,startTime,endTime); |
|
|
|
BigDecimal allNum = BigDecimal.ZERO; |
|
|
|
BigDecimal allTime = BigDecimal.ZERO; |
|
|
|
for (Map<String, Object> data : list) { |
|
|
|
allNum = allNum.add(new BigDecimal(data.get("num").toString())); |
|
|
|
allTime = allTime.add(new BigDecimal(data.get("minuteTime").toString())); |
|
|
|
} |
|
|
|
for (Map<String, Object> data : list) { |
|
|
|
//计算站次占比
|
|
|
|
if (allNum.compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal numRatio = new BigDecimal(data.get("num").toString()).multiply(new BigDecimal("100")).divide(allNum,2, RoundingMode.HALF_UP); |
|
|
|
data.put("numRatio",numRatio); |
|
|
|
} else { |
|
|
|
data.put("numRatio",0); |
|
|
|
} |
|
|
|
public AjaxResult selectTollStationAnalysis(String searchType,String[] facilityIdList,String controlType,String startTime,String endTime){ |
|
|
|
|
|
|
|
//计算时长占比
|
|
|
|
if (allTime.compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal timeRatio = new BigDecimal(data.get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(allTime,2, RoundingMode.HALF_UP); |
|
|
|
data.put("timeRatio",timeRatio); |
|
|
|
} else { |
|
|
|
data.put("timeRatio",0); |
|
|
|
} |
|
|
|
} |
|
|
|
//站点
|
|
|
|
if ("1".equals(searchType)){ |
|
|
|
List<Map<String,Object>> list = trafficIncidentsMapper.selectTollStationAnalysisByFacility(facilityIdList,startTime,endTime); |
|
|
|
return AjaxResult.success(list); |
|
|
|
|
|
|
|
//去年同期
|
|
|
|
try { |
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
|
|
|
|
Date startDate = dateFormat.parse(startTime); |
|
|
|
cal.setTime(startDate); |
|
|
|
cal.add(Calendar.YEAR,-1); |
|
|
|
String lastStartTime = dateFormat.format(cal.getTime()); |
|
|
|
|
|
|
|
Date endDate = dateFormat.parse(endTime); |
|
|
|
cal.setTime(endDate); |
|
|
|
cal.add(Calendar.YEAR,-1); |
|
|
|
String lastEndTime = dateFormat.format(cal.getTime()); |
|
|
|
|
|
|
|
List<Map<String,Object>> lastList = trafficIncidentsMapper.selectTollStationAnalysis(controlType,lastStartTime,lastEndTime); |
|
|
|
BigDecimal lastAllNum = BigDecimal.ZERO; |
|
|
|
BigDecimal lastAllTime = BigDecimal.ZERO; |
|
|
|
|
|
|
|
for (int i = 0; i < lastList.size(); i++) { |
|
|
|
//去年同期站次
|
|
|
|
lastAllNum = lastAllNum.add(new BigDecimal(lastList.get(i).get("num").toString())); |
|
|
|
list.get(i).put("lastYearNum",lastList.get(i).get("num").toString()); |
|
|
|
|
|
|
|
//去年同期时长
|
|
|
|
lastAllTime = lastAllTime.add(new BigDecimal(lastList.get(i).get("minuteTime").toString())); |
|
|
|
list.get(i).put("lastYearTime",lastList.get(i).get("minuteTime").toString()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
//原因
|
|
|
|
|
|
|
|
for (int i = 0; i < lastList.size(); i++) { |
|
|
|
//去年同期站次占比
|
|
|
|
if (lastAllNum.compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal numRatio = new BigDecimal(lastList.get(i).get("num").toString()).multiply(new BigDecimal("100")).divide(lastAllNum,2, RoundingMode.HALF_UP); |
|
|
|
list.get(i).put("lastYearNumRatio",numRatio); |
|
|
|
if (StringUtils.isEmpty(controlType)){ |
|
|
|
return AjaxResult.error("请选择事件类型"); |
|
|
|
} |
|
|
|
//目标时段
|
|
|
|
List<Map<String,Object>> list = trafficIncidentsMapper.selectTollStationAnalysis(facilityIdList,controlType,startTime,endTime); |
|
|
|
BigDecimal allNum = BigDecimal.ZERO; |
|
|
|
BigDecimal allTime = BigDecimal.ZERO; |
|
|
|
for (Map<String, Object> data : list) { |
|
|
|
allNum = allNum.add(new BigDecimal(data.get("num").toString())); |
|
|
|
allTime = allTime.add(new BigDecimal(data.get("minuteTime").toString())); |
|
|
|
} |
|
|
|
for (Map<String, Object> data : list) { |
|
|
|
//计算站次占比
|
|
|
|
if (allNum.compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal numRatio = new BigDecimal(data.get("num").toString()).multiply(new BigDecimal("100")).divide(allNum,2, RoundingMode.HALF_UP); |
|
|
|
data.put("numRatio",numRatio); |
|
|
|
} else { |
|
|
|
list.get(i).put("lastYearNumRatio",0); |
|
|
|
data.put("numRatio",0); |
|
|
|
} |
|
|
|
////去年同期时长占比
|
|
|
|
if (lastAllTime.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
BigDecimal timeRatio = new BigDecimal(lastList.get(i).get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(lastAllTime, 2, RoundingMode.HALF_UP); |
|
|
|
list.get(i).put("lastYearTimeRatio", timeRatio); |
|
|
|
|
|
|
|
//计算时长占比
|
|
|
|
if (allTime.compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal timeRatio = new BigDecimal(data.get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(allTime,2, RoundingMode.HALF_UP); |
|
|
|
data.put("timeRatio",timeRatio); |
|
|
|
} else { |
|
|
|
list.get(i).put("lastYearTimeRatio", 0); |
|
|
|
data.put("timeRatio",0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//同比
|
|
|
|
for (Map<String, Object> map : list) { |
|
|
|
//站次同比
|
|
|
|
if (new BigDecimal(map.get("lastYearNum").toString()).compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal yearNumRatio = new BigDecimal(map.get("num").toString()).multiply(new BigDecimal("100")).divide(new BigDecimal(map.get("lastYearNum").toString()),2, RoundingMode.HALF_UP); |
|
|
|
map.put("yearNumRatio",yearNumRatio); |
|
|
|
} else { |
|
|
|
map.put("yearNumRatio",0); |
|
|
|
//去年同期
|
|
|
|
try { |
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
|
|
|
|
Date startDate = dateFormat.parse(startTime); |
|
|
|
cal.setTime(startDate); |
|
|
|
cal.add(Calendar.YEAR,-1); |
|
|
|
String lastStartTime = dateFormat.format(cal.getTime()); |
|
|
|
|
|
|
|
Date endDate = dateFormat.parse(endTime); |
|
|
|
cal.setTime(endDate); |
|
|
|
cal.add(Calendar.YEAR,-1); |
|
|
|
String lastEndTime = dateFormat.format(cal.getTime()); |
|
|
|
|
|
|
|
List<Map<String,Object>> lastList = trafficIncidentsMapper.selectTollStationAnalysis(facilityIdList,controlType,lastStartTime,lastEndTime); |
|
|
|
BigDecimal lastAllNum = BigDecimal.ZERO; |
|
|
|
BigDecimal lastAllTime = BigDecimal.ZERO; |
|
|
|
|
|
|
|
for (int i = 0; i < lastList.size(); i++) { |
|
|
|
//去年同期站次
|
|
|
|
lastAllNum = lastAllNum.add(new BigDecimal(lastList.get(i).get("num").toString())); |
|
|
|
list.get(i).put("lastYearNum",lastList.get(i).get("num").toString()); |
|
|
|
|
|
|
|
//去年同期时长
|
|
|
|
lastAllTime = lastAllTime.add(new BigDecimal(lastList.get(i).get("minuteTime").toString())); |
|
|
|
list.get(i).put("lastYearTime",lastList.get(i).get("minuteTime").toString()); |
|
|
|
} |
|
|
|
|
|
|
|
//时长同比
|
|
|
|
if (new BigDecimal(map.get("lastYearTime").toString()).compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal yearTimeRatio = new BigDecimal(map.get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(new BigDecimal(map.get("lastYearTime").toString()),2, RoundingMode.HALF_UP); |
|
|
|
map.put("yearTimeRatio",yearTimeRatio); |
|
|
|
} else { |
|
|
|
map.put("yearTimeRatio",0); |
|
|
|
for (int i = 0; i < lastList.size(); i++) { |
|
|
|
//去年同期站次占比
|
|
|
|
if (lastAllNum.compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal numRatio = new BigDecimal(lastList.get(i).get("num").toString()).multiply(new BigDecimal("100")).divide(lastAllNum,2, RoundingMode.HALF_UP); |
|
|
|
list.get(i).put("lastYearNumRatio",numRatio); |
|
|
|
} else { |
|
|
|
list.get(i).put("lastYearNumRatio",0); |
|
|
|
} |
|
|
|
////去年同期时长占比
|
|
|
|
if (lastAllTime.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
BigDecimal timeRatio = new BigDecimal(lastList.get(i).get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(lastAllTime, 2, RoundingMode.HALF_UP); |
|
|
|
list.get(i).put("lastYearTimeRatio", timeRatio); |
|
|
|
} else { |
|
|
|
list.get(i).put("lastYearTimeRatio", 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//同比
|
|
|
|
for (Map<String, Object> map : list) { |
|
|
|
//站次同比
|
|
|
|
if (new BigDecimal(map.get("lastYearNum").toString()).compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal yearNumRatio = new BigDecimal(map.get("num").toString()).multiply(new BigDecimal("100")).divide(new BigDecimal(map.get("lastYearNum").toString()),2, RoundingMode.HALF_UP); |
|
|
|
map.put("yearNumRatio",yearNumRatio); |
|
|
|
} else { |
|
|
|
map.put("yearNumRatio",0); |
|
|
|
} |
|
|
|
|
|
|
|
//时长同比
|
|
|
|
if (new BigDecimal(map.get("lastYearTime").toString()).compareTo(BigDecimal.ZERO) > 0){ |
|
|
|
BigDecimal yearTimeRatio = new BigDecimal(map.get("minuteTime").toString()).multiply(new BigDecimal("100")).divide(new BigDecimal(map.get("lastYearTime").toString()),2, RoundingMode.HALF_UP); |
|
|
|
map.put("yearTimeRatio",yearTimeRatio); |
|
|
|
} else { |
|
|
|
map.put("yearTimeRatio",0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return AjaxResult.success(list); |
|
|
|
|
|
|
|
return AjaxResult.success(list); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String customKey(Map<String,Object> map){ |
|
|
|
return map.get("facilityId").toString(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|