|
|
@@ -0,0 +1,846 @@
|
|
|
+package com.yunfeiyun.agmp.iotm.device.pest.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.yunfeiyun.agmp.common.core.page.PageDomain;
|
|
|
+import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.*;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.resvo.IoPestResVo;
|
|
|
+import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestRecogPeriodReqVo;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogExportResVo;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogGroupByNameResVo;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogResVo;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestrecogService;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.xy.domain.IotXyinfoPestTotalDto;
|
|
|
+import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.mongodb.core.aggregation.*;
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class IotPestrecogServiceImpl implements IIotPestrecogService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MongoService mongoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IIotPestService iotPestService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IIotDeviceService iotDeviceService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param reqVo
|
|
|
+ * @param pageDomain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<IotPestrecogResVo> selectIotPestrecogList(IotPestRecogPeriodReqVo reqVo, PageDomain pageDomain) throws JsonProcessingException {
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
+ String pestrecogMarktype = reqVo.getPestrecogMarktype();
|
|
|
+ String cbdRecogType = reqVo.getCbdRecogType();
|
|
|
+ List<String> pestBids = reqVo.getPestBids();
|
|
|
+
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
+ if(StringUtils.isNotEmpty(pestrecogMarktype)){
|
|
|
+ criteria.and("pestrecogMarktype").is(pestrecogMarktype);
|
|
|
+ }
|
|
|
+ List<IotPest> iotPestList = new ArrayList<>();
|
|
|
+ if(pestBids != null){
|
|
|
+ criteria.and("pestBusid").in(pestBids);
|
|
|
+ iotPestList = iotPestService.selectIotPestListBatchByBid(pestBids);
|
|
|
+ }
|
|
|
+ Map<String, IotPest> iotPestMap = new HashMap<>();
|
|
|
+ if(iotPestList != null){
|
|
|
+ for(IotPest iotPest: iotPestList){
|
|
|
+ String pestId = iotPest.getPestId();
|
|
|
+ if(!iotPestMap.containsKey(pestId)){
|
|
|
+ iotPestMap.put(pestId, iotPest);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
+ .andExclude("_id")
|
|
|
+ .and("$$ROOT").as("pr");
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
|
|
|
+ "IotCbdpest", "pr.pestrecogBid", "pestrecogBid", "cp"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
|
|
|
+ "IotCbdrecog", "cp.cbdrecogBid", "cbdrecogBid", "cr"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCr = Aggregation.unwind("cr", true);
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdimg = Aggregation.lookup(
|
|
|
+ "IotCbdimg", "cr.cbdimgBid", "cbdimgBid", "ci"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCi = Aggregation.unwind("ci", true);
|
|
|
+
|
|
|
+ GroupOperation groupOperation = Aggregation.group("cr.cbdrecogBid")
|
|
|
+ .first("pr").as("pr")
|
|
|
+ .first("cr").as("cr")
|
|
|
+ .first("ci").as("ci")
|
|
|
+ .sum("pr.pestrecogNum").as("pestrecogNum");
|
|
|
+
|
|
|
+ Criteria criteria2 = new Criteria()
|
|
|
+ .and("ci.cbdimgDelstatus").is("0")
|
|
|
+ .and("cr.cbdrecogType").is(cbdRecogType)
|
|
|
+ .and("cr.cbdrecogMarktype").is(pestrecogMarktype);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
|
|
|
+ criteria2 = criteria2.andOperator(
|
|
|
+ Criteria.where("cr.cbdrecogCreatedDate").gte(startTime),
|
|
|
+ Criteria.where("cr.cbdrecogCreatedDate").lte(endTime)
|
|
|
+ );
|
|
|
+ } else if (StringUtils.isNotEmpty(startTime)) {
|
|
|
+ criteria2 = criteria2.and("cr.cbdrecogCreatedDate").gte(startTime);
|
|
|
+ } else if (StringUtils.isNotEmpty(endTime)) {
|
|
|
+ criteria2 = criteria2.and("cr.cbdrecogCreatedDate").lte(endTime);
|
|
|
+ }
|
|
|
+ MatchOperation matchOperation2 = Aggregation.match(criteria2);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
+ .and("pr.pestrecogBid").as("pestrecogBid")
|
|
|
+ .and("pr.devBid").as("devBid")
|
|
|
+ .and("pr.devtypeBid").as("devtypeBid")
|
|
|
+ .and("pr.pestrecogAt").as("pestrecogAt")
|
|
|
+ .and("pr.pestrecogAh").as("pestrecogAh")
|
|
|
+ .and("pr.pestrecogLng").as("pestrecogLng")
|
|
|
+ .and("pr.pestrecogLat").as("pestrecogLat")
|
|
|
+ .and("pr.pestrecogProvince").as("pestrecogProvince")
|
|
|
+ .and("pr.pestrecogCity").as("pestrecogCity")
|
|
|
+ .and("pr.pestrecogDistrict").as("pestrecogDistrict")
|
|
|
+ .and("pr.pestBusid").as("pestBusid")
|
|
|
+
|
|
|
+ .and("pestrecogNum").as("pestrecogNum")
|
|
|
+ .and("cr.cbdrecogCreatedDate").as("pestrecogCreatedDate")
|
|
|
+ .and("cr.cbdrecogAddr").as("cbdrecogAddr")
|
|
|
+ .and("cr.cbdrecogManualaddr").as("cbdrecogManualaddr")
|
|
|
+ .and("cr.cbdrecogMarktype").as("cbdrecogMarktype")
|
|
|
+ .and("cr.cbdrecogManualmark").as("cbdrecogManualmark")
|
|
|
+ .and("cr.cbdrecogMachinemark").as("cbdrecogMachinemark")
|
|
|
+ .and("cr.cbdrecogBid").as("cbdrecogBid")
|
|
|
+
|
|
|
+ .and("cr.cbdrecogCreatedDate").as("cbdrecogCreatedDate")
|
|
|
+ .and("ci.cbdimgBid").as("cbdimgBid")
|
|
|
+ .and("ci.cbdimgPestnum").as("cbdimgPestnum")
|
|
|
+ .and("ci.cbdimgRecognum").as("cbdimgRecognum")
|
|
|
+ .and("ci.cbdimgAddr").as("cbdimgAddr");
|
|
|
+
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "cbdrecogCreatedDate");
|
|
|
+
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation,
|
|
|
+ projectionOperation,
|
|
|
+ lookupOperationIotCbdpest,
|
|
|
+ unwindOperationCp,
|
|
|
+ lookupOperationIotCbdrecog,
|
|
|
+ unwindOperationCr,
|
|
|
+ lookupOperationIotCbdimg,
|
|
|
+ unwindOperationCi,
|
|
|
+ matchOperation2,
|
|
|
+ groupOperation,
|
|
|
+ projectionOperationResult,
|
|
|
+ sortOperation
|
|
|
+ );
|
|
|
+ IPage<IotPestrecogResVo> listPage = mongoService.aggregate(
|
|
|
+ IotPestrecog.class, aggregation, IotPestrecogResVo.class, pageDomain
|
|
|
+ );
|
|
|
+ List<IotPestrecogResVo> records = listPage.getRecords();
|
|
|
+
|
|
|
+ for(IotPestrecogResVo iotPestrecogResVo: records){
|
|
|
+ String cbdrecogMachinemark = iotPestrecogResVo.getCbdrecogMachinemark();
|
|
|
+
|
|
|
+ List pestList = (List) JSON.parse(cbdrecogMachinemark);
|
|
|
+ if(pestList == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ StringBuilder newResult = new StringBuilder();
|
|
|
+ for(Object o: pestList){
|
|
|
+ JSONObject jsonObject = JSONObject.from(o);
|
|
|
+ for(String k: jsonObject.keySet()){
|
|
|
+ if(iotPestMap.containsKey(k)){
|
|
|
+ newResult.append("{'")
|
|
|
+ .append(k).append("': ").append(jsonObject.getJSONArray(k))
|
|
|
+ .append("}").append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (newResult.length() > 0){
|
|
|
+ newResult.deleteCharAt(newResult.length()-1);
|
|
|
+ newResult.insert(0, "[");
|
|
|
+ newResult.append("]");
|
|
|
+ iotPestrecogResVo.setCbdrecogMachinemark(newResult.toString());
|
|
|
+ listPage.setRecords(records);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return listPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param reqVo
|
|
|
+ * @return
|
|
|
+ * @throws JsonProcessingException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<IotPestrecog> selectIotPestrecogList(IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException {
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
+ String pestrecogMarktype = reqVo.getPestrecogMarktype();
|
|
|
+ String cbdRecogType = reqVo.getCbdRecogType();
|
|
|
+ List<String> pestBids = reqVo.getPestBids();
|
|
|
+
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
+ if(StringUtils.isNotEmpty(pestrecogMarktype)){
|
|
|
+ criteria.and("pestrecogMarktype").is(pestrecogMarktype);
|
|
|
+ }
|
|
|
+ List<IotPest> iotPestList = new ArrayList<>();
|
|
|
+ if(pestBids != null){
|
|
|
+ criteria.and("pestBusid").in(pestBids);
|
|
|
+ iotPestList = iotPestService.selectIotPestListBatchByBid(pestBids);
|
|
|
+ }
|
|
|
+ Map<String, IotPest> iotPestMap = new HashMap<>();
|
|
|
+ if(iotPestList != null){
|
|
|
+ for(IotPest iotPest: iotPestList){
|
|
|
+ String pestId = iotPest.getPestId();
|
|
|
+ if(!iotPestMap.containsKey(pestId)){
|
|
|
+ iotPestMap.put(pestId, iotPest);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
+ .andExclude("_id")
|
|
|
+ .and("$$ROOT").as("pr");
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
|
|
|
+ "IotCbdpest", "pr.pestrecogBid", "pestrecogBid", "cp"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
|
|
|
+ "IotCbdrecog", "cp.cbdrecogBid", "cbdrecogBid", "cr"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCr = Aggregation.unwind("cr", true);
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdimg = Aggregation.lookup(
|
|
|
+ "IotCbdimg", "cr.cbdimgBid", "cbdimgBid", "ci"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCi = Aggregation.unwind("ci", true);
|
|
|
+
|
|
|
+ GroupOperation groupOperation = Aggregation.group("cr.cbdrecogBid")
|
|
|
+ .first("pr").as("pr")
|
|
|
+ .first("cr").as("cr")
|
|
|
+ .first("ci").as("ci")
|
|
|
+ .sum("pr.pestrecogNum").as("pestrecogNum");
|
|
|
+
|
|
|
+ Criteria criteria2 = new Criteria()
|
|
|
+ .and("ci.cbdimgDelstatus").is("0")
|
|
|
+ .and("cr.cbdrecogType").is(cbdRecogType)
|
|
|
+ .and("cr.cbdrecogMarktype").is(pestrecogMarktype);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
|
|
|
+ criteria2 = criteria2.andOperator(
|
|
|
+ Criteria.where("cr.cbdrecogCreatedDate").gte(startTime),
|
|
|
+ Criteria.where("cr.cbdrecogCreatedDate").lte(endTime)
|
|
|
+ );
|
|
|
+ } else if (StringUtils.isNotEmpty(startTime)) {
|
|
|
+ criteria2 = criteria2.and("cr.cbdrecogCreatedDate").gte(startTime);
|
|
|
+ } else if (StringUtils.isNotEmpty(endTime)) {
|
|
|
+ criteria2 = criteria2.and("cr.cbdrecogCreatedDate").lte(endTime);
|
|
|
+ }
|
|
|
+ MatchOperation matchOperation2 = Aggregation.match(criteria2);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
+ .and("pr.pestrecogBid").as("pestrecogBid")
|
|
|
+ .and("pr.devBid").as("devBid")
|
|
|
+ .and("pr.devtypeBid").as("devtypeBid")
|
|
|
+ .and("pr.pestrecogAt").as("pestrecogAt")
|
|
|
+ .and("pr.pestrecogAh").as("pestrecogAh")
|
|
|
+ .and("pr.pestrecogLng").as("pestrecogLng")
|
|
|
+ .and("pr.pestrecogLat").as("pestrecogLat")
|
|
|
+ .and("pr.pestrecogProvince").as("pestrecogProvince")
|
|
|
+ .and("pr.pestrecogCity").as("pestrecogCity")
|
|
|
+ .and("pr.pestrecogDistrict").as("pestrecogDistrict")
|
|
|
+ .and("pr.pestBusid").as("pestBusid")
|
|
|
+
|
|
|
+ .and("pestrecogNum").as("pestrecogNum")
|
|
|
+ .and("cr.cbdrecogCreatedDate").as("pestrecogCreatedDate")
|
|
|
+ .and("cr.cbdrecogAddr").as("cbdrecogAddr")
|
|
|
+ .and("cr.cbdrecogManualaddr").as("cbdrecogManualaddr")
|
|
|
+ .and("cr.cbdrecogMarktype").as("cbdrecogMarktype")
|
|
|
+ .and("cr.cbdrecogManualmark").as("cbdrecogManualmark")
|
|
|
+ .and("cr.cbdrecogMachinemark").as("cbdrecogMachinemark")
|
|
|
+ .and("cr.cbdrecogBid").as("cbdrecogBid")
|
|
|
+
|
|
|
+ .and("cr.cbdrecogCreatedDate").as("cbdrecogCreatedDate")
|
|
|
+ .and("ci.cbdimgBid").as("cbdimgBid")
|
|
|
+ .and("ci.cbdimgPestnum").as("cbdimgPestnum")
|
|
|
+ .and("ci.cbdimgRecognum").as("cbdimgRecognum")
|
|
|
+ .and("ci.cbdimgAddr").as("cbdimgAddr");
|
|
|
+
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "cbdrecogCreatedDate");
|
|
|
+
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation,
|
|
|
+ projectionOperation,
|
|
|
+ lookupOperationIotCbdpest,
|
|
|
+ unwindOperationCp,
|
|
|
+ lookupOperationIotCbdrecog,
|
|
|
+ unwindOperationCr,
|
|
|
+ lookupOperationIotCbdimg,
|
|
|
+ unwindOperationCi,
|
|
|
+ matchOperation2,
|
|
|
+ groupOperation,
|
|
|
+ projectionOperationResult,
|
|
|
+ sortOperation
|
|
|
+ );
|
|
|
+ List<IotPestrecog> iotPestrecogList = mongoService.aggregate(
|
|
|
+ IotPestrecog.class, aggregation, IotPestrecog.class
|
|
|
+ );
|
|
|
+ return iotPestrecogList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param reqVo
|
|
|
+ * @return
|
|
|
+ * @throws JsonProcessingException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<IotPestrecogExportResVo> exportIotPestrecogList(IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException {
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
+ String pestrecogMarktype = reqVo.getPestrecogMarktype();
|
|
|
+ String cbdRecogType = reqVo.getCbdRecogType();
|
|
|
+ List<String> pestBids = reqVo.getPestBids();
|
|
|
+
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
+ if(StringUtils.isNotEmpty(pestrecogMarktype)){
|
|
|
+ criteria.and("pestrecogMarktype").is(pestrecogMarktype);
|
|
|
+ }
|
|
|
+ List<IotPest> iotPestList = new ArrayList<>();
|
|
|
+ if(pestBids != null){
|
|
|
+ criteria.and("pestBusid").in(pestBids);
|
|
|
+ iotPestList = iotPestService.selectIotPestListBatchByBid(pestBids);
|
|
|
+ }
|
|
|
+ Map<String, IotPest> iotPestMap = new HashMap<>();
|
|
|
+ if(iotPestList != null){
|
|
|
+ for(IotPest iotPest: iotPestList){
|
|
|
+ String pestId = iotPest.getPestId();
|
|
|
+ if(!iotPestMap.containsKey(pestId)){
|
|
|
+ iotPestMap.put(pestId, iotPest);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
+ .andExclude("_id")
|
|
|
+ .and("$$ROOT").as("pr");
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
|
|
|
+ "IotCbdpest", "pr.pestrecogBid", "pestrecogBid", "cp"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCp = Aggregation.unwind("cp", true);
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
|
|
|
+ "IotCbdrecog", "cp.cbdrecogBid", "cbdrecogBid", "cr"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCr = Aggregation.unwind("cr", true);
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdimg = Aggregation.lookup(
|
|
|
+ "IotCbdimg", "cr.cbdimgBid", "cbdimgBid", "ci"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCi = Aggregation.unwind("ci", true);
|
|
|
+
|
|
|
+ GroupOperation groupOperation = Aggregation.group("cr.cbdrecogBid")
|
|
|
+ .first("pr").as("pr")
|
|
|
+ .first("cr").as("cr")
|
|
|
+ .first("ci").as("ci")
|
|
|
+ .sum("pr.pestrecogNum").as("pestrecogNum");
|
|
|
+
|
|
|
+ Criteria criteria2 = new Criteria()
|
|
|
+ .and("ci.cbdimgDelstatus").is("0")
|
|
|
+ .and("cr.cbdrecogType").is(cbdRecogType)
|
|
|
+ .and("cr.cbdrecogMarktype").is(pestrecogMarktype);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
|
|
|
+ criteria2 = criteria2.andOperator(
|
|
|
+ Criteria.where("cr.cbdrecogCreatedDate").gte(startTime),
|
|
|
+ Criteria.where("cr.cbdrecogCreatedDate").lte(endTime)
|
|
|
+ );
|
|
|
+ } else if (StringUtils.isNotEmpty(startTime)) {
|
|
|
+ criteria2 = criteria2.and("cr.cbdrecogCreatedDate").gte(startTime);
|
|
|
+ } else if (StringUtils.isNotEmpty(endTime)) {
|
|
|
+ criteria2 = criteria2.and("cr.cbdrecogCreatedDate").lte(endTime);
|
|
|
+ }
|
|
|
+ MatchOperation matchOperation2 = Aggregation.match(criteria2);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project("_id")
|
|
|
+ .and("pr.pestrecogBid").as("pestrecogBid")
|
|
|
+ .and("pr.devBid").as("devBid")
|
|
|
+ .and("pr.devtypeBid").as("devtypeBid")
|
|
|
+ .and("pr.pestrecogAt").as("pestrecogAt")
|
|
|
+ .and("pr.pestrecogAh").as("pestrecogAh")
|
|
|
+ .and("pr.pestrecogLng").as("pestrecogLng")
|
|
|
+ .and("pr.pestrecogLat").as("pestrecogLat")
|
|
|
+ .and("pr.pestrecogProvince").as("pestrecogProvince")
|
|
|
+ .and("pr.pestrecogCity").as("pestrecogCity")
|
|
|
+ .and("pr.pestrecogDistrict").as("pestrecogDistrict")
|
|
|
+ .and("pr.pestBusid").as("pestBusid")
|
|
|
+
|
|
|
+ .and("pestrecogNum").as("pestrecogNum")
|
|
|
+ .and("cr.cbdrecogCreatedDate").as("pestrecogCreatedDate")
|
|
|
+ .and("cr.cbdrecogAddr").as("cbdrecogAddr")
|
|
|
+ .and("cr.cbdrecogManualaddr").as("cbdrecogManualaddr")
|
|
|
+ .and("cr.cbdrecogMarktype").as("cbdrecogMarktype")
|
|
|
+ .and("cr.cbdrecogManualmark").as("cbdrecogManualmark")
|
|
|
+ .and("cr.cbdrecogMachinemark").as("cbdrecogMachinemark")
|
|
|
+ .and("cr.cbdrecogBid").as("cbdrecogBid")
|
|
|
+ .and("cr.cbdrecogResult").as("cbdrecogResult")
|
|
|
+ .and("cr.cbdrecogResultManual").as("cbdrecogResultManual")
|
|
|
+
|
|
|
+ .and("cr.cbdrecogCreatedDate").as("cbdrecogCreatedDate")
|
|
|
+ .and("ci.cbdimgBid").as("cbdimgBid")
|
|
|
+ .and("ci.cbdimgPestnum").as("cbdimgPestnum")
|
|
|
+ .and("ci.cbdimgRecognum").as("cbdimgRecognum")
|
|
|
+ .and("ci.cbdimgAddr").as("cbdimgAddr");
|
|
|
+
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "cbdrecogCreatedDate");
|
|
|
+
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation,
|
|
|
+ projectionOperation,
|
|
|
+ lookupOperationIotCbdpest,
|
|
|
+ unwindOperationCp,
|
|
|
+ lookupOperationIotCbdrecog,
|
|
|
+ unwindOperationCr,
|
|
|
+ lookupOperationIotCbdimg,
|
|
|
+ unwindOperationCi,
|
|
|
+ matchOperation2,
|
|
|
+ groupOperation,
|
|
|
+ projectionOperationResult,
|
|
|
+ sortOperation
|
|
|
+ );
|
|
|
+ List<IotPestrecogExportResVo> iotPestrecogList = mongoService.aggregate(
|
|
|
+ IotPestrecog.class, aggregation, IotPestrecogExportResVo.class
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ //查询设备号
|
|
|
+ IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
+
|
|
|
+ Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo2();
|
|
|
+
|
|
|
+ for (IotPestrecogExportResVo item: iotPestrecogList) {
|
|
|
+
|
|
|
+ if(findDevice != null){
|
|
|
+ item.setDevCode(findDevice.getDevCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ item.setPestrecogResult(parseRecogResult(item.getCbdrecogResult(),pestMap));
|
|
|
+
|
|
|
+ if("0".equals(item.getCbdrecogMarktype())){
|
|
|
+ item.setCbdrecogAddr(item.getCbdrecogManualaddr());
|
|
|
+ item.setPestrecogResult(parseRecogResult(item.getCbdrecogResultManual(),pestMap));
|
|
|
+ }
|
|
|
+ item.setAddress(item.getPestrecogProvince()+item.getPestrecogCity()+item.getPestrecogDistrict());
|
|
|
+ item.setLnglat(item.getPestrecogLng()+","+item.getPestrecogLat());
|
|
|
+
|
|
|
+ item.setDevtypeName(IotDeviceDictEnum.getNameByCode(item.getDevtypeBid()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return iotPestrecogList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析识别结果
|
|
|
+ *
|
|
|
+ * @param result "21,3#260,1#71,1#115,2"
|
|
|
+ * @return 害虫名称和数量
|
|
|
+ */
|
|
|
+ private String parseRecogResult(String result, Map<String, IotPest> pestMap){
|
|
|
+
|
|
|
+ String ret = "";
|
|
|
+ if(StringUtils.isNotEmpty(result)){
|
|
|
+ String[] arr = result.split("#");
|
|
|
+ for(int i=0;i<arr.length;i++){
|
|
|
+ if(StringUtils.isNotEmpty(arr[i])){
|
|
|
+ String[] arr2 = arr[i].split(",");
|
|
|
+ String pestName = "未命名";
|
|
|
+ if(pestMap.get(arr2[0])!=null&&StringUtils.isNotEmpty(pestMap.get(arr2[0]).getPestName())){
|
|
|
+ pestName = pestMap.get(arr2[0]).getPestName();
|
|
|
+ }
|
|
|
+ ret += pestName+""+arr2[1]+""+"头,";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //去除最后一个逗号
|
|
|
+ if(ret.endsWith(",")){
|
|
|
+ ret = ret.substring(0,ret.length()-1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param reqVo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<IotPestrecogGroupByNameResVo> groupByName(IotDeviceDataListReqVo reqVo) {
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String cbdRecogType = reqVo.getCbdRecogType();
|
|
|
+ String pestrecogMarktype = reqVo.getPestrecogMarktype();
|
|
|
+
|
|
|
+ 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");
|
|
|
+ LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
|
|
|
+ "IotCbdrecog", "c.cbdimgBid", "cbdimgBid", "ce"
|
|
|
+ );
|
|
|
+ Criteria cbdRecogCriteria = new Criteria()
|
|
|
+ .and("ce.cbdrecogType").is(cbdRecogType)
|
|
|
+ .and("ce.cbdrecogMarktype").is(pestrecogMarktype);
|
|
|
+
|
|
|
+ MatchOperation cbdRecogMatchOperation = Aggregation.match(cbdRecogCriteria);
|
|
|
+ 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);
|
|
|
+ Criteria criteria2 = new Criteria()
|
|
|
+ .and("pr.pestrecogMarktype").is(pestrecogMarktype);
|
|
|
+ MatchOperation matchOperation2 = Aggregation.match(criteria2);
|
|
|
+
|
|
|
+ GroupOperation groupOperation = Aggregation.group("pr.pestBusid")
|
|
|
+ .first("pr.pestBusid").as("pestBusid")
|
|
|
+ .sum("pr.pestrecogNum").as("sum");
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation2 = Aggregation.project()
|
|
|
+ .and("pestBusid").as("pestBid")
|
|
|
+ .and("sum").as("sum");
|
|
|
+
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "sum");
|
|
|
+
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation,
|
|
|
+ projectionOperation,
|
|
|
+ lookupOperationIotCbdrecog,
|
|
|
+ unwindOperationCe,
|
|
|
+ cbdRecogMatchOperation,
|
|
|
+ lookupOperationIotCbdpest,
|
|
|
+ unwindOperationCp,
|
|
|
+ lookupOperationIotPestrecog,
|
|
|
+ unwindOperationPr,
|
|
|
+ matchOperation2,
|
|
|
+ groupOperation,
|
|
|
+ projectionOperation2,
|
|
|
+ sortOperation
|
|
|
+ );
|
|
|
+ List<IotPestrecogGroupByNameResVo> iotPestrecogGroupByNameResVoList = mongoService.aggregate(
|
|
|
+ IotCbdimg.class, aggregation, IotPestrecogGroupByNameResVo.class
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo();
|
|
|
+ return iotPestrecogGroupByNameResVoList.stream().filter(item->
|
|
|
+ {
|
|
|
+ if(pestMap.containsKey(item.getPestBid())){
|
|
|
+ item.setPestName(pestMap.get(item.getPestBid()).getPestName());
|
|
|
+ }
|
|
|
+ return StringUtils.isNotEmpty(item.getPestBid());
|
|
|
+ }
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param reqVo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<IotPestrecog> groupByDateName(IotDeviceDataListReqVo reqVo) {
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String cbdRecogType = reqVo.getCbdRecogType();
|
|
|
+ String pestrecogMarktype = reqVo.getPestrecogMarktype();
|
|
|
+
|
|
|
+ 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");
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdrecog = Aggregation.lookup(
|
|
|
+ "IotCbdrecog", "c.cbdimgBid", "cbdimgBid", "ce"
|
|
|
+ );
|
|
|
+ Criteria cbdRecogCriteria = new Criteria()
|
|
|
+ .and("ce.cbdrecogType").is(cbdRecogType)
|
|
|
+ .and("ce.cbdrecogMarktype").is(pestrecogMarktype);
|
|
|
+ MatchOperation cbdRecogMatchOperation = Aggregation.match(cbdRecogCriteria);
|
|
|
+ UnwindOperation unwindOperationCe = Aggregation.unwind("ce", false);
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotCbdpest = Aggregation.lookup(
|
|
|
+ "IotCbdpest", "ce.cbdrecogBid", "cbdrecogBid", "cp"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationCp = Aggregation.unwind("cp", false);
|
|
|
+
|
|
|
+ LookupOperation lookupOperationIotPestrecog = Aggregation.lookup(
|
|
|
+ "IotPestrecog", "cp.pestrecogBid", "pestrecogBid", "pr"
|
|
|
+ );
|
|
|
+ UnwindOperation unwindOperationPr = Aggregation.unwind("pr", false);
|
|
|
+ Criteria pestRecogCriteria = new Criteria()
|
|
|
+ .and("pr.pestrecogMarktype").is(pestrecogMarktype);
|
|
|
+ MatchOperation pestRecogMatchOperation = Aggregation.match(pestRecogCriteria);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation2 = Aggregation.project()
|
|
|
+ .and("pr.pestBusid").as("pestBusid")
|
|
|
+ .and("pr.pestrecogNum").as("pestrecogNum")
|
|
|
+ .andExpression(
|
|
|
+ "{$dateTrunc: {date: {$dateFromString: {dateString: '$pr.pestrecogCreatedDate', format: '%Y-%m-%d %H:%M:%S'}}, unit:'day'}}").as("pestrecogCreatedDate");
|
|
|
+
|
|
|
+ GroupOperation groupOperation = Aggregation.group("pestrecogCreatedDate", "pestBusid")
|
|
|
+ .sum("pestrecogNum").as("pestrecogNum");
|
|
|
+ ProjectionOperation projectionOperation3 = Aggregation.project()
|
|
|
+ .and("_id.pestBusid").as("pestBusid")
|
|
|
+ .and("pestrecogNum").as("pestrecogNum")
|
|
|
+ .andExpression(
|
|
|
+ "{$dateToString: { format: '%Y-%m-%d', date: '$_id.pestrecogCreatedDate'}}").as("pestrecogCreatedDate");
|
|
|
+
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation,
|
|
|
+ projectionOperation,
|
|
|
+ lookupOperationIotCbdrecog,
|
|
|
+ unwindOperationCe,
|
|
|
+ cbdRecogMatchOperation,
|
|
|
+ lookupOperationIotCbdpest,
|
|
|
+ unwindOperationCp,
|
|
|
+ lookupOperationIotPestrecog,
|
|
|
+ unwindOperationPr,
|
|
|
+ pestRecogMatchOperation,
|
|
|
+ projectionOperation2,
|
|
|
+ groupOperation,
|
|
|
+ projectionOperation3
|
|
|
+ );
|
|
|
+ List<IotPestrecog> iotPestrecogList = mongoService.aggregate(
|
|
|
+ IotCbdimg.class, aggregation, IotPestrecog.class
|
|
|
+ );
|
|
|
+ return iotPestrecogList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取性诱设备虫情识别总数
|
|
|
+ * @param devBidList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<IotXyinfoPestTotalDto> getIotXyinfoPestTotal(List<String> devBidList) {
|
|
|
+ Criteria criteria = new Criteria()
|
|
|
+ .and("devBid").in(devBidList);
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
+ .and("devBid").as("devBid")
|
|
|
+ .andExpression("{$convert: {input: '$xycb2dataContent.ct', to: 'int', onError: 0, onNull: 0}}").as("ct");
|
|
|
+
|
|
|
+ GroupOperation groupOperation = Aggregation.group("devBid")
|
|
|
+ .sum("ct").as("pestTotal");
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation2 = Aggregation.project()
|
|
|
+ .and("_id").as("devBid")
|
|
|
+ .and("pestTotal").as("pestTotal");
|
|
|
+
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation,
|
|
|
+ projectionOperation,
|
|
|
+ groupOperation,
|
|
|
+ projectionOperation2
|
|
|
+ );
|
|
|
+
|
|
|
+ List<IotXyinfoPestTotalDto> iotXyinfoPestTotalDtoList = mongoService.aggregate(
|
|
|
+ IotYfXycb2data.class, aggregation, IotXyinfoPestTotalDto.class
|
|
|
+ );
|
|
|
+
|
|
|
+ return iotXyinfoPestTotalDtoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取性诱设备虫情识别总数
|
|
|
+ * @param devBidList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, IotXyinfoPestTotalDto> getIotXyinfoPestTotalMap(List<String> devBidList) {
|
|
|
+ List<IotXyinfoPestTotalDto> iotXyinfoPestTotalDtoList = getIotXyinfoPestTotal(devBidList);
|
|
|
+ Map<String, IotXyinfoPestTotalDto> iotXyinfoPestTotalDtoMap = new HashMap<>();
|
|
|
+ for(IotXyinfoPestTotalDto iotXyinfoPestTotalDto: iotXyinfoPestTotalDtoList){
|
|
|
+ iotXyinfoPestTotalDtoMap.put(iotXyinfoPestTotalDto.getDevBid(), iotXyinfoPestTotalDto);
|
|
|
+ }
|
|
|
+ return iotXyinfoPestTotalDtoMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param reqVo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> period(IotPestRecogPeriodReqVo reqVo) {
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String startTime = reqVo.getStartTime();
|
|
|
+ String endTime = reqVo.getEndTime();
|
|
|
+ String pestBusid = reqVo.getPestBid();
|
|
|
+
|
|
|
+ Criteria criteria = new Criteria().and("devBid").is(devBid).and("pestBusid").is(pestBusid);
|
|
|
+ if(StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)){
|
|
|
+ criteria = criteria.andOperator(
|
|
|
+ Criteria.where("pestrecogCreatedDate").gte(startTime),
|
|
|
+ Criteria.where("pestrecogCreatedDate").lte(endTime)
|
|
|
+ );
|
|
|
+ } else if (StringUtils.isNotEmpty(startTime)) {
|
|
|
+ criteria = criteria.and("pestrecogCreatedDate").gte(startTime);
|
|
|
+ } else if (StringUtils.isNotEmpty(endTime)) {
|
|
|
+ criteria = criteria.and("pestrecogCreatedDate").lte(endTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project("_id")
|
|
|
+ .and("pestrecogNum").as("pestrecogNum")
|
|
|
+ .andExpression("{$dateTrunc: {date: {$dateFromString: {dateString: '$pestrecogCreatedDate', format: '%Y-%m-%d %H:%M:%S'}}, unit:'day'}}").as("date");
|
|
|
+
|
|
|
+ GroupOperation groupOperation = Aggregation.group("date")
|
|
|
+ .sum("pestrecogNum").as("pestrecogNum");
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation2 = Aggregation.project("_id")
|
|
|
+ .and("_id").as("date")
|
|
|
+ .and("pestrecogNum").as("pestrecogNum")
|
|
|
+ .andExpression("{$dateToString: {'date': '$_id', 'format': '%Y-%m-%d %H:%M:%S'}}").as("dataStr");
|
|
|
+
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "date");
|
|
|
+
|
|
|
+ GroupOperation groupOperation2 = Aggregation.group()
|
|
|
+ .push("$$ROOT").as("dataList");
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation3 = Aggregation.project()
|
|
|
+ .and("dataList").as("dataList")
|
|
|
+ .andExpression("{'$first': '$dataList'}").as("seeTimeInfo")
|
|
|
+ .andExpression("{'$last': '$dataList'}").as("endInPeriodInfo");
|
|
|
+
|
|
|
+ UnwindOperation unwindOperation = Aggregation.unwind("dataList");
|
|
|
+
|
|
|
+ SortOperation sortOperation2 = Aggregation.sort(Sort.Direction.DESC, "dataList.pestrecogNum");
|
|
|
+
|
|
|
+ LimitOperation limitOperation = Aggregation.limit(1);
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation4 = Aggregation.project()
|
|
|
+ .and("seeTimeInfo").as("seeTimeInfo")
|
|
|
+ .and("endInPeriodInfo").as("endInPeriodInfo")
|
|
|
+ .and("dataList").as("fastigiumInfo");
|
|
|
+
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation,
|
|
|
+ projectionOperation,
|
|
|
+ groupOperation,
|
|
|
+ projectionOperation2,
|
|
|
+ sortOperation,
|
|
|
+ groupOperation2,
|
|
|
+ projectionOperation3,
|
|
|
+ unwindOperation,
|
|
|
+ sortOperation2,
|
|
|
+ limitOperation,
|
|
|
+ projectionOperation4
|
|
|
+ );
|
|
|
+ List<JSONObject> jsonObjectList = mongoService.aggregate(
|
|
|
+ IotPestrecog.class, aggregation, JSONObject.class
|
|
|
+ );
|
|
|
+
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("seeTimes", "");
|
|
|
+ resultMap.put("fastigium", "");
|
|
|
+ resultMap.put("fastigiumaNum", "");
|
|
|
+ resultMap.put("endInPeriod", "");
|
|
|
+
|
|
|
+ if(jsonObjectList.size() > 0){
|
|
|
+ JSONObject result = jsonObjectList.get(0);
|
|
|
+ resultMap.put("seeTimes", result.getJSONObject("seeTimeInfo").getString("dataStr"));
|
|
|
+ resultMap.put("fastigium", result.getJSONObject("fastigiumInfo").getString("dataStr"));
|
|
|
+ resultMap.put("fastigiumaNum", result.getJSONObject("fastigiumInfo").getInteger("pestrecogNum"));
|
|
|
+ resultMap.put("endInPeriod", result.getJSONObject("endInPeriodInfo").getString("dataStr"));
|
|
|
+ }
|
|
|
+
|
|
|
+ IoPestResVo ioPestResVo = iotPestService.selectIotPestDetailByPestBid(reqVo.getPestBid());
|
|
|
+ if (ioPestResVo == null) {
|
|
|
+ ioPestResVo = new IoPestResVo();
|
|
|
+ }
|
|
|
+ resultMap.put("pic", ioPestResVo.getPic());
|
|
|
+ resultMap.put("course", ioPestResVo.getCourse());
|
|
|
+ resultMap.put("calamRemark",ioPestResVo.getCalamRemark());
|
|
|
+ resultMap.put("alias", "");
|
|
|
+ String cropsList = iotPestService.selectIotPestCropsByCalarmId(ioPestResVo.getCalarmId());
|
|
|
+ resultMap.put("crops", cropsList);
|
|
|
+
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+}
|