水位告警生成消息

master
wany 2024-09-19 17:04:36 +08:00
parent 521255ff8d
commit 0512f7d4a5
6 changed files with 119 additions and 36 deletions

View File

@ -3,6 +3,10 @@ package com.gunshi.project.xyt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gunshi.project.xyt.model.MessageCenter;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* :
@ -12,4 +16,19 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MessageCenterMapper extends BaseMapper<MessageCenter> {
@Select("""
<script>
select user_id from public.sys_user_role where role_id in
(select role_id from public.sys_role where role_name ='')
</script>
""")
List<Long> queryUserIds();
@Select("""
<script>
select * from public.message_center where type = #{type}
and to_char(publish_time,'YYYY-MM-DD') = #{date}
</script>
""")
List<MessageCenter> queryTodayMes(@Param("date") String date,@Param("type") Integer type);
}

View File

@ -356,7 +356,7 @@ public class AttResBase implements Serializable {
@TableField(value="cal_flood_lev")
@Schema(description="校核洪水位")
// @Size(max = 0,message = "校核洪水位最大长度要小于 0")
private String calFloodLev;
private BigDecimal calFloodLev;
/**
*
@ -364,7 +364,7 @@ public class AttResBase implements Serializable {
@TableField(value="des_flood_lev")
@Schema(description="设计洪水位")
// @Size(max = 0,message = "设计洪水位最大长度要小于 0")
private String desFloodLev;
private BigDecimal desFloodLev;
/**
*

View File

@ -93,4 +93,11 @@ public class MessageCenter implements Serializable {
@Schema(description="是否已读0否 1是")
private Integer status;
/**
* 1 2 3
*/
@TableField(value="type")
@Schema(description="类型1超校核 2超设计 3超汛限")
private Integer type;
}

View File

@ -77,7 +77,7 @@ public class InspectTaskDetailService extends ServiceImpl<InspectTaskDetailMappe
for (InspectTaskDetailVo record : value) {
record.setInspectPics(fileService.queryFileList(record.getId().toString(),getGroupId(),getPicType()));
record.setInspectVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getVideoType()));
if(record.getIsHandle() == 1){
if(record.getIsHandle() != null && record.getIsHandle() == 1){
record.setHandlePics(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandlePicType()));
record.setHandleVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandleVideoType()));
}
@ -96,7 +96,7 @@ public class InspectTaskDetailService extends ServiceImpl<InspectTaskDetailMappe
for (InspectProblemVo record : records) {
record.setInspectPics(fileService.queryFileList(record.getId().toString(),getGroupId(),getPicType()));
record.setInspectVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getVideoType()));
if(record.getIsHandle() == 1){
if(record.getIsHandle() != null && record.getIsHandle() == 1){
record.setHandlePics(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandlePicType()));
record.setHandleVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandleVideoType()));
}

View File

