diff --git a/src/main/java/com/example/zxweb/init/LoadCelueInit.java b/src/main/java/com/example/zxweb/init/LoadCelueInit.java index c990464..c76c15c 100644 --- a/src/main/java/com/example/zxweb/init/LoadCelueInit.java +++ b/src/main/java/com/example/zxweb/init/LoadCelueInit.java @@ -8,12 +8,15 @@ import com.example.zxweb.entity.ZxCelue; import com.example.zxweb.service.IZxCelueService; import com.example.zxweb.utils.IotUtils; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.context.annotation.Configuration; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -29,7 +32,7 @@ public class LoadCelueInit implements ApplicationRunner{ @Override public void run(ApplicationArguments args) throws Exception { //获取网关的数据,同步到数据库中 - /*String gateway_5lqh = DevConstant.gateway.gateway_5lqh;//5楼网关 + 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); @@ -40,10 +43,28 @@ public class LoadCelueInit implements ApplicationRunner{ JSONArray list = outputData.getJSONArray("list"); if (!CollectionUtils.isEmpty(list)) { List zxCelues = list.toJavaList(ZxCelue.class); + for (ZxCelue zxCelue : zxCelues) { + List devidList=new ArrayList<>(); + String action = zxCelue.getAction(); + if (StringUtils.isNotBlank(action)) { + String[] split = action.split("&&"); + for (String s : split) { + String[] split1 = s.split("\\."); + String s1 = split1[0]; + devidList.add(s1); + } + } + zxCelue.setDevid(String.join(",",devidList)); + } //更新库表 zxCelueService.saveOrUpdateBatch(zxCelues); } } - }*/ + } + } + + public static void main(String[] args) { + ArrayList devidList = new ArrayList<>(Arrays.asList("1,2")); + System.out.println(String.join(",",devidList));; } } diff --git a/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java b/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java index 022b76d..339299e 100644 --- a/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java +++ b/src/main/java/com/example/zxweb/service/impl/ZxCelueServiceImpl.java @@ -119,6 +119,7 @@ public class ZxCelueServiceImpl extends ServiceImpl impl @Override public boolean editStatus(ZxCelue zxCelue) { String status="0"; + AssertUtils.notEmpty(zxCelue.getCelueid(),"当前策略id不可用"); try { ZxCelue celue = getById(zxCelue.getCelueid()); LambdaUpdateWrapper updateWrapper=new LambdaUpdateWrapper<>(); diff --git a/src/main/java/com/example/zxweb/utils/IotUtils.java b/src/main/java/com/example/zxweb/utils/IotUtils.java index bf81e63..e4dc46c 100644 --- a/src/main/java/com/example/zxweb/utils/IotUtils.java +++ b/src/main/java/com/example/zxweb/utils/IotUtils.java @@ -68,6 +68,8 @@ public class IotUtils { if (code==1) { return true; } + }else{ + throw new BusinessException(outputData.getString("message")); } } } @@ -97,6 +99,8 @@ public class IotUtils { Integer code1 = outputData.getInteger("code"); if (code1!=null && 1==code1) { return true;//更改成功 + }else{ + throw new BusinessException(outputData.getString("message")); } } } @@ -121,6 +125,8 @@ public class IotUtils { if (outputData != null) { Integer code = outputData.getInteger("code"); return code == 1; + }else{ + throw new BusinessException(outputData.getString("message")); } } }catch (Exception e){