|
@@ -5,30 +5,32 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.yunfeiyun.agmp.common.core.page.PageDomain;
|
|
import com.yunfeiyun.agmp.common.core.page.PageDomain;
|
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
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.*;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.resvo.IoPestResVo;
|
|
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;
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
|
|
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.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.IotPestrecogGroupByNameResVo;
|
|
|
|
|
+import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogListExportResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogListResVo;
|
|
import com.yunfeiyun.agmp.iotm.device.pest.domain.IotPestrecogListResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
|
|
import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestService;
|
|
|
import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestrecogService;
|
|
import com.yunfeiyun.agmp.iotm.device.pest.service.IIotPestrecogService;
|
|
|
import com.yunfeiyun.agmp.iotm.device.xy.domain.IotXyinfoPestTotalDto;
|
|
import com.yunfeiyun.agmp.iotm.device.xy.domain.IotXyinfoPestTotalDto;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
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.aggregation.*;
|
|
import org.springframework.data.mongodb.core.aggregation.*;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class IotPestrecogServiceImpl implements IIotPestrecogService {
|
|
public class IotPestrecogServiceImpl implements IIotPestrecogService {
|
|
|
|
|
|
|
@@ -144,9 +146,8 @@ public class IotPestrecogServiceImpl implements IIotPestrecogService {
|
|
|
replaceRootOperation,
|
|
replaceRootOperation,
|
|
|
projectionOperation
|
|
projectionOperation
|
|
|
);
|
|
);
|
|
|
- IPage<IotPestrecogListResVo> listPage = mongoService.aggregate(
|
|
|
|
|
- IotCbdimg.class, aggregation, IotPestrecogListResVo.class, pageDomain
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ IPage<IotPestrecogListResVo> listPage = mongoService.aggregate(IotCbdimg.class, aggregation,
|
|
|
|
|
+ IotPestrecogListResVo.class, pageDomain);
|
|
|
return listPage;
|
|
return listPage;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -156,150 +157,111 @@ public class IotPestrecogServiceImpl implements IIotPestrecogService {
|
|
|
* @throws JsonProcessingException
|
|
* @throws JsonProcessingException
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public List<IotPestrecogExportResVo> exportIotPestrecogList(IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException {
|
|
|
|
|
|
|
+ public List<IotPestrecogListExportResVo> exportIotPestrecogList(IotPestRecogPeriodReqVo reqVo) throws JsonProcessingException {
|
|
|
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 cbdrecogMarktype = reqVo.getCbdrecogMarktype();
|
|
String cbdrecogMarktype = reqVo.getCbdrecogMarktype();
|
|
|
String cbdrecogType = reqVo.getCbdrecogType();
|
|
String cbdrecogType = reqVo.getCbdrecogType();
|
|
|
List<String> pestBids = reqVo.getPestBids();
|
|
List<String> pestBids = reqVo.getPestBids();
|
|
|
|
|
+ List<String> cbdrecogBids = reqVo.getCbdrecogBids();
|
|
|
|
|
+ String cbdrecogAddrStr = ".cbdrecogAddr";
|
|
|
|
|
+ if(Objects.equals(cbdrecogMarktype, EnumCbdMarkType.HAND.getCode())){
|
|
|
|
|
+ cbdrecogAddrStr = ".cbdrecogManualaddr";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Criteria criteria = new Criteria()
|
|
|
|
|
+ .and("devBid").is(devBid)
|
|
|
|
|
+ .and("cbdimgDelstatus").is("0");
|
|
|
|
|
|
|
|
- Criteria criteria = new Criteria().and("devBid").is(devBid);
|
|
|
|
|
- if(StringUtils.isNotEmpty(cbdrecogMarktype)){
|
|
|
|
|
- criteria.and("pestrecogMarktype").is(cbdrecogMarktype);
|
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
|
|
|
|
|
+ criteria = criteria.andOperator(
|
|
|
|
|
+ Criteria.where("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").gte(startTime),
|
|
|
|
|
+ Criteria.where("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").lte(endTime)
|
|
|
|
|
+ );
|
|
|
|
|
+ } else if (StringUtils.isNotEmpty(startTime)) {
|
|
|
|
|
+ criteria = criteria.and("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").gte(startTime);
|
|
|
|
|
+ } else if (StringUtils.isNotEmpty(endTime)) {
|
|
|
|
|
+ criteria = criteria.and("cbdrecog." + cbdrecogType + ".cbdrecogModifieddate").lte(endTime);
|
|
|
}
|
|
}
|
|
|
- List<IotPest> iotPestList = new ArrayList<>();
|
|
|
|
|
- if(pestBids != null){
|
|
|
|
|
- criteria.and("pestBusid").in(pestBids);
|
|
|
|
|
- iotPestList = iotPestService.selectIotPestListBatchByBid(pestBids);
|
|
|
|
|
|
|
+ if(cbdrecogBids != null && !cbdrecogBids.isEmpty()){
|
|
|
|
|
+ criteria = criteria.and("cbdrecog." + cbdrecogType + ".cbdrecogBid").in(cbdrecogBids);
|
|
|
}
|
|
}
|
|
|
- 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);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if(pestBids != null && !pestBids.isEmpty()){
|
|
|
|
|
+ criteria = criteria.and("cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype + ".pestBusid").in(pestBids);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ criteria = criteria.and("cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype + ".pestBusid").exists(true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
MatchOperation matchOperation = Aggregation.match(criteria);
|
|
MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
|
|
|
|
|
ProjectionOperation projectionOperation = Aggregation.project()
|
|
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(cbdrecogMarktype);
|
|
|
|
|
|
|
+ .and("cbdimgAddr").as("cbdimgAddr")
|
|
|
|
|
+ .and("cbdrecog." + cbdrecogType + ".cbdrecogBid").as("cbdrecogBid")
|
|
|
|
|
+ .and("cbdrecog." + cbdrecogType + cbdrecogAddrStr).as("cbdrecogAddr")
|
|
|
|
|
+ .and("cbdrecog." + cbdrecogType + ".pestrecog." + cbdrecogMarktype).as("pestrecog");
|
|
|
|
|
|
|
|
- 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")
|
|
|
|
|
|
|
+ UnwindOperation unwindOperation = Aggregation.unwind("pestrecog", false);
|
|
|
|
|
|
|
|
- .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");
|
|
|
|
|
|
|
+ Map<String, String> pestrecogNumMap = new HashMap<>();
|
|
|
|
|
+ pestrecogNumMap.put("$toString", "$pestrecog.pestrecogNum");
|
|
|
|
|
+ Map<String, Object> pestInfoMap = new HashMap<>();
|
|
|
|
|
+ pestInfoMap.put("pestName", "$pestrecog.pestName");
|
|
|
|
|
+ pestInfoMap.put("pestrecogNum", pestrecogNumMap);
|
|
|
|
|
+
|
|
|
|
|
+ GroupOperation groupOperation = Aggregation.group("cbdrecogBid")
|
|
|
|
|
+ .last("cbdimgAddr").as("cbdimgAddr")
|
|
|
|
|
+ .last("cbdrecogAddr").as("cbdrecogAddr")
|
|
|
|
|
+ .last("pestrecog.pestrecogAt").as("pestrecogAt")
|
|
|
|
|
+ .last("pestrecog.pestrecogAh").as("pestrecogAh")
|
|
|
|
|
+ .last("pestrecog.pestrecogCreatedDate").as("pestrecogCreatedDate")
|
|
|
|
|
+ .push(pestInfoMap).as("pestInfoList");
|
|
|
|
|
+
|
|
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project()
|
|
|
|
|
+ .and("cbdrecogBid").as("cbdrecogBid")
|
|
|
|
|
+ .and("cbdimgAddr").as("cbdimgAddr")
|
|
|
|
|
+ .and("cbdrecogAddr").as("cbdrecogAddr")
|
|
|
|
|
+ .and("pestrecogAt").as("pestrecogAt")
|
|
|
|
|
+ .and("pestrecogAh").as("pestrecogAh")
|
|
|
|
|
+ .and("pestrecogCreatedDate").as("pestrecogCreatedDate")
|
|
|
|
|
+ .andExpression(" {'$trim': {'input': {'$reduce': {'input': '$pestInfoList','initialValue': '','in': {'$concat': {'$$value', {'$concat': {'$$this.pestName', '$$this.pestrecogNum', '头,'}}}}}},'chars': ','}}").as("pestrecogResult");
|
|
|
|
|
+
|
|
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "pestrecogCreatedDate");
|
|
|
|
|
|
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
|
matchOperation,
|
|
matchOperation,
|
|
|
projectionOperation,
|
|
projectionOperation,
|
|
|
- lookupOperationIotCbdpest,
|
|
|
|
|
- unwindOperationCp,
|
|
|
|
|
- lookupOperationIotCbdrecog,
|
|
|
|
|
- unwindOperationCr,
|
|
|
|
|
- lookupOperationIotCbdimg,
|
|
|
|
|
- unwindOperationCi,
|
|
|
|
|
- matchOperation2,
|
|
|
|
|
|
|
+ unwindOperation,
|
|
|
groupOperation,
|
|
groupOperation,
|
|
|
projectionOperationResult,
|
|
projectionOperationResult,
|
|
|
sortOperation
|
|
sortOperation
|
|
|
);
|
|
);
|
|
|
- List<IotPestrecogExportResVo> iotPestrecogList = mongoService.aggregate(
|
|
|
|
|
- IotPestrecog.class, aggregation, IotPestrecogExportResVo.class
|
|
|
|
|
|
|
+ log.info("查询iotPestrecogList的聚合语句为: " + aggregation);
|
|
|
|
|
+ List<IotPestrecogListExportResVo> iotPestrecogList = mongoService.aggregate(
|
|
|
|
|
+ IotCbdimg.class, aggregation, IotPestrecogListExportResVo.class
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //查询设备号
|
|
|
|
|
IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
|
|
+ String address = findDevice.getDevProvince()+findDevice.getDevCity()+findDevice.getDevDistrict();
|
|
|
|
|
+ if(StringUtils.isNotEmpty(findDevice.getDevProvincealign()) && StringUtils.isNotEmpty(findDevice.getDevCityalign())){
|
|
|
|
|
+ address = findDevice.getDevProvincealign()+findDevice.getDevCityalign()+findDevice.getDevDistrictalign();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- Map<String, IotPest> pestMap = iotPestService.selectIotPestMapAllInfo2();
|
|
|
|
|
-
|
|
|
|
|
- for (IotPestrecogExportResVo item: iotPestrecogList) {
|
|
|
|
|
-
|
|
|
|
|
- if(findDevice != null){
|
|
|
|
|
- item.setDevCode(findDevice.getDevCode());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ String lnglat = findDevice.getDevLng()+","+findDevice.getDevLat();
|
|
|
|
|
+ if(findDevice.getDevLngalign()!=null && findDevice.getDevLatalign()!=null){
|
|
|
|
|
+ lnglat = findDevice.getDevLngalign()+","+findDevice.getDevLatalign();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- item.setPestrecogResult(parseRecogResult(item.getCbdrecogResult(),pestMap));
|
|
|
|
|
|
|
+ for(IotPestrecogListExportResVo vo : iotPestrecogList){
|
|
|
|
|
+ vo.setDevCode(findDevice.getDevCode());
|
|
|
|
|
+ vo.setDevtypeName(findDevice.getDevtypeName());
|
|
|
|
|
+ vo.setCbdrecogMarktype(cbdrecogMarktype);
|
|
|
|
|
+ vo.setAddress(address);
|
|
|
|
|
+ vo.setLnglat(lnglat);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- 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;
|
|
return iotPestrecogList;
|
|
|
}
|
|
}
|