diff --git a/pom.xml b/pom.xml index eccde1a..add2483 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,11 @@ ctg-ag-sdk-core 2.5.0-SNAPSHOT + + org.apache.httpcomponents + httpclient + 4.5.14 + diff --git a/src/main/java/com/mh/garrison/constant/Constants.java b/src/main/java/com/mh/garrison/constant/Constants.java index 876aff2..e979dbc 100644 --- a/src/main/java/com/mh/garrison/constant/Constants.java +++ b/src/main/java/com/mh/garrison/constant/Constants.java @@ -11,8 +11,10 @@ public class Constants { // 测试 // public static final String NEW_NB_METER_FILE = "D:\\ljf\\项目文档以及资料\\物数和\\警备区\\MeterLogDatas\\"; - // 生产 + // 生产,AEP平台,电表,设备数据变化通知 public static final String NEW_NB_METER_FILE = "E:\\MH_NB\\jingbeiqu\\AEP\\MeterLogDatas\\"; + + public static final String SUCCESS = "success"; } diff --git a/src/main/java/com/mh/garrison/controller/AepHuaNanWaterController.java b/src/main/java/com/mh/garrison/controller/AepHuaNanWaterController.java new file mode 100644 index 0000000..e45565c --- /dev/null +++ b/src/main/java/com/mh/garrison/controller/AepHuaNanWaterController.java @@ -0,0 +1,141 @@ +package com.mh.garrison.controller; + +import com.alibaba.fastjson.JSONObject; +import com.mh.garrison.constant.Constants; +import com.mh.garrison.mhutils.UUid; +import org.springframework.web.bind.annotation.*; + +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * + * @ClassName: AepHuaNanWaterController + * @Description:TODO(设备服务调用接口) + * @author: 铭汉科技—CJL + * @date: 2026年2月5日 19:22:10 + * + */ +@RestController +public class AepHuaNanWaterController { + /** + * 设备数据变化:主要是冷水表,华南分节点 + * + * @param jsonParam + * @return + * @throws IOException + */ + @ResponseBody + @RequestMapping(value = "/na/iocm/devNotify/v1.1.2/updateDeviceData", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") + public String getByJSON(@RequestBody JSONObject jsonParam) throws IOException, InterruptedException { + + // 直接将json信息打印出来 + System.out.println("单个设备数据变化————" + jsonParam.toJSONString() + ",大小长度: " + jsonParam.toJSONString().length()); + + SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss-SSS"); + String formatStr2 = formatter2.format(new Date()); + System.out.println(formatStr2);// 2017-09-15 + UUid uid = new UUid(); // 生成全球唯一标识 + String uidStr = uid.uuid(); + + // FileOutputStream fileOutputStream = null; + // 把报文保存在本地 + // D:\MH_NB\test\SingleMeterLogDatas + int length = jsonParam.toJSONString().length(); +// File file = new File("E:\\MH_NB\\jingbeiqu\\TEST\\AEP\\WaterLogData\\" + formatStr2 + "_" + uidStr + ".txt"); + File file = new File("E:\\MH_NB\\jingbeiqu\\WaterLogDatas\\" + formatStr2 + "_" + uidStr + ".txt"); + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + String causeStr = e.getCause().getMessage(); + System.out.println(">>>>>>>-------------" + causeStr); + } + } + BufferedWriter out = null; + try { + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true))); + out.write(jsonParam.toJSONString() + "\r\n"); + } catch (Exception e) { + String causeStr = e.getCause().getMessage(); + System.out.println(">>>>>>>-------------" + causeStr); + } finally { + try { + if (out != null) { + out.close(); + } + } catch (IOException e) { + String causeStr = e.getCause().getMessage(); + System.out.println(">>>>>>>-------------" + causeStr); + } + } + + // 将获取的json数据封装一层,然后在给返回 + JSONObject result = new JSONObject(); + result.put("msg", "ok"); + + return result.toJSONString(); + } + + /** + * 批量设备数据变化:主要是冷水表 + * + * @param jsonParam + * @return + * @throws IOException + */ + @ResponseBody + @RequestMapping(value = "/na/iocm/devNotify/v1.1.2/updateDeviceDatas", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") + public String getByJSON2(@RequestBody JSONObject jsonParam) throws IOException, InterruptedException { + + // 直接将json信息打印出来 + System.out.println("多个设备数据变化————" + jsonParam.toJSONString() + ",大小长度: " + jsonParam.toJSONString().length()); + + SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss-SSS"); + String formatStr2 = formatter2.format(new Date()); + System.out.println(formatStr2);// 2017-09-15 + UUid uid = new UUid(); // 生成全球唯一标识 + String uidStr = uid.uuid(); + + // FileOutputStream fileOutputStream = null; + // 把报文保存在本地 + // D:\MH_NB\test\SingleMeterLogDatas + int length = jsonParam.toJSONString().length(); +// File file = new File("E:\\MH_NB\\jingbeiqu\\TEST\\AEP\\WaterLogDatas\\" + formatStr2 + "_" + uidStr + ".txt"); + File file = new File("E:\\MH_NB\\jingbeiqu\\WaterLogDatas\\" + formatStr2 + "_" + uidStr + ".txt"); + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + String causeStr = e.getCause().getMessage(); + System.out.println(">>>>>>>-------------" + causeStr); + } + } + BufferedWriter out = null; + try { + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true))); + out.write(jsonParam.toJSONString() + "\r\n"); + } catch (Exception e) { + String causeStr = e.getCause().getMessage(); + System.out.println(">>>>>>>-------------" + causeStr); + } finally { + try { + if (out != null) { + out.close(); + } + } catch (IOException e) { + String causeStr = e.getCause().getMessage(); + System.out.println(">>>>>>>-------------" + causeStr); + } + } + + // 将获取的json数据封装一层,然后在给返回 + JSONObject result = new JSONObject(); + result.put("msg", "ok"); + + return result.toJSONString(); + } +} diff --git a/src/main/java/com/mh/garrison/controller/DeviceController.java b/src/main/java/com/mh/garrison/controller/DeviceController.java index cf0dee6..c6f8f85 100644 --- a/src/main/java/com/mh/garrison/controller/DeviceController.java +++ b/src/main/java/com/mh/garrison/controller/DeviceController.java @@ -38,46 +38,51 @@ public class DeviceController { @ResponseBody @RequestMapping(value = "/na/iocm/devNotify/v1.1.0/updateDeviceData", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") public String getByJSON1(@RequestBody JSONObject jsonParam) throws IOException { - // 直接将json信息打印出来 - System.out.println("单个设备数据变化————" + jsonParam.toJSONString() + ",大小长度:" + jsonParam.toJSONString().length()); - - SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss-SSS"); - String formatStr2 = formatter2.format(new Date()); -// System.out.println(formatStr2);// 2017-09-15 - UUid uid = new UUid(); // 生成全球唯一标识 - String uidStr = uid.uuid(); +// System.out.println("单个设备数据变化————" + jsonParam.toJSONString() + ",大小长度:" + jsonParam.toJSONString().length()); +// +// SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss-SSS"); +// String formatStr2 = formatter2.format(new Date()); +//// System.out.println(formatStr2);// 2017-09-15 +// UUid uid = new UUid(); // 生成全球唯一标识 +// String uidStr = uid.uuid(); // FileOutputStream fileOutputStream = null; // 把报文保存在本地 - int length = jsonParam.toJSONString().length(); - File file; - if (length > 500) { - file = new File( Constants.NEW_NB_METER_FILE + formatStr2 + "_" + uidStr + ".txt"); - if (!file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - BufferedWriter out = null; - try { - out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true))); - out.write(jsonParam.toJSONString() + "\r\n"); - } catch (Exception e) { - String causeStr = e.getCause().getMessage(); - System.out.println(">>>>>>>-------------" + causeStr); - } finally { - try { - out.close(); - } catch (IOException e) { - String causeStr = e.getCause().getMessage(); - System.out.println(">>>>>>>-------------" + causeStr); - } - } - } +// int length = jsonParam.toJSONString().length(); +// File file; +// if (length > 500) { +// if(jsonParam.toJSONString().contains("onlineCode")){ +// System.out.println("保存水表记录值"); +// file = new File("E:\\MH_NB\\jingbeiqu\\TEST\\OC\\WaterLogData\\" + formatStr2 + "_" + uidStr + ".txt"); +// }else { +//// file = new File(Constants.NEW_NB_METER_FILE + formatStr2 + "_" + uidStr + ".txt"); +// file = new File("E:\\MH_NB\\jingbeiqu\\TEST\\OC\\MeterLogData\\" + formatStr2 + "_" + uidStr + ".txt"); +// } +// if (!file.exists()) { +// try { +// file.createNewFile(); +// } catch (IOException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// } +// BufferedWriter out = null; +// try { +// out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true))); +// out.write(jsonParam.toJSONString() + "\r\n"); +// } catch (Exception e) { +// String causeStr = e.getCause().getMessage(); +// System.out.println(">>>>>>>-------------" + causeStr); +// } finally { +// try { +// out.close(); +// } catch (IOException e) { +// String causeStr = e.getCause().getMessage(); +// System.out.println(">>>>>>>-------------" + causeStr); +// } +// } +// } // else { // file = new File("E:\\MH_NB\\jingbeiqu\\MeterLogDatas\\" + formatStr2 + "_" + uidStr + ".txt"); // } @@ -160,6 +165,36 @@ public class DeviceController { System.out.println(">>>>>>>-------------" + causeStr); } } +// File file2 = null; +// if (length > 500) { +// System.out.println("保存水表记录值2"); +// file2 = new File("E:\\MH_NB\\jingbeiqu\\TEST\\OC\\WaterLogDatas\\" + formatStr2 + "_" + uidStr + ".txt"); +// } +// assert file2 != null; +// if (!file2.exists()) { +// try { +// file2.createNewFile(); +// } catch (IOException e) { +// // TODO Auto-generated catch block +// String causeStr = e.getCause().getMessage(); +// System.out.println(">>>>>>>-------------" + causeStr); +// } +// } +// BufferedWriter out2 = null; +// try { +// out2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2, true))); +// out2.write(jsonParam.toJSONString() + "\r\n"); +// } catch (Exception e) { +// String causeStr = e.getCause().getMessage(); +// System.out.println(">>>>>>>-------------" + causeStr); +// } finally { +// try { +// out2.close(); +// } catch (IOException e) { +// String causeStr = e.getCause().getMessage(); +// System.out.println(">>>>>>>-------------" + causeStr); +// } +// } // Thread.sleep(300); // 创建线程,读取本地报文文件 diff --git a/src/main/java/com/mh/garrison/job/DealWaterLogJob.java b/src/main/java/com/mh/garrison/job/DealWaterLogJob.java index 3a5636e..c2dd8ea 100644 --- a/src/main/java/com/mh/garrison/job/DealWaterLogJob.java +++ b/src/main/java/com/mh/garrison/job/DealWaterLogJob.java @@ -23,6 +23,7 @@ import com.mh.garrison.mhutils.FastJson; public class DealWaterLogJob { @Scheduled(cron = "0 0/30 * * * ? ") +// @Scheduled(cron = "0 0/1 * * * ? ") public void dealMeterLogJob() { String filePath = "E:\\MH_NB\\jingbeiqu\\WaterLogDatas\\"; GetTxts1(filePath); diff --git a/src/main/java/com/mh/garrison/mhutils/HttpsUtil.java b/src/main/java/com/mh/garrison/mhutils/HttpsUtil.java index e53f0c1..c2cf8c3 100644 --- a/src/main/java/com/mh/garrison/mhutils/HttpsUtil.java +++ b/src/main/java/com/mh/garrison/mhutils/HttpsUtil.java @@ -35,6 +35,7 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; + @SuppressWarnings("deprecation") public class HttpsUtil extends DefaultHttpClient { public final static String HTTPGET = "GET"; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f7cbe89..2e247d7 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,16 +4,22 @@ spring: name: druidDataSource type: com.alibaba.druid.pool.DruidDataSource druid: - # 生产配置 +# # 生产配置 # url: jdbc:sqlserver://134.175.248.88:2008;DatabaseName=yjc_jingbeiqu # driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver # username: sa # password: mhtech@803 - # 测试配置 - url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=yjc_jingbeiqu + # 生产配置 + # url: jdbc:sqlserver://134.175.248.88:2008;DatabaseName=yjc_jingbeiqu + url: jdbc:sqlserver://172.16.16.7:2008;DatabaseName=yjc_jingbeiqu driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver - username: sa - password: mh@803 + username: yjc_jingbeiqu + password: jbq_W$1@e3Yu.k+9 + # 测试配置 +# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=yjc_jingbeiqu +# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver +# username: sa +# password: mh@803 filters: stat,wall,config max-active: 100 initial-size: 1