|
@@ -7,15 +7,14 @@ import com.yunfeiyun.agmp.iot.common.domain.IotCbdpest;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotCbdrecog;
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotCbdrecog;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotPestrecog;
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotPestrecog;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.resvo.IotScreenCbdStatResVo;
|
|
import com.yunfeiyun.agmp.iot.common.domain.resvo.IotScreenCbdStatResVo;
|
|
|
|
|
+import com.yunfeiyun.agmp.iot.common.enums.EnumCbdMarkType;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
-import com.yunfeiyun.agmp.iot.common.service.mongo.LookupWithPipelineOperation;
|
|
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotCbdimgGroupDateListResVo;
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotCbdimgGroupDateListResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotCbdimgSumInfoResVo;
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotCbdimgSumInfoResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestRecogPeriodReqVo;
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestRecogPeriodReqVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.service.IIotCbdimgService;
|
|
import com.yunfeiyun.agmp.iotm.device.pest.service.IIotCbdimgService;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
|
|
import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
-import org.bson.Document;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
@@ -27,9 +26,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -54,12 +51,125 @@ public class IotCbdimgServiceImpl implements IIotCbdimgService {
|
|
|
/**
|
|
/**
|
|
|
* @param reqVo
|
|
* @param reqVo
|
|
|
*/
|
|
*/
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public IotCbdimgSumInfoResVo sumInfo(IotPestRecogPeriodReqVo reqVo) {
|
|
|
|
|
+// String devBid = reqVo.getDevBid();
|
|
|
|
|
+// String startTime = reqVo.getStartTime();
|
|
|
|
|
+// String endTime = reqVo.getEndTime();
|
|
|
|
|
+// String cbdRecogType = reqVo.getCbdRecogType();
|
|
|
|
|
+// String cbdrecogMarktype = reqVo.getCbdrecogMarktype();
|
|
|
|
|
+//
|
|
|
|
|
+// Criteria criteria = new Criteria()
|
|
|
|
|
+// .and("devBid").is(devBid)
|
|
|
|
|
+// .and("cbdimgDelstatus").is("0");
|
|
|
|
|
+// if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
|
|
|
|
|
+// criteria = criteria.andOperator(
|
|
|
|
|
+// Criteria.where("cbdimgCreatedDate").gte(startTime),
|
|
|
|
|
+// Criteria.where("cbdimgCreatedDate").lte(endTime)
|
|
|
|
|
+// );
|
|
|
|
|
+// } else if (StringUtils.isNotEmpty(startTime)) {
|
|
|
|
|
+// criteria = criteria.and("cbdimgCreatedDate").gte(startTime);
|
|
|
|
|
+// } else if (StringUtils.isNotEmpty(endTime)) {
|
|
|
|
|
+// criteria = criteria.and("cbdimgCreatedDate").lte(endTime);
|
|
|
|
|
+// }
|
|
|
|
|
+// MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
+// ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
|
|
+// .andExclude("_id")
|
|
|
|
|
+// .and("$$ROOT").as("c");
|
|
|
|
|
+// LookupWithPipelineOperation lookupWithPipelineOperation = new LookupWithPipelineOperation(
|
|
|
|
|
+// "IotCbdrecog", "c.cbdimgBid", "cbdimgBid", "ce",
|
|
|
|
|
+// new Document().append("$match", new Document().append("cbdrecogType", cbdRecogType).append("cbdrecogMarktype", "1")));
|
|
|
|
|
+// UnwindOperation unwindOperationCe = Aggregation.unwind("ce", true);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
|
|
|
|
|
+// "IotCbdpest", "ce.cbdrecogBid", "cbdrecogBid", "cp"
|
|
|
|
|
+// );
|
|
|
|
|
+// UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// LookupOperation lookupOperationIotPestrecog = Aggregation.lookup(
|
|
|
|
|
+// "IotPestrecog", "cp.pestrecogBid", "pestrecogBid", "pr"
|
|
|
|
|
+// );
|
|
|
|
|
+// UnwindOperation unwindOperationPr = Aggregation.unwind("pr", true);
|
|
|
|
|
+//
|
|
|
|
|
+// GroupOperation groupOperation = Aggregation.group("c.cbdimgBid")
|
|
|
|
|
+// .push("cp").as("recogArray")
|
|
|
|
|
+// .push("pr.pestrecogNum").as("pestArray")
|
|
|
|
|
+// .addToSet("pr.pestBusid").as("pestTypeArray");
|
|
|
|
|
+//
|
|
|
|
|
+// ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
|
|
+// .and("_id").as("cbdimgBid")
|
|
|
|
|
+// .andExpression("{'$cond': {'if': {'$eq': {{'$size': '$recogArray'},0}},'then': 1,'else':0}}").as("noRecog")
|
|
|
|
|
+// .and("pestTypeArray").as("pestTypeArray")
|
|
|
|
|
+// .andExpression("{$sum: '$pestArray'}").as("pestNum");
|
|
|
|
|
+//
|
|
|
|
|
+// GroupOperation groupOperation2 = Aggregation.group()
|
|
|
|
|
+// .count().as("imgCount")
|
|
|
|
|
+// .sum("noRecog").as("noRecogImgCount")
|
|
|
|
|
+// .sum("pestNum").as("sum")
|
|
|
|
|
+// .push("pestTypeArray").as("pestTypeArray");
|
|
|
|
|
+//
|
|
|
|
|
+// UnwindOperation unwindOperationPest = Aggregation.unwind("pestTypeArray", true);
|
|
|
|
|
+// GroupOperation groupOperation3 = Aggregation.group()
|
|
|
|
|
+// .first("imgCount").as("imgCount")
|
|
|
|
|
+// .first("noRecogImgCount").as("noRecogImgCount")
|
|
|
|
|
+// .first("sum").as("sum")
|
|
|
|
|
+// .addToSet("pestTypeArray").as("pestTypeArray");
|
|
|
|
|
+// ProjectionOperation projectionOperationResult2 = Aggregation.project("_id")
|
|
|
|
|
+// .and("imgCount").as("imgCount")
|
|
|
|
|
+// .and("sum").as("sum")
|
|
|
|
|
+// .and("noRecogImgCount").as("noRecogImgCount")
|
|
|
|
|
+// .andExpression("{$size: '$pestTypeArray'}").as("typeCount");
|
|
|
|
|
+//
|
|
|
|
|
+// Aggregation aggregation = Aggregation.newAggregation(
|
|
|
|
|
+// matchOperation,
|
|
|
|
|
+// projectionOperation,
|
|
|
|
|
+// lookupWithPipelineOperation,
|
|
|
|
|
+// unwindOperationCe,
|
|
|
|
|
+// lookupOperationIotCbdpest,
|
|
|
|
|
+// unwindOperationCp,
|
|
|
|
|
+// lookupOperationIotPestrecog,
|
|
|
|
|
+// unwindOperationPr,
|
|
|
|
|
+// groupOperation,
|
|
|
|
|
+// projectionOperationResult,
|
|
|
|
|
+// groupOperation2,
|
|
|
|
|
+// unwindOperationPest,
|
|
|
|
|
+// unwindOperationPest,
|
|
|
|
|
+// groupOperation3,
|
|
|
|
|
+// projectionOperationResult2
|
|
|
|
|
+// );
|
|
|
|
|
+//
|
|
|
|
|
+// List<IotCbdimgSumInfoResVo> iIotCbdimgSumInfoResVoList = mongoService.aggregate(
|
|
|
|
|
+// IotCbdimg.class, aggregation, IotCbdimgSumInfoResVo.class
|
|
|
|
|
+// );
|
|
|
|
|
+//
|
|
|
|
|
+// IotCbdimgSumInfoResVo iotCbdimgSumInfoResVo = new IotCbdimgSumInfoResVo();
|
|
|
|
|
+// iotCbdimgSumInfoResVo.setSum(0);
|
|
|
|
|
+// iotCbdimgSumInfoResVo.setImgCount(0);
|
|
|
|
|
+// iotCbdimgSumInfoResVo.setNoRecogImgCount(0);
|
|
|
|
|
+// iotCbdimgSumInfoResVo.setTypeCount(0);
|
|
|
|
|
+// iotCbdimgSumInfoResVo.setRecogImgCount(0);
|
|
|
|
|
+//
|
|
|
|
|
+// if (iIotCbdimgSumInfoResVoList.size() > 0) {
|
|
|
|
|
+// iotCbdimgSumInfoResVo = iIotCbdimgSumInfoResVoList.get(0);
|
|
|
|
|
+// iotCbdimgSumInfoResVo.setRecogImgCount(iotCbdimgSumInfoResVo.getImgCount() - iotCbdimgSumInfoResVo.getNoRecogImgCount());
|
|
|
|
|
+// }
|
|
|
|
|
+// return iotCbdimgSumInfoResVo;
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public IotCbdimgSumInfoResVo sumInfo(IotPestRecogPeriodReqVo reqVo) {
|
|
public IotCbdimgSumInfoResVo sumInfo(IotPestRecogPeriodReqVo reqVo) {
|
|
|
String devBid = reqVo.getDevBid();
|
|
String devBid = reqVo.getDevBid();
|
|
|
String startTime = reqVo.getStartTime();
|
|
String startTime = reqVo.getStartTime();
|
|
|
String endTime = reqVo.getEndTime();
|
|
String endTime = reqVo.getEndTime();
|
|
|
- String cbdRecogType = reqVo.getCbdRecogType();
|
|
|
|
|
|
|
+ String cbdrecogType = reqVo.getCbdRecogType();
|
|
|
|
|
+ String cbdrecogMarktype = reqVo.getCbdrecogMarktype();
|
|
|
|
|
+ String cbdrecogPestnumStr = ".cbdrecogPestnum";
|
|
|
|
|
+ if(Objects.equals(cbdrecogMarktype, EnumCbdMarkType.HAND.getCode())){
|
|
|
|
|
+ cbdrecogPestnumStr = ".cbdrecogPestnumManual";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
Criteria criteria = new Criteria()
|
|
Criteria criteria = new Criteria()
|
|
|
.and("devBid").is(devBid)
|
|
.and("devBid").is(devBid)
|
|
@@ -74,73 +184,35 @@ public class IotCbdimgServiceImpl implements IIotCbdimgService {
|
|
|
} else if (StringUtils.isNotEmpty(endTime)) {
|
|
} else if (StringUtils.isNotEmpty(endTime)) {
|
|
|
criteria = criteria.and("cbdimgCreatedDate").lte(endTime);
|
|
criteria = criteria.and("cbdimgCreatedDate").lte(endTime);
|
|
|
}
|
|
}
|
|
|
- MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
- ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
|
|
- .andExclude("_id")
|
|
|
|
|
- .and("$$ROOT").as("c");
|
|
|
|
|
- LookupWithPipelineOperation lookupWithPipelineOperation = new LookupWithPipelineOperation(
|
|
|
|
|
- "IotCbdrecog", "c.cbdimgBid", "cbdimgBid", "ce",
|
|
|
|
|
- new Document().append("$match", new Document().append("cbdrecogType", cbdRecogType).append("cbdrecogMarktype", "1")));
|
|
|
|
|
- UnwindOperation unwindOperationCe = Aggregation.unwind("ce", true);
|
|
|
|
|
|
|
|
|
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
|
|
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
|
|
+ .and("cbdimgBid").as("cbdimgBid")
|
|
|
|
|
+ .andExpression("{'$ifNull': {'$cbdrecog." + cbdrecogType + cbdrecogPestnumStr + "', 0}}").as("cbdrecogPestnum")
|
|
|
|
|
+ .andExpression("{'$ifNull': {'$cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype + ".pestBusid', {}}}").as("pestrecog");
|
|
|
|
|
|
|
|
- LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
|
|
|
|
|
- "IotCbdpest", "ce.cbdrecogBid", "cbdrecogBid", "cp"
|
|
|
|
|
- );
|
|
|
|
|
- UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
|
|
|
|
|
|
|
+ UnwindOperation unwindOperationCp = Aggregation.unwind("pestrecog", true);
|
|
|
|
|
+ Map<String, String> cbdimgListMap = new HashMap<>();
|
|
|
|
|
+ cbdimgListMap.put("cbdimgBid", "$cbdimgBid");
|
|
|
|
|
+ cbdimgListMap.put("cbdrecogPestnum", "$cbdrecogPestnum");
|
|
|
|
|
+ GroupOperation groupOperation = Aggregation.group()
|
|
|
|
|
+ .addToSet("pestrecog").as("pestrecogList")
|
|
|
|
|
+ .addToSet(cbdimgListMap).as("cbdimgList");
|
|
|
|
|
|
|
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project()
|
|
|
|
|
+ .andExpression("{'$size': '$cbdimgList'}").as("imgCount")
|
|
|
|
|
+ .andExpression("{'$size': '$pestrecogList'}").as("typeCount")
|
|
|
|
|
+ .andExpression("{'$size': {'$filter': {'input': '$cbdimgList', 'as': 'item', 'cond': {'$eq': {'$$item.cbdrecogPestnum', 0}}}}}").as("noRecogImgCount")
|
|
|
|
|
+ .andExpression("{'$toInt': {'$reduce': {'input': '$cbdimgList', 'initialValue': 0, 'in': {'$add': {'$$value', '$$this.cbdrecogPestnum'}}}}}").as("sum");
|
|
|
|
|
|
|
|
- LookupOperation lookupOperationIotPestrecog = Aggregation.lookup(
|
|
|
|
|
- "IotPestrecog", "cp.pestrecogBid", "pestrecogBid", "pr"
|
|
|
|
|
- );
|
|
|
|
|
- UnwindOperation unwindOperationPr = Aggregation.unwind("pr", true);
|
|
|
|
|
-
|
|
|
|
|
- GroupOperation groupOperation = Aggregation.group("c.cbdimgBid")
|
|
|
|
|
- .push("cp").as("recogArray")
|
|
|
|
|
- .push("pr.pestrecogNum").as("pestArray")
|
|
|
|
|
- .addToSet("pr.pestBusid").as("pestTypeArray");
|
|
|
|
|
-
|
|
|
|
|
- ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
|
|
- .and("_id").as("cbdimgBid")
|
|
|
|
|
- .andExpression("{'$cond': {'if': {'$eq': {{'$size': '$recogArray'},0}},'then': 1,'else':0}}").as("noRecog")
|
|
|
|
|
- .and("pestTypeArray").as("pestTypeArray")
|
|
|
|
|
- .andExpression("{$sum: '$pestArray'}").as("pestNum");
|
|
|
|
|
-
|
|
|
|
|
- GroupOperation groupOperation2 = Aggregation.group()
|
|
|
|
|
- .count().as("imgCount")
|
|
|
|
|
- .sum("noRecog").as("noRecogImgCount")
|
|
|
|
|
- .sum("pestNum").as("sum")
|
|
|
|
|
- .push("pestTypeArray").as("pestTypeArray");
|
|
|
|
|
-
|
|
|
|
|
- UnwindOperation unwindOperationPest = Aggregation.unwind("pestTypeArray", true);
|
|
|
|
|
- GroupOperation groupOperation3 = Aggregation.group()
|
|
|
|
|
- .first("imgCount").as("imgCount")
|
|
|
|
|
- .first("noRecogImgCount").as("noRecogImgCount")
|
|
|
|
|
- .first("sum").as("sum")
|
|
|
|
|
- .addToSet("pestTypeArray").as("pestTypeArray");
|
|
|
|
|
- ProjectionOperation projectionOperationResult2 = Aggregation.project("_id")
|
|
|
|
|
- .and("imgCount").as("imgCount")
|
|
|
|
|
- .and("sum").as("sum")
|
|
|
|
|
- .and("noRecogImgCount").as("noRecogImgCount")
|
|
|
|
|
- .andExpression("{$size: '$pestTypeArray'}").as("typeCount");
|
|
|
|
|
|
|
|
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
|
matchOperation,
|
|
matchOperation,
|
|
|
projectionOperation,
|
|
projectionOperation,
|
|
|
- lookupWithPipelineOperation,
|
|
|
|
|
- unwindOperationCe,
|
|
|
|
|
- lookupOperationIotCbdpest,
|
|
|
|
|
unwindOperationCp,
|
|
unwindOperationCp,
|
|
|
- lookupOperationIotPestrecog,
|
|
|
|
|
- unwindOperationPr,
|
|
|
|
|
groupOperation,
|
|
groupOperation,
|
|
|
- projectionOperationResult,
|
|
|
|
|
- groupOperation2,
|
|
|
|
|
- unwindOperationPest,
|
|
|
|
|
- unwindOperationPest,
|
|
|
|
|
- groupOperation3,
|
|
|
|
|
- projectionOperationResult2
|
|
|
|
|
|
|
+ projectionOperationResult
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
List<IotCbdimgSumInfoResVo> iIotCbdimgSumInfoResVoList = mongoService.aggregate(
|
|
List<IotCbdimgSumInfoResVo> iIotCbdimgSumInfoResVoList = mongoService.aggregate(
|
|
@@ -154,7 +226,7 @@ public class IotCbdimgServiceImpl implements IIotCbdimgService {
|
|
|
iotCbdimgSumInfoResVo.setTypeCount(0);
|
|
iotCbdimgSumInfoResVo.setTypeCount(0);
|
|
|
iotCbdimgSumInfoResVo.setRecogImgCount(0);
|
|
iotCbdimgSumInfoResVo.setRecogImgCount(0);
|
|
|
|
|
|
|
|
- if (iIotCbdimgSumInfoResVoList.size() > 0) {
|
|
|
|
|
|
|
+ if (!iIotCbdimgSumInfoResVoList.isEmpty()) {
|
|
|
iotCbdimgSumInfoResVo = iIotCbdimgSumInfoResVoList.get(0);
|
|
iotCbdimgSumInfoResVo = iIotCbdimgSumInfoResVoList.get(0);
|
|
|
iotCbdimgSumInfoResVo.setRecogImgCount(iotCbdimgSumInfoResVo.getImgCount() - iotCbdimgSumInfoResVo.getNoRecogImgCount());
|
|
iotCbdimgSumInfoResVo.setRecogImgCount(iotCbdimgSumInfoResVo.getImgCount() - iotCbdimgSumInfoResVo.getNoRecogImgCount());
|
|
|
}
|
|
}
|