|
|
@@ -1,11 +1,13 @@
|
|
|
package com.yunfeiyun.agmp.iotm.device.pest.service.impl;
|
|
|
|
|
|
-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.domain.*;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotCbdimg;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotPest;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotYfXycb2data;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.resvo.IoPestResVo;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.EnumCbdMarkType;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
@@ -16,6 +18,7 @@ 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 lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.mongodb.core.aggregation.*;
|
|
|
@@ -492,101 +495,86 @@ public class IotPestrecogServiceImpl implements IIotPestrecogService {
|
|
|
* @param reqVo
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String, Object> period(IotPestRecogPeriodReqVo reqVo) {
|
|
|
- String devBid = reqVo.getDevBid();
|
|
|
+ public IotPestRecogPeriodInfoResVo period(IotPestRecogPeriodReqVo reqVo) {
|
|
|
String startTime = reqVo.getStartTime();
|
|
|
String endTime = reqVo.getEndTime();
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+ String cbdrecogType = reqVo.getCbdrecogType();
|
|
|
+ String cbdrecogMarktype = reqVo.getCbdrecogMarktype();
|
|
|
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 = new Criteria()
|
|
|
+ .and("devBid").is(devBid)
|
|
|
+ .and("cbdimgDelstatus").is("0")
|
|
|
+ .and("cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype + ".pestBusid").is(pestBusid);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
|
|
|
criteria = criteria.andOperator(
|
|
|
- Criteria.where("pestrecogCreatedDate").gte(startTime),
|
|
|
- Criteria.where("pestrecogCreatedDate").lte(endTime)
|
|
|
+ Criteria.where("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").gte(startTime),
|
|
|
+ Criteria.where("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").lte(endTime)
|
|
|
);
|
|
|
} else if (StringUtils.isNotEmpty(startTime)) {
|
|
|
- criteria = criteria.and("pestrecogCreatedDate").gte(startTime);
|
|
|
+ criteria = criteria.and("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").gte(startTime);
|
|
|
} else if (StringUtils.isNotEmpty(endTime)) {
|
|
|
- criteria = criteria.and("pestrecogCreatedDate").lte(endTime);
|
|
|
+ criteria = criteria.and("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").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");
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
+ .and("cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype).as("pestrecog");
|
|
|
|
|
|
- SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "date");
|
|
|
+ UnwindOperation unwindOperation = Aggregation.unwind("pestrecog", false);
|
|
|
|
|
|
- GroupOperation groupOperation2 = Aggregation.group()
|
|
|
- .push("$$ROOT").as("dataList");
|
|
|
+ Criteria criteria2 = new Criteria().and("pestrecog.pestBusid").is(pestBusid);
|
|
|
+ MatchOperation matchOperation2 = Aggregation.match(criteria2);
|
|
|
|
|
|
- ProjectionOperation projectionOperation3 = Aggregation.project()
|
|
|
- .and("dataList").as("dataList")
|
|
|
- .andExpression("{'$first': '$dataList'}").as("seeTimeInfo")
|
|
|
- .andExpression("{'$last': '$dataList'}").as("endInPeriodInfo");
|
|
|
+ ProjectionOperation projectionOperation2 = Aggregation.project()
|
|
|
+ .and("pestrecog.pestBusid").as("pestBusid")
|
|
|
+ .and("pestrecog.pestName").as("pestName")
|
|
|
+ .and("pestrecog.pestrecogNum").as("pestrecogNum")
|
|
|
+ .and("pestrecog.pestrecogCreatedDate").as("pestrecogCreatedDate");
|
|
|
|
|
|
- UnwindOperation unwindOperation = Aggregation.unwind("dataList");
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "pestrecogCreatedDate");
|
|
|
|
|
|
- SortOperation sortOperation2 = Aggregation.sort(Sort.Direction.DESC, "dataList.pestrecogNum");
|
|
|
+ Map<String, String> dataMap = new HashMap<>();
|
|
|
+ dataMap.put("pestrecogNum", "$pestrecogNum");
|
|
|
+ dataMap.put("pestrecogCreatedDate", "$pestrecogCreatedDate");
|
|
|
|
|
|
- LimitOperation limitOperation = Aggregation.limit(1);
|
|
|
+ GroupOperation groupOperation = Aggregation.group()
|
|
|
+ .first("pestName").as("pestName")
|
|
|
+ .push(dataMap).as("dataList");
|
|
|
|
|
|
- ProjectionOperation projectionOperation4 = Aggregation.project()
|
|
|
- .and("seeTimeInfo").as("seeTimeInfo")
|
|
|
- .and("endInPeriodInfo").as("endInPeriodInfo")
|
|
|
- .and("dataList").as("fastigiumInfo");
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project()
|
|
|
+ .and("pestName").as("pestName")
|
|
|
+ .andExpression("{'$substrBytes': {{'$first': '$dataList.pestrecogCreatedDate'}, 0, 10}}").as("seeTimes")
|
|
|
+ .andExpression("{'$substrBytes': {{'$last': '$dataList.pestrecogCreatedDate'}, 0, 10}}").as("endInPeriod")
|
|
|
+ .andExpression("{'$substrBytes': {{'$max': '$dataList.pestrecogCreatedDate'}, 0, 10}}").as("fastigium");
|
|
|
|
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
|
matchOperation,
|
|
|
projectionOperation,
|
|
|
- groupOperation,
|
|
|
+ unwindOperation,
|
|
|
+ matchOperation2,
|
|
|
projectionOperation2,
|
|
|
sortOperation,
|
|
|
- groupOperation2,
|
|
|
- projectionOperation3,
|
|
|
- unwindOperation,
|
|
|
- sortOperation2,
|
|
|
- limitOperation,
|
|
|
- projectionOperation4
|
|
|
+ groupOperation,
|
|
|
+ projectionOperationResult
|
|
|
);
|
|
|
- List<JSONObject> jsonObjectList = mongoService.aggregate(
|
|
|
- IotPestrecog.class, aggregation, JSONObject.class
|
|
|
+ List<IotPestRecogPeriodInfoResVo> infoResVoList = mongoService.aggregate(
|
|
|
+ IotCbdimg.class, aggregation, IotPestRecogPeriodInfoResVo.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();
|
|
|
+ IotPestRecogPeriodInfoResVo result = new IotPestRecogPeriodInfoResVo();
|
|
|
+ if(infoResVoList != null && infoResVoList.size() > 0){
|
|
|
+ result = infoResVoList.get(0);
|
|
|
+ IoPestResVo ioPestResVo = null;
|
|
|
+ if(Objects.equals(cbdrecogMarktype, EnumCbdMarkType.AUTO.getCode())){
|
|
|
+ ioPestResVo = iotPestService.selectIotPestDetailByPestBid(pestBusid);
|
|
|
+ }else{
|
|
|
+ ioPestResVo = iotPestService.selectIotPestDetailByPestName(pestBusid);
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(ioPestResVo, result);
|
|
|
}
|
|
|
- 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;
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|