|
|
@@ -5,11 +5,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotSensor;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.IotAlarmRule;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleSource;
|
|
|
+import com.xunmei.common.core.enums.OrgTypeEnum;
|
|
|
import com.xunmei.common.core.utils.IDHelper;
|
|
|
import com.xunmei.common.core.utils.StringUtils;
|
|
|
+import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.iot.dto.alarm.IotAlarmRuleSourceDetailDto;
|
|
|
import com.xunmei.iot.dto.alarm.IotAlarmRuleSourceDeviceBatchJoin;
|
|
|
import com.xunmei.iot.dto.alarm.IotAlarmRuleSourceDeviceDto;
|
|
|
@@ -22,14 +25,12 @@ import com.xunmei.iot.mapper.IotAlarmRuleSourceMapper;
|
|
|
import com.xunmei.iot.mapper.IotCommonSensorMapper;
|
|
|
import com.xunmei.iot.service.IotAlarmRuleSourceService;
|
|
|
import com.xunmei.iot.vo.alarm.*;
|
|
|
+import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -60,8 +61,9 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
|
|
|
//2.获取告警规则对应有哪些设备的告警属性规则。
|
|
|
List<ProductTypeDataVo> productTypeDataVos = iotAlarmRuleSourceMapper.selectRuleDevice(detailVo.getRuleId());
|
|
|
//3.处理其他sql获取不了的数据
|
|
|
+ final List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
for (ProductTypeDataVo pdv : productTypeDataVos) {
|
|
|
- dealDevice(pdv);
|
|
|
+ dealDevice(pdv, cacheList);
|
|
|
}
|
|
|
iotAlarmRuleSourceDetailVo.setTypeDataList(productTypeDataVos);
|
|
|
return iotAlarmRuleSourceDetailVo;
|
|
|
@@ -73,9 +75,31 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
|
|
|
page.setSize(param.getSize());
|
|
|
page.setCurrent(param.getPage());
|
|
|
Page<IotAlarmRuleSourceDeviceVo> result = iotAlarmRuleSourceMapper.selectDeviceList(page, param);
|
|
|
+ final List<IotAlarmRuleSourceDeviceVo> records = result.getRecords();
|
|
|
+ if (ObjectUtil.isEmpty(records)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ final List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+
|
|
|
+ for (IotAlarmRuleSourceDeviceVo record : records) {
|
|
|
+ final String orgName = dealOrgName(cacheList, record.getOrgPath(), record.getOrgName());
|
|
|
+ record.setOrgName(orgName);
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private String dealOrgName(List<SysOrgVO> cacheList, String orgPath, String orgName) {
|
|
|
+ List<String> orgNameList = new ArrayList<>();
|
|
|
+ final List<Long> collect = Arrays.stream(orgPath.split("-")).map(Long::parseLong).collect(Collectors.toList());
|
|
|
+ //地区名称
|
|
|
+ cacheList.stream().filter(org -> collect.contains(org.getId()) && OrgTypeEnum.DIQU_HANG_SHE.getCode().equals(org.getType())).findFirst().ifPresent(org -> orgNameList.add(org.getShortName()));
|
|
|
+ //行社名称
|
|
|
+ cacheList.stream().filter(org -> collect.contains(org.getId()) && OrgTypeEnum.HANG_SHE.getCode().equals(org.getType())).findFirst().ifPresent(org -> orgNameList.add(org.getShortName()));
|
|
|
+ orgNameList.add(orgName);
|
|
|
+ return String.join("-", orgNameList);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateRuleAndProductDevice(IotAlarmRuleSourceDetailVo detailDto) throws Exception {
|
|
|
@@ -170,7 +194,7 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
|
|
|
* @param pdv
|
|
|
* @return
|
|
|
*/
|
|
|
- private void dealDevice(ProductTypeDataVo pdv) {
|
|
|
+ private void dealDevice(ProductTypeDataVo pdv, List<SysOrgVO> cacheList) {
|
|
|
String valueType = pdv.getValueType();
|
|
|
|
|
|
if (StringUtils.isEmpty(valueType)) {
|
|
|
@@ -190,15 +214,14 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
|
|
|
List<String> deviceIds = deviceTempList.stream().map(ProductDeviceTempVo::getDeviceId).collect(Collectors.toList());
|
|
|
|
|
|
List<IotSensor> iotSensors = iotCommonSensorMapper.selectByIds(deviceIds);
|
|
|
- final Map<String, List<IotSensor>> deviceIdAndName = iotSensors.stream().collect(Collectors.groupingBy(IotSensor::getDeviceCode));
|
|
|
+ // CONCAT(org_id,'-',device_code) as device_code
|
|
|
+ final Map<String, IotSensor> deviceIdAndName = iotSensors.stream().collect(Collectors.toMap(IotSensor::getDeviceCode, Function.identity()));
|
|
|
for (ProductDeviceTempVo ptv : deviceTempList) {
|
|
|
- final List<IotSensor> sensorList = deviceIdAndName.get(ptv.getDeviceId());
|
|
|
- if (ObjectUtil.isNull(sensorList)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- for (IotSensor iotSensor : sensorList) {
|
|
|
- ptv.setDeviceName(iotSensor.getDeviceName());
|
|
|
- ptv.setOrgName(iotSensor.getOrgName());
|
|
|
+ final IotSensor sensor = deviceIdAndName.get(ptv.getStrDeviceId());
|
|
|
+ if (sensor != null) {
|
|
|
+ ptv.setDeviceName(sensor.getDeviceName());
|
|
|
+ final String orgName = dealOrgName(cacheList, sensor.getOrgPath(), sensor.getOrgName());
|
|
|
+ ptv.setOrgName(orgName);
|
|
|
}
|
|
|
}
|
|
|
}
|