|
@@ -15,6 +15,8 @@ import com.baosight.hdsdk.exception.HDSdkException;
|
|
import com.google.common.eventbus.AsyncEventBus;
|
|
import com.google.common.eventbus.AsyncEventBus;
|
|
import com.sckj.common.exception.OperateException;
|
|
import com.sckj.common.exception.OperateException;
|
|
import com.sckj.common.manager.ScheduledTaskManager;
|
|
import com.sckj.common.manager.ScheduledTaskManager;
|
|
|
|
+import com.sckj.common.util.ExcelUtils;
|
|
|
|
+import com.sckj.opc.dto.HDRecordExport;
|
|
import com.sckj.opc.dto.HdTagDTO;
|
|
import com.sckj.opc.dto.HdTagDTO;
|
|
import com.sckj.opc.entity.OPCData;
|
|
import com.sckj.opc.entity.OPCData;
|
|
import com.sckj.opc.entity.OPCServer;
|
|
import com.sckj.opc.entity.OPCServer;
|
|
@@ -27,24 +29,21 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.expression.ExpressionParser;
|
|
import org.springframework.expression.ExpressionParser;
|
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.PreDestroy;
|
|
import javax.annotation.PreDestroy;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.IOException;
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
-import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
-import java.util.concurrent.TimeoutException;
|
|
|
|
-import java.util.concurrent.Executors;
|
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
|
-import java.util.concurrent.Future;
|
|
|
|
|
|
+import java.util.concurrent.*;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -269,7 +268,7 @@ public class HDServiceImpl {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- private void createSubscription(OPCServer opcServer,final THdTag hdTag) {
|
|
|
|
|
|
+ private void createSubscription(OPCServer opcServer, final THdTag hdTag) {
|
|
if (ObjectUtils.isEmpty(opcServer) || ObjectUtils.isEmpty(hdTag)) {
|
|
if (ObjectUtils.isEmpty(opcServer) || ObjectUtils.isEmpty(hdTag)) {
|
|
throw new OperateException("未获取到服务器或标记信息");
|
|
throw new OperateException("未获取到服务器或标记信息");
|
|
}
|
|
}
|
|
@@ -358,7 +357,7 @@ public class HDServiceImpl {
|
|
// 复杂逻辑表达式,使用Spring SpEL
|
|
// 复杂逻辑表达式,使用Spring SpEL
|
|
try {
|
|
try {
|
|
StandardEvaluationContext context = new StandardEvaluationContext();
|
|
StandardEvaluationContext context = new StandardEvaluationContext();
|
|
- context.setVariable("val", data instanceof Number ? ((Number)data).doubleValue() : data);
|
|
|
|
|
|
+ context.setVariable("val", data instanceof Number ? ((Number) data).doubleValue() : data);
|
|
ExpressionParser parser = new SpelExpressionParser();
|
|
ExpressionParser parser = new SpelExpressionParser();
|
|
condValid = parser.parseExpression(cond).getValue(context, Boolean.class);
|
|
condValid = parser.parseExpression(cond).getValue(context, Boolean.class);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -777,9 +776,9 @@ public class HDServiceImpl {
|
|
List<HDRecord> tempRawRecordList = dp.queryTagHisRawRecords(tagID, st, et);
|
|
List<HDRecord> tempRawRecordList = dp.queryTagHisRawRecords(tagID, st, et);
|
|
rawRecordsList.addAll(tempRawRecordList);
|
|
rawRecordsList.addAll(tempRawRecordList);
|
|
// 限制最大返回条数
|
|
// 限制最大返回条数
|
|
- if (rawRecordsList.size() >= MAX_RECORD_COUNT) {
|
|
|
|
- return rawRecordsList.subList(0, MAX_RECORD_COUNT);
|
|
|
|
- }
|
|
|
|
|
|
+// if (rawRecordsList.size() >= MAX_RECORD_COUNT) {
|
|
|
|
+// return rawRecordsList.subList(0, MAX_RECORD_COUNT);
|
|
|
|
+// }
|
|
if (tempRawRecordList.size() == 65535) { // 时间范围内记录条数超出65535,以最后一条记录的timestamp作为endTime继续查询
|
|
if (tempRawRecordList.size() == 65535) { // 时间范围内记录条数超出65535,以最后一条记录的timestamp作为endTime继续查询
|
|
et = dateFormat.parse(rawRecordsList.get(65534).getTimeStampStr());
|
|
et = dateFormat.parse(rawRecordsList.get(65534).getTimeStampStr());
|
|
} else {
|
|
} else {
|
|
@@ -916,6 +915,43 @@ public class HDServiceImpl {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public void exportTagHisRawRecords(int tagID, String startTime, String endTime, HttpServletResponse response) throws IOException {
|
|
|
|
+ THdTag hdTag = new THdTag();
|
|
|
|
+ hdTag.setTagId(tagID);
|
|
|
|
+ HdTagDTO opcPointDTO = hdTagService.selectInfoWithServer(hdTag);
|
|
|
|
+ if (ObjectUtils.isEmpty(opcPointDTO)) {
|
|
|
|
+ throw new OperateException("未查询到数据");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<HDRecordExport> hdRecordExportList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ List<HDRecord> hdRecords = queryTagHisRawRecords(tagID, startTime, endTime);
|
|
|
|
+ if (ObjectUtils.isNotEmpty(hdRecords)) {
|
|
|
|
+ for (HDRecord hdRecord : hdRecords) {
|
|
|
|
+ hdRecordExportList.add(
|
|
|
|
+ HDRecordExport.builder()
|
|
|
|
+ .data(hdRecord.getValueStr())
|
|
|
|
+ .sourceTime(hdRecord.getTimeStampStr())
|
|
|
|
+ .belongTagID(hdRecord.getBelongTagID())
|
|
|
|
+ .build());
|
|
|
|
+ }
|
|
|
|
+ ExcelUtils.exportExcel(hdRecordExportList, HDRecordExport.class, opcPointDTO.getTagName(), sanitizeFileName(opcPointDTO.getTagDesc(), System.getProperty("os.name").toLowerCase().contains("windows")), response);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String sanitizeFileName(String input, boolean isWindows) {
|
|
|
|
+ if (isWindows) {
|
|
|
|
+ // 移除Windows非法字符
|
|
|
|
+ return input.replaceAll("[<>:\"/\\\\|?*]", "");
|
|
|
|
+ } else {
|
|
|
|
+ // 移除Linux非法字符(主要是斜杠)
|
|
|
|
+ return input.replaceAll("/", "");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
// 判断tagName是否已被订阅
|
|
// 判断tagName是否已被订阅
|
|
public boolean isSubscribed(String tagName) {
|
|
public boolean isSubscribed(String tagName) {
|
|
return taskNameSet.contains(tagName);
|
|
return taskNameSet.contains(tagName);
|