7 changed files with 233 additions and 42 deletions
@ -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(); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue