فهرست منبع

Merge remote-tracking branch 'origin/master'

zhangcl 2 ماه پیش
والد
کامیت
db2e9751ff

+ 119 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/ThingsModelDTO.java

@@ -0,0 +1,119 @@
+package cn.iocoder.yudao.module.pms;
+
+import lombok.Data;
+
+/**
+ * 物模型对象 iot_things_model
+ *
+ * @author kerwincui
+ * @date 2023-01-14
+ */
+@Data
+public class ThingsModelDTO {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 物模型ID
+     */
+    private Long modelId;
+
+    /**
+     * 物模型名称
+     */
+    private String modelName;
+
+    /**
+     * 产品ID
+     */
+    private Long productId;
+
+    /**
+     * 产品名称
+     */
+    private String productName;
+
+    /**
+     * 租户ID
+     */
+    private Long tenantId;
+
+    /**
+     * 租户名称
+     */
+    private String tenantName;
+
+    /**
+     * 标识符,产品下唯一
+     */
+    private String identifier;
+
+    /**
+     * 模型类别(1-属性,2-功能,3-事件)
+     */
+    private Integer type;
+
+    /**
+     * 计算公式
+     */
+    private String formula;
+
+    /**
+     * 数据定义
+     */
+    private String specs;
+
+    /**
+     * 是否图表显示(0-否,1-是)
+     */
+    private Integer isChart;
+
+    /**
+     * 是否历史存储(0-否,1-是)
+     */
+    private Integer isHistory;
+
+    /**
+     * 是否实时监测(0-否,1-是)
+     */
+    private Integer isMonitor;
+
+    /**
+     * 是否分享设备权限(0-否,1-是)
+     */
+    private Integer isSharePerm;
+
+    /**
+     * 是否分享设备权限(0-否,1-是)
+     */
+    private Integer isApp;
+
+    /**
+     * 删除标志(0代表存在 2代表删除)
+     */
+    private String delFlag;
+
+    private String unit;
+
+    private String limitValue;
+
+    /**
+     * 是否只读数据(0-否,1-是)
+     */
+    private Integer isReadonly;
+
+
+    private Integer modelOrder;
+
+    private String value = "";
+
+    private String ts;
+
+    private String serialNumber;
+
+    private Boolean isShadow;
+    /**
+     * 是否可下发指令 0 -不可操作 1-可
+     */
+    private Integer canSend;
+
+}

+ 3 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/IotDeviceController.java

