|
@@ -14,9 +14,6 @@ import com.usky.common.core.bean.ApiResult;
|
|
|
import com.usky.common.core.bean.CommonPage;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
-import com.usky.demo.RemoteTsdbProxyService;
|
|
|
-import com.usky.demo.domain.LastInnerQueryVO;
|
|
|
-import com.usky.demo.domain.LastInnerResultVO;
|
|
|
import com.usky.iot.domain.*;
|
|
|
import com.usky.iot.mapper.BaseAlarmMapper;
|
|
|
import com.usky.iot.mapper.DmpDeviceTypeMapper;
|
|
@@ -30,6 +27,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
@@ -72,9 +70,6 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
|
|
|
@Autowired
|
|
|
private DataQueryClient dataQueryClient;
|
|
|
|
|
|
- @Autowired
|
|
|
- private RemoteTsdbProxyService remoteTsdbProxyService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private DmpDeviceStatusService dmpDeviceStatusService;
|
|
|
|
|
@@ -197,75 +192,85 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
|
|
|
|
|
|
public CommonPage<BaseAlarm> page(BaseAlarmListVO baseAlarmListVO){
|
|
|
List<BaseAlarm> list = new ArrayList<>();
|
|
|
- IPage<BaseAlarm> page = new Page<>(baseAlarmListVO.getCurrent(), baseAlarmListVO.getSize());
|
|
|
- LambdaQueryWrapper<BaseAlarm> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.eq(StringUtils.isNotBlank(baseAlarmListVO.getDeviceId()),BaseAlarm::getDeviceId,baseAlarmListVO.getDeviceId())
|
|
|
- .eq(StringUtils.isNotBlank(baseAlarmListVO.getProductCode()),BaseAlarm::getProductCode,baseAlarmListVO.getProductCode())
|
|
|
- .in(CollectionUtils.isNotEmpty(baseAlarmListVO.getAlarmType()),BaseAlarm::getAlarmType,
|
|
|
- baseAlarmListVO.getAlarmType())
|
|
|
- .eq(null != baseAlarmListVO.getHandleStatus(),BaseAlarm::getHandleStatus,baseAlarmListVO.getHandleStatus())
|
|
|
- .between(StringUtils.isNotBlank(baseAlarmListVO.getStartTime()) && StringUtils.isNotBlank(baseAlarmListVO.getEndTime()),BaseAlarm::getAlarmTime,baseAlarmListVO.getStartTime(),baseAlarmListVO.getEndTime())
|
|
|
- .eq(BaseAlarm::getTenantId,SecurityUtils.getTenantId())
|
|
|
- .eq(Objects.nonNull(baseAlarmListVO.getId()),BaseAlarm::getId,baseAlarmListVO.getId());
|
|
|
- if (StringUtils.isNotBlank(baseAlarmListVO.getTypeCode())){
|
|
|
- if (baseAlarmListVO.getTypeCode().equals("1")){
|
|
|
- queryWrapper.eq(BaseAlarm::getAlarmGrade,1)
|
|
|
- .orderByDesc(BaseAlarm::getId);
|
|
|
- }else if (baseAlarmListVO.getTypeCode().equals("2")){
|
|
|
- queryWrapper.ne(BaseAlarm::getAlarmGrade,1)
|
|
|
- .orderByDesc(BaseAlarm::getId);
|
|
|
+
|
|
|
+ List<String> devIdList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<DmpDeviceInfo> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.eq(DmpDeviceInfo::getTenantId,SecurityUtils.getTenantId())
|
|
|
+ .eq(DmpDeviceInfo::getDeleteFlag,0);
|
|
|
+ List<DmpDeviceInfo> deviceInfo = dmpDeviceInfoService.list(queryWrapper1);
|
|
|
+ if(CollectionUtils.isNotEmpty(deviceInfo)){
|
|
|
+ for(int j=0;j<deviceInfo.size();j++){
|
|
|
+ devIdList.add(deviceInfo.get(j).getDeviceId());
|
|
|
}
|
|
|
- }else {
|
|
|
- queryWrapper.orderByDesc(BaseAlarm::getId);
|
|
|
}
|
|
|
- page = this.page(page,queryWrapper);
|
|
|
-// List<BaseAlarm> records = this.list(queryWrapper);
|
|
|
- if(page.getRecords().size()>0){
|
|
|
- List<String> devList = new ArrayList<>();
|
|
|
- for(int i=0;i<page.getRecords().size();i++){
|
|
|
- devList.add(page.getRecords().get(i).getDeviceId());
|
|
|
+
|
|
|
+ IPage<BaseAlarm> page = new Page<>(baseAlarmListVO.getCurrent(), baseAlarmListVO.getSize());
|
|
|
+ if(CollectionUtils.isNotEmpty(devIdList)){
|
|
|
+ LambdaQueryWrapper<BaseAlarm> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.in(BaseAlarm::getDeviceId,devIdList)
|
|
|
+ .eq(StringUtils.isNotBlank(baseAlarmListVO.getDeviceId()),BaseAlarm::getDeviceId,baseAlarmListVO.getDeviceId())
|
|
|
+ .eq(StringUtils.isNotBlank(baseAlarmListVO.getProductCode()),BaseAlarm::getProductCode,baseAlarmListVO.getProductCode())
|
|
|
+ .in(CollectionUtils.isNotEmpty(baseAlarmListVO.getAlarmType()),BaseAlarm::getAlarmType,
|
|
|
+ baseAlarmListVO.getAlarmType())
|
|
|
+ .eq(null != baseAlarmListVO.getHandleStatus(),BaseAlarm::getHandleStatus,baseAlarmListVO.getHandleStatus())
|
|
|
+ .between(StringUtils.isNotBlank(baseAlarmListVO.getStartTime()) && StringUtils.isNotBlank(baseAlarmListVO.getEndTime()),BaseAlarm::getAlarmTime,baseAlarmListVO.getStartTime(),baseAlarmListVO.getEndTime())
|
|
|
+ .eq(BaseAlarm::getTenantId,SecurityUtils.getTenantId())
|
|
|
+ .eq(Objects.nonNull(baseAlarmListVO.getId()),BaseAlarm::getId,baseAlarmListVO.getId());
|
|
|
+ if (StringUtils.isNotBlank(baseAlarmListVO.getTypeCode())){
|
|
|
+ if (baseAlarmListVO.getTypeCode().equals("1")){
|
|
|
+ queryWrapper.eq(BaseAlarm::getAlarmGrade,1)
|
|
|
+ .orderByDesc(BaseAlarm::getId);
|
|
|
+ }else if (baseAlarmListVO.getTypeCode().equals("2")){
|
|
|
+ queryWrapper.ne(BaseAlarm::getAlarmGrade,1)
|
|
|
+ .orderByDesc(BaseAlarm::getId);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ queryWrapper.orderByDesc(BaseAlarm::getId);
|
|
|
}
|
|
|
+ page = this.page(page,queryWrapper);
|
|
|
+// List<BaseAlarm> records = this.list(queryWrapper);
|
|
|
+ if(page.getRecords().size()>0){
|
|
|
+ List<String> devList = new ArrayList<>();
|
|
|
+ for(int i=0;i<page.getRecords().size();i++){
|
|
|
+ devList.add(page.getRecords().get(i).getDeviceId());
|
|
|
+ }
|
|
|
|
|
|
- if(devList.size() > 0){
|
|
|
- LambdaQueryWrapper<DmpDeviceInfo> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
- queryWrapper1.in(DmpDeviceInfo::getDeviceId,devList)
|
|
|
- .eq(DmpDeviceInfo::getTenantId,SecurityUtils.getTenantId())
|
|
|
- .eq(DmpDeviceInfo::getDeleteFlag,0);
|
|
|
- List<DmpDeviceInfo> deviceInfo = dmpDeviceInfoService.list(queryWrapper1);
|
|
|
- LambdaQueryWrapper<BaseFacilityDevice> lambdaQuery1 = Wrappers.lambdaQuery();
|
|
|
- lambdaQuery1.in(BaseFacilityDevice::getDeviceId,devList);
|
|
|
- List<BaseFacilityDevice> records1 = baseFacilityDeviceService.list(lambdaQuery1);
|
|
|
- if(CollectionUtils.isNotEmpty(deviceInfo)){
|
|
|
- for(int i=0;i<page.getRecords().size();i++){
|
|
|
- for(int j=0;j<deviceInfo.size();j++){
|
|
|
- if(page.getRecords().get(i).getDeviceId().equals(deviceInfo.get(j).getDeviceId())){
|
|
|
- page.getRecords().get(i).setDeviceName(deviceInfo.get(j).getDeviceName());
|
|
|
- page.getRecords().get(i).setDeviceType(deviceInfo.get(j).getDeviceType());
|
|
|
- break;
|
|
|
+ if(devList.size() > 0){
|
|
|
+ LambdaQueryWrapper<BaseFacilityDevice> lambdaQuery1 = Wrappers.lambdaQuery();
|
|
|
+ lambdaQuery1.in(BaseFacilityDevice::getDeviceId,devList);
|
|
|
+ List<BaseFacilityDevice> records1 = baseFacilityDeviceService.list(lambdaQuery1);
|
|
|
+ if(CollectionUtils.isNotEmpty(deviceInfo)){
|
|
|
+ for(int i=0;i<page.getRecords().size();i++){
|
|
|
+ for(int j=0;j<deviceInfo.size();j++){
|
|
|
+ if(page.getRecords().get(i).getDeviceId().equals(deviceInfo.get(j).getDeviceId())){
|
|
|
+ page.getRecords().get(i).setDeviceName(deviceInfo.get(j).getDeviceName());
|
|
|
+ page.getRecords().get(i).setDeviceType(deviceInfo.get(j).getDeviceType());
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- for(int k=0;k<records1.size();k++){
|
|
|
- if(page.getRecords().get(i).getDeviceId().equals(records1.get(k).getDeviceId())){
|
|
|
- page.getRecords().get(i).setFacilityId(records1.get(k).getFacilityId());
|
|
|
- break;
|
|
|
+ for(int k=0;k<records1.size();k++){
|
|
|
+ if(page.getRecords().get(i).getDeviceId().equals(records1.get(k).getDeviceId())){
|
|
|
+ page.getRecords().get(i).setFacilityId(records1.get(k).getFacilityId());
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- List<BaseAlarmType> alarmTypeList = baseMapper.getAlarmTypeList();
|
|
|
- if(CollectionUtils.isNotEmpty(alarmTypeList)){
|
|
|
- for(int i=0;i<page.getRecords().size();i++){
|
|
|
- for(int j=0;j<alarmTypeList.size();j++){
|
|
|
- if(page.getRecords().get(i).getAlarmType().equals(alarmTypeList.get(j).getTypeCode())){
|
|
|
- page.getRecords().get(i).setTypeImg(alarmTypeList.get(j).getTypeImg());
|
|
|
- break;
|
|
|
+ List<BaseAlarmType> alarmTypeList = baseMapper.getAlarmTypeList();
|
|
|
+ if(CollectionUtils.isNotEmpty(alarmTypeList)){
|
|
|
+ for(int i=0;i<page.getRecords().size();i++){
|
|
|
+ for(int j=0;j<alarmTypeList.size();j++){
|
|
|
+ if(page.getRecords().get(i).getAlarmType().equals(alarmTypeList.get(j).getTypeCode())){
|
|
|
+ page.getRecords().get(i).setTypeImg(alarmTypeList.get(j).getTypeImg());
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotBlank(baseAlarmListVO.getDeviceName())){
|
|
@@ -624,9 +629,67 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Async("asyncServiceExecutor")
|
|
|
+ public void deviceAlarm(List<StatusVO> list, List<DmpDeviceInfo> devInfoList, List<BaseAlarm> baseUnAlarmList){
|
|
|
+ log.info("定时同步设备告警数据 start");
|
|
|
+ if(CollectionUtils.isNotEmpty(devInfoList)){
|
|
|
+ for(int i=0;i<list.size();i++){
|
|
|
+ String currentDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ if(Objects.nonNull(list.get(i).getTime()) && currentDate.equals(list.get(i).getTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))){
|
|
|
+ //设备离线告警恢复在线自动默认处理
|
|
|
+ if(CollectionUtils.isNotEmpty(baseUnAlarmList)){
|
|
|
+ for(int j=0;j<baseUnAlarmList.size();j++){
|
|
|
+ if(list.get(i).getDeviceId().equals(baseUnAlarmList.get(j).getDeviceId()) && list.get(i).getProductCode().equals(baseUnAlarmList.get(j).getProductCode())){
|
|
|
+ LambdaUpdateWrapper<BaseAlarm> updateWrapper1 = Wrappers.lambdaUpdate();
|
|
|
+ updateWrapper1.set(BaseAlarm::getHandleStatus,1)
|
|
|
+ .set(BaseAlarm::getHandleBy,"YT_admin")
|
|
|
+ .set(BaseAlarm::getHandleTime,LocalDateTime.now())
|
|
|
+ .eq(BaseAlarm::getDeviceId,list.get(i).getDeviceId())
|
|
|
+ .eq(BaseAlarm::getHandleStatus,0)
|
|
|
+ .eq(BaseAlarm::getProductCode,list.get(i).getProductCode());
|
|
|
+ this.update(updateWrapper1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ for(int j=0;j<devInfoList.size();j++){
|
|
|
+ if(list.get(i).getDeviceId().equals(devInfoList.get(j).getDeviceId()) && list.get(i).getProductCode().equals(devInfoList.get(j).getProductCode())){
|
|
|
+ int count = 0;
|
|
|
+ for(int k=0;k<baseUnAlarmList.size();k++){
|
|
|
+ if(list.get(i).getDeviceId().equals(baseUnAlarmList.get(k).getDeviceId()) && list.get(i).getProductCode().equals(baseUnAlarmList.get(k).getProductCode())){
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(count == 0){
|
|
|
+ BaseAlarm baseAlarm = new BaseAlarm();
|
|
|
+ baseAlarm.setDeviceId(list.get(i).getDeviceId());
|
|
|
+ baseAlarm.setAlarmTime(LocalDateTime.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"))+":00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ baseAlarm.setAlarmType("001");
|
|
|
+ baseAlarm.setAlarmObject(devInfoList.get(j).getDeviceName());
|
|
|
+ baseAlarm.setAlarmData("");
|
|
|
+ baseAlarm.setAlarmAttribute("离线告警");
|
|
|
+ baseAlarm.setAlarmContent("设备离线告警");
|
|
|
+ baseAlarm.setAlarmGrade(1);
|
|
|
+
|
|
|
+ baseAlarm.setAlarmAddress(devInfoList.get(j).getInstallAddress());
|
|
|
+ baseAlarm.setProductCode(devInfoList.get(j).getProductCode());
|
|
|
+ this.add(baseAlarm);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("定时同步设备告警数据 end");
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void deviceOffLineAlarm(){
|
|
|
- log.info("定时同步设备告警数据 start");
|
|
|
List<StatusVO> list = new ArrayList<>();
|
|
|
List<String> devList = new ArrayList<>();
|
|
|
LambdaQueryWrapper<DmpDeviceStatus> queryWrapper = Wrappers.lambdaQuery();
|
|
@@ -646,69 +709,13 @@ public class BaseAlarmServiceImpl extends AbstractCrudService<BaseAlarmMapper, B
|
|
|
if(CollectionUtils.isNotEmpty(list)){
|
|
|
List<DmpDeviceInfo> devInfoList = new ArrayList<>();
|
|
|
List<BaseAlarm> baseUnAlarmList = new ArrayList<>();
|
|
|
-// List<BaseAlarm> baseAlarmList = new ArrayList<>();
|
|
|
if(devList.size() > 0) {
|
|
|
devInfoList = baseMapper.getDeviceInfoList(devList);
|
|
|
baseUnAlarmList = baseMapper.getUnDeviceAlarmList(devList);
|
|
|
-// baseAlarmList = baseMapper.getDeviceAlarmList(devList);
|
|
|
- }
|
|
|
-
|
|
|
- if(CollectionUtils.isNotEmpty(devInfoList)){
|
|
|
- for(int i=0;i<list.size();i++){
|
|
|
- String currentDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
- if(Objects.nonNull(list.get(i).getTime()) && currentDate.equals(list.get(i).getTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))){
|
|
|
- //设备离线告警恢复在线自动默认处理
|
|
|
- if(CollectionUtils.isNotEmpty(baseUnAlarmList)){
|
|
|
- for(int j=0;j<baseUnAlarmList.size();j++){
|
|
|
- if(list.get(i).getDeviceId().equals(baseUnAlarmList.get(j).getDeviceId()) && list.get(i).getProductCode().equals(baseUnAlarmList.get(j).getProductCode())){
|
|
|
- LambdaUpdateWrapper<BaseAlarm> updateWrapper1 = Wrappers.lambdaUpdate();
|
|
|
- updateWrapper1.set(BaseAlarm::getHandleStatus,1)
|
|
|
- .set(BaseAlarm::getHandleBy,"YT_admin")
|
|
|
- .set(BaseAlarm::getHandleTime,LocalDateTime.now())
|
|
|
- .eq(BaseAlarm::getDeviceId,list.get(i).getDeviceId())
|
|
|
- .eq(BaseAlarm::getHandleStatus,0)
|
|
|
- .eq(BaseAlarm::getProductCode,list.get(i).getProductCode());
|
|
|
- this.update(updateWrapper1);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }else{
|
|
|
-
|
|
|
- for(int j=0;j<devInfoList.size();j++){
|
|
|
- if(list.get(i).getDeviceId().equals(devInfoList.get(j).getDeviceId()) && list.get(i).getProductCode().equals(devInfoList.get(j).getProductCode())){
|
|
|
- int count = 0;
|
|
|
- for(int k=0;k<baseUnAlarmList.size();k++){
|
|
|
- if(list.get(i).getDeviceId().equals(baseUnAlarmList.get(k).getDeviceId()) && list.get(i).getProductCode().equals(baseUnAlarmList.get(k).getProductCode())){
|
|
|
- count++;
|
|
|
- }
|
|
|
- }
|
|
|
- if(count == 0){
|
|
|
- BaseAlarm baseAlarm = new BaseAlarm();
|
|
|
- baseAlarm.setDeviceId(list.get(i).getDeviceId());
|
|
|
- baseAlarm.setAlarmTime(LocalDateTime.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"))+":00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- baseAlarm.setAlarmType("001");
|
|
|
- baseAlarm.setAlarmObject(devInfoList.get(j).getDeviceName());
|
|
|
- baseAlarm.setAlarmData("");
|
|
|
- baseAlarm.setAlarmAttribute("离线告警");
|
|
|
- baseAlarm.setAlarmContent("设备离线告警");
|
|
|
- baseAlarm.setAlarmGrade(1);
|
|
|
-
|
|
|
- baseAlarm.setAlarmAddress(devInfoList.get(j).getInstallAddress());
|
|
|
- baseAlarm.setProductCode(devInfoList.get(j).getProductCode());
|
|
|
- this.add(baseAlarm);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
+ this.deviceAlarm(list,devInfoList,baseUnAlarmList);
|
|
|
}
|
|
|
- log.info("定时同步设备告警数据 end");
|
|
|
}
|
|
|
|
|
|
@Override
|