diff --git a/src/main/java/com/example/zxweb/init/LoadCelueInit.java b/src/main/java/com/example/zxweb/init/LoadCelueInit.java index f2c52cc..fb3ac50 100644 --- a/src/main/java/com/example/zxweb/init/LoadCelueInit.java +++ b/src/main/java/com/example/zxweb/init/LoadCelueInit.java @@ -35,8 +35,9 @@ public class LoadCelueInit implements ApplicationRunner{ String gateway_5lqh = DevConstant.gateway.gateway_5lqh;//5楼网关 String format = String.format("{\"serial\":\"%s\",\"productId\":\"\",\"methodName\":\"celueListQuery\",\"inputData\":{\"devid\":\"%s\"}}", gateway_5lqh,gateway_5lqh); JSONObject requestBody = JSONObject.parseObject(format); - JSONObject responseBody = IotUtils.postApi(IotApiEnum.getPathByText("向设备发送方法"), requestBody); - log.info(responseBody.toJSONString()); + /*JSONObject responseBody = IotUtils.postApi(IotApiEnum.getPathByText("向设备发送方法"), requestBody); + log.info(responseBody.toJSONString());*/ + JSONObject responseBody = JSONObject.parseObject("{\"code\":\"0\",\"data\":{\"outputData\":{\"devid\":\"0cefafd605f7\",\"code\":1,\"list\":[{\"devid\":\"3381bbfeffea3590\",\"triggereTime\":\"20 18 * * 1,4,6\",\"name\":\"策略1\",\"action\":\"light00001.light.controlLight.ctrl_ch0_status=\\\"0\\\"&&chazuo000001.plug.controlPlug.ctrl_ch0_status=\\\"0\\\"\",\"startTime\":\"2023-11-12 10:00:00\",\"endTime\":\"2023-11-12 11:30:00\",\"celueid\":\"100000000001\"},{\"devid\":\"0cefafd605f7\",\"triggerCondition\":\"body0001.body_exist.status.report_status=\\\"0\\\"##900\",\"name\":\"策略2\",\"action\":\"light00001.light.controlLight.ctrl_ch0_status=\\\"0\\\"&&chazuo000001.plug.controlPlug.ctrl_ch0_status=\\\"0\\\"\",\"startTime\":\"2023-11-12 10:00:00\",\"endTime\":\"2023-11-12 11:30:00\",\"celueid\":\"100000000002\"},{\"devid\":\"0cefafd605f7\",\"triggereTime\":\"20 18 * * 1,4,6\",\"name\":\"策略3\",\"action\":\"e826ecfeff81f68c.light.controlLight.ctrl_ch0_status=\\\"0\\\"\",\"startTime\":\"2023-09-12 10:00:00\",\"endTime\":\"2023-09-30 11:30:00\",\"celueid\":\"100000000003\"}]}}}\n"); JSONObject data = responseBody.getJSONObject("data"); if (data!=null) { JSONObject outputData = data.getJSONObject("outputData"); @@ -56,6 +57,8 @@ public class LoadCelueInit implements ApplicationRunner{ } } zxCelue.setDevid(String.join(",",devidList)); + //获取状态 + zxCelue.setStatus(IotUtils.getCelueStatus(zxCelue.getCelueid())); } //更新库表 zxCelueService.saveOrUpdateBatch(zxCelues); diff --git a/src/main/java/com/example/zxweb/utils/IotUtils.java b/src/main/java/com/example/zxweb/utils/IotUtils.java index ae6defa..53e67f0 100644 --- a/src/main/java/com/example/zxweb/utils/IotUtils.java +++ b/src/main/java/com/example/zxweb/utils/IotUtils.java @@ -110,6 +110,29 @@ public class IotUtils { return false; } + /** + * 获取策略的状态 + * @param celueId 策略id + * @return 1-运行中,0-停止中 + */ + public static String getCelueStatus(String celueId){ + String str="{\"serial\":\""+serial+"\",\"productId\":\"\",\"methodName\":\"celueStatusQuery\",\"inputData\":{\"devid\":\""+serial+"\",\"celueid\":\""+celueId+"\"}}"; + JSONObject requestBody = JSONObject.parseObject(str); + JSONObject responseBody = IotUtils.getApi(IotApiEnum.getPathByText("查询方法历史数据"), requestBody); + JSONObject data = responseBody.getJSONObject("data"); + try { + if (data!=null) { + JSONObject outputData = data.getJSONObject("outputData"); + if (outputData!=null) { + return outputData.getString("status"); + } + } + }catch (Exception e){ + throw new BusinessException(e.getMessage()); + } + return "0"; + } + /** * 删除策略 * @param celueId 策略id diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 0b77927..325f38d 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -239,6 +239,8 @@ function loadTable(){ contentType: 'application/json;charset=utf-8', success: function(res){ console.log(res) + },error:function (res){ + layer.msg('更改失败,'+res.message, {icon: 1}); } }); console.log(id)