|
|
@@ -1,11 +1,13 @@
|
|
|
package com.xunmei.iot.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.lang.Pair;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.IotServerInfo;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.IotAlarmRule;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleExpress;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleSource;
|
|
|
@@ -17,12 +19,17 @@ import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
import com.xunmei.iot.dto.alarm.IotAlarmRuleDto;
|
|
|
import com.xunmei.iot.dto.alarm.IotAlarmRuleExpressDto;
|
|
|
+import com.xunmei.iot.dto.alarm.IotAlarmRuleQueryDto;
|
|
|
import com.xunmei.iot.mapper.IotAlarmRuleMapper;
|
|
|
import com.xunmei.iot.mapper.IotAlarmRuleSourceMapper;
|
|
|
import com.xunmei.iot.mapper.IotAlarmSystemFieldMapper;
|
|
|
import com.xunmei.iot.service.IotAlarmRuleExpressService;
|
|
|
import com.xunmei.iot.service.IotAlarmRuleService;
|
|
|
+import com.xunmei.iot.service.IotServerInfoService;
|
|
|
import com.xunmei.iot.vo.alarm.*;
|
|
|
+import com.xunmei.system.api.RemoteOrgService;
|
|
|
+import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -42,12 +49,19 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
|
|
|
@Autowired
|
|
|
private IotAlarmRuleSourceMapper iotAlarmRuleSourceMapper;
|
|
|
+ @Autowired
|
|
|
+ private RemoteOrgService orgService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IotServerInfoService serverInfoService;
|
|
|
|
|
|
@Override
|
|
|
public IotInitAlarmRuleVo getAddInitAlarmRuleData() throws Exception {
|
|
|
-
|
|
|
IotInitAlarmRuleVo ruleVo = new IotInitAlarmRuleVo();
|
|
|
- LambdaQueryWrapper<IotAlarmSystemField> lqw = new LambdaQueryWrapper<IotAlarmSystemField>().eq(IotAlarmSystemField::getEnable, 1).eq(IotAlarmSystemField::getAlarmRuleProperty,1).orderByDesc(IotAlarmSystemField::getId);
|
|
|
+ LambdaQueryWrapper<IotAlarmSystemField> lqw = new LambdaQueryWrapper<IotAlarmSystemField>()
|
|
|
+ .eq(IotAlarmSystemField::getEnable, 1)
|
|
|
+ .eq(IotAlarmSystemField::getAlarmRuleProperty, 1)
|
|
|
+ .orderByDesc(IotAlarmSystemField::getId);
|
|
|
List<IotAlarmSystemField> systemFieldList = iotAlarmSystemFieldMapper.selectList(lqw);
|
|
|
//
|
|
|
List<IotAlarmSystemFieldVo> appAlarmSystemFieldVoList = new ArrayList<>();
|
|
|
@@ -82,19 +96,20 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
appAlarmSystemFieldVo.setOperatorsList(operatorsList);
|
|
|
appAlarmSystemFieldVoList.add(appAlarmSystemFieldVo);
|
|
|
}
|
|
|
- Map<Integer, List<IotAlarmSystemFieldVo>> appAlarmSystemFieldVoMapList = appAlarmSystemFieldVoList.stream().collect(Collectors.groupingBy(r -> r.getSourceType()));
|
|
|
+ Map<String, List<IotAlarmSystemFieldVo>> appAlarmSystemFieldVoMapList = appAlarmSystemFieldVoList.stream().collect(Collectors.groupingBy(IotAlarmSystemFieldVo::getProductType));
|
|
|
List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
- for (Integer key : appAlarmSystemFieldVoMapList.keySet()) {
|
|
|
+ for (String key : appAlarmSystemFieldVoMapList.keySet()) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
List<IotAlarmSystemFieldVo> systemFieldVos = appAlarmSystemFieldVoMapList.get(key);
|
|
|
- map.put("sourceTypeDes", systemFieldVos.get(0).getSourceTypeDes());
|
|
|
- map.put("sourceType", systemFieldVos.get(0).getSourceType());
|
|
|
+ map.put("sourceTypeDes", systemFieldVos.get(0).getProductName());
|
|
|
+ map.put("sourceType", systemFieldVos.get(0).getProductType());
|
|
|
map.put("smsType", systemFieldVos.get(0).getSmsType());
|
|
|
+ map.put("order", systemFieldVos.get(0).getOrder());
|
|
|
List<Map<String, Object>> systemFieldsList = new ArrayList<>();
|
|
|
for (IotAlarmSystemFieldVo vo : systemFieldVos) {
|
|
|
Map<String, Object> mapa = new HashMap<>();
|
|
|
- mapa.put("sysFieldCode", vo.getSysFieldCode());
|
|
|
- mapa.put("name", vo.getName());
|
|
|
+ mapa.put("sysFieldCode", vo.getProductProperty());
|
|
|
+ mapa.put("name", vo.getProductPropertyDisplayName());
|
|
|
mapa.put("specsList", vo.getSpecsList());
|
|
|
mapa.put("operatorsList", vo.getOperatorsList());
|
|
|
mapa.put("type", vo.getType());
|
|
|
@@ -105,6 +120,8 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
map.put("systemFields", systemFieldsList);
|
|
|
mapList.add(map);
|
|
|
}
|
|
|
+ Comparator<Map<String, Object>> comparator = Comparator.comparing(map -> (Comparable) map.get("order"));
|
|
|
+ mapList = mapList.stream().sorted(comparator).collect(Collectors.toList());
|
|
|
ruleVo.setSourceTypeList(mapList);
|
|
|
return ruleVo;
|
|
|
}
|
|
|
@@ -125,11 +142,13 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
for (IotAlarmRuleExpress express : appAlarmRuleExpressList) {
|
|
|
IotAlarmRuleExpressEditVo expressNew = new IotAlarmRuleExpressEditVo();
|
|
|
BeanHelper.copyProperties(expressNew, express);
|
|
|
+ expressNew.setSourceType(express.getProductType());
|
|
|
+ expressNew.setFieldcode(express.getProductProperty());
|
|
|
appAlarmRuleExpressEditVos.add(expressNew);
|
|
|
}
|
|
|
- Map<Integer, List<IotAlarmRuleExpressEditVo>> appAlarmSystemFieldVoMapList = appAlarmRuleExpressEditVos.stream().collect(Collectors.groupingBy(r -> r.getSourceType()));
|
|
|
+ Map<String, List<IotAlarmRuleExpressEditVo>> appAlarmSystemFieldVoMapList = appAlarmRuleExpressEditVos.stream().collect(Collectors.groupingBy(IotAlarmRuleExpressEditVo::getSourceType));
|
|
|
List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
- for (Integer key : appAlarmSystemFieldVoMapList.keySet()) {
|
|
|
+ for (String key : appAlarmSystemFieldVoMapList.keySet()) {
|
|
|
Map<String, Object> map = new HashMap();
|
|
|
map.put("sourceType", key);
|
|
|
map.put("appAlarmRuleExpressList", appAlarmSystemFieldVoMapList.get(key));
|
|
|
@@ -140,19 +159,12 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public TableDataInfo<IotInitAlarmRuleVo> getAlarmRuleDatas(String alarmType, String ruleName, Long pageIndex, Long pageSize) throws Exception {
|
|
|
- LambdaQueryWrapper<IotAlarmRule> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- if(alarmType!=null && !alarmType.isEmpty())
|
|
|
- {
|
|
|
- queryWrapper.eq(IotAlarmRule::getType,alarmType);
|
|
|
- }
|
|
|
- if(ruleName !=null && !ruleName.isEmpty())
|
|
|
- {
|
|
|
- queryWrapper.like(IotAlarmRule::getName,ruleName);
|
|
|
+ public TableDataInfo<IotInitAlarmRuleVo> getAlarmRuleData(IotAlarmRuleQueryDto args) throws Exception {
|
|
|
+ if (args.getCheckSub()) {
|
|
|
+ final SysOrg sysOrg = orgService.selectOrgById(args.getOrgId(), SecurityConstants.INNER);
|
|
|
+ args.setOrgPath(sysOrg.getPath());
|
|
|
}
|
|
|
- Page<IotAlarmRule> page = new Page<>(pageIndex,pageSize);
|
|
|
-
|
|
|
- IPage<IotAlarmRule> appAlarmRule= this.baseMapper.selectPage(page,queryWrapper);
|
|
|
+ IPage<IotAlarmRule> appAlarmRule = this.baseMapper.selectPageData(args.getPageRequest(), args);
|
|
|
|
|
|
List<IotInitAlarmRuleVo> datas = new ArrayList<>();
|
|
|
appAlarmRule.getRecords().stream().forEach(i -> {
|
|
|
@@ -163,7 +175,7 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- TableDataInfo<IotInitAlarmRuleVo> pageDatas= TableDataInfo.build(datas);
|
|
|
+ TableDataInfo<IotInitAlarmRuleVo> pageDatas = TableDataInfo.build(datas);
|
|
|
pageDatas.setCode(200);
|
|
|
pageDatas.setTotal(appAlarmRule.getTotal());
|
|
|
return pageDatas;
|
|
|
@@ -178,12 +190,12 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
rule.setId(IDHelper.id());
|
|
|
rule.setCreateTime(LocalDateTime.now());
|
|
|
rule.setCreateBy(SecurityUtils.getUsername());
|
|
|
- rule.setUpdateBy(SecurityUtils.getUsername());
|
|
|
- rule.setUpdateTime(LocalDateTime.now());
|
|
|
- } else {//修改
|
|
|
- rule.setUpdateBy(SecurityUtils.getUsername());
|
|
|
- rule.setUpdateTime(LocalDateTime.now());
|
|
|
+ rule.setIsdeleted(0);
|
|
|
}
|
|
|
+ rule.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ rule.setUpdateTime(LocalDateTime.now());
|
|
|
+ rule.setOrgId(ruleDto.getOrgId());
|
|
|
+ rule.setIotCode(ruleDto.getIotCode());
|
|
|
List<IotAlarmRuleExpressDto> appAlarmRuleExpressDtos = ruleDto.getIotAlarmRuleExpressDtoList();
|
|
|
List<IotAlarmRuleExpress> appAlarmRuleExpressesList = new ArrayList<>();
|
|
|
if (appAlarmRuleExpressDtos != null && appAlarmRuleExpressDtos.size() > 0) {
|
|
|
@@ -191,6 +203,8 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
IotAlarmRuleExpress express = new IotAlarmRuleExpress();
|
|
|
BeanHelper.copyProperties(express, vo);
|
|
|
express.setRuleId(rule.getId());
|
|
|
+ express.setProductType(vo.getSourceType());
|
|
|
+ express.setProductProperty(vo.getFieldcode());
|
|
|
express.setId(IDHelper.id());
|
|
|
express.setCreateTime(LocalDateTime.now());
|
|
|
express.setUpdateBy(SecurityUtils.getUsername());
|
|
|
@@ -198,8 +212,8 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
appAlarmRuleExpressesList.add(express);
|
|
|
}
|
|
|
}
|
|
|
- Set<Integer> sourceTypes = new HashSet<>();
|
|
|
- appAlarmRuleExpressesList.forEach(r -> sourceTypes.add(r.getSourceType()));
|
|
|
+ Set<String> sourceTypes = new HashSet<>();
|
|
|
+ appAlarmRuleExpressesList.forEach(r -> sourceTypes.add(r.getProductType()));
|
|
|
this.saveOrUpdate(rule);
|
|
|
//规则先删除原来的然重新插入
|
|
|
iotAlarmRuleExpressService.remove(new LambdaQueryWrapper<IotAlarmRuleExpress>().eq(IotAlarmRuleExpress::getRuleId, rule.getId()));
|
|
|
@@ -208,18 +222,26 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void deleteAlarmRule(Long ruleId)
|
|
|
- {
|
|
|
+ public void deleteAlarmRule(Long ruleId) {
|
|
|
LambdaQueryWrapper<IotAlarmRule> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(IotAlarmRule::getId,ruleId);
|
|
|
+ queryWrapper.eq(IotAlarmRule::getId, ruleId);
|
|
|
this.baseMapper.delete(queryWrapper);
|
|
|
LambdaQueryWrapper<IotAlarmRuleExpress> ruleExpressWrapper = new LambdaQueryWrapper<>();
|
|
|
- ruleExpressWrapper.eq(IotAlarmRuleExpress::getRuleId,ruleId);
|
|
|
+ ruleExpressWrapper.eq(IotAlarmRuleExpress::getRuleId, ruleId);
|
|
|
iotAlarmRuleExpressService.remove(ruleExpressWrapper);
|
|
|
|
|
|
//删除绑定设备数据
|
|
|
LambdaQueryWrapper<IotAlarmRuleSource> iots = new LambdaQueryWrapper<>();
|
|
|
- iots.eq(IotAlarmRuleSource::getRuleId,ruleId);
|
|
|
+ iots.eq(IotAlarmRuleSource::getRuleId, ruleId);
|
|
|
iotAlarmRuleSourceMapper.delete(iots);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Pair<String, String>> getConnectHostOrg(Long orgId) {
|
|
|
+ final List<IotServerInfo> connectOrg = serverInfoService.selectConnectOrg(false, orgId, null);
|
|
|
+ if (CollectionUtils.isEmpty(connectOrg)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return connectOrg.stream().map(serverInfo -> Pair.of(serverInfo.getIotName(), serverInfo.getIotCode())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
}
|