fix:对象选择错误
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package org.nl.b_lms.pdm.error.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.Timestamp;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("device_fault_info")
|
||||
public class DeviceFault implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableField(value = "device_code")
|
||||
private String deviceCode;
|
||||
|
||||
@TableField(value = "device_name")
|
||||
private String deviceName;
|
||||
|
||||
@TableField(value = "error_code")
|
||||
private String errorCode;
|
||||
|
||||
@TableField(value = "error_message")
|
||||
private String errorMessage;
|
||||
|
||||
@TableField(value = "start_time")
|
||||
private String startTime;
|
||||
|
||||
private int duration;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.nl.b_lms.pdm.error.model.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.b_lms.bst.ivt.cutpointivt.service.dao.BstIvtCutpointivt;
|
||||
import org.nl.b_lms.bst.ivt.cutpointivt.service.dto.CutpointAirShhaftDto;
|
||||
import org.nl.b_lms.pdm.error.model.DeviceFault;
|
||||
import org.nl.b_lms.sch.tasks.slitter.mapper.dto.SlitterPlanDistinctDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lyd
|
||||
* @date 2024-02-26
|
||||
**/
|
||||
public interface DeviceFaultMapper extends BaseMapper<DeviceFault> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.b_lms.pdm.error.model.mapper.DeviceFaultMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.nl.b_lms.pdm.error.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.b_lms.pdm.error.model.DeviceFault;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface DeviceFaultService extends IService<DeviceFault> {
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package org.nl.b_lms.pdm.error.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.b_lms.pdm.error.model.DeviceFault;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.nl.wms.basedata.master.service.FaultDeviceService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FaultManager {
|
||||
public final ConcurrentHashMap<String, DeviceFault> memory = new ConcurrentHashMap<>();
|
||||
|
||||
public void add(DeviceFault f) {
|
||||
memory.put(f.getDeviceCode(), f);
|
||||
}
|
||||
|
||||
public static class CompareResult {
|
||||
public final List<DeviceFault> toInsert;
|
||||
public final Set<String> endedKeys;
|
||||
|
||||
public CompareResult(List<DeviceFault> toInsert, Set<String> endedKeys) {
|
||||
this.toInsert = toInsert;
|
||||
this.endedKeys = endedKeys;
|
||||
}
|
||||
}
|
||||
|
||||
public CompareResult compareAndCollectToInsert(long nowMillis, List<DeviceFault> latest) {
|
||||
Set<String> apiKeys = new HashSet<>();
|
||||
for (DeviceFault f : latest) apiKeys.add(f.getDeviceCode());
|
||||
Set<String> memKeys = new HashSet<>(memory.keySet());
|
||||
log.info("内存数据-------"+ memKeys);
|
||||
List<DeviceFault> toInsert = new ArrayList<>();
|
||||
Set<String> ended = new HashSet<>();
|
||||
for (String k : memKeys)
|
||||
if (!apiKeys.contains(k)) {
|
||||
DeviceFault m = memory.get(k);
|
||||
if (m != null) {
|
||||
long sm = parseMillis(m.getStartTime());
|
||||
int durationSec = (int) Math.max(0, (nowMillis - sm) / 1000);
|
||||
m.setDuration(durationSec);
|
||||
toInsert.add(m);
|
||||
ended.add(k);
|
||||
}
|
||||
}
|
||||
for (DeviceFault f : latest)
|
||||
if (!memKeys.contains(f.getDeviceCode())) {
|
||||
f.setStartTime(formatMillis(nowMillis));
|
||||
f.setDuration(0);
|
||||
add(f);
|
||||
}
|
||||
return new CompareResult(toInsert, ended);
|
||||
}
|
||||
|
||||
public void removeAll(Set<String> keys) {
|
||||
if (keys == null || keys.isEmpty()) return;
|
||||
for (String k : keys) memory.remove(k);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
long s = System.nanoTime();
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
//todo 调用ACS获取
|
||||
FaultDeviceService bean = SpringContextHolder.getBean(FaultDeviceService.class);
|
||||
List<DeviceFault> latest = bean.getErrorDeviceInfo(null);
|
||||
log.info("获取数据-------"+latest.toString());
|
||||
CompareResult result = compareAndCollectToInsert(now, latest);
|
||||
List<DeviceFault> toInsert = result.toInsert;
|
||||
log.info("插入数据-------"+toInsert.toString());
|
||||
DeviceFaultService bean1 = SpringContextHolder.getBean(DeviceFaultService.class);
|
||||
bean1.saveBatch(toInsert);
|
||||
|
||||
//插入到数据库当中
|
||||
removeAll(result.endedKeys);
|
||||
} finally {
|
||||
long ms = (System.nanoTime() - s) / 1_000_000;
|
||||
if (ms > 5000) log.warn("process time(ms)=" + ms);
|
||||
}
|
||||
}
|
||||
|
||||
private static long parseMillis(String s) {
|
||||
if (s == null || s.isEmpty() || "0".equals(s)) return 0L;
|
||||
try {
|
||||
LocalDateTime dt = LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
return dt.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
} catch (Exception e) { return 0L; }
|
||||
}
|
||||
|
||||
private static String formatMillis(long ms) {
|
||||
LocalDateTime dt = Instant.ofEpochMilli(ms).atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
return DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(dt);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.nl.b_lms.pdm.error.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.b_lms.pdm.error.model.DeviceFault;
|
||||
import org.nl.b_lms.pdm.error.model.mapper.DeviceFaultMapper;
|
||||
import org.nl.b_lms.pdm.error.service.DeviceFaultService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DeviceFaultServiceImpl extends ServiceImpl<DeviceFaultMapper, DeviceFault> implements DeviceFaultService {
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.nl.b_lms.sch.tasks.first_floor_area.auto;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.b_lms.pdm.error.service.FaultManager;
|
||||
import org.nl.b_lms.sch.tasks.TwoOutBoxTask;
|
||||
import org.nl.b_lms.storage_manage.ios.enums.IOSEnum;
|
||||
import org.nl.b_lms.storage_manage.ios.service.iostorInv.util.service.OutBoxManageService;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.nl.wms.sch.AcsTaskDto;
|
||||
import org.nl.wms.sch.AcsUtil;
|
||||
import org.nl.wms.sch.manage.TaskStatusEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.nl.wms.util.TaskUtil.getRoutePlanCode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AutoSynErrorDevice {
|
||||
|
||||
//自动执行等待的桁架任务
|
||||
public void run() {
|
||||
try {
|
||||
FaultManager bean = SpringContextHolder.getBean(FaultManager.class);
|
||||
bean.tick();
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user