Browse Source

NB文件名常量优化

dev
1YGPQV9T9360JF4\Administrator 3 weeks ago
parent
commit
6b8c8d47a9
  1. 4
      src/main/java/com/mh/garrison/constant/Constants.java
  2. 66
      src/main/java/com/mh/garrison/controller/AepHuaNanWaterController.java
  3. 69
      src/main/java/com/mh/garrison/controller/DeviceController.java
  4. 3
      src/main/java/com/mh/garrison/job/DealMeterLogJob.java
  5. 3
      src/main/java/com/mh/garrison/job/DealWaterLogJob.java
  6. 7
      src/main/resources/application.yml

4
src/main/java/com/mh/garrison/constant/Constants.java

@ -13,6 +13,10 @@ public class Constants {
// public static final String NEW_NB_METER_FILE = "D:\\ljf\\项目文档以及资料\\物数和\\警备区\\MeterLogDatas\\"; // public static final String NEW_NB_METER_FILE = "D:\\ljf\\项目文档以及资料\\物数和\\警备区\\MeterLogDatas\\";
// 生产,AEP平台,电表,设备数据变化通知 // 生产,AEP平台,电表,设备数据变化通知
public static final String NEW_NB_METER_FILE = "E:\\MH_NB\\jingbeiqu\\AEP\\MeterLogDatas\\"; public static final String NEW_NB_METER_FILE = "E:\\MH_NB\\jingbeiqu\\AEP\\MeterLogDatas\\";
// 生产,OC平台,电表,设备数据变化通知
public static final String NB_METER_FILE = "E:\\MH_NB\\jingbeiqu\\MeterLogDatas\\";
// 生产,OC平台和AEP平台,冷水表,设备数据变化通知
public static final String NB_WATER_FILE = "E:\\MH_NB\\jingbeiqu\\WaterLogDatas\\";

66
src/main/java/com/mh/garrison/controller/AepHuaNanWaterController.java

@ -39,72 +39,8 @@ public class AepHuaNanWaterController {
UUid uid = new UUid(); // 生成全球唯一标识 UUid uid = new UUid(); // 生成全球唯一标识
String uidStr = uid.uuid(); String uidStr = uid.uuid();
// FileOutputStream fileOutputStream = null;
// 把报文保存在本地 // 把报文保存在本地
// D:\MH_NB\test\SingleMeterLogDatas File file = new File(Constants.NB_WATER_FILE + formatStr2 + "_" + uidStr + ".txt");
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()) { if (!file.exists()) {
try { try {
file.createNewFile(); file.createNewFile();

69
src/main/java/com/mh/garrison/controller/DeviceController.java

@ -38,70 +38,6 @@ public class DeviceController {
@ResponseBody @ResponseBody
@RequestMapping(value = "/na/iocm/devNotify/v1.1.0/updateDeviceData", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") @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 { 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();
// FileOutputStream fileOutputStream = null;
// 把报文保存在本地
// 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");
// }
// File file = new File("E:\\EEMS_NB\\XT_DBC\\LogDatas\\" + formatStr2 + "_" + uidStr + ".txt");
// File file = new File("E:\\GZ_WATER\\TEST\\LogDatas\\" + formatStr2 + "_" + uidStr + ".txt");
// 创建线程,读取本地报文文件
// 创建线程
// ThreadUtil threadUtil = new ThreadUtil();
// Thread thread = new Thread(threadUtil);
// if (thread.isAlive() == false) {
// thread.start();
// }else {
// System.out.println("线程已启动");
// }
// 将获取的json数据封装一层,然后在给返回
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("msg", "ok"); result.put("msg", "ok");
@ -135,9 +71,10 @@ public class DeviceController {
File file = null; File file = null;
if (length > 500) { if (length > 500) {
System.out.println("保存水表记录值"); System.out.println("保存水表记录值");
file = new File("E:\\MH_NB\\jingbeiqu\\WaterLogDatas\\" + formatStr2 + "_" + uidStr + ".txt"); file = new File(Constants.NB_WATER_FILE + formatStr2 + "_" + uidStr + ".txt");
} else { } else {
file = new File("E:\\MH_NB\\jingbeiqu\\MeterLogDatas\\" + formatStr2 + "_" + uidStr + ".txt"); System.out.println("保存电表记录值");
file = new File(Constants.NB_METER_FILE + formatStr2 + "_" + uidStr + ".txt");
} }
// File file = new File("D:\\NB_Project\\xiamenshuangqiao\\MeterDataLogs\\" + formatStr2 + "_" + uidStr + ".txt"); // File file = new File("D:\\NB_Project\\xiamenshuangqiao\\MeterDataLogs\\" + formatStr2 + "_" + uidStr + ".txt");
assert file != null; assert file != null;

3
src/main/java/com/mh/garrison/job/DealMeterLogJob.java

@ -5,6 +5,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import com.mh.garrison.constant.Constants;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -24,7 +25,7 @@ public class DealMeterLogJob {
// @Scheduled(cron = "0 0/30 * * * ? *") // @Scheduled(cron = "0 0/30 * * * ? *")
@Scheduled(cron = "0/30 * * * * ? ") @Scheduled(cron = "0/30 * * * * ? ")
public void dealMeterLogJob() { public void dealMeterLogJob() {
String filePath = "E:\\MH_NB\\jingbeiqu\\MeterLogDatas\\"; String filePath = Constants.NB_METER_FILE;
GetTxts(filePath); GetTxts(filePath);
} }

3
src/main/java/com/mh/garrison/job/DealWaterLogJob.java

@ -5,6 +5,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import com.mh.garrison.constant.Constants;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -25,7 +26,7 @@ public class DealWaterLogJob {
@Scheduled(cron = "0 0/30 * * * ? ") @Scheduled(cron = "0 0/30 * * * ? ")
// @Scheduled(cron = "0 0/1 * * * ? ") // @Scheduled(cron = "0 0/1 * * * ? ")
public void dealMeterLogJob() { public void dealMeterLogJob() {
String filePath = "E:\\MH_NB\\jingbeiqu\\WaterLogDatas\\"; String filePath = Constants.NB_WATER_FILE;
GetTxts1(filePath); GetTxts1(filePath);
} }

7
src/main/resources/application.yml

@ -4,12 +4,7 @@ spring:
name: druidDataSource name: druidDataSource
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
druid: 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://134.175.248.88:2008;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 url: jdbc:sqlserver://172.16.16.7:2008;DatabaseName=yjc_jingbeiqu
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

Loading…
Cancel
Save