@ -1,20 +1,30 @@
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.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gunshi.project.xyt.entity.so.MessageCenterPageSo;
import com.gunshi.project.xyt.mapper.AttResBaseMapper;
import com.gunshi.project.xyt.mapper.MessageCenterMapper;
import com.gunshi.project.xyt.model.AttResBase;
import com.gunshi.project.xyt.model.MessageCenter;
import com.gunshi.project.xyt.model.StRsvrR;
import com.gunshi.project.xyt.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.Optional;
import java.util.stream.Collectors;
/**
* :
@ -26,6 +36,8 @@ import java.util.List;
@Transactional(rollbackFor = Exception.class)
public class MessageCenterService extends ServiceImpl<MessageCenterMapper, MessageCenter>
{
@Autowired
private AttResBaseMapper resBaseMapper;
public void insertMessage(List<MessageCenter> messageCenters){
for(MessageCenter messageCenter : messageCenters){
@ -55,6 +67,75 @@ public class MessageCenterService extends ServiceImpl<MessageCenterMapper, Messa
.eq(MessageCenter::getReceiveUserId, receiveUserId)
.update();
}
public void rzWarnMes(List<StRsvrR> rlist) {
AttResBase attResBase = resBaseMapper.selectById("42120250085");
String stcd = attResBase.getStcd();
Optional<StRsvrR> first = rlist.stream().filter(o -> o.getStcd().equals(stcd)).findFirst();
if(first.isPresent()){
BigDecimal rz = new BigDecimal(first.get().getRz());
MessageCenter center =new MessageCenter();
center.setPublishUserId(1L);
center.setPublishUserName("admin");
center.setTitle("水位告警");
String content = "系统检测到小玉潭水库水位";
//校核水位
BigDecimal calFloodLev = attResBase.getCalFloodLev();
if(calFloodLev.compareTo(rz) > 0){
center.setType(1);
content = content + "超校核"+ calFloodLev.subtract(rz) +"m";
center.setContent(content);
addRzMessage(center,1);
return;
}
//设计水位
BigDecimal desFloodLev = attResBase.getDesFloodLev();
if(desFloodLev.compareTo(rz) > 0){
center.setType(2);
content = content + "超设计"+ desFloodLev.subtract(rz) +"m";
center.setContent(content);
addRzMessage(center,2);
return;
}
//汛限水位
BigDecimal flLowLimLev = attResBase.getFlLowLimLev();
if(flLowLimLev.compareTo(rz) > 0){
center.setType(3);
content = content + "超汛限"+ flLowLimLev.subtract(rz) +"m";
center.setContent(content);
addRzMessage(center,3);
}
}
}
private void addRzMessage(MessageCenter center, Integer type) {
String date = DateUtil.convertDateToString(new Date());
List<MessageCenter> list = this.baseMapper.queryTodayMes(date,type);
//如果当日不存在该类型的水位告警,则直接新增
if(CollectionUtils.isEmpty(list)){
rzMesHandle(center);
}else{
this.removeBatchByIds(list);
rzMesHandle(center);
}
}
private void rzMesHandle(MessageCenter center){
//查找接收角色关联的人员
List<Long> ids = this.baseMapper.queryUserIds();
List<MessageCenter> mesList = ids.stream().map(o -> {
MessageCenter mes = new MessageCenter();
BeanUtils.copyProperties(center, mes);
mes.setReceiveUserId(o);
return mes;
}).collect(Collectors.toList());
this.insertMessage(mesList);
}
}

View File

@ -11,33 +11,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.gunshi.project.xyt.entity.SkSyncData;
import com.gunshi.project.xyt.entity.SkSyncResp;
import com.gunshi.project.xyt.entity.SyncDataReq;
import com.gunshi.project.xyt.model.StImgR;
import com.gunshi.project.xyt.model.StImgRReal;
import com.gunshi.project.xyt.model.StPptnR;
import com.gunshi.project.xyt.model.StPptnRD;
import com.gunshi.project.xyt.model.StPptnRH;
import com.gunshi.project.xyt.model.StPptnRReal;
import com.gunshi.project.xyt.model.StRsvrR;
import com.gunshi.project.xyt.model.StRsvrRReal;
import com.gunshi.project.xyt.model.StStbprpB;
import com.gunshi.project.xyt.service.StImgRRealService;
import com.gunshi.project.xyt.service.StImgRService;
import com.gunshi.project.xyt.service.StPptnRDService;
import com.gunshi.project.xyt.service.StPptnRHService;
import com.gunshi.project.xyt.service.StPptnRRealService;
import com.gunshi.project.xyt.service.StPptnRService;
import com.gunshi.project.xyt.service.StRsvrRRealService;
import com.gunshi.project.xyt.service.StRsvrRService;
import com.gunshi.project.xyt.service.StStbprpBService;
import com.gunshi.project.xyt.model.*;
import com.gunshi.project.xyt.service.*;
import com.gunshi.project.xyt.util.OkHttpUtil;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
@ -49,13 +27,7 @@ import ru.olegcherednik.jackson_utils.JacksonUtils;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -142,6 +114,9 @@ public class DataTask {
@Autowired
private StImgRService stImgRService;
@Autowired
private MessageCenterService messageCenterService;
/**
* @description:
@ -561,6 +536,7 @@ public class DataTask {
UpdateWrapper<StRsvrRReal> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("stcd", stRsvrRReal.getStcd());
stRsvrRRealService.saveOrUpdate(stRsvrRReal, updateWrapper);
messageCenterService.rzWarnMes(rlist);
}
}
}