|
|
@@ -1,14 +1,21 @@
|
|
|
package com.usky.ems.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.ems.domain.BaseSpace;
|
|
|
+import com.usky.ems.domain.BaseSpaceGateway;
|
|
|
+import com.usky.ems.domain.DmpDevice;
|
|
|
import com.usky.ems.domain.EmsDeviceItemCode;
|
|
|
+import com.usky.ems.domain.EmsEnergyItemCode;
|
|
|
import com.usky.ems.domain.EmsProductEnergyType;
|
|
|
import com.usky.ems.domain.EmsProject;
|
|
|
import com.usky.ems.domain.EmsProjectDeviceSystem;
|
|
|
+import com.usky.ems.mapper.BaseSpaceGatewayMapper;
|
|
|
+import com.usky.ems.mapper.DmpDeviceMapper;
|
|
|
import com.usky.ems.mapper.EmsDeviceItemCodeMapper;
|
|
|
+import com.usky.ems.mapper.EmsEnergyItemCodeMapper;
|
|
|
import com.usky.ems.mapper.EmsProductEnergyTypeMapper;
|
|
|
import com.usky.ems.mapper.EmsProjectDeviceSystemMapper;
|
|
|
import com.usky.ems.mapper.EmsProjectMapper;
|
|
|
@@ -26,9 +33,11 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 项目维护实现(逻辑参考原 ProjectServiceImpl:省市区校验、创建项目空间、设备系统关联、删除前校验叶子节点等)
|
|
|
@@ -50,6 +59,12 @@ public class EmsProjectServiceImpl implements EmsProjectService {
|
|
|
private EmsProductEnergyTypeMapper emsProductEnergyTypeMapper;
|
|
|
@Autowired
|
|
|
private EmsDeviceItemCodeMapper emsDeviceItemCodeMapper;
|
|
|
+ @Autowired
|
|
|
+ private BaseSpaceGatewayMapper baseSpaceGatewayMapper;
|
|
|
+ @Autowired
|
|
|
+ private DmpDeviceMapper dmpDeviceMapper;
|
|
|
+ @Autowired
|
|
|
+ private EmsEnergyItemCodeMapper emsEnergyItemCodeMapper;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -182,6 +197,82 @@ public class EmsProjectServiceImpl implements EmsProjectService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<DmpDevice> listAreaDevices(Integer spaceId) {
|
|
|
+ List<String> gatewayUuids = resolveGatewayUuidsBySpaceId(spaceId);
|
|
|
+ if (gatewayUuids.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return dmpDeviceMapper.selectList(
|
|
|
+ Wrappers.<DmpDevice>lambdaQuery()
|
|
|
+ .in(DmpDevice::getGatewayUuid, gatewayUuids)
|
|
|
+ .eq(DmpDevice::getCategoryType, 3)
|
|
|
+ .eq(DmpDevice::getDeleteFlag, 0));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EmsEnergyItemCode> listAreaDeviceItemCodes(Integer spaceId) {
|
|
|
+ List<DmpDevice> devices = listAreaDevices(spaceId);
|
|
|
+ if (devices.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<String> deviceUuids = devices.stream()
|
|
|
+ .map(DmpDevice::getDeviceUuid)
|
|
|
+ .filter(StringUtils::hasText)
|
|
|
+ .map(String::trim)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (deviceUuids.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<EmsDeviceItemCode> deviceItemCodes = emsDeviceItemCodeMapper.selectList(
|
|
|
+ Wrappers.<EmsDeviceItemCode>lambdaQuery()
|
|
|
+ .in(EmsDeviceItemCode::getDeviceUuid, deviceUuids)
|
|
|
+ .eq(EmsDeviceItemCode::getTenantId, SecurityUtils.getTenantId()));
|
|
|
+ if (deviceItemCodes.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<String> itemCodes = deviceItemCodes.stream()
|
|
|
+ .map(EmsDeviceItemCode::getItemCode)
|
|
|
+ .filter(StringUtils::hasText)
|
|
|
+ .map(String::trim)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (itemCodes.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return emsEnergyItemCodeMapper.selectList(
|
|
|
+ Wrappers.<EmsEnergyItemCode>lambdaQuery()
|
|
|
+ .in(EmsEnergyItemCode::getCode, itemCodes)
|
|
|
+ .orderByAsc(EmsEnergyItemCode::getCode));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> resolveGatewayUuidsBySpaceId(Integer spaceId) {
|
|
|
+ if (spaceId == null) {
|
|
|
+ throw new BusinessException("空间id不能为空");
|
|
|
+ }
|
|
|
+ BaseSpace space = baseSpaceService.getById(spaceId.longValue());
|
|
|
+ if (space == null) {
|
|
|
+ throw new BusinessException("空间不存在");
|
|
|
+ }
|
|
|
+ List<Long> spaceIds = baseSpaceService.getAuthorizedSpaceIds(space.getId());
|
|
|
+ if (spaceIds.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<BaseSpaceGateway> links = baseSpaceGatewayMapper.selectList(
|
|
|
+ Wrappers.<BaseSpaceGateway>lambdaQuery()
|
|
|
+ .in(BaseSpaceGateway::getSpaceId, spaceIds));
|
|
|
+ if (CollectionUtils.isEmpty(links)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ return links.stream()
|
|
|
+ .map(BaseSpaceGateway::getGatewayUuid)
|
|
|
+ .filter(StringUtils::hasText)
|
|
|
+ .map(String::trim)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 对应原 UserService.hasLoggedUser(projectId)。接入统一用户/权限模块后可在此查询用户与项目绑定关系。
|
|
|
*/
|