|
@@ -24,6 +24,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
import org.springframework.data.mongodb.core.query.Update;
|
|
|
import org.springframework.data.mongodb.core.query.UpdateDefinition;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -74,7 +75,8 @@ public class LeanModelStatistics {
|
|
|
* 精益模型统计数据
|
|
|
* 执行完后,间隔1秒继续执行
|
|
|
*/
|
|
|
- @Scheduled(fixedDelay = 1000 * 60)
|
|
|
+
|
|
|
+ @Scheduled(fixedDelay = 2000 * 60)
|
|
|
public void t1(){
|
|
|
leanModel();
|
|
|
}
|
|
@@ -83,6 +85,7 @@ public class LeanModelStatistics {
|
|
|
* 变更占比
|
|
|
* 0 0 03 * * * 每日3点执行 测试期间1ms一次
|
|
|
*/
|
|
|
+ @Async
|
|
|
@Scheduled(cron = "0 0 03 * * *")
|
|
|
// @Scheduled(fixedDelay = 1000)
|
|
|
public void t2(){
|
|
@@ -92,6 +95,7 @@ public class LeanModelStatistics {
|
|
|
/**
|
|
|
* 设备启停统计数据
|
|
|
*/
|
|
|
+
|
|
|
@Scheduled(fixedDelay = 1000 * 60)
|
|
|
public void t3(){
|
|
|
deviceStatistics();
|
|
@@ -151,51 +155,29 @@ public class LeanModelStatistics {
|
|
|
// 尖峰平谷时段配置
|
|
|
List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
|
|
|
BigDecimal zb = new BigDecimal("100");
|
|
|
+ // 系统变量查询
|
|
|
+ QueryWrapper<SystemVariable> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("variable_address", "sys_run_current_limit");
|
|
|
+ queryWrapper.eq("status", 0);
|
|
|
+ SystemVariable systemVariable = systemVariableService.getOne(queryWrapper);
|
|
|
//遍历设备集合
|
|
|
deviceInformationllist.forEach(deviceInformationlinfo -> {
|
|
|
// 查询设备对应数据
|
|
|
LambdaQueryWrapper<FpgGatherData> fpgGatherQuery = new LambdaQueryWrapper<FpgGatherData>().isNull(FpgGatherData::getFpgTotalUpdatetime).eq(FpgGatherData::getDeviceInformationId, deviceInformationlinfo.getId()).isNotNull(FpgGatherData::getRunCurrent).isNotNull(FpgGatherData::getActivePower).orderByAsc(FpgGatherData::getCreateTime).last("limit 1000");
|
|
|
List<FpgGatherData> fpgGatherList = fpgGatherDataService.list(fpgGatherQuery);
|
|
|
- // 系统变量查询
|
|
|
- QueryWrapper<SystemVariable> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("variable_address", "sys_run_current_limit");
|
|
|
- queryWrapper.eq("status", 0);
|
|
|
- SystemVariable systemVariable = systemVariableService.getOne(queryWrapper);
|
|
|
-
|
|
|
- LambdaQueryWrapper<FpgGatherData> dataLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- dataLambdaQueryWrapper.eq(FpgGatherData::getDeviceInformationId,deviceInformationlinfo.getId());
|
|
|
- dataLambdaQueryWrapper.orderByDesc(FpgGatherData::getCreateTime).last("LIMIT 1");
|
|
|
- List<FpgGatherData> list = fpgGatherDataService.list(dataLambdaQueryWrapper);
|
|
|
-
|
|
|
- if (!list.isEmpty()) {
|
|
|
- FpgGatherData latestRecord = list.get(0);
|
|
|
- // 使用 latestRecord
|
|
|
- DeviceInformation deviceInformation = deviceInformationService.getOne(
|
|
|
- new LambdaQueryWrapper<DeviceInformation>()
|
|
|
- .eq(DeviceInformation::getId, latestRecord.getDeviceInformationId())
|
|
|
- );
|
|
|
- // 比较大小
|
|
|
- int result = compareStringWithBigDecimal(systemVariable.getDefaultValue(), latestRecord.getRunCurrent());
|
|
|
- if (result > 0) {
|
|
|
- if (!"1".equals(deviceInformation.getStatus())) { // 只有状态变更时记录日志
|
|
|
- deviceOperationLogService.logDeviceOperation(deviceInformation.getDeviceTitle(), "启动", latestRecord.getCreateTime());
|
|
|
- }
|
|
|
- deviceInformation.setStatus("1");
|
|
|
- } else if (result < 0) {
|
|
|
-
|
|
|
- if (!"0".equals(deviceInformation.getStatus())) { // 只有状态变更时记录日志
|
|
|
- deviceOperationLogService.logDeviceOperation(deviceInformation.getDeviceTitle(), "停止", latestRecord.getCreateTime());
|
|
|
- }
|
|
|
- deviceInformation.setStatus("0");
|
|
|
- }
|
|
|
- // 只有在 systemVariable 不为空时才进行更新操作
|
|
|
- deviceInformationService.updateById(deviceInformation);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
// 处理数据业务逻辑
|
|
|
fpgGatherList.forEach(fpgGatherData -> { // 循环处理采集数据处理
|
|
|
try {
|
|
|
+ // 设备状态变更 启停日志
|
|
|
+ int result = compareStringWithBigDecimal(systemVariable.getDefaultValue(), fpgGatherData.getRunCurrent()); // > 0 启动, < 0 停止
|
|
|
+ String deviceStatus = result > 0 ? "1" : "0"; // 1:停止 0:正常
|
|
|
+ if (!deviceStatus.equals(deviceInformationlinfo.getStatus())) { // 状态变更处理
|
|
|
+ deviceOperationLogService.logDeviceOperation(deviceInformationlinfo.getDeviceTitle()+" ", result > 0 ? "启动" : "停止", fpgGatherData.getCreateTime());
|
|
|
+ // 变更状态
|
|
|
+ deviceInformationlinfo.setStatus(deviceStatus);
|
|
|
+ deviceInformationlinfo.setId(deviceInformationlinfo.getId());
|
|
|
+ deviceInformationService.updateById(deviceInformationlinfo);
|
|
|
+ }
|
|
|
fpgGatherData.setFpgTotalUpdatetime(new Date());
|
|
|
// 采集时间
|
|
|
Instant instant = fpgGatherData.getCreateTime().toInstant();
|
|
@@ -508,15 +490,23 @@ public class LeanModelStatistics {
|
|
|
});
|
|
|
// 组合mongodb条件
|
|
|
Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("devicePointId").is(fpgGatherData.getDevicePointId()))
|
|
|
- .addCriteria(Criteria.where("dates").is(dayDate))
|
|
|
- .addCriteria(Criteria.where("datestr").is(finalDatestr));
|
|
|
- if(fpgGatherData.getDeviceRegionId() != null && !fpgGatherData.getDeviceRegionId().isEmpty()){ // 区域特殊处理
|
|
|
- query.addCriteria(Criteria.where("deviceRegionId").is(fpgGatherData.getDeviceRegionId()));
|
|
|
- }
|
|
|
- if(fpgGatherData.getDeviceInformationId() != null && !fpgGatherData.getDeviceInformationId().isEmpty()){ // 设备特殊处理
|
|
|
- query.addCriteria(Criteria.where("deviceInformationId").is(fpgGatherData.getDeviceInformationId()));
|
|
|
+ // 是否已区域为维度
|
|
|
+ if(fpgLeanModeInfo.getDeviceRegionStatus() == 1){
|
|
|
+ query.addCriteria(Criteria.where("deviceRegionId").is(fpgGatherData.getDeviceRegionId()))
|
|
|
+ .addCriteria(Criteria.where("dates").is(dayDate))
|
|
|
+ .addCriteria(Criteria.where("datestr").is(finalDatestr));
|
|
|
+ }else{
|
|
|
+ query.addCriteria(Criteria.where("devicePointId").is(fpgGatherData.getDevicePointId()))
|
|
|
+ .addCriteria(Criteria.where("dates").is(dayDate))
|
|
|
+ .addCriteria(Criteria.where("datestr").is(finalDatestr));
|
|
|
+ if(fpgGatherData.getDeviceRegionId() != null && !fpgGatherData.getDeviceRegionId().isEmpty()){ // 区域特殊处理
|
|
|
+ query.addCriteria(Criteria.where("deviceRegionId").is(fpgGatherData.getDeviceRegionId()));
|
|
|
+ }
|
|
|
+ if(fpgGatherData.getDeviceInformationId() != null && !fpgGatherData.getDeviceInformationId().isEmpty()){ // 设备特殊处理
|
|
|
+ query.addCriteria(Criteria.where("deviceInformationId").is(fpgGatherData.getDeviceInformationId()));
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if(!classs.isEmpty()){ // 增加班次条件
|
|
|
query.addCriteria(Criteria.where("classs").is(classs));
|
|
|
}
|
|
@@ -530,7 +520,6 @@ public class LeanModelStatistics {
|
|
|
} else {
|
|
|
collectionName = "leanmodel_" + leanModelCode;
|
|
|
}
|
|
|
-
|
|
|
FpgStatiscsModelMongodb fpgStatiscsModelMongo = mongoTemplate.findOne(query, FpgStatiscsModelMongodb.class, collectionName);
|
|
|
// 功率 5 分钟上报一次 除以 12
|
|
|
BigDecimal activePower = fpgGatherData.getActivePower().compareTo(new BigDecimal("0.00")) > 0 ? fpgGatherData.getActivePower().divide(new BigDecimal("12"), 8, RoundingMode.HALF_UP) : new BigDecimal("0.00");
|