Commit 6be5cfcf authored by lisong's avatar lisong

添加单位换算逻辑

parent 2f30e585
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.feign.systemctl.model.MessageModel;
import com.yeejoin.equipmanage.common.datasync.entity.FireEquipmentDefectAlarm;
......@@ -608,6 +609,10 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
BigDecimal minValue = getBigDecimal(map.get("minValues"));
BigDecimal maxValue = getBigDecimal(map.get("maxValues"));
BigDecimal nowValue = getBigDecimal(iotDataVO.getValue());
BigDecimal checkValue = checkUnit(iotDataVO.getKey().toLowerCase(), nowValue);
if (!ObjectUtils.isEmpty(checkValue)){
nowValue =checkValue;
}
if (nowValue.compareTo(minValue) < 0 || nowValue.compareTo(maxValue) > 0) {
String body = "";
if (nowValue.compareTo(minValue) < 0) {
......@@ -660,7 +665,6 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
MessageModel model = new MessageModel();
Map<String, Object> map = fireFightingSystemMapper.getWaterPoolLevel(equipmentSpecificIndex.getEquipmentSpecificId());
if (!ObjectUtils.isEmpty(map)) {
BigDecimal minValues = new BigDecimal(map.get("minValues").toString());
BigDecimal minValue = getBigDecimal(map.get("minValues"));
BigDecimal maxValue = getBigDecimal(map.get("maxValues"));
BigDecimal nowValue = getBigDecimal(iotDataVO.getValue());
......@@ -678,6 +682,10 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
}
nowValue = add.divide(new BigDecimal(i), 2, RoundingMode.HALF_UP);
}
BigDecimal checkValue = checkUnit(iotDataVO.getKey().toLowerCase(), nowValue);
if (!ObjectUtils.isEmpty(checkValue)){
nowValue =checkValue;
}
if (nowValue.compareTo(minValue) < 0 || nowValue.compareTo(maxValue) > 0) {
String body = "";
if (nowValue.compareTo(minValue) < 0) {
......@@ -716,6 +724,20 @@ public class MqttReceiveServiceImpl implements MqttReceiveService {
return alarmFlag;
}
private BigDecimal checkUnit(String indexKey, BigDecimal nowValue){
LambdaQueryWrapper<EquipmentIndex> eq = new QueryWrapper<EquipmentIndex>().lambda().eq(EquipmentIndex::getPerfQuotaDefinitionId, indexKey);
EquipmentIndex one = equipmentIndexService.getOne(eq);
if (!ObjectUtils.isEmpty(one) || !ObjectUtils.isEmpty(one.getUnit())){
if (UnitEnum.MM.getKey().equalsIgnoreCase(one.getUnit()) || UnitEnum.MM.getName().equals(one.getUnit())){
BigDecimal divide = new BigDecimal(1000);
nowValue = nowValue.divide(divide,2,BigDecimal.ROUND_HALF_UP);
}else if (UnitEnum.CM.getKey().equalsIgnoreCase(one.getUnit()) || UnitEnum.CM.getName().equals(one.getUnit())){
BigDecimal divide = new BigDecimal(100);
nowValue = nowValue.divide(divide,2,BigDecimal.ROUND_HALF_UP);
}
}
return nowValue;
}
private BigDecimal getBigDecimal( Object value ) {
BigDecimal val = null;
if( value != null ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment