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 e34ac4ca..41b68888 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,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 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 devices = (List) 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 params = jsonObject.toJavaObject(new TypeReference>() { + }); + 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); } /** diff --git a/zc-business/src/main/java/com/zc/business/controller/DcMYSQLJob.java b/zc-business/src/main/java/com/zc/business/controller/DcMYSQLJob.java index 27f24f1a..922f6527 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcMYSQLJob.java +++ b/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 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 +43,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 +52,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"; diff --git a/zc-business/src/main/java/com/zc/business/controller/DcMYSQLUtil.java b/zc-business/src/main/java/com/zc/business/controller/DcMYSQLUtil.java index 02f946c8..5262517d 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcMYSQLUtil.java +++ b/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 = "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"); if (os.contains("Windows")) { // Windows 需要加上 cmd /c cmd = "cmd /c " + cmd; + } else { + // Windows 需要加上 /usr/local/mysql/bin/ + cmd = "/usr/local/mysql/bin/" + cmd; } System.out.printf("cmd命令为:%s%n", cmd); try {