|
|
@@ -18,6 +18,7 @@ import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
|
|
|
+import com.yunfeiyun.agmp.iotm.device.ybq.domain.IotYbqPredictIntoDto;
|
|
|
import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceRefreshService;
|
|
|
import com.yunfeiyun.agmp.iotm.device.ybq.service.IotYbqEnvDataService;
|
|
|
import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
|
|
|
@@ -25,10 +26,16 @@ import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotDeviceListResVo;
|
|
|
import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
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.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -51,14 +58,66 @@ public class IotYbqController extends BaseController {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 水稻稻瘟病
|
|
|
+ * dwb 水稻稻瘟病
|
|
|
+ * cmb 小麦赤霉病
|
|
|
+ * dbb 玉米大斑病
|
|
|
*
|
|
|
* @param reqVo
|
|
|
* @return
|
|
|
*/
|
|
|
- @GetMapping("/device/list/dwb")
|
|
|
- public TableDataInfo getDwbDevicelist(IotDeviceListReqVo reqVo) {
|
|
|
- return selectDevice(IotDeviceDictConst.TYPE_HS_YBQ_DWB, reqVo);
|
|
|
+ @GetMapping({"/device/list/dwb", "/device/list/cmb", "/device/list/dbb"})
|
|
|
+ public TableDataInfo getDevicelist(HttpServletRequest request, IotDeviceListReqVo reqVo) {
|
|
|
+ String reqUri = request.getRequestURI();
|
|
|
+ String devTypeBid = null;
|
|
|
+ if(reqUri.endsWith("/device/list/dwb")){
|
|
|
+ devTypeBid = IotDeviceDictConst.TYPE_HS_YBQ_DWB;
|
|
|
+ }else if(reqUri.endsWith("/device/list/cmb")){
|
|
|
+ devTypeBid = IotDeviceDictConst.TYPE_HS_YBQ_CMB;
|
|
|
+ } else if (reqUri.endsWith("/device/list/dbb")) {
|
|
|
+ devTypeBid = IotDeviceDictConst.TYPE_HS_YBQ_DBB;
|
|
|
+ }
|
|
|
+ if(devTypeBid == null){
|
|
|
+ throw new IotBizException(IotErrorCode.FAILURE.getCode(), "不支持的设备类型");
|
|
|
+ }
|
|
|
+ reqVo.setDevtypeBid(devTypeBid);
|
|
|
+ startPage();
|
|
|
+ List<IotDeviceListResVo> devList = iIotDeviceService.selectIotDeviceListByType(reqVo);
|
|
|
+
|
|
|
+ List<String> devBidList = new ArrayList<>();
|
|
|
+ if(!devList.isEmpty()){
|
|
|
+ for(IotDeviceListResVo dev : devList){
|
|
|
+ devBidList.add(dev.getDevBid());
|
|
|
+ }
|
|
|
+ Criteria criteria = new Criteria().and("devBid").in(devBidList);
|
|
|
+ MatchOperation matchOperation = Aggregation.match(criteria);
|
|
|
+ SortOperation sortOperation = Aggregation.sort(Sort.Direction.DESC, "deviceId", "computeDate");
|
|
|
+ ProjectionOperation projectionOperation = Aggregation.project("devBid", "deviceId", "computeDate", "value");
|
|
|
+ GroupOperation groupOperation = Aggregation.group("devBid")
|
|
|
+ .first("$$ROOT").as("latestData");
|
|
|
+ ProjectionOperation projectionOperation2 = Aggregation.project("devBid", "deviceId", "computeDate")
|
|
|
+ .andExpression("{$convert: {input: '$value', to: 'double', onError: 0, onNull: 0}}").as("value");
|
|
|
+
|
|
|
+ ReplaceRootOperation replaceRootOperation = Aggregation.replaceRoot("latestData");
|
|
|
+ Aggregation aggregation = Aggregation.newAggregation(
|
|
|
+ matchOperation, sortOperation, projectionOperation, groupOperation,
|
|
|
+ replaceRootOperation, projectionOperation2
|
|
|
+ );
|
|
|
+
|
|
|
+ List<IotYbqPredictIntoDto> ybqPredictIntoResVoList = mongoService.aggregate(
|
|
|
+ IotYbqPredictData.class, aggregation, IotYbqPredictIntoDto.class
|
|
|
+ );
|
|
|
+ Map<String, IotYbqPredictIntoDto> intoResVoMap = new HashMap<>();
|
|
|
+ if(ybqPredictIntoResVoList != null && !ybqPredictIntoResVoList.isEmpty()) {
|
|
|
+ for (IotYbqPredictIntoDto ybqPredictIntoResVo : ybqPredictIntoResVoList) {
|
|
|
+ intoResVoMap.put(ybqPredictIntoResVo.getDevBid(), ybqPredictIntoResVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(IotDeviceListResVo dev : devList){
|
|
|
+ IotYbqPredictIntoDto ybqPredictIntoResVo = intoResVoMap.get(dev.getDevBid());
|
|
|
+ dev.setIotYbqPredictIntoDto(ybqPredictIntoResVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return getDataTable(devList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -79,37 +138,6 @@ public class IotYbqController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 小麦赤霉病
|
|
|
- *
|
|
|
- * @param reqVo
|
|
|
- * @return
|
|
|
- */
|
|
|
- @GetMapping("/device/list/cmb")
|
|
|
- public TableDataInfo getCmbDevicelist(IotDeviceListReqVo reqVo) {
|
|
|
- return selectDevice(IotDeviceDictConst.TYPE_HS_YBQ_CMB, reqVo);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 玉米大斑病
|
|
|
- *
|
|
|
- * @param reqVo
|
|
|
- * @return
|
|
|
- */
|
|
|
- @GetMapping("/device/list/dbb")
|
|
|
- public TableDataInfo getDbbDevicelist(IotDeviceListReqVo reqVo) {
|
|
|
- return selectDevice(IotDeviceDictConst.TYPE_HS_YBQ_DBB, reqVo);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- TableDataInfo selectDevice(String devTypeId, IotDeviceListReqVo reqVo) {
|
|
|
- reqVo.setDevtypeBid(devTypeId);
|
|
|
- startPage();
|
|
|
- List<IotDeviceListResVo> list = iIotDeviceService.selectIotDeviceListByType(reqVo);
|
|
|
- return getDataTable(list);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 获取预测数据
|
|
|
*/
|
|
|
@RequestMapping("/data/predict/list")
|