|
|
@@ -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,33 +61,56 @@ 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;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<IotAlarmRuleSourceDeviceVo> selectDeviceList(IotAlarmRuleSourceDeviceDto param)throws Exception {
|
|
|
+ public Page<IotAlarmRuleSourceDeviceVo> selectDeviceList(IotAlarmRuleSourceDeviceDto param) throws Exception {
|
|
|
Page<IotAlarmRuleSourceDeviceVo> page = new Page<>();
|
|
|
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 {
|
|
|
//删除设备绑定数据
|
|
|
LambdaQueryWrapper<IotAlarmRuleSource> qw = new LambdaQueryWrapper<IotAlarmRuleSource>();
|
|
|
- qw.eq(IotAlarmRuleSource::getRuleId,detailDto.getRuleId());
|
|
|
+ qw.eq(IotAlarmRuleSource::getRuleId, detailDto.getRuleId());
|
|
|
iotAlarmRuleSourceMapper.delete(qw);
|
|
|
|
|
|
//重新绑定设置
|
|
|
List<ProductTypeDataVo> deviceData = detailDto.getTypeDataList();
|
|
|
- if(ObjectUtil.isEmpty(deviceData)){
|
|
|
+ if (ObjectUtil.isEmpty(deviceData)) {
|
|
|
return;
|
|
|
}
|
|
|
IotAlarmRuleSource ruleSource = null;
|
|
|
@@ -106,9 +130,9 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
|
|
|
for (ProductDeviceTempVo deviceTempVo : productType.getDeviceTempList()) {
|
|
|
//查询当前设备是否有其他规则绑定,如果有则删除,解绑
|
|
|
QueryWrapper<IotAlarmRuleSource> iqw = new QueryWrapper<>();
|
|
|
- iqw.lambda().eq(IotAlarmRuleSource::getOrgId,deviceTempVo.getOrgId())
|
|
|
- .eq(IotAlarmRuleSource::getValue,deviceTempVo.getDeviceId())
|
|
|
- .eq(IotAlarmRuleSource::getSourceType,productType.getType());
|
|
|
+ iqw.lambda().eq(IotAlarmRuleSource::getOrgId, deviceTempVo.getOrgId())
|
|
|
+ .eq(IotAlarmRuleSource::getValue, deviceTempVo.getDeviceId())
|
|
|
+ .eq(IotAlarmRuleSource::getSourceType, productType.getType());
|
|
|
iotAlarmRuleSourceMapper.delete(iqw);
|
|
|
ruleSource.setId(IDHelper.id());
|
|
|
ruleSource.setOrgId(deviceTempVo.getOrgId());
|
|
|
@@ -135,7 +159,7 @@ public class IotAlarmRuleSourceServiceImpl extends ServiceImpl<IotAlarmRuleSourc
|
|
|
IotSensor productDevice = (IotSensor) hashMap.get(deviceId);
|
|
|
if (productDevice == null) {
|
|
|
QueryWrapper<IotSensor> qw = new QueryWrapper<>();
|
|
|
- qw.lambda().eq(IotSensor::getDeviceCode,deviceId).eq(IotSensor::getDeleted,0);
|
|
|
+ qw.lambda().eq(IotSensor::getDeviceCode, deviceId).eq(IotSensor::getDeleted, 0);
|
|
|
hashMap.put(deviceId, productDevice);
|
|
|
}
|
|
|
String code = productDevice.getDeviceType();
|
|
|
@@ -166,37 +190,39 @@ 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)){
|
|
|
+ if (StringUtils.isEmpty(valueType)) {
|
|
|
//未配置设备关联时
|
|
|
pdv.setIsAllDeviceEnable(false);
|
|
|
pdv.setValueType(ValueTypeEnum.Device.getText());
|
|
|
- }else{
|
|
|
- if(ValueTypeEnum.AllDevice.getText().equals(valueType)){
|
|
|
+ } else {
|
|
|
+ if (ValueTypeEnum.AllDevice.getText().equals(valueType)) {
|
|
|
//配置按设备类型关联时
|
|
|
pdv.setIsAllDeviceEnable(true);
|
|
|
}
|
|
|
|
|
|
- if(ValueTypeEnum.Device.getText().equals(valueType)){
|
|
|
+ if (ValueTypeEnum.Device.getText().equals(valueType)) {
|
|
|
//配置具体设备关联时
|
|
|
List<ProductDeviceTempVo> deviceTempList = pdv.getDeviceTempList();
|
|
|
//获取对应的设备id
|
|
|
List<String> deviceIds = deviceTempList.stream().map(ProductDeviceTempVo::getDeviceId).collect(Collectors.toList());
|
|
|
|
|
|
List<IotSensor> iotSensors = iotCommonSensorMapper.selectByIds(deviceIds);
|
|
|
- Map<String, IotSensor> deviceIdAndName = iotSensors.stream().collect(Collectors.toMap(IotSensor::getDeviceCode, Function.identity()));
|
|
|
+ // 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) {
|
|
|
- IotSensor iotSensor = deviceIdAndName.get(ptv.getDeviceId());
|
|
|
- if( iotSensor!= null){
|
|
|
- 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);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|