|
@@ -1,9 +1,11 @@
|
|
|
package com.bizmatics.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.bizmatics.common.core.exception.BusinessException;
|
|
|
import com.bizmatics.common.core.util.BeanMapperUtils;
|
|
|
+import com.bizmatics.model.AlarmPower;
|
|
|
import com.bizmatics.model.Device;
|
|
|
import com.bizmatics.model.Site;
|
|
|
import com.bizmatics.persistence.mapper.AlarmPowerMapper;
|
|
@@ -13,16 +15,19 @@ import com.bizmatics.service.DeviceService;
|
|
|
import com.bizmatics.service.SiteService;
|
|
|
import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
import com.bizmatics.service.enums.DeviceStatusCode;
|
|
|
+import com.bizmatics.service.enums.DeviceType;
|
|
|
import com.bizmatics.service.util.SessionLocal;
|
|
|
import com.bizmatics.service.vo.DeviceCountVO;
|
|
|
import com.bizmatics.service.vo.SiteVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import net.sf.ehcache.search.parser.MAggregate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -41,6 +46,8 @@ public class SiteServiceImpl extends AbstractCrudService<SiteMapper, Site> imple
|
|
|
|
|
|
@Autowired
|
|
|
private DeviceService deviceService;
|
|
|
+ @Autowired
|
|
|
+ private AlarmPowerMapper alarmPowerMapper;
|
|
|
@Override
|
|
|
public DeviceCountVO selectCount() {
|
|
|
Integer userId = SessionLocal.getUserId();
|
|
@@ -64,36 +71,49 @@ public class SiteServiceImpl extends AbstractCrudService<SiteMapper, Site> imple
|
|
|
Integer userId = SessionLocal.getUserId();
|
|
|
List<Site> sites = baseMapper.list(SessionLocal.getUserId(), name);
|
|
|
List<Device> deviceList = deviceMapper.list(userId, null, null, null, null, null);
|
|
|
- sites.forEach(site -> list.add(enhanceSite(deviceList,site)));
|
|
|
+ List<AlarmPower> alarmPowers = alarmPowerMapper.list(userId, null, null, null, null, null, 1);
|
|
|
+ sites.forEach(site -> list.add(enhanceSite(deviceList,site,alarmPowers)));
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public SiteVO getOne(Long siteId) {
|
|
|
Site site = baseMapper.selectOne(Wrappers.lambdaQuery(Site.class).eq(Site::getId, siteId));
|
|
|
- List<String> deviceType = new ArrayList<>();
|
|
|
- LambdaQueryWrapper<Device> deviceLambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
- deviceLambdaQueryWrapper.eq(Device::getSiteId,site.getId());
|
|
|
- List<Device> list = deviceService.list(deviceLambdaQueryWrapper);
|
|
|
- list.forEach(device -> deviceType.add(DeviceStatusCode.pase(Integer.parseInt(device.getDeviceType())).getDescribe()));
|
|
|
return Optional.ofNullable(site)
|
|
|
.map(st -> {
|
|
|
- SiteVO map = BeanMapperUtils.map(site, SiteVO.class);
|
|
|
- map.setDeviceType(deviceType);
|
|
|
- return map;
|
|
|
+ LambdaQueryWrapper<Device> deviceLambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
+ deviceLambdaQueryWrapper.eq(Device::getSiteId,site.getId());
|
|
|
+ List<Device> list = deviceService.list(deviceLambdaQueryWrapper);
|
|
|
+ Integer count = alarmPowerMapper.selectCount(null, site.getId(), null, null, null, null, 1);
|
|
|
+ SiteVO siteVO = enhanceSite(list, site, null);
|
|
|
+ siteVO.setAlarmPowerCount(count);
|
|
|
+ return siteVO;
|
|
|
})
|
|
|
.orElseThrow(() -> new BusinessException("站点信息不存在"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
- public SiteVO enhanceSite(List<Device> list,Site site){
|
|
|
+ public SiteVO enhanceSite(List<Device> list,Site site,List<AlarmPower> alarmPowers){
|
|
|
SiteVO siteVo = BeanMapperUtils.map(site, SiteVO.class);
|
|
|
siteVo.setDeviceCount(list.size());
|
|
|
- long deviceCount = list.stream().filter(device -> DeviceStatusCode.DEVICE.getValue().equals(device.getDeviceStatus())).count();
|
|
|
- long faultCount = list.stream().filter(device -> DeviceStatusCode.FAULT.getValue().equals(device.getDeviceStatus())).count();
|
|
|
- long offCount = list.stream().filter(device -> DeviceStatusCode.OFFLINE.getValue().equals(device.getDeviceStatus())).count();
|
|
|
-// siteVo.setAlarmPowerCount(alarmPowerMapper.selectCount(userId,site.getId(),null,null,null,null,1));
|
|
|
+ long deviceCount = list.stream()
|
|
|
+ .filter(device -> device.getSiteId().equals(site.getId()))
|
|
|
+ .filter(device -> DeviceStatusCode.DEVICE.getValue().equals(device.getDeviceStatus()))
|
|
|
+ .count();
|
|
|
+ long faultCount = list.stream()
|
|
|
+ .filter(device -> device.getSiteId().equals(site.getId()))
|
|
|
+ .filter(device -> DeviceStatusCode.FAULT.getValue().equals(device.getDeviceStatus()))
|
|
|
+ .count();
|
|
|
+ long offCount = list.stream()
|
|
|
+ .filter(device -> device.getSiteId().equals(site.getId()))
|
|
|
+ .filter(device -> DeviceStatusCode.OFFLINE.getValue().equals(device.getDeviceStatus()))
|
|
|
+ .count();
|
|
|
+ if (CollectionUtils.isNotEmpty(alarmPowers)){
|
|
|
+ siteVo.setAlarmPowerCount((int) alarmPowers.stream().filter(alarmPower -> alarmPower.getSiteId().equals(site.getId())).count());
|
|
|
+ }else {
|
|
|
+ siteVo.setAlarmPowerCount(0);
|
|
|
+ }
|
|
|
if (deviceCount > 0){
|
|
|
siteVo.setStatus(DeviceStatusCode.FAULT.getDescribe());
|
|
|
}else if (offCount > 0){
|
|
@@ -103,6 +123,11 @@ public class SiteServiceImpl extends AbstractCrudService<SiteMapper, Site> imple
|
|
|
}else {
|
|
|
siteVo.setStatus(DeviceStatusCode.NORMAL.getDescribe());
|
|
|
}
|
|
|
+ List<String> deviceType = new ArrayList<>();
|
|
|
+ list.stream()
|
|
|
+ .filter(device -> device.getSiteId().equals(site.getId()))
|
|
|
+ .forEach(device -> deviceType.add(DeviceType.pase(device.getDeviceType()).getName()));
|
|
|
+ siteVo.setDeviceType(deviceType);
|
|
|
return siteVo;
|
|
|
}
|
|
|
}
|