解决隐患预警分页查询,渗压监测分页查询报错;测值查询多图单表测点无详细数据时返回空数组
parent
26ad44d4a0
commit
08d9a806d3
|
|
@ -35,7 +35,7 @@ public interface OsmoticPressRMapper extends BaseMapper<OsmoticPressR> {
|
|||
t.station_code =#{obj.stationCode}
|
||||
</if>
|
||||
<if test="obj.profileCode != null and obj.profileCode !=''">
|
||||
s.profile_code =#{obj.profileCode}
|
||||
and s.profile_code =#{obj.profileCode}
|
||||
</if>
|
||||
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null">
|
||||
and t.tm <![CDATA[>=]]> #{obj.dateTimeRangeSo.start}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ public interface OsmoticWarnRMapper extends BaseMapper<OsmoticWarnR> {
|
|||
t.type = #{obj.type}
|
||||
</if>
|
||||
<if test="obj.level != null">
|
||||
t.level = #{obj.level}
|
||||
and t.level = #{obj.level}
|
||||
</if>
|
||||
<if test="obj.stationCode != null and obj.stationCode !=''">
|
||||
t.station_code LIKE concat('%',#{obj.stationCode},'%')
|
||||
and t.station_code like concat('%', #{obj.stationCode}::text, '%')
|
||||
</if>
|
||||
<if test="obj.dateTimeRangeSo != null and obj.dateTimeRangeSo.start != null">
|
||||
and t.tm <![CDATA[>=]]> #{obj.dateTimeRangeSo.start}
|
||||
|
|
|
|||
|
|
@ -100,6 +100,8 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
|
|||
if(year == null){
|
||||
vo.setDetailVos(bindData(MyBeanUtil.collectionCopy(list,OsmoticChartDetailVo.class),MyBeanUtil.collectionCopy(voList,OsmoticChartDetailVo.class)));
|
||||
}
|
||||
}else {
|
||||
vo.setDetailVos(new ArrayList<>());
|
||||
}
|
||||
resList.add(vo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.gunshi.project.xyt.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
|
@ -9,14 +11,20 @@ import com.gunshi.project.xyt.entity.so.WarnPageSo;
|
|||
import com.gunshi.project.xyt.entity.so.WarnSo;
|
||||
import com.gunshi.project.xyt.entity.vo.OsmoticWarnVo;
|
||||
import com.gunshi.project.xyt.mapper.OsmoticWarnRMapper;
|
||||
import com.gunshi.project.xyt.mapper.OsmoticWarnRuleMapper;
|
||||
import com.gunshi.project.xyt.model.OsmoticShiftR;
|
||||
import com.gunshi.project.xyt.model.OsmoticWarnR;
|
||||
import com.gunshi.project.xyt.model.OsmoticWarnRule;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -30,10 +38,10 @@ import java.util.stream.Collectors;
|
|||
public class OsmoticWarnRService extends ServiceImpl<OsmoticWarnRMapper, OsmoticWarnR>
|
||||
{
|
||||
@Resource
|
||||
private OsmoticWarnRMapper mapper;
|
||||
private OsmoticWarnRuleMapper warnRuleMapper;
|
||||
|
||||
public Page<OsmoticWarnVo> queryPage(WarnPageSo warnPageSo) {
|
||||
return mapper.queryPage(warnPageSo.getPageSo().toPage(),warnPageSo);
|
||||
return this.baseMapper.queryPage(warnPageSo.getPageSo().toPage(),warnPageSo);
|
||||
}
|
||||
|
||||
public Map<Integer, Long> stat(WarnSo warnSo) {
|
||||
|
|
@ -56,6 +64,127 @@ public class OsmoticWarnRService extends ServiceImpl<OsmoticWarnRMapper, Osmotic
|
|||
List<OsmoticWarnR> list = this.list(wrapper);
|
||||
return list.stream().collect(Collectors.groupingBy(OsmoticWarnR::getLevel, Collectors.counting()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成位移预警
|
||||
*/
|
||||
public void saveShiftWarn(OsmoticShiftR shiftR){
|
||||
String stationCode = shiftR.getStationCode();
|
||||
Date tm = shiftR.getTm();
|
||||
BigDecimal x = shiftR.getX();
|
||||
savePressWarn(stationCode,x,tm,"x");
|
||||
BigDecimal y = shiftR.getY();
|
||||
savePressWarn(stationCode,y,tm,"y");
|
||||
BigDecimal h = shiftR.getH();
|
||||
savePressWarn(stationCode,h,tm,"h");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成渗压/渗流预警
|
||||
* @param
|
||||
*/
|
||||
public void savePressWarn(String stationCode,BigDecimal value,Date tm,String direction) {
|
||||
//查询预警规则,每个测点至多只有2条预警规则
|
||||
LambdaQueryWrapper<OsmoticWarnRule> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(OsmoticWarnRule::getStationCode,stationCode)
|
||||
.eq(OsmoticWarnRule::getStatus,1);
|
||||
if(StringUtils.isNotEmpty(direction)){
|
||||
queryWrapper.eq(OsmoticWarnRule::getDirection,direction);
|
||||
}
|
||||
List<OsmoticWarnRule> ruleList = warnRuleMapper.selectList(queryWrapper);
|
||||
if(CollectionUtils.isNotEmpty(ruleList)){
|
||||
Boolean isRedWarn = false;
|
||||
//先判断是否符合红色预警
|
||||
Optional<OsmoticWarnRule> red = ruleList.stream().filter(o -> o.getLevel() == 2).findFirst();
|
||||
if(red.isPresent()){
|
||||
OsmoticWarnRule redRule = red.get();
|
||||
isRedWarn = saveWarnData(redRule,value,tm);
|
||||
if (isRedWarn){
|
||||
return;
|
||||
}
|
||||
//没有生成红色预警,再判断是否符合黄色预警
|
||||
Optional<OsmoticWarnRule> yellow = ruleList.stream().filter(o -> o.getLevel() == 1).findFirst();
|
||||
if(yellow.isPresent()){
|
||||
OsmoticWarnRule yellowRule = yellow.get();
|
||||
saveWarnData(yellowRule,value,tm);
|
||||
}
|
||||
}else {
|
||||
OsmoticWarnRule yellowRule = ruleList.get(0);
|
||||
saveWarnData(yellowRule,value,tm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean saveWarnData(OsmoticWarnRule rule,BigDecimal value,Date tm){
|
||||
String conditionOne = rule.getConditionOne();
|
||||
BigDecimal valueOne = rule.getValueOne();
|
||||
Integer condition = rule.getCondition();
|
||||
Boolean flagOne = getFlag(conditionOne,valueOne,value);
|
||||
/**
|
||||
* 没有第二条件时,条件1满足就生成预警
|
||||
* 有第二条件时,当为或时,条件1满足就生成预警,条件1不满足就判断条件2是否满足;当为且时,需条件1和条件2同时满足才生成预警
|
||||
*/
|
||||
if(condition == null){
|
||||
if(flagOne){
|
||||
//生成预警
|
||||
return geneWarn(rule,value,tm);
|
||||
}
|
||||
}else{
|
||||
String conditionTwo = rule.getConditionTwo();
|
||||
BigDecimal valueTwo = rule.getValueTwo();
|
||||
Boolean flagTwo = getFlag(conditionTwo,valueTwo,value);
|
||||
if(condition == 1){
|
||||
if(flagOne && flagTwo){
|
||||
//生成预警
|
||||
return geneWarn(rule,value,tm);
|
||||
}
|
||||
}else{
|
||||
if(flagOne || flagTwo){
|
||||
//生成预警
|
||||
return geneWarn(rule,value,tm);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Boolean geneWarn(OsmoticWarnRule rule,BigDecimal value,Date tm) {
|
||||
OsmoticWarnR warnR = new OsmoticWarnR();
|
||||
warnR.setId(IdWorker.getId());
|
||||
warnR.setStationCode(rule.getStationCode());
|
||||
warnR.setRuleId(rule.getId());
|
||||
warnR.setValue(value);
|
||||
warnR.setTm(tm);
|
||||
warnR.setType(rule.getType());
|
||||
warnR.setLevel(rule.getLevel());
|
||||
this.baseMapper.insert(warnR);
|
||||
return true;
|
||||
}
|
||||
|
||||
private Boolean getFlag(String condition,BigDecimal ruleValue,BigDecimal value){
|
||||
Boolean flag = false;
|
||||
switch (condition) {
|
||||
case ">" :
|
||||
flag = value.compareTo(ruleValue) > 0;
|
||||
break;
|
||||
case ">=" :
|
||||
flag = value.compareTo(ruleValue) >= 0;
|
||||
break;
|
||||
case "<" :
|
||||
flag = value.compareTo(ruleValue) < 0;
|
||||
break;
|
||||
case "<=" :
|
||||
flag = value.compareTo(ruleValue) <= 0;
|
||||
break;
|
||||
case "=" :
|
||||
flag = value.compareTo(ruleValue) == 0;
|
||||
break;
|
||||
case "!=" :
|
||||
flag = value.compareTo(ruleValue) != 0;
|
||||
break;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue