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 bf72978f..d35315d4 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 @@ -1,16 +1,19 @@ package com.zc.business.controller; +import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; + import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.zc.business.constant.DeviceTypeConstants; import com.zc.business.domain.DcDevice; @@ -25,6 +28,7 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.v3.oas.annotations.Parameter; import okhttp3.Response; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.StringUtils; @@ -34,6 +38,8 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -687,4 +693,117 @@ public class DcDeviceController extends BaseController { Map map = new ObjectMapper().convertValue(object, Map.class); return batchInvokedFunction(map); } + + /** + * 分页查询设备名称列表 + * @param dcDevice 请求参数 + * @return 分页查询结果 + */ + @GetMapping("/selectDeviceNameList") + public TableDataInfo selectDeviceNameList(DcDevice dcDevice) { + startPage(); + return getDataTable(dcDeviceService.selectDeviceNameList(dcDevice)); + } + @GetMapping("/deviceParameter") + public TableDataInfo selectDeviceParameterProperties(DcDevice dcDevice) { + if (dcDevice==null||dcDevice.getDeviceType()==null){ + TableDataInfo tableDataInfo = new TableDataInfo(); + tableDataInfo.setCode(500); + tableDataInfo.setMsg("参数错误"); + return tableDataInfo; + } + startPage(); + return getDataTable(dcDeviceService.selectDeviceParameterProperties(dcDevice)); + } + /** + * 查询设备指定属性属性列表 + * param参数 + * deviceId 设备id + * propertyId 属性id + * propertyName 属性名称 + * deviceType 设备类型 + * dateTime 时间 + * @return 属性列表 + */ + @PostMapping("/properties/deviceNameData") + public AjaxResult queryDevice(@RequestBody HashMap map) throws HttpException, IOException { + if (map==null||!map.containsKey("deviceId")||!map.containsKey("deviceType") + ||!map.containsKey("propertyName")||!map.containsKey("propertyId") + ||!map.containsKey("dateTime")){ + return AjaxResult.error("参数错误"); + } + String deviceType = map.get("deviceType").toString();//设备类型 + String deviceId = map.get("deviceId").toString();//设备id + String propertyId = map.get("propertyId").toString();//属性id + String propertyName = map.get("propertyName").toString();//属性名称 + HashMap props = new HashMap<>(); + // 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内 + props.put("terms[0].column", "timestamp$BTW"); + ArrayList dateList = new ArrayList<>(); + // 添加当前日期的开始和结束时间到列表,用于设定时间范围 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date date = dateFormat.parse((String) map.get("dateTime")); + dateList.add(DateUtil.beginOfDay(date).toString()); + dateList.add(DateUtil.endOfDay(date).toString()); + } catch (ParseException e) { + e.printStackTrace(); + } + // 将日期列表以逗号分隔并设置为查询条件的值 + props.put("terms[0].value", String.join(",", dateList)); + props.put("paging", false); + props.put("sorts[0].order", "asc"); + props.put("sorts[0].name", "timestamp"); + AjaxResult ajaxResult = queryDeviceProperties(deviceId, propertyId, props); + String code = ajaxResult.get("code").toString(); + if ("500".equals(code)){ + return ajaxResult; + } + if ("13".equals(deviceType) || "16".equals(deviceType)) { //判断是否为设备箱/远端机 + JSONObject data = (JSONObject) ajaxResult.get("data"); + JSONArray dataVale = (JSONArray) data.get("data"); + List jsonObjectList = dataVale.toJavaList(JSONObject.class); + // 定义一个时间格式转换的工具 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + // 使用Stream API提取每个JSONObject中的timestamp和propertyName值 + List> results = jsonObjectList.stream() + .map(jsonObject -> { + long timestamp = jsonObject.getLongValue("timestamp"); // 假设timestamp是long类型 + Date date = new Date(timestamp); // 将时间戳转换为Date对象 + String formattedTime = sdf.format(date); // 将Date对象格式化为字符串 + JSONObject formatValue = jsonObject.getJSONObject("formatValue"); // 获取嵌套的JSONObject + String result = formatValue.getString(propertyName); // 从嵌套的JSONObject中获取电压值 + Map hashMap = new HashMap<>(); + hashMap.put("timestamp", formattedTime); // 使用"timestamp"作为键来存储格式化后的时间 + hashMap.put("result", result); // 使用"voltage"作为键来存储电压值 + return hashMap; + }) + .collect(Collectors.toList()); + results.sort(Comparator.comparing(hashMap -> hashMap.get("timestamp"))); + return AjaxResult.success(results); + } + if ("3".equals(deviceType)||"17".equals(deviceType)){ //气象预警/ups设备 + JSONObject data = (JSONObject) ajaxResult.get("data"); + JSONArray dataValue = (JSONArray) data.get("data"); + List jsonObjectList = dataValue.toJavaList(JSONObject.class); + // 定义一个时间格式转换的工具 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + List> results = jsonObjectList.stream() + .map(jsonObject -> { + long timestamp = jsonObject.getLongValue("timestamp"); // 假设timestamp是long类型 + Date date = new Date(timestamp); // 将时间戳转换为Date对象 + String formattedTime = sdf.format(date); // 将Date对象格式化为字符串 + String result = jsonObject.getString(propertyName); + HashMap hashMap = new HashMap<>(); + hashMap.put("timestamp", formattedTime); // 使用时间戳作为键可能不是最佳实践,但这里保持与原始逻辑一致 + hashMap.put("result", result); + return hashMap; + }) + .collect(Collectors.toList()); + results.sort(Comparator.comparing(hashMap -> hashMap.get("timestamp"))); + return AjaxResult.success(results); + } + return null; + } + } diff --git a/zc-business/src/main/java/com/zc/business/controller/DcEventProcessController.java b/zc-business/src/main/java/com/zc/business/controller/DcEventProcessController.java index 08f1bf54..594dba25 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcEventProcessController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcEventProcessController.java @@ -9,6 +9,8 @@ import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.exception.file.InvalidExtensionException; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.MimeTypeUtils; +import com.zc.business.domain.DcEvent; +import com.zc.business.service.IDcEventService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; @@ -43,6 +45,8 @@ public class DcEventProcessController extends BaseController { @Autowired private IDcEventProcessService dcEventProcessService; + @Autowired + private IDcEventService dcEventService; /** * 查询事件处理流程列表 @@ -101,6 +105,10 @@ public class DcEventProcessController extends BaseController @Log(title = "事件处理流程", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody DcEventProcess dcEventProcess){ + DcEvent dcEvent = dcEventService.selectDcEventById(dcEventProcess.getEventId()); + if (dcEvent.getEventState() == 2){ + return AjaxResult.error("事件已结束,无法进行操作!"); + } if (dcEventProcess.getProcessType() != null && dcEventProcess.getProcessType() == 1){ int status = dcEventProcessService.selectPreviousNodeStatus(dcEventProcess.getEventId(),dcEventProcess.getProcessId()); if (status < 1){ diff --git a/zc-business/src/main/java/com/zc/business/domain/DcEventTrafficControl.java b/zc-business/src/main/java/com/zc/business/domain/DcEventTrafficControl.java index 32c2b6fa..50e5ec94 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcEventTrafficControl.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcEventTrafficControl.java @@ -66,7 +66,7 @@ public class DcEventTrafficControl extends BaseEntity */ @ApiModelProperty("匝道(立交)") @Excel(name = "匝道", readConverterExp = "立=交") - private Long rampId; + private String rampId; /* @ApiModelProperty("高速公路 id") private Long roadId; diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java index 86c480c9..64e50b2a 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java @@ -5,6 +5,7 @@ import com.zc.business.domain.DcDevice; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,4 +26,10 @@ public interface DcDeviceMapper extends BaseMapper { List selectNearBoard(@Param("direction") String direction,@Param("startMileage") Integer startMileage,@Param("endMileage") Integer endMileage); List> countTheNumberOfEligibleItems(); + + + //设备查询-设备名称列表 + public List> selectDeviceNameList(DcDevice dcDevice); + //设备查询-设备参数属性列表 + public List> selectDeviceParameterProperties(DcDevice dcDevice); } diff --git a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java index 030098bd..4452e5cf 100644 --- a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java +++ b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java @@ -84,6 +84,7 @@ public class DeviceMessageHandler { DcDevice device = redisCache.getCacheMapValue(RedisKeyConstants.DC_DEVICES, dcDevice.getIotDeviceId()); if (!ObjectUtils.isEmpty(device)) { dcDevice.setId(device.getId()); + dcDevice.setDeviceType(device.getDeviceType()); } }); diff --git a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java index 342c1510..191970be 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java @@ -6,6 +6,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcStakeMark; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -104,4 +105,9 @@ public interface IDcDeviceService extends IService { * 查询上游10公里内的情报板 */ AjaxResult selectNearBoard(String stakeMark, String direction); + + //设备查询-设备名称列表 + public List> selectDeviceNameList(DcDevice dcDevice); + //设备查询-设备参数属性列表 + public List> selectDeviceParameterProperties(DcDevice dcDevice); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java index 81b00640..ebf7399c 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java @@ -533,5 +533,16 @@ public class DcDeviceServiceImpl extends ServiceImpl i } return AjaxResult.success(boardList); } + + //设备查询-设备名称列表 + @Override + public List> selectDeviceNameList(DcDevice dcDevice) { + return dcDeviceMapper.selectDeviceNameList(dcDevice); + } + //设备查询-设备参数属性列表 + @Override + public List> selectDeviceParameterProperties(DcDevice dcDevice) { + return dcDeviceMapper.selectDeviceParameterProperties(dcDevice); + } } 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 8fea891a..8fb9bc13 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 @@ -219,22 +219,39 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { */ public void customPublishingDataFormatProcessing(List deviceList, JSONObject otherConfig, int deviceType) { List> contentList = new ArrayList<>(); - deviceList.forEach(dcDevice -> { - Map map = new HashMap<>(); - map.put("dcDeviceId",dcDevice.getId()); - map.put("deviceName",dcDevice.getDeviceName()); - if (deviceType == DeviceTypeEnum.VARIABLE_INFORMATION_FLAG.getCode()) { - JSONObject dcInfoBoardTemplate = JSON.parseObject(otherConfig.get("dcInfoBoardTemplate").toString()); - dcInfoBoardTemplate.keySet().forEach(key -> map.put(key, dcInfoBoardTemplate.get(key))); - }else { - // 语音广播 - map.put("content",otherConfig.get("content")); - } - contentList.add(map); - }); + if (!ObjectUtils.isEmpty(otherConfig.get("contentList"))) { + contentList.addAll((List>) otherConfig.get("contentList")); + contentList.removeIf(cont -> deviceList.stream().noneMatch(device -> device.getId().toString().equals(cont.get("dcDeviceId").toString()))); + deviceList.forEach(dcDevice -> { + boolean filter = contentList.stream().anyMatch(content -> + content.get("dcDeviceId").toString().equals(dcDevice.getId().toString())); + if (!filter) { + handleContentList(dcDevice,deviceType,otherConfig,contentList); + } + }); + }else { + deviceList.forEach(dcDevice -> { + handleContentList(dcDevice,deviceType,otherConfig,contentList); + }); + } + otherConfig.put("contentList",contentList); } + public void handleContentList(DcDevice dcDevice, int deviceType, JSONObject otherConfig, List> contentList) { + Map map = new HashMap<>(); + map.put("dcDeviceId",dcDevice.getId()); + map.put("deviceName",dcDevice.getDeviceName()); + if (deviceType == DeviceTypeEnum.VARIABLE_INFORMATION_FLAG.getCode()) { + JSONObject dcInfoBoardTemplate = JSON.parseObject(otherConfig.get("dcInfoBoardTemplate").toString()); + dcInfoBoardTemplate.keySet().forEach(key -> map.put(key, dcInfoBoardTemplate.get(key))); + }else { + // 语音广播 + map.put("content",otherConfig.get("content")); + } + contentList.add(map); + } + /** * 交通事件-根据事件、单个执行操作筛选设备 * @param dcEventAnDcEmergencyPlans @@ -647,14 +664,14 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { // 车辆故障 DcEventVehicleAccident dcEventVehicleAccident = dcEvent.getDcEventVehicleAccident(); int locationType = Integer.parseInt(dcEventVehicleAccident.getLocationType().toString()); - // 路广设施id - Integer facilityId = dcEventVehicleAccident.getFacilityId(); - DcFacility facility = dcFacilityService.getFacility(facilityId.toString()); - String facilityName = facility.getFacilityName(); if (locationType == 1) { content = "前方*高速主线发生车辆故障"; } else if (locationType == 2 || locationType == 3 || locationType == 4) { // 服务区、立交、收费站 + // 路广设施id + Integer facilityId = dcEventVehicleAccident.getFacilityId(); + DcFacility facility = dcFacilityService.getFacility(facilityId.toString()); + String facilityName = facility.getFacilityName(); content = "前方*"+facilityName+"发生车辆故障"; } @@ -838,14 +855,14 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { JSONObject foundContent = contentList.stream() .map(content -> JSON.parseObject(content.toString())) .filter(jsonObject -> - Integer.parseInt(jsonObject.get("dcDeviceId").toString()) == device.getId()) + jsonObject.get("dcDeviceId").toString().equals(device.getId().toString())) .findFirst() .orElse(null); if (foundContent == null) { // 说明没有匹配到设备 JSONObject errorResult = new JSONObject(); errorResult.put("device",device.getId()); - errorResult.put("errorMessage","未匹配到对应的模板内容"); + errorResult.put("content","未匹配到对应的模板内容"); resultArray.add(errorResult); }else { JSONObject jsonObject = new JSONObject(); @@ -867,7 +884,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { JSONObject foundContent = contentList.stream() .map(content -> JSON.parseObject(content.toString())) .filter(jsonObject -> - Integer.parseInt(jsonObject.get("dcDeviceId").toString()) == device.getId()) + jsonObject.get("dcDeviceId").toString().equals(device.getId().toString())) .findFirst() .orElse(null); if (foundContent == null) { @@ -875,7 +892,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { JSONObject errorResult = new JSONObject(); errorResult.put("device",device.getId()); errorResult.put("deviceName",device.getDeviceName()); - errorResult.put("errorMessage","未匹配到对应的广播内容"); + errorResult.put("content","未匹配到对应的广播内容"); resultArray.add(errorResult); } if (StringUtils.isEmpty(foundContent.getString("content"))) { 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 99b4d8fc..f47a16ce 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 @@ -170,6 +170,10 @@ public class DcEventServiceImpl extends ServiceImpl impl String facilityId = String.valueOf(dcEvent.getDcEventTrafficControl().getFacilityIds()[0]); dcEvent.setStakeMark(extracted(facilityId)); } + if (eventType == 3 && dcEvent.getDcEventTrafficControl().getFacilityId() != null && dcEvent.getDcEventTrafficControl().getFacilityId()>0) { + String facilityId = String.valueOf(dcEvent.getDcEventTrafficControl().getFacilityId()); + dcEvent.setStakeMark(extracted(facilityId)); + } //交通拥堵 if (eventType == 4 && dcEvent.getDcEventTrafficCongestion().getFacilityId() != null) { String facilityId = String.valueOf(dcEvent.getDcEventTrafficCongestion().getFacilityId()); @@ -219,6 +223,11 @@ public class DcEventServiceImpl extends ServiceImpl impl //交通管制 case 3: if (dcEvent.getDcEventTrafficControl() != null) { + if (dcEvent.getDcEventTrafficControl().getFacilityId()==null || dcEvent.getDcEventTrafficControl().getFacilityId()>0){ + dcEvent.getDcEventTrafficControl().setId(uuid); + int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl()); + break; + } // 插入多个收费站 if (dcEvent.getDcEventTrafficControl().getFacilityIds().length == 1) {//facilityIds==1 说明只选择了一个收费站 @@ -352,6 +361,7 @@ public class DcEventServiceImpl extends ServiceImpl impl } } + } break; //交通拥堵 diff --git a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml index a98fa87e..cefa97fb 100644 --- a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml @@ -153,5 +153,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" GROUP BY dc_road_section.id; + + diff --git a/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml b/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml index de518f99..b2a01e7c 100644 --- a/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml @@ -543,4 +543,4 @@ - \ No newline at end of file +