Browse Source

Merge branch 'develop' of http://39.106.31.193:9211/mengff/jihe-dc into develop

develop
xiepufeng 1 year ago
parent
commit
d795547621
  1. 5
      zc-business/src/main/java/com/zc/business/constant/DeviceFunctionIdConstants.java
  2. 42
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  3. 15
      zc-business/src/main/java/com/zc/business/controller/DcMYSQLJob.java
  4. 7
      zc-business/src/main/java/com/zc/business/controller/DcMYSQLUtil.java
  5. 77
      zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java
  6. 2
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSectionDataServiceImpl.java

5
zc-business/src/main/java/com/zc/business/constant/DeviceFunctionIdConstants.java

@ -28,4 +28,9 @@ public class DeviceFunctionIdConstants {
* 可变信息标志 1B 功能码
*/
public static final String VARIABLE_INFORMATION_FLAG_1B = "1B";
/**
* 激光疲劳唤醒 SETTM 功能码
*/
public static final String VARIABLE_INFORMATION_FLAG_SETTM = "SETTM";
}

42
zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

@ -1,12 +1,15 @@
package com.zc.business.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
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.zc.business.constant.DeviceTypeConstants;
import com.zc.business.domain.DcDevice;
import com.zc.business.request.DeviceGetPropertiesOperateRequest;
import com.zc.business.service.IDcDeviceService;
@ -25,9 +28,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 设备Controller
@ -45,6 +46,9 @@ public class DcDeviceController extends BaseController {
@Value("${iot.address}")
private String iotAddress;
@Resource
private BroadcastController broadcastController;
//*********************************设备增删改查******************************************
/**
@ -368,16 +372,28 @@ public class DcDeviceController extends BaseController {
@ApiOperation("批量设备功能调用")
@PostMapping("/batchFunctions")
public AjaxResult batchInvokedFunction(@RequestBody Map<String, Object> props) throws HttpException, IOException, InterruptedException {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams(props);
Response response // 请求响应
= okHttp
.url(iotAddress + "/api/iot/device/batchFunctions") // 请求地址
.data(requestParams)
.post(); // 请求方法
return JSON.parseObject(response.body().string(), AjaxResult.class);
List<DcDevice> devices = (List<DcDevice>) props.get("devices");
JSONArray functions = (JSONArray) props.get("functions");
JSONArray resultArray = new JSONArray();
for (DcDevice device : devices) {
String iotDeviceId = device.getIotDeviceId();
for (Object function : functions) {
JSONObject functionJSONObject = JSONObject.parseObject(String.valueOf(function));
String functionId = functionJSONObject.getString("functionId");
JSONObject jsonObject = functionJSONObject.getJSONObject("params");
HashMap<String, Object> params = jsonObject.toJavaObject(new TypeReference<HashMap<String, Object>>() {
});
JSONObject result = new JSONObject();
result.put("device", device.getId());
if (device.getDeviceType().equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) {
result.put("result", broadcastController.nearCamListDistance(jsonObject));
} else {
result.put("result", invokedFunction(iotDeviceId, functionId, params));
}
resultArray.add(result);
}
}
return AjaxResult.success(resultArray);
}
/**

15
zc-business/src/main/java/com/zc/business/controller/DcMYSQLJob.java

@ -2,7 +2,6 @@ package com.zc.business.controller;
import com.ruoyi.common.config.RuoYiConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@ -20,7 +19,7 @@ import java.util.Date;
@Component
@Slf4j
public class DcMYSQLJob {
private final Environment environment;
//private final Environment environment;
private static final String IP = "10.0.81.202";
@ -30,12 +29,12 @@ public class DcMYSQLJob {
private static final String PASSWORD = "mysql123!@#";
public DcMYSQLJob(Environment environment) {
this.environment = environment;
}
//public DcMYSQLJob(Environment environment) {
// this.environment = environment;
//}
@Scheduled(cron = "0 0 22 * * ?")
//@Scheduled(cron = "0 25 * * * ?")
//@Scheduled(cron = "0 10 * * * ?")
public void backupAthena() throws IOException {
String url = "jdbc:mysql://10.0.81.202:3306/athena?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true";
@ -43,7 +42,7 @@ public class DcMYSQLJob {
}
@Scheduled(cron = "0 30 22 * * ?")
//@Scheduled(cron = "0 27 * * * ?")
//@Scheduled(cron = "0 20 * * * ?")
public void backupJiHeDC() throws IOException {
// 数据库配置信息
String url = "jdbc:mysql://10.0.81.202:3306/jihe-dc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true";
@ -52,7 +51,7 @@ public class DcMYSQLJob {
}
@Scheduled(cron = "0 0 23 * * ?")
//@Scheduled(cron = "0 56 * * * ?")
//@Scheduled(cron = "0 30 * * * ?")
public void backupJiHeDCPro() throws IOException {
// 数据库配置信息
String url = "jdbc:mysql://10.0.81.202:3306/jihe-dc-pro?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true";

7
zc-business/src/main/java/com/zc/business/controller/DcMYSQLUtil.java

@ -16,11 +16,14 @@ public class DcMYSQLUtil {
*/
public static void backup(String host, String port, String userName, String password, String dbName, File file) {
String cmd = "mysqldump --single-transaction " + " -h" + host + " -P" + port + " -u" + userName + " -p" + password + " --databases --skip-extended-insert " + dbName + " > " + file.getPath();
String cmd = "";
String os = System.getProperties().getProperty("os.name");
if (os.contains("Windows")) {
// Windows 需要加上 cmd /c
cmd = "cmd /c " + cmd;
cmd = "cmd /c mysqldump --single-transaction " + " -h" + host + " -P" + port + " -u" + userName + " -p" + password + " --databases --skip-extended-insert " + dbName + " > " + file.getPath();
} else {
// Linux 需要加上 /usr/local/mysql/bin/
cmd = "bash -c /usr/local/mysql/bin/mysqldump --single-transaction " + " -h" + host + " -P" + port + " -u" + userName + " -p'" + password + "' --databases --skip-extended-insert " + dbName + " > " + file.getPath();
}
System.out.printf("cmd命令为:%s%n", cmd);
try {

77
zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java

@ -21,6 +21,8 @@ import com.zc.business.service.DcEmergencyPlansService;
import com.zc.business.service.DcExecuteActionService;
import com.zc.business.service.IDcDeviceService;
import com.zc.common.core.httpclient.exception.HttpException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -31,6 +33,7 @@ import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
@Resource
@ -46,6 +49,9 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
@Resource
private EventPlanAssocMapper eventPlanAssocMapper;
@Resource
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
/**
* 查询事件预案
@ -207,6 +213,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
public Map<String, List<DcInfoBoardTemplate>> getBoardTemplate(List<DcDevice> dcDevices) {
Map<String, List<DcInfoBoardTemplate>> map = new HashMap<>();
dcDevices.forEach(dcDevice -> {
threadPoolTaskExecutor.execute(() -> {
try {
if (StringUtils.isEmpty(dcDevice.getIotDeviceId())) {
return;
@ -247,12 +254,14 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
e.printStackTrace();
}
});
});
return map;
}
/**
* 执行操作中的规则筛选
*
* @param dcExecuteAction
* @param markArray
* @param direction
@ -276,8 +285,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
List<String> deviceList = (List<String>) otherConfig.get("deviceList");
queryWrapper.in(DcDevice::getIotDeviceId, deviceList);
dcDevices = dcDeviceService.list(queryWrapper);
}
else if (searchRule.equals(2)) {
} else if (searchRule.equals(2)) {
// 事件上游最近
if (direction.equals("1")) {
@ -318,8 +326,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
}
}
}
else if (searchRule.equals(3)) {
} else if (searchRule.equals(3)) {
// 事件下游最近
if (direction.equals("1")) {
// 上行 取最大的几个
@ -360,8 +367,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
dcDevices = dcDevices.subList(0, dcExecuteAction.getNumber());
}
}
}
else {
} else {
// 最近公里数
Integer kilometers = Integer.parseInt(markArray[0].replaceAll("K", ""));
// 根据事件桩号、公里数 计算出 桩号范围
@ -400,6 +406,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
/**
* 感知事件-情报板自动生成
*
* @param dcEventAnDcEmergencyPlans
* @return
*/
@ -429,6 +436,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
/**
* 交通事件-情报板自动生成
*
* @return
*/
@Override
@ -484,6 +492,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
/**
* 感知事件确认
*
* @param dcEventAnDcEmergencyPlans 事件数据 事件预案数据
* @return
*/
@ -501,6 +510,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
/**
* 事件确认
*
* @param dcEventAnDcEmergencyPlans 事件数据 事件预案数据
* @return
*/
@ -575,18 +585,20 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
/**
* 根据不通设备类型执行不通的功能操作
*/
public void invokedFunction(
Integer operationType,
public void invokedFunction(Integer operationType,
List<DcDevice> dcDevices,
JSONObject otherConfig,
JSONArray resultArray) throws HttpException, IOException {
String iotDeviceId = "";
String functionId = "";
JSONArray resultArray) {
for (DcDevice device : dcDevices) {
threadPoolTaskExecutor.execute(() -> {
String iotDeviceId = "";
String functionId = "";
iotDeviceId = device.getIotDeviceId();
HashMap<String, Object> props = new HashMap<>();
try {
if (device.getDeviceType().equals(DeviceTypeConstants.DRIVING_GUIDANCE)) {
// 行车诱导
functionId = DeviceFunctionIdConstants.DRIVING_GUIDANCE;
@ -613,16 +625,19 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
result.put("result", ajaxResult);
resultArray.add(result);
}
else if (device.getDeviceType().equals(DeviceTypeConstants.VARIABLE_INFORMATION_FLAG)) {
if (operationType == 1) {
// 执行操作
// 可变信息标志 分三步
// 1:执行11功能码
functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_11;
props.put("fileName", "play011.lst");
props.put("size", "65535");
AjaxResult ajaxResult11 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props);
AjaxResult ajaxResult11;
ajaxResult11 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props);
if (ajaxResult11.get("code").equals(200)) {
// 2:执行13功能码
HashMap<String, Object> props11 = new HashMap<>();
@ -653,7 +668,8 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
parameters.put("formatStyle", dcInfoBoardTemplate.getFormatStyle());
list.add(parameters);
props11.put("parameters", list);
AjaxResult ajaxResult13 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props11);
AjaxResult ajaxResult13 = null;
ajaxResult13 = dcDeviceController.invokedFunction(iotDeviceId, functionId, props11);
JSONObject result = new JSONObject();
if (ajaxResult13.get("code").equals(200)) {
HashMap<String, Object> props1B = new HashMap<>();
@ -661,22 +677,25 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
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);
}
}
}
else {
} else {
// 恢复操作
props.put("fileId", "10");
functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B;
AjaxResult ajaxResult1B = dcDeviceController.invokedFunction(iotDeviceId, functionId, props);
AjaxResult ajaxResult1B;
ajaxResult1B = dcDeviceController.invokedFunction(iotDeviceId, functionId, props);
JSONObject result = new JSONObject();
result.put("device", device.getId());
result.put("result", ajaxResult1B);
@ -696,35 +715,45 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
JSONArray termList = new JSONArray();
termList.add(JSON.parseObject(device.getOtherConfig()));
params.put("termList", termList);
JSONObject returnResult = broadcastController.nearCamListDistance(params);
JSONObject result = new JSONObject();
result.put("device", device.getId());
result.put("result", returnResult);
resultArray.add(result);
}
else if (device.getDeviceType().equals(DeviceTypeConstants.LASER_FATIGUE_AWAKENING)) {
// 激光疲劳唤醒
functionId = otherConfig.get("state").toString();
AjaxResult ajaxResultState = dcDeviceController.invokedFunction(iotDeviceId, functionId, new HashMap<>());
// 将调用结果存入到 resultArray(操作结果) 中
JSONObject result = new JSONObject();
result.put("device", device.getId());
result.put("result", ajaxResultState);
resultArray.add(result);
// 操作时长
String operationDuration = "SETTM" + otherConfig.get("operationDuration").toString();
AjaxResult ajaxResult = dcDeviceController.invokedFunction(iotDeviceId, operationDuration, new HashMap<>());
HashMap<String, Object> propsTime = new HashMap<>();
propsTime.put("SET", operationDuration);
functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_SETTM;
AjaxResult ajaxResult = dcDeviceController.invokedFunction(iotDeviceId, functionId, propsTime);
JSONObject resultTime = new JSONObject();
resultTime.put("device", device.getId());
resultTime.put("result", ajaxResult);
resultArray.add(resultTime);
} else {
break;
}
}
} catch (HttpException | IOException e) {
log.error(e.toString());
throw new RuntimeException(e);
}
});
}
}

2
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficSectionDataServiceImpl.java

@ -122,7 +122,7 @@ public class DcTrafficSectionDataServiceImpl
/**
* 定义每小时第20分钟执行的任务用于清除过期缓存数据并将缓存中的数据整合后保存至数据库
*/
@Scheduled(cron = "0 20 * * * ?") // 每小时的20分整点执行该任务
// @Scheduled(cron = "0 20 * * * ?") // 每小时的20分整点执行该任务
public void performHourlyCleanupAndPersist() {
// 清除已过期的缓存数据
DailyTrafficStatisticsCache.clearExpiredData();

Loading…
Cancel
Save