|
|
@@ -6,16 +6,12 @@ import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.*;
|
|
|
import com.yunfeiyun.agmp.iots.warn.mapper.IotWarnBussinessMapper;
|
|
|
-import com.yunfeiyun.agmp.iots.warn.model.IotWarnconfigCbdInfoVo;
|
|
|
-import com.yunfeiyun.agmp.iots.warn.model.IotWarnconfigDevVo;
|
|
|
-import com.yunfeiyun.agmp.iots.warn.model.WarnConfigInfo;
|
|
|
-import com.yunfeiyun.agmp.iots.warn.model.WarnResult;
|
|
|
+import com.yunfeiyun.agmp.iots.warn.model.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
-import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
|
-import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
|
+import org.springframework.data.mongodb.core.aggregation.*;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -194,34 +190,47 @@ public class IotWarnBussinessService {
|
|
|
/**
|
|
|
* 统计设备的虫子种类数量
|
|
|
*
|
|
|
- * @param devBid 设备业务标识
|
|
|
+ * @param devBid 设备业务标识
|
|
|
* @param startTime 开始时间
|
|
|
* @param endTime 结束时间
|
|
|
* @return 虫子种类数量
|
|
|
*/
|
|
|
public int statPestTypeCountByDevBid(String devBid, String startTime, String endTime) {
|
|
|
- Query query = new Query();
|
|
|
+ // 创建匹配条件
|
|
|
+ MatchOperation matchOperation = Aggregation.match(
|
|
|
+ new Criteria().andOperator(
|
|
|
+ Criteria.where("devBid").is(devBid),
|
|
|
+ Criteria.where("pestrecogCreatedDate").gte(startTime).lte(endTime)
|
|
|
+ )
|
|
|
+ );
|
|
|
|
|
|
- // 添加条件:设备业务标识
|
|
|
- query.addCriteria(Criteria.where("devBid").is(devBid));
|
|
|
+ // 分组操作,按pestBusid分组
|
|
|
+ GroupOperation groupOperation = Aggregation.group("pestBusid");
|
|
|
|
|
|
- // 添加条件:创建时间在指定范围内
|
|
|
- query.addCriteria(Criteria.where("pestrecogCreatedDate").gte(startTime).lte(endTime));
|
|
|
+ // 计数操作
|
|
|
+ CountOperation countOperation = Aggregation.count().as("pestTypesCount");
|
|
|
|
|
|
- // 只查询害虫业务标识字段
|
|
|
- query.fields().include("pestBusid");
|
|
|
+ // 构建聚合管道
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(matchOperation, groupOperation, countOperation);
|
|
|
|
|
|
- // 去重查询害虫业务标识
|
|
|
- List<String> pestTypes = mongoTemplate.findDistinct(query, "pestBusid", IotPestrecog.class, String.class);
|
|
|
+ // 执行聚合查询
|
|
|
+ AggregationResults<CountResultDto> results = mongoTemplate.aggregate(aggregation, "IotPestrecog", CountResultDto.class);
|
|
|
+
|
|
|
+ // 获取结果
|
|
|
+ List<CountResultDto> mappedResults = results.getMappedResults();
|
|
|
+ if (mappedResults != null && !mappedResults.isEmpty()) {
|
|
|
+ return mappedResults.get(0).getPestTypesCount();
|
|
|
+ }
|
|
|
|
|
|
- // 返回去重后的害虫类型数量
|
|
|
- return pestTypes.size();
|
|
|
+ // 如果没有结果,则返回0
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 统计设备的虫子总数量
|
|
|
*
|
|
|
- * @param devBid 设备业务标识
|
|
|
+ * @param devBid 设备业务标识
|
|
|
* @param startTime 开始时间
|
|
|
* @param endTime 结束时间
|
|
|
* @return 虫子总数量
|
|
|
@@ -280,13 +289,13 @@ public class IotWarnBussinessService {
|
|
|
* @param iotWarnindicator 告警指标,存储所有与告警相关的指标信息
|
|
|
* @return 告警指标,存储所有与告警相关的指标信息集合
|
|
|
*/
|
|
|
- public Map<String, List<IotWarnindicator>> selectIotWarnindicatorMap(IotWarnindicator iotWarnindicator){
|
|
|
+ public Map<String, List<IotWarnindicator>> selectIotWarnindicatorMap(IotWarnindicator iotWarnindicator) {
|
|
|
List<IotWarnindicator> iotWarnindicatorList = iotWarnBussinessMapper.selectIotWarnindicatorList(iotWarnindicator);
|
|
|
Map<String, List<IotWarnindicator>> iotWarnindicatorMap = new HashMap<>();
|
|
|
- for(IotWarnindicator item: iotWarnindicatorList){
|
|
|
+ for (IotWarnindicator item : iotWarnindicatorList) {
|
|
|
String wcBid = item.getWcBid();
|
|
|
- if(!iotWarnindicatorMap.containsKey(wcBid)){
|
|
|
- iotWarnindicatorMap.put(wcBid,new ArrayList<>());
|
|
|
+ if (!iotWarnindicatorMap.containsKey(wcBid)) {
|
|
|
+ iotWarnindicatorMap.put(wcBid, new ArrayList<>());
|
|
|
}
|
|
|
iotWarnindicatorMap.get(wcBid).add(item);
|
|
|
}
|
|
|
@@ -295,16 +304,17 @@ public class IotWarnBussinessService {
|
|
|
|
|
|
/**
|
|
|
* 查询测报灯设备所有告警配置信息
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
|
|
|
- public Map<String, List<IotWarnindicator>> selectCbdIndicatorAllMap(){
|
|
|
+ public Map<String, List<IotWarnindicator>> selectCbdIndicatorAllMap() {
|
|
|
List<IotWarnindicator> iotWarnindicators = iotWarnBussinessMapper.selectCbdIndicatorAllList();
|
|
|
Map<String, List<IotWarnindicator>> iotWarnindicatorMap = new LinkedHashMap<>();
|
|
|
- for(IotWarnindicator iotWarnindicator : iotWarnindicators){
|
|
|
+ for (IotWarnindicator iotWarnindicator : iotWarnindicators) {
|
|
|
String wcBid = iotWarnindicator.getWcBid();
|
|
|
- if(!iotWarnindicatorMap.containsKey(wcBid)){
|
|
|
- iotWarnindicatorMap.put(wcBid,new ArrayList<>());
|
|
|
+ if (!iotWarnindicatorMap.containsKey(wcBid)) {
|
|
|
+ iotWarnindicatorMap.put(wcBid, new ArrayList<>());
|
|
|
}
|
|
|
iotWarnindicatorMap.get(wcBid).add(iotWarnindicator);
|
|
|
}
|
|
|
@@ -322,12 +332,12 @@ public class IotWarnBussinessService {
|
|
|
Map<String, List<IotWarnindicator>> iotWarnindicatorMap = selectCbdIndicatorAllMap();
|
|
|
List<IotWarnconfigCbdInfoVo> iotWarnconfigCbdInfoVoList = new ArrayList<>();
|
|
|
List<String> parentbidList = new ArrayList<>();
|
|
|
- for(IotWarnconfigDevVo iotWarnconfigDevVo : iotWarnconfigDevVoList){
|
|
|
+ for (IotWarnconfigDevVo iotWarnconfigDevVo : iotWarnconfigDevVoList) {
|
|
|
String wcBid = iotWarnconfigDevVo.getWcBid();
|
|
|
List<IotWarnindicator> iotWarnindicatorList = iotWarnindicatorMap.get(wcBid);
|
|
|
- for(IotWarnindicator item: iotWarnindicatorList){
|
|
|
+ for (IotWarnindicator item : iotWarnindicatorList) {
|
|
|
String wiCode = item.getWiCode();
|
|
|
- if("pestDetail".equals(wiCode)){
|
|
|
+ if ("pestDetail".equals(wiCode)) {
|
|
|
parentbidList.add(item.getWiBid());
|
|
|
}
|
|
|
}
|
|
|
@@ -340,17 +350,17 @@ public class IotWarnBussinessService {
|
|
|
iotWarnconfigCbdInfoVo.setIotWarnindicatorList(iotWarnindicatorList);
|
|
|
iotWarnconfigCbdInfoVoList.add(iotWarnconfigCbdInfoVo);
|
|
|
}
|
|
|
- if(!parentbidList.isEmpty()){
|
|
|
+ if (!parentbidList.isEmpty()) {
|
|
|
IotWarnindicator selectIotWarnindicator = new IotWarnindicator();
|
|
|
selectIotWarnindicator.setWiParentbidList(parentbidList);
|
|
|
Map<String, List<IotWarnindicator>> iotMap = selectIotWarnindicatorMap(selectIotWarnindicator);
|
|
|
- for(IotWarnconfigCbdInfoVo cbdInfoVo : iotWarnconfigCbdInfoVoList){
|
|
|
+ for (IotWarnconfigCbdInfoVo cbdInfoVo : iotWarnconfigCbdInfoVoList) {
|
|
|
String wcBid = cbdInfoVo.getWcBid();
|
|
|
List<IotWarnindicator> pestDetailList = iotMap.get(wcBid);
|
|
|
List<IotWarnindicator> iotWarnindicatorList = cbdInfoVo.getIotWarnindicatorList();
|
|
|
- for(IotWarnindicator item: iotWarnindicatorList){
|
|
|
+ for (IotWarnindicator item : iotWarnindicatorList) {
|
|
|
String wiCode = item.getWiCode();
|
|
|
- if("pestDetail".equals(wiCode)){
|
|
|
+ if ("pestDetail".equals(wiCode)) {
|
|
|
item.setChildrenList(pestDetailList);
|
|
|
}
|
|
|
}
|