|
|
@@ -1,11 +1,11 @@
|
|
|
package com.yunfeiyun.agmp.iotm.web.service.impl;
|
|
|
|
|
|
import com.yunfeiyun.agmp.common.constant.ErrorCode;
|
|
|
+import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.SecurityUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.IotCmdlog;
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.IotCmdtask;
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.IotDevicelasteddata;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.*;
|
|
|
+import com.yunfeiyun.agmp.iot.common.enums.EnumCbdMarkType;
|
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
import com.yunfeiyun.agmp.iot.common.util.dev.DevTypeUtil;
|
|
|
@@ -24,6 +24,9 @@ import com.yunfeiyun.agmp.iotm.web.domain.resvo.*;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.*;
|
|
|
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.*;
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@@ -159,4 +162,74 @@ public class IotScreenServiceImpl implements IIotScreenService {
|
|
|
return iIotDeviceService.selectIotDeviceListByType(reqVo);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public IotCbdRecogStatResVo cbdRecogStat(IotScreenStatReqVo reqVo) {
|
|
|
+ String devBid = reqVo.getDevBid();
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(devBid)){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备标识不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ IotDevice iotDevice = iIotDeviceService.selectIotDeviceByDevBid(devBid);
|
|
|
+ if(iotDevice == null){
|
|
|
+ throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String todayDate = DateUtils.getDate();
|
|
|
+ String startTime = todayDate + " 00:00:00";
|
|
|
+ String endTime = todayDate + " 23:59:59";
|
|
|
+
|
|
|
+ String cbdrecogType = iotDevice.getDevCbdrecogtype();
|
|
|
+ String devRecogtype = iotDevice.getDevRecogtype();
|
|
|
+ String cbdrecogMarktype = EnumCbdMarkType.AUTO.getCode();
|
|
|
+
|
|
|
+ Criteria criteria = new Criteria()
|
|
|
+ .and("devBid").is(devBid)
|
|
|
+ .and("cbdimgDelstatus").is("0")
|
|
|
+ .and("cbdrecog." + cbdrecogType + ".cbdrecogMarktype").is(cbdrecogMarktype)
|
|
|
+ .andOperator(
|
|
|
+ Criteria.where("cbdimgCreatedDate").gte(startTime),
|
|
|
+ Criteria.where("cbdimgCreatedDate").lte(endTime)
|
|
|
+ );
|
|
|
+
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "cbdimgCreatedDate");
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project()
|
|
|
+ .and("cbdimgTotalnum").as("cbdimgTotalnum")
|
|
|
+ .and("cbdimgAddr").as("cbdimgAddr")
|
|
|
+ .and("cbdrecog." + cbdrecogMarktype + ".cbdrecogPestnum").as("cbdrecogPestnum")
|
|
|
+ .and("cbdrecog." + cbdrecogMarktype + ".cbdrecogAddr").as("cbdrecogAddr");
|
|
|
+
|
|
|
+ GroupOperation groupOperation = Aggregation.group()
|
|
|
+ .sum("cbdimgTotalnum").as("cbdimgTotalnum")
|
|
|
+ .sum("cbdrecogPestnum").as("cbdrecogPestnum")
|
|
|
+ .push("cbdimgAddr").as("cbdimgAddrArray")
|
|
|
+ .push("cbdrecogAddr").as("cbdrecogAddrArray");
|
|
|
+
|
|
|
+ ProjectionOperation projectionOperationResult = Aggregation.project()
|
|
|
+ .and("cbdimgTotalnum").as("cbdimgTotalnum")
|
|
|
+ .and("cbdrecogPestnum").as("cbdrecogPestnum");
|
|
|
+ if("1".equals(devRecogtype)){
|
|
|
+ projectionOperationResult = projectionOperationResult.andExpression("{'$slice': {'$cbdrecogAddrArray', 0, 3}}").as("imgAddrList");
|
|
|
+ }else{
|
|
|
+ projectionOperationResult = projectionOperationResult.andExpression("{'$slice': {'$cbdimgAddrArray', 0, 3}}").as("imgAddrList");
|
|
|
+ }
|
|
|
+
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation, sortOperation, projectionOperation, groupOperation, projectionOperationResult);
|
|
|
+
|
|
|
+ List<IotCbdRecogStatResVo> resVoList = mongoService.aggregate(IotCbdimg.class, aggregation, IotCbdRecogStatResVo.class);
|
|
|
+
|
|
|
+ IotCbdRecogStatResVo resVo = new IotCbdRecogStatResVo();
|
|
|
+ resVo.setCbdimgTotalnum(0);
|
|
|
+ resVo.setCbdrecogPestnum(0);
|
|
|
+ resVo.setImgAddrList(null);
|
|
|
+
|
|
|
+ if(resVoList != null){
|
|
|
+ resVo = resVoList.get(0);
|
|
|
+ }
|
|
|
+ return resVo;
|
|
|
+ }
|
|
|
+
|
|
|
}
|