| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package com.ruoyi.data.controller;
- import java.util.ArrayList;
- import java.util.List;
- import cn.hutool.json.JSONArray;
- import cn.hutool.json.JSONObject;
- import com.ruoyi.common.core.domain.entity.SysDictData;
- import com.ruoyi.common.core.domain.entity.SysDictType;
- import com.ruoyi.data.domain.*;
- import com.ruoyi.data.domain.bo.*;
- import com.ruoyi.data.domain.vo.*;
- import com.ruoyi.data.service.*;
- import com.ruoyi.system.service.ISysDictTypeService;
- import lombok.RequiredArgsConstructor;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.validation.annotation.Validated;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.PageQuery;
- import com.ruoyi.common.core.page.TableDataInfo;
- /**
- * 网关设备点位数据
- *
- * @author ruoyi
- * @date 2023-12-05
- */
- @Validated
- @RequiredArgsConstructor
- @RestController
- @RequestMapping("/data/device")
- public class TblDataController extends BaseController {
- private final ITblEquipmentService iTblEquipmentService;
- private final ITblDatapointService iTblDatapointService;
- private final ITblGatewayService iTblGatewayService;
- private final ITblGatewayEquipmentService iTblGatewayEquipmentService;
- private final ITblSensorService iTblSensorService;
- private final ITblUnitService iTblUnitService;
- private final ISysDictTypeService iSysDictTypeService;
- /**
- * 查询网关设备列表
- */
- @GetMapping("/deviceList")
- public TableDataInfo<GateWaySensor> list(TblEquipmentBo bo, PageQuery pageQuery) {
- TableDataInfo<GateWaySensor> obj = new TableDataInfo<GateWaySensor>();
- TblGatewayBo tblGatewayBo = new TblGatewayBo();
- List<SysDictData> sysDictTypeList = iSysDictTypeService.selectDictDataByType("protocal_type");
- List<TblGatewayVo> gatewayVoList = iTblGatewayService.queryList(tblGatewayBo);
- TblEquipmentBo tblEquipmentBo = new TblEquipmentBo();
- List<GateWaySensor> gateWaySensorList = new ArrayList<GateWaySensor>();
- List<TblEquipmentVo> equipmentVoList = iTblEquipmentService.queryList(tblEquipmentBo);
- List<SensorPoint> sensorPointList = getSensorPointList();
- for(TblGatewayVo tblGatewayVo:gatewayVoList){
- GateWaySensor gateWaySensor = new GateWaySensor();
- gateWaySensor.setTblGateway(tblGatewayVo);
- List<SensorPoint> sensorPoints = new ArrayList<SensorPoint>();
- for(TblEquipmentVo tblEquipmentvo:equipmentVoList){
- if(tblEquipmentvo.getGatewayId() == tblGatewayVo.getId()){
- for(SensorPoint sensorPoint:sensorPointList){
- if(sensorPoint.getTblSensorVo().getDeviceId() == tblEquipmentvo.getId()){
- sensorPoints.add(sensorPoint);
- }
- }
- }
- }
- gateWaySensor.setSensorPointList(sensorPoints);
- gateWaySensorList.add(gateWaySensor);
- }
- for(GateWaySensor gateWaySensor:gateWaySensorList){
- gateWaySensor.setSn(gateWaySensor.getTblGateway().getSn());
- for(SysDictData sysDictData:sysDictTypeList){
- if(gateWaySensor.getTblGateway().getProtocalType() == Integer.valueOf(sysDictData.getDictValue())){
- gateWaySensor.setProtocalTypeName(sysDictData.getDictLabel());
- }
- }
- }
- obj.setRows(gateWaySensorList);
- return obj;
- }
- private List<SensorPoint> getSensorPointList(){
- List<SensorPoint> list = new ArrayList<>();
- List<PointData> pointUnitlist = new ArrayList<>();
- TblSensorBo sensorBo = new TblSensorBo();
- List<TblSensorVo> tblSeneorVoList = iTblSensorService.queryList(sensorBo);
- TblDatapointBo tblDatapointBo = new TblDatapointBo();
- List<TblDatapointVo> tblDatapointVoList = iTblDatapointService.queryList(tblDatapointBo);
- TblUnitBo tblUnitBo = new TblUnitBo();
- for(TblSensorVo tblSensorVo:tblSeneorVoList){
- SensorPoint sensorPoint = new SensorPoint();
- sensorPoint.setTblSensorVo(tblSensorVo);
- List<PointData> pointDatas = new ArrayList<PointData>();
- JSONArray pointArry = new JSONArray(tblSensorVo.getDatapoints());
- for(Object pointObject:pointArry){
- JSONObject jsonObject = new JSONObject(pointObject);
- if(jsonObject.get("dataPointId")!=null){
- Long pointId = Long.valueOf((String) jsonObject.get("dataPointId"));
- for(TblDatapointVo tblDatapointVo:tblDatapointVoList){
- if( pointId == tblDatapointVo.getId()) {
- PointData pointData = new PointData();
- pointData.setName((String) jsonObject.get("name"));
- pointData.setLabel((String) jsonObject.get("label"));
- pointData.setUnit((String) jsonObject.get("unit"));
- pointData.setUnitType((String) jsonObject.get("unitType"));
- pointData.setDataPointInfo(tblDatapointVo);
- pointDatas.add(pointData);
- }
- }
- }else{
- PointData pointData = new PointData();
- pointData.setName((String) jsonObject.get("name"));
- pointData.setLabel((String) jsonObject.get("label"));
- pointData.setUnit((String) jsonObject.get("unit"));
- pointData.setUnitType((String) jsonObject.get("unitType"));
- pointDatas.add(pointData);
- }
- }
- tblSensorVo.setDatapoints(null);
- sensorPoint.setDataPoints(pointDatas);
- list.add(sensorPoint);
- }
- return list;
- }
- }
|