package org.flume.alarm.restful; import net.sf.json.JSONObject; import org.flume.alarm.core.util.DateUtils; import org.flume.alarm.util.Configure; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * 可信上链工具 */ @Component @Async public class PublicUtilDTO { //告警上链 public static void sendAlarmBusiness(String devcode, String devType, String factory, String message, String alarmDate) { JSONObject headerJson = new JSONObject(); JSONObject businessJson = new JSONObject(); JSONObject businessEventJson = new JSONObject(); JSONObject staticPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson1 = new JSONObject(); JSONObject dynamicPropertyJson2 = new JSONObject(); JSONObject dynamicPropertyJson3 = new JSONObject(); List<JSONObject> objectList = new ArrayList<>(); List<JSONObject> dynamicList = new ArrayList<>(); headerJson.put("category", "报警管理"); headerJson.put("version", "1.1.1"); headerJson.put("publicKey", "4e71573846eb4a0dbddcdfd7197f28cf"); businessJson.put("businessNumber", System.currentTimeMillis()); businessJson.put("businessName", devType); businessJson.put("type", "1"); businessJson.put("description", "报警管理"); businessJson.put("itemName", "智慧管网专项"); businessEventJson.put("assetEvent", "报警查询"); businessEventJson.put("currentState", "无"); businessEventJson.put("createTime", DateUtils.sdf4.format(new Date())); businessEventJson.put("deptName", "住建部"); staticPropertyJson.put("chineseName", "设备编号"); staticPropertyJson.put("englishName", "DEVCODE"); staticPropertyJson.put("value", devcode); objectList.add(staticPropertyJson); dynamicPropertyJson.put("chineseName", "设备类型"); dynamicPropertyJson.put("englishName", "TYPENAME"); dynamicPropertyJson.put("value", devType); dynamicList.add(dynamicPropertyJson); dynamicPropertyJson1.put("chineseName", "报警位置"); dynamicPropertyJson1.put("englishName", "FACTORY"); dynamicPropertyJson1.put("value", factory); dynamicList.add(dynamicPropertyJson1); dynamicPropertyJson2.put("chineseName", "报警消息"); dynamicPropertyJson2.put("englishName", "MESSAGE"); dynamicPropertyJson2.put("value", message); dynamicList.add(dynamicPropertyJson2); dynamicPropertyJson3.put("chineseName", "报警时间"); dynamicPropertyJson3.put("englishName", "RECORDDATE"); dynamicPropertyJson3.put("value", alarmDate); dynamicList.add(dynamicPropertyJson3); headerJson.put("business", businessJson); headerJson.put("businessEvent", businessEventJson); headerJson.put("static", objectList); headerJson.put("dynamic", dynamicList); String responseMsg = HttpClientUtils.post(Configure.getProperty("pubUrl"), headerJson.toString()); System.out.println("****发送数据****" + headerJson.toString()); System.out.println("****可信返回结果****" + responseMsg); } //井盖数据上链 public static void sendWellBusiness(String devcode, String devType, String factory, String status) { JSONObject headerJson = new JSONObject(); JSONObject businessJson = new JSONObject(); JSONObject businessEventJson = new JSONObject(); JSONObject staticPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson1 = new JSONObject(); JSONObject dynamicPropertyJson2 = new JSONObject(); List<JSONObject> objectList = new ArrayList<>(); List<JSONObject> dynamicList = new ArrayList<>(); headerJson.put("category", "井盖监测"); headerJson.put("version", "1.1.1"); headerJson.put("publicKey", "271fcde752e4444eb30f14a9c00a2b6a"); businessJson.put("businessNumber", System.currentTimeMillis()); businessJson.put("businessName", devType); businessJson.put("type", "1"); businessJson.put("description", "井盖监测数据上传"); businessJson.put("itemName", "智慧管网专项"); businessEventJson.put("assetEvent", "数据查询"); businessEventJson.put("currentState", "无"); businessEventJson.put("createTime", DateUtils.sdf4.format(new Date())); businessEventJson.put("deptName", "住建部"); staticPropertyJson.put("chineseName", "设备编号"); staticPropertyJson.put("englishName", "DEVCODE"); staticPropertyJson.put("value", devcode); objectList.add(staticPropertyJson); dynamicPropertyJson.put("chineseName", "设备类型"); dynamicPropertyJson.put("englishName", "TYPENAME"); dynamicPropertyJson.put("value", devType); dynamicList.add(dynamicPropertyJson); dynamicPropertyJson1.put("chineseName", "设备位置"); dynamicPropertyJson1.put("englishName", "FACTORY"); dynamicPropertyJson1.put("value", factory); dynamicList.add(dynamicPropertyJson1); dynamicPropertyJson2.put("chineseName", "设备状态"); dynamicPropertyJson2.put("englishName", "STATUS"); dynamicPropertyJson2.put("value", status); dynamicList.add(dynamicPropertyJson2); headerJson.put("business", businessJson); headerJson.put("businessEvent", businessEventJson); headerJson.put("static", objectList); headerJson.put("dynamic", dynamicList); String responseMsg = HttpClientUtils.post(Configure.getProperty("pubUrl"), headerJson.toString()); System.out.println("****发送数据****" + headerJson.toString()); System.out.println("****可信返回结果****" + responseMsg); } //调压站泄漏监测上链 public static void sendMethaneBusiness(String devcode, String devType, String factory, String strength, String uptime) { JSONObject headerJson = new JSONObject(); JSONObject businessJson = new JSONObject(); JSONObject businessEventJson = new JSONObject(); JSONObject staticPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson1 = new JSONObject(); JSONObject dynamicPropertyJson2 = new JSONObject(); JSONObject dynamicPropertyJson3 = new JSONObject(); List<JSONObject> objectList = new ArrayList<>(); List<JSONObject> dynamicList = new ArrayList<>(); headerJson.put("category", "调压站泄漏监测"); headerJson.put("version", "1.1.1"); headerJson.put("publicKey", "94882d82ea994d819a2552bc11e1330e"); businessJson.put("businessNumber", System.currentTimeMillis()); businessJson.put("businessName", devType); businessJson.put("type", "1"); businessJson.put("description", "燃气浓度上报"); businessJson.put("itemName", "智慧管网专项"); businessEventJson.put("assetEvent", "数据查询"); businessEventJson.put("currentState", "无"); businessEventJson.put("createTime", DateUtils.sdf4.format(new Date())); businessEventJson.put("deptName", "住建部"); staticPropertyJson.put("chineseName", "设备编号"); staticPropertyJson.put("englishName", "DEVCODE"); staticPropertyJson.put("value", devcode); objectList.add(staticPropertyJson); dynamicPropertyJson.put("chineseName", "设备类型"); dynamicPropertyJson.put("englishName", "TYPENAME"); dynamicPropertyJson.put("value", devType); dynamicList.add(dynamicPropertyJson); dynamicPropertyJson1.put("chineseName", "设备位置"); dynamicPropertyJson1.put("englishName", "FACTORY"); dynamicPropertyJson1.put("value", factory); dynamicList.add(dynamicPropertyJson1); dynamicPropertyJson2.put("chineseName", "当前浓度"); dynamicPropertyJson2.put("englishName", "STRENGTH"); dynamicPropertyJson2.put("value", strength); dynamicList.add(dynamicPropertyJson2); dynamicPropertyJson3.put("chineseName", "采集时间"); dynamicPropertyJson3.put("englishName", "UPTIME"); dynamicPropertyJson3.put("value", uptime); dynamicList.add(dynamicPropertyJson3); headerJson.put("business", businessJson); headerJson.put("businessEvent", businessEventJson); headerJson.put("static", objectList); headerJson.put("dynamic", dynamicList); String responseMsg = HttpClientUtils.post(Configure.getProperty("pubUrl"), headerJson.toString()); System.out.println("****发送数据****" + headerJson.toString()); System.out.println("****可信返回结果****" + responseMsg); } //调压站泄漏监测上链 public static void sendLiquidBusiness(String devcode, String devType, String factory, String liquid, String uptime) { JSONObject headerJson = new JSONObject(); JSONObject businessJson = new JSONObject(); JSONObject businessEventJson = new JSONObject(); JSONObject staticPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson1 = new JSONObject(); JSONObject dynamicPropertyJson2 = new JSONObject(); JSONObject dynamicPropertyJson3 = new JSONObject(); List<JSONObject> objectList = new ArrayList<>(); List<JSONObject> dynamicList = new ArrayList<>(); headerJson.put("category", "负荷监测"); headerJson.put("version", "1.1.1"); headerJson.put("publicKey", "0d5465dc7844482f9fe5b1185d47bac9"); businessJson.put("businessNumber", System.currentTimeMillis()); businessJson.put("businessName", devType); businessJson.put("type", "1"); businessJson.put("description", "液位上报"); businessJson.put("itemName", "智慧管网专项"); businessEventJson.put("assetEvent", "数据查询"); businessEventJson.put("currentState", "无"); businessEventJson.put("createTime", DateUtils.sdf4.format(new Date())); businessEventJson.put("deptName", "住建部"); staticPropertyJson.put("chineseName", "设备编号"); staticPropertyJson.put("englishName", "DEVCODE"); staticPropertyJson.put("value", devcode); objectList.add(staticPropertyJson); dynamicPropertyJson.put("chineseName", "设备类型"); dynamicPropertyJson.put("englishName", "TYPENAME"); dynamicPropertyJson.put("value", devType); dynamicList.add(dynamicPropertyJson); dynamicPropertyJson1.put("chineseName", "设备位置"); dynamicPropertyJson1.put("englishName", "FACTORY"); dynamicPropertyJson1.put("value", factory); dynamicList.add(dynamicPropertyJson1); dynamicPropertyJson2.put("chineseName", "液位值"); dynamicPropertyJson2.put("englishName", "LIQUIDDATA"); dynamicPropertyJson2.put("value", liquid); dynamicList.add(dynamicPropertyJson2); dynamicPropertyJson3.put("chineseName", "采集时间"); dynamicPropertyJson3.put("englishName", "UPTIME"); dynamicPropertyJson3.put("value", uptime); dynamicList.add(dynamicPropertyJson3); headerJson.put("business", businessJson); headerJson.put("businessEvent", businessEventJson); headerJson.put("static", objectList); headerJson.put("dynamic", dynamicList); String responseMsg = HttpClientUtils.post(Configure.getProperty("pubUrl"), headerJson.toString()); System.out.println("****发送数据****" + headerJson.toString()); System.out.println("****可信返回结果****" + responseMsg); } //消防栓数据上链 public static void sendHydrantBusiness(String devcode, String devType, String factory, String status) { JSONObject headerJson = new JSONObject(); JSONObject businessJson = new JSONObject(); JSONObject businessEventJson = new JSONObject(); JSONObject staticPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson1 = new JSONObject(); JSONObject dynamicPropertyJson2 = new JSONObject(); List<JSONObject> objectList = new ArrayList<>(); List<JSONObject> dynamicList = new ArrayList<>(); headerJson.put("category", "消防栓监测"); headerJson.put("version", "1.1.1"); headerJson.put("publicKey", "30266eecba7545e0a9dadb12b78d4032"); businessJson.put("businessNumber", System.currentTimeMillis()); businessJson.put("businessName", devType); businessJson.put("type", "1"); businessJson.put("description", "消防栓监测数据上传"); businessJson.put("itemName", "智慧管网专项"); businessEventJson.put("assetEvent", "数据查询"); businessEventJson.put("currentState", "无"); businessEventJson.put("createTime", DateUtils.sdf4.format(new Date())); businessEventJson.put("deptName", "住建部"); staticPropertyJson.put("chineseName", "设备编号"); staticPropertyJson.put("englishName", "DEVCODE"); staticPropertyJson.put("value", devcode); objectList.add(staticPropertyJson); dynamicPropertyJson.put("chineseName", "设备类型"); dynamicPropertyJson.put("englishName", "TYPENAME"); dynamicPropertyJson.put("value", devType); dynamicList.add(dynamicPropertyJson); dynamicPropertyJson1.put("chineseName", "安装位置"); dynamicPropertyJson1.put("englishName", "FACTORY"); dynamicPropertyJson1.put("value", factory); dynamicList.add(dynamicPropertyJson1); dynamicPropertyJson2.put("chineseName", "设备状态"); dynamicPropertyJson2.put("englishName", "STATUS"); dynamicPropertyJson2.put("value", status); dynamicList.add(dynamicPropertyJson2); headerJson.put("business", businessJson); headerJson.put("businessEvent", businessEventJson); headerJson.put("static", objectList); headerJson.put("dynamic", dynamicList); String responseMsg = HttpClientUtils.post(Configure.getProperty("pubUrl"), headerJson.toString()); System.out.println("****发送数据****" + headerJson.toString()); System.out.println("****可信返回结果****" + responseMsg); } //破损监测上链 public static void sendNoiseBusiness(String devcode, String devType, String factory, String noise, String uptime) { JSONObject headerJson = new JSONObject(); JSONObject businessJson = new JSONObject(); JSONObject businessEventJson = new JSONObject(); JSONObject staticPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson1 = new JSONObject(); JSONObject dynamicPropertyJson2 = new JSONObject(); JSONObject dynamicPropertyJson3 = new JSONObject(); List<JSONObject> objectList = new ArrayList<>(); List<JSONObject> dynamicList = new ArrayList<>(); headerJson.put("category", "破损监测"); headerJson.put("version", "1.1.1"); headerJson.put("publicKey", "0d5465dc7844482f9fe5b1185d47bac9"); businessJson.put("businessNumber", System.currentTimeMillis()); businessJson.put("businessName", devType); businessJson.put("type", "1"); businessJson.put("description", "噪声上报"); businessJson.put("itemName", "智慧管网专项"); businessEventJson.put("assetEvent", "数据查询"); businessEventJson.put("currentState", "无"); businessEventJson.put("createTime", DateUtils.sdf4.format(new Date())); businessEventJson.put("deptName", "住建部"); staticPropertyJson.put("chineseName", "设备编号"); staticPropertyJson.put("englishName", "DEVCODE"); staticPropertyJson.put("value", devcode); objectList.add(staticPropertyJson); dynamicPropertyJson.put("chineseName", "设备类型"); dynamicPropertyJson.put("englishName", "TYPENAME"); dynamicPropertyJson.put("value", devType); dynamicList.add(dynamicPropertyJson); dynamicPropertyJson1.put("chineseName", "设备位置"); dynamicPropertyJson1.put("englishName", "FACTORY"); dynamicPropertyJson1.put("value", factory); dynamicList.add(dynamicPropertyJson1); dynamicPropertyJson2.put("chineseName", "噪声"); dynamicPropertyJson2.put("englishName", "DDATA"); dynamicPropertyJson2.put("value", noise); dynamicList.add(dynamicPropertyJson2); dynamicPropertyJson3.put("chineseName", "噪声采集时间"); dynamicPropertyJson3.put("englishName", "UPTIME"); dynamicPropertyJson3.put("value", uptime); dynamicList.add(dynamicPropertyJson3); headerJson.put("business", businessJson); headerJson.put("businessEvent", businessEventJson); headerJson.put("static", objectList); headerJson.put("dynamic", dynamicList); String responseMsg = HttpClientUtils.post(Configure.getProperty("pubUrl"), headerJson.toString()); System.out.println("****发送数据****" + headerJson.toString()); System.out.println("****可信返回结果****" + responseMsg); } //查询设备基础信息上链 public static void sendDeviceBusiness(String devcode, String devType) { JSONObject headerJson = new JSONObject(); JSONObject businessJson = new JSONObject(); JSONObject businessEventJson = new JSONObject(); JSONObject staticPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson = new JSONObject(); List<JSONObject> objectList = new ArrayList<>(); List<JSONObject> dynamicList = new ArrayList<>(); headerJson.put("category", "设备基础信息"); headerJson.put("version", "1.1.1"); headerJson.put("publicKey", "5afecd7b732e4096849bfd3fa36a3bd6"); businessJson.put("businessNumber", System.currentTimeMillis()); businessJson.put("businessName", devType); businessJson.put("type", "1"); businessJson.put("description", "设备查询"); businessJson.put("itemName", "智慧管网专项"); businessEventJson.put("assetEvent", "设备查询"); businessEventJson.put("currentState", "无"); businessEventJson.put("createTime", DateUtils.sdf4.format(new Date())); businessEventJson.put("deptName", "住建部"); staticPropertyJson.put("chineseName", "设备编号"); staticPropertyJson.put("englishName", "DEVCODE"); staticPropertyJson.put("value", devcode); dynamicList.add(staticPropertyJson); dynamicPropertyJson.put("chineseName", "传感器类型"); dynamicPropertyJson.put("englishName", "TYPENAME"); dynamicPropertyJson.put("value", devType); dynamicList.add(dynamicPropertyJson); headerJson.put("business", businessJson); headerJson.put("businessEvent", businessEventJson); headerJson.put("static", objectList); headerJson.put("dynamic", dynamicList); String responseMsg = HttpClientUtils.post(Configure.getProperty("pubUrl"), headerJson.toString()); System.out.println("****发送数据****" + headerJson.toString()); System.out.println("****可信返回结果****" + responseMsg); } //新增设备上链 public static void sendAddDeviceBusiness(String devcode, String devType, String factory, String lon, String lat, String businessNumber) { JSONObject headerJson = new JSONObject(); JSONObject businessJson = new JSONObject(); JSONObject businessEventJson = new JSONObject(); JSONObject staticPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson = new JSONObject(); JSONObject dynamicPropertyJson1 = new JSONObject(); JSONObject dynamicPropertyJson2 = new JSONObject(); JSONObject dynamicPropertyJson3 = new JSONObject(); List<JSONObject> objectList = new ArrayList<>(); List<JSONObject> dynamicList = new ArrayList<>(); headerJson.put("category", "设备基础信息"); headerJson.put("version", "1.1.1"); headerJson.put("publicKey", "5afecd7b732e4096849bfd3fa36a3bd6"); businessJson.put("businessNumber", businessNumber); businessJson.put("businessName", devType); businessJson.put("type", "1"); businessJson.put("description", "设备新增"); businessJson.put("itemName", "智慧管网专项"); businessEventJson.put("assetEvent", "设备新增"); businessEventJson.put("currentState", "无"); businessEventJson.put("createTime", DateUtils.sdf4.format(new Date())); businessEventJson.put("deptName", "住建部"); staticPropertyJson.put("chineseName", "设备编号"); staticPropertyJson.put("englishName", "DEVCODE"); staticPropertyJson.put("value", devcode); objectList.add(staticPropertyJson); dynamicPropertyJson.put("chineseName", "传感器类型"); dynamicPropertyJson.put("englishName", "TYPENAME"); dynamicPropertyJson.put("value", devType); dynamicList.add(dynamicPropertyJson); dynamicPropertyJson1.put("chineseName", "设备位置"); dynamicPropertyJson1.put("englishName", "FACTORY"); dynamicPropertyJson1.put("value", factory); dynamicList.add(dynamicPropertyJson1); dynamicPropertyJson2.put("chineseName", "经度"); dynamicPropertyJson2.put("englishName", "LONGTITUDE"); dynamicPropertyJson2.put("value", lon); dynamicList.add(dynamicPropertyJson2); dynamicPropertyJson3.put("chineseName", "纬度"); dynamicPropertyJson3.put("englishName", "LATITUDE"); dynamicPropertyJson3.put("value", lat); dynamicList.add(dynamicPropertyJson3); headerJson.put("business", businessJson); headerJson.put("businessEvent", businessEventJson); headerJson.put("static", objectList); headerJson.put("dynamic", dynamicList); String responseMsg = HttpClientUtils.post(Configure.getProperty("pubUrl"), headerJson.toString()); System.out.println("****发送数据****" + headerJson.toString()); System.out.println("****可信返回结果****" + responseMsg); } //删除设备上链 public static void sendDeleteDeviceBusiness(String devcode, String businessNumber) { JSONObject headerJson = new JSONObject(); JSONObject businessEventJson = new JSONObject(); JSONObject dynamicPropertyJson = new JSONObject(); List<JSONObject> dynamicList = new ArrayList<>(); headerJson.put("category", "设备基础信息"); headerJson.put("version", "1.1.1"); // headerJson.put("publicKey", "5afecd7b732e4096849bfd3fa36a3bd6"); businessEventJson.put("businessNumber", businessNumber); businessEventJson.put("assetEvent", "设备删除"); businessEventJson.put("currentState", "无"); businessEventJson.put("createTime", DateUtils.sdf4.format(new Date())); businessEventJson.put("deptName", "住建部"); dynamicPropertyJson.put("chineseName", "设备编号"); dynamicPropertyJson.put("englishName", "DEVCODE"); dynamicPropertyJson.put("value", devcode); dynamicList.add(dynamicPropertyJson); headerJson.put("businessEvent", businessEventJson); headerJson.put("dynamic", dynamicList); String responseMsg = HttpClientUtils.post(Configure.getProperty("pubEventUrl"), headerJson.toString()); System.out.println("****发送数据****" + headerJson.toString()); System.out.println("****可信返回结果****" + responseMsg); } }