|
@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.aliyun.oss.common.utils.StringUtils;
|
|
|
import com.imcs.admin.db.service.JdbcService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -42,7 +43,7 @@ public class DeviceCollectionTaskJob {
|
|
|
* 设备采集任务FANUC
|
|
|
* FANUC
|
|
|
*/
|
|
|
- @Scheduled(cron = "0/5 * * * * *")
|
|
|
+ @Scheduled(cron = "0/10 * * * * *")
|
|
|
void deviceCollectionTaskFanuc() throws Exception {
|
|
|
Object fanucObj = this.redisGet("FANUC_COLLECTION");
|
|
|
this.executorHandle(fanucObj);
|
|
@@ -52,7 +53,7 @@ public class DeviceCollectionTaskJob {
|
|
|
* 设备采集任务Opcua
|
|
|
* 西门子
|
|
|
*/
|
|
|
- @Scheduled(cron = "0/5 * * * * *")
|
|
|
+ @Scheduled(cron = "0/10 * * * * *")
|
|
|
void deviceCollectionTaskOpcua() throws Exception {
|
|
|
Object opcuaObj = this.redisGet("OPCUA_COLLECTION");
|
|
|
this.executorHandle(opcuaObj);
|
|
@@ -62,7 +63,7 @@ public class DeviceCollectionTaskJob {
|
|
|
* 设备采集任务Heidenhain
|
|
|
* 海德汉
|
|
|
*/
|
|
|
- @Scheduled(cron = "0/5 * * * * *")
|
|
|
+ @Scheduled(cron = "0/10 * * * * *")
|
|
|
void deviceCollectionTaskHeidenhain() throws Exception {
|
|
|
Object heidenhainObj = this.redisGet("HEIDENHAIN_COLLECTION");
|
|
|
this.executorHandle(heidenhainObj);
|
|
@@ -72,7 +73,7 @@ public class DeviceCollectionTaskJob {
|
|
|
* 设备采集任务Mitsubishi
|
|
|
* 三菱
|
|
|
*/
|
|
|
- @Scheduled(cron = "0/5 * * * * *")
|
|
|
+ @Scheduled(cron = "0/10 * * * * *")
|
|
|
void deviceCollectionTaskMitsubishi() throws Exception {
|
|
|
Object mitsubishiObj = this.redisGet("MITSUBISHI_COLLECTION");
|
|
|
this.executorHandle(mitsubishiObj);
|
|
@@ -82,12 +83,12 @@ public class DeviceCollectionTaskJob {
|
|
|
* 设备采集任务MtConnect
|
|
|
* 赫克
|
|
|
*/
|
|
|
- @Scheduled(cron = "0/5 * * * * *")
|
|
|
+ /*@Scheduled(cron = "0/10 * * * * *")
|
|
|
void deviceCollectionTaskMtConnect() throws Exception {
|
|
|
Object mtConnectObj = this.redisGet("MTCONNECT_COLLECTION");
|
|
|
this.executorHandle(mtConnectObj);
|
|
|
}
|
|
|
-
|
|
|
+*/
|
|
|
/**
|
|
|
* 多线程处理
|
|
|
*/
|
|
@@ -103,10 +104,14 @@ public class DeviceCollectionTaskJob {
|
|
|
if(returnInfo !=null){
|
|
|
JSONObject returnJson = JSONUtil.parseObj(returnInfo);
|
|
|
if((boolean)returnJson.get("result")){
|
|
|
- this.saveOrUpdateDeviceCollection(returnJson,map.get("serverUrl"));
|
|
|
- this.saveOrUpdateDeviceCollectionDetail(returnJson,map.get("serverUrl"));
|
|
|
+ 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,map.get("serverUrl"));
|
|
|
+ this.deviceCollectionInfoWriteFile(returnJson,ip);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -124,10 +129,18 @@ public class DeviceCollectionTaskJob {
|
|
|
* @param returnJson
|
|
|
* @param ip
|
|
|
*/
|
|
|
- public void saveOrUpdateDeviceCollection(JSONObject returnJson,Object ip){
|
|
|
+ public void saveOrUpdateDeviceCollection(JSONObject returnJson,Object ip,String deviceType){
|
|
|
//组装参数,更新设备采集表
|
|
|
+ Object mainProg = returnJson.get("mainProg");
|
|
|
JSONObject deviceInfo = new JSONObject();
|
|
|
- deviceInfo.putOnce("mainProg",returnJson.get("mainProg"));
|
|
|
+ if("Opcua".equals(deviceType) && !Objects.isNull(mainProg)){
|
|
|
+ if(mainProg.toString().contains("/")){
|
|
|
+ String[] split = mainProg.toString().split("/");
|
|
|
+ mainProg = split[split.length - 1];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ deviceInfo.putOnce("mainProg",mainProg);
|
|
|
deviceInfo.putOnce("actFeed",returnJson.get("actFeed"));
|
|
|
deviceInfo.putOnce("spindleMagnification",returnJson.get("spindleMagnification"));
|
|
|
deviceInfo.putOnce("actSpindle",returnJson.get("actSpindle"));
|
|
@@ -251,7 +264,7 @@ public class DeviceCollectionTaskJob {
|
|
|
list.add(map);
|
|
|
detailInfo = JSONUtil.toJsonStr(list);
|
|
|
long todayEarliestPowerOnTime = 0;
|
|
|
- if(!Objects.isNull(powerOnTime.toString())){
|
|
|
+ if(!Objects.isNull(powerOnTime) && !StringUtils.isNullOrEmpty(powerOnTime.toString()) && !"null".equals(powerOnTime.toString())){
|
|
|
todayEarliestPowerOnTime = Long.parseLong(powerOnTime.toString());
|
|
|
}
|
|
|
String sql = "insert into device_collection_detail (device_rate,today_earliest_power_on_time,detail_info,create_date,device_ip) values(?,?,?,?,?) ";
|
|
@@ -322,12 +335,12 @@ public class DeviceCollectionTaskJob {
|
|
|
String url = "http://localhost:9000/DeviceApi";
|
|
|
String returnInfo = null;
|
|
|
try{
|
|
|
- // returnInfo = restTemplate.postForObject(url, formEntity, String.class);
|
|
|
+ returnInfo = restTemplate.postForObject(url, formEntity, String.class);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
log.info("连接报错,参数:{}",data);
|
|
|
}
|
|
|
- returnInfo = "{" +
|
|
|
+ /*returnInfo = "{" +
|
|
|
"code:0," +
|
|
|
"result:true," +
|
|
|
"msg:调用成功," +
|
|
@@ -338,7 +351,7 @@ public class DeviceCollectionTaskJob {
|
|
|
"actSpindle:1," +
|
|
|
"powerOnTime:26947355," +
|
|
|
"deviceState:不在线" +
|
|
|
- "}";
|
|
|
+ "}";*/
|
|
|
log.info("返回值:{}",returnInfo);
|
|
|
return returnInfo;
|
|
|
}
|