Browse Source

优化设备批量操作接口

优化解决SQL数据备份功能
develop
zhaoxianglong 9 months ago
parent
commit
d3852ff163
  1. 42
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 6
      zc-business/src/main/java/com/zc/business/controller/DcMYSQLJob.java
  3. 5
      zc-business/src/main/java/com/zc/business/controller/DcMYSQLUtil.java

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

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

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

@ -35,7 +35,7 @@ public class DcMYSQLJob {
} }
@Scheduled(cron = "0 0 22 * * ?") @Scheduled(cron = "0 0 22 * * ?")
//@Scheduled(cron = "0 25 * * * ?") //@Scheduled(cron = "0 10 * * * ?")
public void backupAthena() throws IOException { 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"; 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 +43,7 @@ public class DcMYSQLJob {
} }
@Scheduled(cron = "0 30 22 * * ?") @Scheduled(cron = "0 30 22 * * ?")
//@Scheduled(cron = "0 27 * * * ?") //@Scheduled(cron = "0 20 * * * ?")
public void backupJiHeDC() throws IOException { 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"; 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 +52,7 @@ public class DcMYSQLJob {
} }
@Scheduled(cron = "0 0 23 * * ?") @Scheduled(cron = "0 0 23 * * ?")
//@Scheduled(cron = "0 56 * * * ?") //@Scheduled(cron = "0 30 * * * ?")
public void backupJiHeDCPro() throws IOException { 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"; 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";

5
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) { 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 = "mysqldump --single-transaction " + " -h" + host + " -P'" + port + "' -u" + userName + " -p" + password + " --databases --skip-extended-insert " + dbName + " > " + file.getPath();
String os = System.getProperties().getProperty("os.name"); String os = System.getProperties().getProperty("os.name");
if (os.contains("Windows")) { if (os.contains("Windows")) {
// Windows 需要加上 cmd /c // Windows 需要加上 cmd /c
cmd = "cmd /c " + cmd; cmd = "cmd /c " + cmd;
} else {
// Windows 需要加上 /usr/local/mysql/bin/
cmd = "/usr/local/mysql/bin/" + cmd;
} }
System.out.printf("cmd命令为:%s%n", cmd); System.out.printf("cmd命令为:%s%n", cmd);
try { try {

Loading…
Cancel
Save