|
|
@@ -29,6 +29,7 @@ import com.usky.rule.service.RuleEngineService;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import javax.annotation.Resource;
|
|
|
@@ -47,6 +48,8 @@ import org.springframework.util.CollectionUtils;
|
|
|
@DisallowConcurrentExecution
|
|
|
@Slf4j
|
|
|
public class ConsumptionJob implements Job {
|
|
|
+
|
|
|
+ private static final DateTimeFormatter CONSUMPTION_TIME_DISPLAY = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
@Resource
|
|
|
private Cache<Long, List<DeviceTrigger>> consumptionTriggerCache;
|
|
|
@Resource
|
|
|
@@ -63,13 +66,14 @@ public class ConsumptionJob implements Job {
|
|
|
}
|
|
|
|
|
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
|
|
- LocalDateTime[] times = new LocalDateTime[2];
|
|
|
+ String[] times = new String[2];
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
for(CacheEntry<Long, List<DeviceTrigger>> entry : this.consumptionTriggerCache.entries()) {
|
|
|
log.info("consumptionTriggerCache: {}, now: {}", entry.getKey(), now);
|
|
|
Long engineId = (Long)entry.getKey();
|
|
|
RuleEngine ruleEngine = (RuleEngine)this.ruleEngineService.getById(engineId);
|
|
|
+ log.info("ruleEngine: {}", ruleEngine);
|
|
|
if (ruleEngine == null || ruleEngine.getStatus() == null || ruleEngine.getStatus() != 1) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -106,14 +110,14 @@ public class ConsumptionJob implements Job {
|
|
|
|
|
|
HistorysInnerRequestVO requestVO = new HistorysInnerRequestVO();
|
|
|
requestVO.setDeviceuuid(Collections.singletonList(device.getDeviceUuid()));
|
|
|
- requestVO.setMetrics(Collections.singletonList(identifier));
|
|
|
- requestVO.setStartTime(times[0].toString());
|
|
|
- requestVO.setEndTime(times[1].toString());
|
|
|
+ requestVO.setMetrics(Collections.singletonList(identifier.toLowerCase()));
|
|
|
+ requestVO.setStartTime(times[0]);
|
|
|
+ requestVO.setEndTime(times[1]);
|
|
|
ApiResult<List<HistorysInnerResultVO>> historyApi = remoteTsdbProxyService.queryHistoryDeviceData(requestVO);
|
|
|
List<HistorysInnerResultVO> result = historyApi != null && historyApi.getData() != null
|
|
|
? historyApi.getData()
|
|
|
: Collections.emptyList();
|
|
|
- List<DataPointVO> dataPointVOList = findDataPointsForMetric(result, device.getDeviceUuid(), identifier);
|
|
|
+ List<DataPointVO> dataPointVOList = findDataPointsForMetric(result, device.getDeviceUuid(), identifier.toLowerCase());
|
|
|
if (dataPointVOList.isEmpty()) {
|
|
|
boolConstraintExp.append(false);
|
|
|
} else {
|
|
|
@@ -162,7 +166,7 @@ public class ConsumptionJob implements Job {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public static void initStartTimeAndEndTime(LocalDateTime now, LocalDateTime[] times, TimeRange timeRange) {
|
|
|
+ public static void initStartTimeAndEndTime(LocalDateTime now, String[] times, TimeRange timeRange) {
|
|
|
Integer start = timeRange.getStart();
|
|
|
Integer end = timeRange.getEnd();
|
|
|
Assert.notNull(start, "start不能为空");
|
|
|
@@ -227,8 +231,9 @@ public class ConsumptionJob implements Job {
|
|
|
throw new IllegalArgumentException("不支持的时间类型: " + typeEnum);
|
|
|
}
|
|
|
|
|
|
- times[0] = startTime;
|
|
|
- times[1] = endTime;
|
|
|
+ times[0] = startTime.format(CONSUMPTION_TIME_DISPLAY);
|
|
|
+ times[1] = endTime.format(CONSUMPTION_TIME_DISPLAY);
|
|
|
+ log.debug("initStartTimeAndEndTime type={} startTime={} endTime={}", typeEnum, times[0], times[1]);
|
|
|
}
|
|
|
|
|
|
public static boolean preAssertFalse(StringBuilder boolConstraintExp, String operator) {
|