Bläddra i källkod

新增 获取病害设备列表接口

zhaiyifei 8 månader sedan
förälder
incheckning
0e02561e8a

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iotm/device/ybq/controller/IotYbqController.java

@@ -95,7 +95,7 @@ public class IotYbqController extends BaseController {
             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");
+                    .andExpression("{$round: { {$convert: {input: '$value', to: 'double', onError: 0, onNull: 0}}, 2}}").as("value");
 
             ReplaceRootOperation replaceRootOperation = Aggregation.replaceRoot("latestData");
             Aggregation aggregation = Aggregation.newAggregation(

+ 10 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/controller/IotScreenController.java

@@ -165,4 +165,14 @@ public class IotScreenController extends BaseController {
         return success(iIotScreenService.cbdRecogChartStat(reqVo));
     }
 
+    /**
+     * 获取病害设备列表接口
+     * @param
+     * @return
+     */
+    @GetMapping("/device/ybq/list")
+    public AjaxResult ybqList(IotDeviceListReqVo reqVo) {
+        return success(iIotScreenService.ybqList(reqVo));
+    }
+
 }

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotScreenService.java

@@ -36,4 +36,6 @@ public interface IIotScreenService {
     public IotCbdRecogStatResVo cbdRecogStat(IotScreenStatReqVo reqVo);
 
     public List<IotCbdRecogChartResVo> cbdRecogChartStat(IotScreenStatReqVo reqVo);
+
+    public List<IotDeviceListResVo> ybqList(IotDeviceListReqVo reqVo);
 }

+ 45 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotScreenServiceImpl.java

@@ -16,6 +16,7 @@ import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceCommonService;
 import com.yunfeiyun.agmp.iotm.device.monitor.domin.IotMonitorAddressGetReqVo;
 import com.yunfeiyun.agmp.iotm.device.monitor.service.IotMonitorService;
+import com.yunfeiyun.agmp.iotm.device.ybq.domain.IotYbqPredictIntoDto;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotHomeDeviceListReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotScreenStatReqVo;
@@ -306,4 +307,48 @@ public class IotScreenServiceImpl implements IIotScreenService {
         return resVoList;
     }
 
+    @Override
+    public List<IotDeviceListResVo> ybqList(IotDeviceListReqVo reqVo) {
+        String[] devTypeList = DevTypeUtil.getAllYbqTypes();
+        reqVo.setTid(SecurityUtils.getTid());
+        reqVo.setDevtypeBidList(Arrays.asList(devTypeList));
+        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("{$round: { {$convert: {input: '$value', to: 'double', onError: 0, onNull: 0}}, 2}}").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 devList;
+    }
+
 }