@@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.pms.ThingsModelDTO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceperson.vo.IotDevicePersonRelationSaveReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.*;
@@ -127,9 +128,9 @@ public class IotDeviceController {
     @Operation(summary = "获得设备台账")
     @Parameter(name = "id", description = "编号", required = true, example = "1024")
     @PreAuthorize("@ss.hasPermission('rq:iot-device:query')")
-    public CommonResult<List<ThingsModelDO>> getIotDeviceTd(@RequestParam("id") Long id) {
+    public CommonResult<List<ThingsModelDTO>> getIotDeviceTd(@RequestParam("id") Long id) {
         IotDeviceDO iotDevice = iotDeviceService.getIotDevice(id);
-        List<ThingsModelDO> tdParams = iotDeviceService.getTdParams(iotDevice);
+        List<ThingsModelDTO> tdParams = iotDeviceService.getTdParams(iotDevice);
         return success(tdParams);
     }
 

+ 82 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/TableDataInfo.java

@@ -0,0 +1,82 @@
+package cn.iocoder.yudao.module.pms.controller.admin;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 表格分页数据对象
+ *
+ * @author ruoyi
+ */
+public class TableDataInfo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 总记录数
+     */
+    private long total;
+
+    /**
+     * 列表数据
+     */
+    private List<?> rows;
+
+    /**
+     * 消息状态码
+     */
+    private int code;
+
+    /**
+     * 消息内容
+     */
+    private String msg;
+
+    /**
+     * 表格数据对象
+     */
+    public TableDataInfo() {
+    }
+
+    /**
+     * 分页
+     *
+     * @param list  列表数据
+     * @param total 总记录数
+     */
+    public TableDataInfo(List<?> list, int total) {
+        this.rows = list;
+        this.total = total;
+    }
+
+    public long getTotal() {
+        return total;
+    }
+
+    public void setTotal(long total) {
+        this.total = total;
+    }
+
+    public List<?> getRows() {
+        return rows;
+    }
+
+    public void setRows(List<?> rows) {
+        this.rows = rows;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+}

+ 7 - 4
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java

@@ -412,17 +412,20 @@ public class IotStaticController {
     @Resource
     private DictDataService dictDataService;
     @GetMapping("/home/device/status")
-    public CommonResult<Map<String, Long>> getDeviceStatusStat() {
+    public CommonResult<List<Map<String, Object>>> getDeviceStatusStat() {
         List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList();
         Map<String, Long> order = iotDeviceDOS.stream().collect(Collectors.groupingBy(IotDeviceDO::getDeviceStatus, Collectors.counting()));
-        Map<String, Long> resultMap = new HashMap<>(order.size());
+        List<Map<String, Object>> results = new ArrayList<>();
         List<DictDataDO> pmsDeviceStatus = dictDataService.getDictDataListByDictType("pms_device_status");
         order.forEach((k,v)->{
             pmsDeviceStatus.stream().filter(e -> e.getValue().equals(k)).findFirst().ifPresent(e -> {
-                resultMap.put(e.getLabel(), v);
+                Map<String, Object> resultMap = new HashMap<>();
+                resultMap.put("name", e.getLabel());
+                resultMap.put("value", v);
+                results.add(resultMap);
             });
         });
-        return CommonResult.success(resultMap);
+        return CommonResult.success(results);
     }
 
     @GetMapping("/home/device/type")

+ 4 - 4
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/TDDeviceMapper.java

@@ -44,14 +44,14 @@ public interface TDDeviceMapper extends BaseMapperX<TDDeviceDO> {
             "<script>",
             "SELECT",
             "  identity,",
-            "  LAST(log_value) AS logValue",
+            "  LAST(log_value) AS logValue ",
 
-            "FROM iot_log.device_${deviceName} ",
-            "WHERE identity IN ",
+            "FROM iot_log.device_log ",
+            "WHERE serial_number = '${deviceName}' and identity IN ",
             "<foreach collection='params' item='value' open='(' close=')' separator=','>",
             "   #{value}",
             "</foreach>",
-            "GROUP BY identity",
+            "group BY identity",
             "</script>"
     })
     @DS("tdengine")

+ 2 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceService.java

@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pms.service;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
+import cn.iocoder.yudao.module.pms.ThingsModelDTO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSaveReqVO;
@@ -20,7 +21,7 @@ import java.util.Map;
  * @author 芋道源码
  */
 public interface IotDeviceService {
-    List<ThingsModelDO> getTdParams(IotDeviceDO iotDeviceDO);
+    List<ThingsModelDTO> getTdParams(IotDeviceDO iotDeviceDO);
     /**
      * 创建设备台账
      *

+ 27 - 23
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
 import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.common.util.object.PageUtils;
+import cn.iocoder.yudao.module.pms.ThingsModelDTO;
+import cn.iocoder.yudao.module.pms.controller.admin.TableDataInfo;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
@@ -30,6 +32,8 @@ import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
 import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import cn.iocoder.yudao.module.system.service.dict.DictDataService;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.ImmutableMap;
@@ -37,6 +41,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
+import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import java.util.*;
@@ -75,32 +80,31 @@ public class IotDeviceServiceImpl implements IotDeviceService {
     private TDDeviceMapper deviceMapper;
     @Autowired
     private IotBomService iotBomService;
+    @Resource
+    private RestTemplate restTemplate;
 
     @Override
-    public List<ThingsModelDO> getTdParams(IotDeviceDO iotDeviceDO) {
-        List<YfDeviceDO> yfDeviceDO = yfDeviceService.getAllDeviceByColumn("serial_number", iotDeviceDO.getDeviceCode());
-        if (CollUtil.isEmpty(yfDeviceDO)) {
-            throw new ServiceException(IOT_DEVICE_NOT_EXISTS);
+    public List<ThingsModelDTO> getTdParams(IotDeviceDO iotDeviceDO) {
+        TableDataInfo tableDataInfo = restTemplate.getForObject("http://1.94.244.160:86/prod-api/iot/device/listThingsModel?deviceId="+iotDeviceDO.getYfDeviceId()+"&pageNum=1&pageSize=200", TableDataInfo.class);
+        if (tableDataInfo == null) {
+            return new ArrayList<>();
         }
-        Long productId = yfDeviceDO.get(0).getProductId();
-        //点位参数
-        List<ThingsModelDO> productId1 = thingsModelService.selectList("product_id", productId.toString());
-        List<String> collect = productId1.stream().map(ThingsModelDO::getIdentifier).collect(Collectors.toList());
-        //td数据
-        List<DeviceVO> deviceVOS = deviceMapper.selectLastParam(iotDeviceDO.getDeviceCode(), collect);
-        productId1.forEach(deviceVO -> {
-            deviceVOS.stream().filter(e -> e.getIdentity().equals(deviceVO.getIdentifier())).findFirst().ifPresent(ab ->{
-                deviceVO.setValueType(ab.getLogValue());
-                deviceVO.setCode(iotDeviceDO.getDeviceCode());
-            });
-        });
-//        deviceVOS.forEach(deviceVO -> {
-//            productId1.stream().filter(e ->e.getIdentifier().equals(deviceVO.getIdentity())).findFirst().ifPresent(deviceVO1 -> {
-//                deviceVO.setProductName(deviceVO1.getModelName());
-//                deviceVO.setDeviceName(iotDeviceDO.getDeviceCode());
-//            });
-//        });
-        return productId1;
+        List<ThingsModelDTO> rows = JSON.parseArray(JSON.toJSONString(tableDataInfo.getRows()), ThingsModelDTO.class);
+//        List<YfDeviceDO> yfDeviceDO = yfDeviceService.getAllDeviceByColumn("serial_number", iotDeviceDO.getDeviceCode());
+//        if (CollUtil.isEmpty(yfDeviceDO)) {
+//            throw new ServiceException(IOT_DEVICE_NOT_EXISTS);
+//        }
+//        Long productId = yfDeviceDO.get(0).getProductId();
+//        //点位参数
+//        List<ThingsModelDO> productId1 = thingsModelService.selectList("product_id", productId.toString());
+//        List<String> collect = productId1.stream().map(ThingsModelDO::getIdentifier).collect(Collectors.toList());
+//        //td数据
+//        List<DeviceVO> deviceVOS = deviceMapper.selectLastParam(iotDeviceDO.getDeviceCode(), collect);
+//        productId1.forEach(deviceVO -> deviceVOS.stream().filter(e -> e.getIdentity().equals(deviceVO.getIdentifier())).findFirst().ifPresent(ab ->{
+//            deviceVO.setValueType(ab.getLogValue());
+//            deviceVO.setCode(iotDeviceDO.getDeviceCode());
+//        }));
+        return rows.stream().filter(e ->!"lac".equals(e.getIdentifier())&&!"cell_id".equals(e.getIdentifier())&&!"mcc_mnc".equals(e.getIdentifier())).collect(Collectors.toList());
     }
 
     @Override