mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善环保设备预警计算
This commit is contained in:
@@ -2,6 +2,7 @@ package cn.lihongjie.coal.emDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceEntity;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceItemConfig;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
@@ -13,6 +14,8 @@ import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
@@ -31,6 +34,6 @@ public class CreateEmDeviceDto extends OrgCommonDto {
|
||||
|
||||
private String location;
|
||||
|
||||
|
||||
private List<EmDeviceItemConfig> itemConfig;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.lihongjie.coal.emDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceItemConfig;
|
||||
import cn.lihongjie.coal.emDeviceSupplier.dto.EmDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.thirdAccount.dto.ThirdAccountDto;
|
||||
|
||||
@@ -8,6 +9,8 @@ import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class EmDeviceDto extends OrgCommonDto {
|
||||
|
||||
@@ -23,4 +26,6 @@ public class EmDeviceDto extends OrgCommonDto {
|
||||
private String archiveStatus;
|
||||
|
||||
private String archiveStatusName;
|
||||
|
||||
private List<EmDeviceItemConfig> itemConfig;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.lihongjie.coal.emDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceEntity;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceItemConfig;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
@@ -13,6 +14,8 @@ import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
@@ -30,4 +33,6 @@ public class UpdateEmDeviceDto extends OrgCommonDto {
|
||||
private String deviceType;
|
||||
|
||||
private String location;
|
||||
|
||||
private List<EmDeviceItemConfig> itemConfig;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ public class EmDeviceItemConfig {
|
||||
private Double minVal;
|
||||
private Double maxVal;
|
||||
|
||||
private Boolean enable;
|
||||
private Integer sortKey;
|
||||
private Boolean enableAlter;
|
||||
|
||||
|
||||
|
||||
@@ -211,4 +211,6 @@ public class EmDeviceService extends BaseService<EmDeviceEntity, EmDeviceReposit
|
||||
log.info("get realtime data success {} ", deviceIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -62,4 +62,95 @@ public class EmDeviceDataDto extends OrgCommonDto {
|
||||
|
||||
@Comment("臭氧")
|
||||
private Double o3;
|
||||
|
||||
private Long alterMask;
|
||||
|
||||
public int getAlterStatus(String code) {
|
||||
if (alterMask == null) alterMask = 0L;
|
||||
int ans = 0;
|
||||
switch (code) {
|
||||
case "pm25" -> ans = (int) ((alterMask >>> 0) & 0b11);
|
||||
case "pm10" -> ans = (int) ((alterMask >>> 2) & 0b11);
|
||||
case "noise" -> ans = (int) ((alterMask >>> 4) & 0b11);
|
||||
case "tem" -> ans = (int) ((alterMask >>> 6) & 0b11);
|
||||
case "hum" -> ans = (int) ((alterMask >>> 8) & 0b11);
|
||||
case "wp" -> ans = (int) ((alterMask >>> 10) & 0b11);
|
||||
case "ws" -> ans = (int) ((alterMask >>> 12) & 0b11);
|
||||
case "wd8" -> ans = (int) ((alterMask >>> 14) & 0b11);
|
||||
case "wd360" -> ans = (int) ((alterMask >>> 16) & 0b11);
|
||||
case "tsp" -> ans = (int) ((alterMask >>> 18) & 0b11);
|
||||
case "atm" -> ans = (int) ((alterMask >>> 20) & 0b11);
|
||||
case "lux" -> ans = (int) ((alterMask >>> 22) & 0b11);
|
||||
case "co" -> ans = (int) ((alterMask >>> 24) & 0b11);
|
||||
case "so2" -> ans = (int) ((alterMask >>> 26) & 0b11);
|
||||
case "no2" -> ans = (int) ((alterMask >>> 28) & 0b11);
|
||||
case "o3" -> ans = (int) ((alterMask >>> 30) & 0b11);
|
||||
}
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
public int getPm25Alter() {
|
||||
return this.getAlterStatus("pm25");
|
||||
}
|
||||
|
||||
public int getPm10Alter() {
|
||||
return this.getAlterStatus("pm10");
|
||||
}
|
||||
|
||||
public int getNoiseAlter() {
|
||||
return this.getAlterStatus("noise");
|
||||
}
|
||||
|
||||
public int getTemAlter() {
|
||||
return this.getAlterStatus("tem");
|
||||
}
|
||||
|
||||
public int getHumAlter() {
|
||||
return this.getAlterStatus("hum");
|
||||
}
|
||||
|
||||
public int getWpAlter() {
|
||||
return this.getAlterStatus("wp");
|
||||
}
|
||||
|
||||
public int getWsAlter() {
|
||||
return this.getAlterStatus("ws");
|
||||
}
|
||||
|
||||
public int getWd8Alter() {
|
||||
return this.getAlterStatus("wd8");
|
||||
}
|
||||
|
||||
public int getWd360Alter() {
|
||||
return this.getAlterStatus("wd360");
|
||||
}
|
||||
|
||||
public int getTspAlter() {
|
||||
return this.getAlterStatus("tsp");
|
||||
}
|
||||
|
||||
public int getAtmAlter() {
|
||||
return this.getAlterStatus("atm");
|
||||
}
|
||||
|
||||
public int getLuxAlter() {
|
||||
return this.getAlterStatus("lux");
|
||||
}
|
||||
|
||||
public int getCoAlter() {
|
||||
return this.getAlterStatus("co");
|
||||
}
|
||||
|
||||
public int getSo2Alter() {
|
||||
return this.getAlterStatus("so2");
|
||||
}
|
||||
|
||||
public int getNo2Alter() {
|
||||
return this.getAlterStatus("no2");
|
||||
}
|
||||
|
||||
public int getO3Alter() {
|
||||
return this.getAlterStatus("o3");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,4 +73,5 @@ public class EmDeviceDataEntity extends OrgCommonEntity {
|
||||
|
||||
@Comment("报警标记")
|
||||
private Long alterMask;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceEntity;
|
||||
import cn.lihongjie.coal.emDevice.entity.EmDeviceItemConfig;
|
||||
import cn.lihongjie.coal.emDevice.service.EmDeviceService;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.CreateEmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.EmDeviceDataDto;
|
||||
import cn.lihongjie.coal.emDeviceData.dto.UpdateEmDeviceDataDto;
|
||||
@@ -11,8 +14,10 @@ import cn.lihongjie.coal.emDeviceData.entity.EmDeviceDataEntity;
|
||||
import cn.lihongjie.coal.emDeviceData.mapper.EmDeviceDataMapper;
|
||||
import cn.lihongjie.coal.emDeviceData.repository.EmDeviceDataRepository;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -21,6 +26,12 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
@@ -70,4 +81,75 @@ public class EmDeviceDataService extends BaseService<EmDeviceDataEntity, EmDevic
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public static Map<String, Integer> maskMap = new HashMap<>();
|
||||
@Autowired EmDeviceService emDeviceService;
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public List<EmDeviceDataEntity> saveAll(Iterable<EmDeviceDataEntity> emDeviceDataEntities) {
|
||||
|
||||
List<EmDeviceDataEntity> collect =
|
||||
StreamSupport.stream(emDeviceDataEntities.spliterator(), false)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (EmDeviceDataEntity data : emDeviceDataEntities) {
|
||||
EmDeviceEntity device = emDeviceService.get(data.getDeviceId());
|
||||
|
||||
List<EmDeviceItemConfig> itemConfig = device.getItemConfig();
|
||||
|
||||
for (EmDeviceItemConfig config : itemConfig) {
|
||||
|
||||
if (!config.getEnable() || !config.getEnableAlter()) {
|
||||
continue;
|
||||
}
|
||||
Object value = PropertyUtils.getProperty(data, config.getCode());
|
||||
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Double dv = (Double) value;
|
||||
|
||||
if (config.getMinVal() != null && dv < config.getMinVal()) {
|
||||
|
||||
data.setAlterMask(calAlterMask(data.getAlterMask(), config.getCode(), 0b01));
|
||||
|
||||
} else if (config.getMaxVal() != null && dv > config.getMaxVal()) {
|
||||
|
||||
data.setAlterMask(calAlterMask(data.getAlterMask(), config.getCode(), 0b10));
|
||||
|
||||
} else {
|
||||
data.setAlterMask(calAlterMask(data.getAlterMask(), config.getCode(), 0b00));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.saveAll(emDeviceDataEntities);
|
||||
}
|
||||
|
||||
private Long calAlterMask(Long alterMask, String code, int val) {
|
||||
|
||||
if (alterMask == null) alterMask = 0L;
|
||||
switch (code) {
|
||||
case "pm25" -> alterMask = alterMask | (val << (0));
|
||||
case "pm10" -> alterMask = alterMask | ((long) val << (2));
|
||||
case "noise" -> alterMask = alterMask | ((long) val << (4));
|
||||
case "tem" -> alterMask = alterMask | ((long) val << (6));
|
||||
case "hum" -> alterMask = alterMask | ((long) val << (8));
|
||||
case "wp" -> alterMask = alterMask | ((long) val << (10));
|
||||
case "ws" -> alterMask = alterMask | ((long) val << (12));
|
||||
case "wd8" -> alterMask = alterMask | ((long) val << (14));
|
||||
case "wd360" -> alterMask = alterMask | ((long) val << (16));
|
||||
case "tsp" -> alterMask = alterMask | ((long) val << (18));
|
||||
case "atm" -> alterMask = alterMask | ((long) val << (20));
|
||||
case "lux" -> alterMask = alterMask | ((long) val << (22));
|
||||
case "co" -> alterMask = alterMask | ((long) val << (24));
|
||||
case "so2" -> alterMask = alterMask | ((long) val << (26));
|
||||
case "no2" -> alterMask = alterMask | ((long) val << (28));
|
||||
case "o3" -> alterMask = alterMask | ((long) val << (30));
|
||||
}
|
||||
|
||||
return alterMask;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user