|
@@ -6,6 +6,7 @@ import org.jeecg.modules.device.entity.DeviceInformation;
|
|
|
import org.jeecg.modules.device.service.IDeviceInformationService;
|
|
|
import org.jeecg.modules.fpgJob.entity.FpgLeanModel;
|
|
|
import org.jeecg.modules.fpgJob.service.IFpgLeanModelService;
|
|
|
+import org.jeecg.modules.gatherData.entity.DeviceStatiscsModelData;
|
|
|
import org.jeecg.modules.gatherData.entity.FpgGatherData;
|
|
|
import org.jeecg.modules.gatherData.entity.FpgStatiscsModelData;
|
|
|
import org.jeecg.modules.gatherData.entity.FpgStatiscsModelMongodb;
|
|
@@ -113,19 +114,76 @@ public class LeanModelStatistics {
|
|
|
// 设备启停统计数据
|
|
|
public void startStop(String freq) {
|
|
|
log.info("设备启停");
|
|
|
+ // 获取当前时间
|
|
|
+ Date curentDate = new Date(new Date().getTime() + 8 * 60 * 60 * 1000);
|
|
|
// 峰平谷精益模型配置获取
|
|
|
-// LambdaQueryWrapper<DeviceInformation> leanmodelQuery = new LambdaQueryWrapper<DeviceInformation>().eq(DeviceInformation::getDeviceCode, "");
|
|
|
-// List<DeviceInformation> deviceInformationllist = deviceInformationService.list(leanmodelQuery);
|
|
|
-// //遍历设备集合
|
|
|
-// deviceInformationllist.forEach(deviceInformationlinfo -> {
|
|
|
-// LambdaQueryWrapper<FpgGatherData> fpgGatherQuery = new LambdaQueryWrapper<FpgGatherData>().eq(FpgGatherData::getFpgModelState, "0");
|
|
|
-// // 检测是否配置设备特殊条件
|
|
|
-// if(!fpgLeanModeInfo.getDeviceInformationIds().isEmpty()){
|
|
|
-// fpgGatherQuery.in(FpgGatherData::getDeviceInformationId, Arrays.asList(fpgLeanModeInfo.getDeviceInformationIds().split(",")));
|
|
|
-// }
|
|
|
-// List<FpgGatherData> fpgGatherList = fpgGatherDataService.list(fpgGatherQuery);
|
|
|
-// });
|
|
|
+ List<DeviceInformation> deviceInformationllist = deviceInformationService.list();
|
|
|
+ //遍历设备集合
|
|
|
+ deviceInformationllist.forEach(deviceInformationlinfo -> {
|
|
|
+ LambdaQueryWrapper<FpgGatherData> fpgGatherQuery = new LambdaQueryWrapper<FpgGatherData>().eq(FpgGatherData::getFpgModelState, "0");
|
|
|
+ List<FpgGatherData> fpgGatherList = fpgGatherDataService.list(fpgGatherQuery);
|
|
|
+ // 处理数据业务逻辑
|
|
|
+ fpgGatherList.forEach(fpgGatherData -> { // 循环处理采集数据处理
|
|
|
+ try {
|
|
|
+ // 采集时间
|
|
|
+ Instant instant = fpgGatherData.getCreateTime().toInstant();
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
|
|
|
+ // 上报日期
|
|
|
+ String dayDate = new SimpleDateFormat("yyyy-MM-dd").format(fpgGatherData.getCreateTime());
|
|
|
+ String classs = "";
|
|
|
+ // 班次处理
|
|
|
+ if (containsCreateTime(localDateTime, dayDate + " 00:00:00", dayDate + " 07:59:59")) { // 夜班
|
|
|
+ classs = "night";
|
|
|
+ } else if (containsCreateTime(localDateTime, dayDate + " 08:00:00", dayDate + " 15:59:59")) { // 白班
|
|
|
+ classs = "white";
|
|
|
+ } else if (containsCreateTime(localDateTime, dayDate + " 16:00:00", dayDate + " 23:59:59")) { // 中班
|
|
|
+ classs = "center";
|
|
|
+ }
|
|
|
+ // 设备启停统计 start
|
|
|
+ String startStopMonKey = "leanmodel_start_stop_total";
|
|
|
+ DeviceStatiscsModelData startStopStatiscsModelData = new DeviceStatiscsModelData(fpgGatherData, "startstop_total", dayDate, classs, curentDate, curentDate);
|
|
|
+ // 组合mongodb条件
|
|
|
+ Query queryStartStop = new Query()
|
|
|
+ .addCriteria(Criteria.where("deviceRegionId").is(fpgGatherData.getDeviceRegionId())).addCriteria(Criteria.where("deviceInformationId").is(fpgGatherData.getDeviceInformationId()));
|
|
|
+ // 设备停止
|
|
|
+ if(fpgGatherData.getRunCurrent().compareTo(new BigDecimal("0.00")) < 5){ // 设备停止运行 直接更新停止时间结束不用统计任何东西
|
|
|
+ queryStartStop.addCriteria(Criteria.where("deviceStopTime").is(null));
|
|
|
+ UpdateDefinition updateStartStop = new Update()
|
|
|
+ .set("updateTime", curentDate);
|
|
|
+ mongoTemplate.updateFirst(queryStartStop, updateStartStop, FpgStatiscsModelMongodb.class, startStopMonKey);
|
|
|
+ return;
|
|
|
+ } else { // 设备运行状态
|
|
|
+ // 查找上一次运行记录
|
|
|
+ FpgStatiscsModelMongodb startStopMongo = mongoTemplate.findOne(queryStartStop, FpgStatiscsModelMongodb.class, startStopMonKey);
|
|
|
+ if(startStopMongo != null){
|
|
|
+ // 功率
|
|
|
+ BigDecimal runPower = new BigDecimal(String.valueOf(fpgGatherData.getActivePower()));
|
|
|
+ // 运行时常
|
|
|
+ BigDecimal runTime = new BigDecimal("1");
|
|
|
+ // 历史数据
|
|
|
+ BigDecimal oldPower = new BigDecimal(String.valueOf(startStopMongo.getPower()));
|
|
|
+ BigDecimal oldRunTime = new BigDecimal(String.valueOf(startStopMongo.getIngTime()));
|
|
|
+ // 更新启动运行数据
|
|
|
+ UpdateDefinition updateStartStop = new Update()
|
|
|
+ .set("power", oldPower.add(runPower))
|
|
|
+ .set("ingTime", oldRunTime.add(runTime))
|
|
|
+ .set("updateTime", curentDate);
|
|
|
+ mongoTemplate.updateFirst(queryStartStop, updateStartStop, FpgStatiscsModelMongodb.class, startStopMonKey);
|
|
|
+ return;
|
|
|
+ } else { // 直接插入
|
|
|
+ mongoTemplate.insert(startStopStatiscsModelData, startStopMonKey);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 设备启停统计 end
|
|
|
+ // 日统计尖峰平谷数据(功率+占比+电流+运行时长)
|
|
|
+ }catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
+
|
|
|
@Scheduled(fixedDelay = 1000)
|
|
|
public void t1(){
|
|
|
leanModel("1000");
|
|
@@ -153,8 +211,7 @@ public class LeanModelStatistics {
|
|
|
fpgGatherList.forEach(fpgGatherData -> { // 循环处理采集数据处理
|
|
|
try {
|
|
|
// 变更记录状态
|
|
|
-// fpgGatherData.setFpgModelState("1");
|
|
|
- fpgGatherDataService.updateById(fpgGatherData);
|
|
|
+// fpgGatherDataService.updateById(fpgGatherData);
|
|
|
String finalDatestr = "";
|
|
|
// 统计单位
|
|
|
if("minute". equals(fpgLeanModeInfo.getTotalUnit())){ // 分钟
|
|
@@ -195,6 +252,7 @@ public class LeanModelStatistics {
|
|
|
});
|
|
|
// 重组对象
|
|
|
FpgStatiscsModelData fpgStatiscsModelData = new FpgStatiscsModelData(fpgGatherData, fpgLeanModeInfo, finalDatestr, dayDate, classs, curentDate, curentDate);
|
|
|
+ // 组合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()){ // 区域特殊处理
|