|
@@ -1,19 +1,27 @@
|
|
|
package com.warewms.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.jfinal.plugin.activerecord.Db;
|
|
|
+import com.jfinal.plugin.activerecord.Record;
|
|
|
import com.warewms.common.utils.HeXunResponse;
|
|
|
import com.warewms.common.utils.HttpRequest;
|
|
|
import com.warewms.common.utils.JsonUtils;
|
|
|
+import com.warewms.common.utils.RecordUtils;
|
|
|
+import com.warewms.datasources.DataSourceNames;
|
|
|
+import com.warewms.datasources.annotation.DataSource;
|
|
|
import com.warewms.model.HeXunAlarmData;
|
|
|
import com.warewms.model.MachAlarmRecords;
|
|
|
+import com.warewms.model.RtDevice;
|
|
|
+import com.warewms.model.RtRobotInfo;
|
|
|
import com.warewms.service.HeXunDataService;
|
|
|
-import com.warewms.service.MachAlarmRecordsService;
|
|
|
+import com.warewms.utils.Constant;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
* PackageName:com.warewms.service.impl
|
|
@@ -25,19 +33,16 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class HeXunDataServiceImpl implements HeXunDataService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private MachAlarmRecordsService machAlarmRecordsService;
|
|
|
-
|
|
|
@Override
|
|
|
public void uploadAlarmData() {
|
|
|
|
|
|
MachAlarmRecords queryRecord = new MachAlarmRecords();
|
|
|
- queryRecord.setUploadFlag("0");
|
|
|
- List<MachAlarmRecords> machAlarmRecordsList = machAlarmRecordsService.findByModel(queryRecord);
|
|
|
+ List<MachAlarmRecords> machAlarmRecordsList = queryRecord.find("select * from warewms_message.mach_alarm_records where upload_flag = 0 order by alarm_id asc");
|
|
|
for (MachAlarmRecords machAlarmRecords : machAlarmRecordsList) {
|
|
|
|
|
|
HeXunAlarmData heXunAlarmData = new HeXunAlarmData();
|
|
|
- heXunAlarmData.setPrivate_key("E46C9E1EB7");
|
|
|
+ heXunAlarmData.setAlarmId(machAlarmRecords.getAlarmId().toString());
|
|
|
+ heXunAlarmData.setPrivate_key(Constant.HEXUN_PRIVATE_KEY);
|
|
|
heXunAlarmData.setRobotCode(machAlarmRecords.getMachNo());
|
|
|
heXunAlarmData.setMapOrientation(machAlarmRecords.getAlarmMark());
|
|
|
heXunAlarmData.setXCoord(machAlarmRecords.getXCoordinate());
|
|
@@ -53,16 +58,116 @@ public class HeXunDataServiceImpl implements HeXunDataService {
|
|
|
|
|
|
try {
|
|
|
|
|
|
+ log.info("Json:" + JsonUtils.toJson(heXunAlarmData));
|
|
|
String response = HttpRequest.postData("http://hxetm.com:20974/Interface_JCHGJT/info/addAlarm.do", JsonUtils.toJson(heXunAlarmData));
|
|
|
-
|
|
|
- HeXunResponse heXunResponse = (HeXunResponse) JSONObject.parse(response);
|
|
|
+ log.info("http response:" + response);
|
|
|
+ HeXunResponse heXunResponse = JSONObject.parseObject(response, HeXunResponse.class);
|
|
|
if ("200".equals(heXunResponse.getCode())) {
|
|
|
|
|
|
machAlarmRecords.setUploadFlag("1");
|
|
|
machAlarmRecords.setUploadTime(new Date());
|
|
|
machAlarmRecords.update();
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DataSource(name = DataSourceNames.FOURTH)
|
|
|
+ public void uploadRobotOneData() {
|
|
|
+
|
|
|
+ List<Record> recordList = Db.find("select * from x521_1.rt_robot_info");
|
|
|
+ List<RtRobotInfo> firstRobotInfoList = RecordUtils.converModel(recordList, RtRobotInfo.class);
|
|
|
+ uploadRobotData(firstRobotInfoList, "1", "1号机器人", "x521_1");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DataSource(name = DataSourceNames.THIRD)
|
|
|
+ public void uploadRobotTwoData() {
|
|
|
+
|
|
|
+ List<Record> recordList = Db.find("select * from x521_2.rt_robot_info");
|
|
|
+ List<RtRobotInfo> firstRobotInfoList = RecordUtils.converModel(recordList, RtRobotInfo.class);
|
|
|
+ uploadRobotData(firstRobotInfoList, "2", "2号机器人", "x521_2");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 上传设备信息
|
|
|
+ */
|
|
|
+ private void uploadRobotData(List<RtRobotInfo> robotInfos, String deviceId, String deviceName, String deviceCode) {
|
|
|
+
|
|
|
+ for (RtRobotInfo robotInfo : robotInfos) {
|
|
|
+
|
|
|
+ Map<String, String> parameters = new HashMap<>();
|
|
|
+ parameters.put("private_key", Constant.HEXUN_PRIVATE_KEY);
|
|
|
+ parameters.put("deviceId", deviceId);
|
|
|
+ parameters.put("deviceName", deviceName);
|
|
|
+ parameters.put("deviceCode", deviceCode);
|
|
|
+ parameters.put("deviceAddress", "N/A");
|
|
|
+ parameters.put("devicePath", "N/A");
|
|
|
+ parameters.put("parentId", "N/A");
|
|
|
+ parameters.put("siteAddress", robotInfo.getRtX() + "," + robotInfo.getRtY());
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ log.info("Json:" + JsonUtils.toJson(parameters));
|
|
|
+ String response = HttpRequest.postData("http://hxetm.com:20974/Interface_JCHGJT/info/addDevice.do", JsonUtils.toJson(parameters));
|
|
|
+ log.info("http response:" + response);
|
|
|
+ HeXunResponse heXunResponse = JSONObject.parseObject(response, HeXunResponse.class);
|
|
|
+ if ("200".equals(heXunResponse.getCode())) {
|
|
|
+
|
|
|
+ log.info("设备信息上传成功-----------------" + deviceName);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DataSource(name = DataSourceNames.FOURTH)
|
|
|
+ public void uploadPointOneData() {
|
|
|
+
|
|
|
+ List<Record> recordList = Db.find("select * from x521_1.rt_device");
|
|
|
+ List<RtDevice> deviceList = RecordUtils.converModel(recordList, RtDevice.class);
|
|
|
+ uploadPointData(deviceList, "x521_1");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DataSource(name = DataSourceNames.THIRD)
|
|
|
+ public void uploadPointTwoData() {
|
|
|
+
|
|
|
+ List<Record> recordList = Db.find("select * from x521_2.rt_device");
|
|
|
+ List<RtDevice> deviceList = RecordUtils.converModel(recordList, RtDevice.class);
|
|
|
+ uploadPointData(deviceList, "x521_2");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 上传检测点信息
|
|
|
+ */
|
|
|
+ private void uploadPointData(List<RtDevice> rtDevices, String deviceCode) {
|
|
|
+
|
|
|
+ for (RtDevice device : rtDevices) {
|
|
|
+
|
|
|
+ Map<String, String> parameters = new HashMap<>();
|
|
|
+ parameters.put("private_key", Constant.HEXUN_PRIVATE_KEY);
|
|
|
+ parameters.put("checkPointName", device.getDeviceName());
|
|
|
+ parameters.put("checkPointCode", device.getDeviceTag().toString());
|
|
|
+ parameters.put("deviceCode", device.getPointTag().toString());
|
|
|
+ parameters.put("checkPointStandard", device.getDeviceLower().toString() + "~" + device.getDeviceUper().toString());
|
|
|
+ parameters.put("checkPointUnit", device.getDeviceUnit());
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ log.info("Json:" + JsonUtils.toJson(parameters));
|
|
|
+ String response = HttpRequest.postData("http://hxetm.com:20974/Interface_JCHGJT/info/addCheckPoint.do", JsonUtils.toJson(parameters));
|
|
|
log.info("http response:" + response);
|
|
|
+ HeXunResponse heXunResponse = JSONObject.parseObject(response, HeXunResponse.class);
|
|
|
+ if ("200".equals(heXunResponse.getCode())) {
|
|
|
+
|
|
|
+ log.info(deviceCode + "编号设备,检测点上传成功-----------------" + device.getDeviceName());
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|