|
@@ -1,8 +1,10 @@
|
|
|
package com.imcs.admin.common.collection;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUnit;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.lang.Snowflake;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
@@ -39,6 +41,18 @@ public class DeviceCollectionTaskJob {
|
|
|
@Autowired
|
|
|
private JdbcService jdbcService;
|
|
|
|
|
|
+ private static Snowflake snowflake = new Snowflake(1, 1, true);
|
|
|
+
|
|
|
+ /*
|
|
|
+ {
|
|
|
+ "mainProg": "",//主程序号
|
|
|
+ "actFeed": "", //进给速度
|
|
|
+ "spindleMagnification": "", //主轴倍率
|
|
|
+ "actSpindle": "", //主轴转速
|
|
|
+ "powerOnTime": "", //开机时长
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
/**
|
|
|
* 设备采集任务FANUC
|
|
|
* FANUC
|
|
@@ -163,6 +177,8 @@ public class DeviceCollectionTaskJob {
|
|
|
* @param ip
|
|
|
*/
|
|
|
public void saveOrUpdateDeviceCollection(JSONObject returnJson,Object ip,String deviceType){
|
|
|
+ Map<String, Object> device = jdbcService.findOne("select * from a_device where ip = ? ", ip);
|
|
|
+
|
|
|
//组装参数,更新设备采集表
|
|
|
Object mainProg = returnJson.get("mainProg");
|
|
|
JSONObject deviceInfo = new JSONObject();
|
|
@@ -185,7 +201,7 @@ public class DeviceCollectionTaskJob {
|
|
|
Object actSpindle = deviceInfo.get("actSpindle");
|
|
|
if(actFeed!=null || actSpindle !=null) {
|
|
|
if(("0".equals(actFeed.toString()) || "NAN".equals(actFeed.toString()) || "null".equals(actFeed.toString()))
|
|
|
- && ("0".equals(actSpindle.toString()) || "NAN".equals(actSpindle.toString()) || "null".equals(actSpindle.toString()))){
|
|
|
+ || ("0".equals(actSpindle.toString()) || "NAN".equals(actSpindle.toString()) || "null".equals(actSpindle.toString()))){
|
|
|
deviceInfo.putOnce("deviceWorkState","空闲");
|
|
|
}else{
|
|
|
deviceInfo.putOnce("deviceWorkState","加工");
|
|
@@ -194,6 +210,8 @@ public class DeviceCollectionTaskJob {
|
|
|
deviceInfo.putOnce("deviceWorkState","空闲");
|
|
|
}
|
|
|
|
|
|
+ saveOrUpdateDeviceReportInfo(device.get("id"),deviceInfo.get("deviceWorkState").toString());
|
|
|
+
|
|
|
Map<String, Object> deviceCollection = jdbcService.findOne("select * from device_collection where ip = ? ", ip);
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(deviceCollection)){
|
|
@@ -202,7 +220,6 @@ public class DeviceCollectionTaskJob {
|
|
|
jdbcService.update("更新",sql,deviceInfo.toString(), DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"),deviceCollection.get("id"));
|
|
|
}else{
|
|
|
//新增
|
|
|
- Map<String, Object> device = jdbcService.findOne("select * from a_device where ip = ? ", ip);
|
|
|
if(CollectionUtil.isNotEmpty(device)){
|
|
|
Object deviceId = device.get("id");
|
|
|
String sql = "insert into device_collection (device_id,device_info,ip) values(?,?,?) ";
|
|
@@ -220,7 +237,7 @@ public class DeviceCollectionTaskJob {
|
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
map.put("mainProg",returnJson.get("mainProg"));
|
|
|
- map.put("actFeed",returnJson.get("actFeed"));
|
|
|
+ map.put("actFeed",returnJson.get("actFeed")); //主轴ijn
|
|
|
map.put("spindleMagnification",returnJson.get("spindleMagnification"));
|
|
|
map.put("actSpindle",returnJson.get("actSpindle"));
|
|
|
map.put("powerOnTime",returnJson.get("powerOnTime"));
|
|
@@ -300,11 +317,13 @@ public class DeviceCollectionTaskJob {
|
|
|
//当日设备开机时长 = 当日设备开机时长 + 间隔时间
|
|
|
todayPowerOnTime = todayPowerOnTime.add(intervalTime);
|
|
|
|
|
|
+
|
|
|
BigDecimal actFeed = Objects.isNull(returnJson.get("actFeed")) ? BigDecimal.ZERO : new BigDecimal(returnJson.get("actFeed").toString());
|
|
|
BigDecimal actSpindle = Objects.isNull(returnJson.get("actSpindle")) ? BigDecimal.ZERO : new BigDecimal(returnJson.get("actSpindle").toString());
|
|
|
log.info("actFeed:{},actSpindle:{},intervalTime:{}",
|
|
|
returnJson.get("actFeed"),returnJson.get("actSpindle"),intervalTime);
|
|
|
- if(actFeed.compareTo(BigDecimal.ZERO) > 0 || actSpindle.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ //进给速度和主轴转速同时>0 才是工作中
|
|
|
+ if(actFeed.compareTo(BigDecimal.ZERO) > 0 && actSpindle.compareTo(BigDecimal.ZERO) > 0){
|
|
|
todayWorkTime = todayWorkTime.add(intervalTime);
|
|
|
}
|
|
|
}
|
|
@@ -346,6 +365,40 @@ public class DeviceCollectionTaskJob {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void saveOrUpdateDeviceReportInfo(Object deviceId,String deviceWorkState){
|
|
|
+
|
|
|
+ Map<String, Object> deviceReport = jdbcService.findOne("select * from device_report where device_id = ? order by create_time desc LIMIT 1 ", deviceId);
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ if(CollectionUtil.isNotEmpty(deviceReport)){
|
|
|
+ //判断当前设备状态和表中存的数据状态是否一致
|
|
|
+ String hisDeviceWorkState = deviceReport.get("deviceState").toString();
|
|
|
+
|
|
|
+ if(!hisDeviceWorkState.equals(deviceWorkState)){
|
|
|
+ //不一致,状态变更
|
|
|
+
|
|
|
+
|
|
|
+ String startTimeStr = deviceReport.get("startTime").toString().replace("T"," ");
|
|
|
+ DateTime startTime = DateUtil.parse(startTimeStr, "yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ long keepTime = DateUtil.between(startTime, date, DateUnit.MINUTE);
|
|
|
+
|
|
|
+ //更新
|
|
|
+ String updateSql = "update device_report set end_time = ?,keep_time = ? ,create_time = ? where id = ? ";
|
|
|
+ jdbcService.update("更新",updateSql, DateUtil.format(date,"yyyy-MM-dd HH:mm:ss"),keepTime,startTimeStr,deviceReport.get("id"));
|
|
|
+
|
|
|
+ //新增
|
|
|
+ String insertSql = "insert into device_report (id,device_id,start_time,device_state,create_time) values(?,?,?,?,?) ";
|
|
|
+ jdbcService.update(insertSql,snowflake.nextId(), deviceId,DateUtil.format(date,"yyyy-MM-dd HH:mm:ss"),deviceWorkState, DateUtil.format(date,"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //没有数据,新增
|
|
|
+ String insertSql = "insert into device_report (id,device_id,start_time,device_state,create_time) values(?,?,?,?,?) ";
|
|
|
+ jdbcService.update(insertSql,snowflake.nextId(), deviceId,DateUtil.format(date,"yyyy-MM-dd HH:mm:ss"),deviceWorkState, DateUtil.format(date,"yyyy-MM-dd HH:mm:ss"));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void deviceCollectionInfoWriteFile(JSONObject returnJson,Object ip) throws IOException {
|
|
|
Date date = new Date();
|
|
|
String nowDate = DateUtil.format(date, "yyyy-MM-dd");
|