|
@@ -45,8 +45,14 @@ public class DeviceCollectionTaskJob {
|
|
*/
|
|
*/
|
|
@Scheduled(cron = "0/10 * * * * *")
|
|
@Scheduled(cron = "0/10 * * * * *")
|
|
void deviceCollectionTaskFanuc() throws Exception {
|
|
void deviceCollectionTaskFanuc() throws Exception {
|
|
- Object fanucObj = this.redisGet("FANUC_COLLECTION");
|
|
|
|
- this.executorHandle(fanucObj);
|
|
|
|
|
|
+ try{
|
|
|
|
+ Object fanucObj = this.redisGet("FANUC_COLLECTION");
|
|
|
|
+ this.executorHandle(fanucObj);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.info("业务处理报错:{}",getMsg(e));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -55,8 +61,14 @@ public class DeviceCollectionTaskJob {
|
|
*/
|
|
*/
|
|
@Scheduled(cron = "0/10 * * * * *")
|
|
@Scheduled(cron = "0/10 * * * * *")
|
|
void deviceCollectionTaskOpcua() throws Exception {
|
|
void deviceCollectionTaskOpcua() throws Exception {
|
|
- Object opcuaObj = this.redisGet("OPCUA_COLLECTION");
|
|
|
|
- this.executorHandle(opcuaObj);
|
|
|
|
|
|
+ try{
|
|
|
|
+ Object opcuaObj = this.redisGet("OPCUA_COLLECTION");
|
|
|
|
+ this.executorHandle(opcuaObj);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.info("业务处理报错:{}",getMsg(e));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -65,8 +77,14 @@ public class DeviceCollectionTaskJob {
|
|
*/
|
|
*/
|
|
@Scheduled(cron = "0/10 * * * * *")
|
|
@Scheduled(cron = "0/10 * * * * *")
|
|
void deviceCollectionTaskHeidenhain() throws Exception {
|
|
void deviceCollectionTaskHeidenhain() throws Exception {
|
|
- Object heidenhainObj = this.redisGet("HEIDENHAIN_COLLECTION");
|
|
|
|
- this.executorHandle(heidenhainObj);
|
|
|
|
|
|
+ try{
|
|
|
|
+ Object heidenhainObj = this.redisGet("HEIDENHAIN_COLLECTION");
|
|
|
|
+ this.executorHandle(heidenhainObj);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.info("业务处理报错:{}",getMsg(e));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -75,8 +93,14 @@ public class DeviceCollectionTaskJob {
|
|
*/
|
|
*/
|
|
@Scheduled(cron = "0/10 * * * * *")
|
|
@Scheduled(cron = "0/10 * * * * *")
|
|
void deviceCollectionTaskMitsubishi() throws Exception {
|
|
void deviceCollectionTaskMitsubishi() throws Exception {
|
|
- Object mitsubishiObj = this.redisGet("MITSUBISHI_COLLECTION");
|
|
|
|
- this.executorHandle(mitsubishiObj);
|
|
|
|
|
|
+ try{
|
|
|
|
+ Object mitsubishiObj = this.redisGet("MITSUBISHI_COLLECTION");
|
|
|
|
+ this.executorHandle(mitsubishiObj);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.info("业务处理报错:{}",getMsg(e));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -85,8 +109,14 @@ public class DeviceCollectionTaskJob {
|
|
*/
|
|
*/
|
|
/*@Scheduled(cron = "0/10 * * * * *")
|
|
/*@Scheduled(cron = "0/10 * * * * *")
|
|
void deviceCollectionTaskMtConnect() throws Exception {
|
|
void deviceCollectionTaskMtConnect() throws Exception {
|
|
- Object mtConnectObj = this.redisGet("MTCONNECT_COLLECTION");
|
|
|
|
- this.executorHandle(mtConnectObj);
|
|
|
|
|
|
+ try{
|
|
|
|
+ Object mtConnectObj = this.redisGet("MTCONNECT_COLLECTION");
|
|
|
|
+ this.executorHandle(mtConnectObj);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.info("业务处理报错:{}",getMsg(e));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
/**
|
|
/**
|
|
@@ -98,27 +128,30 @@ public class DeviceCollectionTaskJob {
|
|
List<Map> list = JSONUtil.toList(jsonArray, Map.class);
|
|
List<Map> list = JSONUtil.toList(jsonArray, Map.class);
|
|
CompletableFuture[] task = list.stream().map(map -> CompletableFuture.runAsync(() -> {
|
|
CompletableFuture[] task = list.stream().map(map -> CompletableFuture.runAsync(() -> {
|
|
map.put("type","Collect");
|
|
map.put("type","Collect");
|
|
- //if("192.168.10.117".equals(map.get("serverUrl").toString())){
|
|
|
|
- String data = JSONUtil.toJsonStr(map);
|
|
|
|
- String returnInfo = this.httpPost(data);
|
|
|
|
- if(returnInfo !=null){
|
|
|
|
- JSONObject returnJson = JSONUtil.parseObj(returnInfo);
|
|
|
|
- if((boolean)returnJson.get("result")){
|
|
|
|
- Object ip = map.get("serverUrl");
|
|
|
|
- if("Opcua".equals(map.get("deviceType").toString())){
|
|
|
|
- ip = map.get("ip");
|
|
|
|
- }
|
|
|
|
- this.saveOrUpdateDeviceCollection(returnJson,ip,map.get("deviceType").toString());
|
|
|
|
- this.saveOrUpdateDeviceCollectionDetail(returnJson,ip);
|
|
|
|
- try {
|
|
|
|
- this.deviceCollectionInfoWriteFile(returnJson,ip);
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //}
|
|
|
|
-
|
|
|
|
|
|
+ //if("192.168.10.106".equals(map.get("serverUrl").toString())) {
|
|
|
|
+
|
|
|
|
+ String data = JSONUtil.toJsonStr(map);
|
|
|
|
+ String returnInfo = this.httpPost(data);
|
|
|
|
+ if (returnInfo != null) {
|
|
|
|
+ JSONObject returnJson = JSONUtil.parseObj(returnInfo);
|
|
|
|
+ if ((boolean) returnJson.get("result")) {
|
|
|
|
+ Object ip = map.get("serverUrl");
|
|
|
|
+ if ("Opcua".equals(map.get("deviceType").toString())) {
|
|
|
|
+ ip = map.get("ip");
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ this.saveOrUpdateDeviceCollection(returnJson, ip, map.get("deviceType").toString());
|
|
|
|
+ this.saveOrUpdateDeviceCollectionDetail(returnJson, ip);
|
|
|
|
+ this.deviceCollectionInfoWriteFile(returnJson, ip);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.info("业务处理报错:{}", getMsg(e));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // }
|
|
})).toArray(CompletableFuture[]::new);
|
|
})).toArray(CompletableFuture[]::new);
|
|
CompletableFuture.allOf(task).join();
|
|
CompletableFuture.allOf(task).join();
|
|
}
|
|
}
|
|
@@ -267,6 +300,10 @@ public class DeviceCollectionTaskJob {
|
|
|
|
|
|
BigDecimal sumBig = new BigDecimal(workhour);
|
|
BigDecimal sumBig = new BigDecimal(workhour);
|
|
deviceRate = todayPowerOnTime.divide(sumBig, 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
|
|
deviceRate = todayPowerOnTime.divide(sumBig, 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
|
|
|
|
+ if(deviceRate.compareTo(new BigDecimal("100")) > 0){
|
|
|
|
+ deviceRate = new BigDecimal("100");
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -350,25 +387,32 @@ public class DeviceCollectionTaskJob {
|
|
String url = "http://localhost:9000/DeviceApi";
|
|
String url = "http://localhost:9000/DeviceApi";
|
|
String returnInfo = null;
|
|
String returnInfo = null;
|
|
try{
|
|
try{
|
|
- returnInfo = restTemplate.postForObject(url, formEntity, String.class);
|
|
|
|
|
|
+ returnInfo = restTemplate.postForObject(url, formEntity, String.class);
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- log.info("连接报错,参数:{}",data);
|
|
|
|
|
|
+ log.info("连接报错:{}",getMsg(e));
|
|
}
|
|
}
|
|
- /*returnInfo = "{" +
|
|
|
|
- "code:0," +
|
|
|
|
- "result:true," +
|
|
|
|
- "msg:调用成功," +
|
|
|
|
- "statusCode:200," +
|
|
|
|
- "mainProg:7777," +
|
|
|
|
- "actFeed:2," +
|
|
|
|
- "spindleMagnification:2," +
|
|
|
|
- "actSpindle:1," +
|
|
|
|
- "powerOnTime:26947355," +
|
|
|
|
- "deviceState:不在线" +
|
|
|
|
- "}";*/
|
|
|
|
|
|
+ //returnInfo = "{\"code\":0,\"result\":false,\"msg\":\"调用失败\",\"statusCode\":200,\"toolsInfo\":null,\"toolsData\":null,\"errorsInfo\":\"\",\"runDatasInfo\":\"\",\"deviceData\":null,\"mainProg\":null,\"actFeed\":null,\"spindleMagnification\":null,\"feedRateOvr\":null,\"actSpindle\":null,\"powerOnTime\":null,\"deviceState\":\"离线\"}";
|
|
log.info("返回值:{}",returnInfo);
|
|
log.info("返回值:{}",returnInfo);
|
|
return returnInfo;
|
|
return returnInfo;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 异常处理
|
|
|
|
+ * @param e
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private static String getMsg(Exception e) {
|
|
|
|
+ StackTraceElement[] stackTrace = e.getStackTrace();
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ sb.append(e.toString()).append("\r\n");
|
|
|
|
+ for (StackTraceElement stackTraceElement : stackTrace) {
|
|
|
|
+ sb.append("\tat ").append(stackTraceElement.getClassName()).append(".")
|
|
|
|
+ .append(stackTraceElement.getMethodName())
|
|
|
|
+ .append("(").append(stackTraceElement.getFileName()).append(":").append(stackTraceElement.getLineNumber())
|
|
|
|
+ .append(")\r\n");
|
|
|
|
+ }
|
|
|
|
+ return sb.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|