Ver código fonte

'优化data-transfer服务api接口传参方式'

james 6 meses atrás
pai
commit
fae0f06e68
17 arquivos alterados com 32 adições e 131 exclusões
  1. 1 1
      data-transfer/data-transfer-api/src/main/java/com/usky/transfer/RemoteTransferService.java
  2. 1 1
      data-transfer/data-transfer-api/src/main/java/com/usky/transfer/factory/RemoteTransferFallbackFactory.java
  3. 2 2
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/controller/api/DataTransferControllerApi.java
  4. 0 31
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/controller/web/QueryInfluxdbDataController.java
  5. 0 72
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/domain/DataRealTime.java
  6. 2 1
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/domain/QueryInfluxdbData.java
  7. 1 1
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/DmpDeviceCommandMapper.java
  8. 1 1
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/DmpDeviceMapper.java
  9. 6 3
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/DmpDeviceStatusMapper.java
  10. 1 1
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/DmpProductMapper.java
  11. 1 1
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/QueryInfluxdbDataMapper.java
  12. 1 1
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/QueryInfluxdbDataService.java
  13. 1 1
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/DmpDeviceCommandServiceImpl.java
  14. 1 1
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/DmpDeviceServiceImpl.java
  15. 5 3
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/DmpDeviceStatusServiceImpl.java
  16. 1 1
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/DmpProductServiceImpl.java
  17. 7 9
      data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/QueryInfluxdbDataServiceImpl.java

+ 1 - 1
data-transfer/data-transfer-api/src/main/java/com/usky/transfer/RemoteTransferService.java

@@ -24,5 +24,5 @@ public interface RemoteTransferService {
      * 下发单个设备控制命令
      */
     @PostMapping("/deviceControl")
-    Map<String,Object> deviceControl(@RequestParam("topic") String topic, @RequestParam("dataStr") String dataStr);
+    Map<String,Object> deviceControl(@RequestParam("productCode") String productCode, @RequestParam("deviceId") String deviceId, @RequestParam("commandStr") String commandStr);
 }

+ 1 - 1
data-transfer/data-transfer-api/src/main/java/com/usky/transfer/factory/RemoteTransferFallbackFactory.java

@@ -36,7 +36,7 @@ public class RemoteTransferFallbackFactory implements FallbackFactory<RemoteTran
                 throw new BusinessException(throwable.getMessage());
             }
             @Override
-            public Map<String,Object> deviceControl(String topic, String dataStr) {
+            public Map<String,Object> deviceControl(String productCode, String deviceId, String commandStr) {
                 throw new BusinessException(throwable.getMessage());
             }
         };

+ 2 - 2
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/controller/api/DataTransferControllerApi.java

@@ -29,7 +29,7 @@ public class DataTransferControllerApi implements RemoteTransferService {
      * 下发单个设备控制命令
      */
     @Override
-    public Map<String,Object> deviceControl(String topic,String dataStr){
-        return queryInfluxdbDataService.deviceControl(topic,dataStr);
+    public Map<String,Object> deviceControl(String productCode, String deviceId, String commandStr){
+        return queryInfluxdbDataService.deviceControl(productCode, deviceId, commandStr);
     }
 }

+ 0 - 31
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/controller/web/QueryInfluxdbDataController.java

@@ -1,31 +0,0 @@
-package com.usky.transfer.controller.web;
-
-
-import com.usky.common.core.bean.ApiResult;
-import com.usky.transfer.domain.HistoryRequestVO;
-import com.usky.transfer.domain.HistoryResultVO;
-import com.usky.transfer.domain.LastRequestVO;
-import com.usky.transfer.domain.LastResultVO;
-import com.usky.transfer.service.QueryInfluxdbDataService;
-import io.swagger.annotations.Api;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.List;
-
-/**
- * <p>
- *  前端控制器
- * </p>
- *
- * @author ya
- * @since 2024-07-29
- */
-@RestController
-@Api(tags = "数据统一查询")
-@RequestMapping("/dataQuery")
-public class QueryInfluxdbDataController {
-
-
-}
-

+ 0 - 72
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/domain/DataRealTime.java

@@ -1,72 +0,0 @@
-package com.usky.transfer.domain;
-
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import java.time.LocalDateTime;
-import java.io.Serializable;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * <p>
- * 实时数据表
- * </p>
- *
- * @author ya
- * @since 2023-06-07
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-public class DataRealTime implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 主键ID
-     */
-    @TableId(value = "id", type = IdType.AUTO)
-    private Integer id;
-
-    /**
-     * 设备ID
-     */
-    private String deviceId;
-
-    /**
-     * 产品编码
-     */
-    private String productCode;
-
-    /**
-     * 设备类型
-     */
-    private Integer deviceType;
-
-    /**
-     * 属性名称
-     */
-    private String attributeName;
-
-    /**
-     * 属性值
-     */
-    private String attributeData;
-
-    /**
-     * 数据时间
-     */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private LocalDateTime dataTime;
-
-    /**
-     * 插入时间
-     */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private LocalDateTime insertTime;
-
-
-}
-

+ 2 - 1
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/domain/QueryInfluxdbData.java

@@ -1,9 +1,10 @@
 package com.usky.transfer.domain;
 
-import java.io.Serializable;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import java.io.Serializable;
+
 /**
  * <p>
  * 

+ 1 - 1
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/DmpDeviceCommandMapper.java

@@ -13,4 +13,4 @@ import com.usky.common.mybatis.core.CrudMapper;
  */
 public interface DmpDeviceCommandMapper extends CrudMapper<DmpDeviceCommand> {
 
-}
+}

+ 1 - 1
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/DmpDeviceMapper.java

@@ -1,7 +1,7 @@
 package com.usky.transfer.mapper;
 
-import com.usky.transfer.domain.DmpDevice;
 import com.usky.common.mybatis.core.CrudMapper;
+import com.usky.transfer.domain.DmpDevice;
 
 /**
  * <p>

+ 6 - 3
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/DmpDeviceStatusMapper.java

@@ -1,7 +1,11 @@
 package com.usky.transfer.mapper;
 
-import com.usky.transfer.domain.DmpDeviceStatus;
 import com.usky.common.mybatis.core.CrudMapper;
+import com.usky.transfer.domain.DmpDeviceStatus;
+
+import java.util.Date;
+import java.util.List;
+
 
 /**
  * <p>
@@ -9,8 +13,7 @@ import com.usky.common.mybatis.core.CrudMapper;
  * </p>
  *
  * @author ya
- * @since 2024-09-19
+ * @since 2022-10-08
  */
 public interface DmpDeviceStatusMapper extends CrudMapper<DmpDeviceStatus> {
-
 }

+ 1 - 1
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/DmpProductMapper.java

@@ -1,7 +1,7 @@
 package com.usky.transfer.mapper;
 
-import com.usky.transfer.domain.DmpProduct;
 import com.usky.common.mybatis.core.CrudMapper;
+import com.usky.transfer.domain.DmpProduct;
 
 /**
  * <p>

+ 1 - 1
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/mapper/QueryInfluxdbDataMapper.java

@@ -1,7 +1,7 @@
 package com.usky.transfer.mapper;
 
-import com.usky.transfer.domain.QueryInfluxdbData;
 import com.usky.common.mybatis.core.CrudMapper;
+import com.usky.transfer.domain.QueryInfluxdbData;
 
 /**
  * <p>

+ 1 - 1
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/QueryInfluxdbDataService.java

@@ -18,6 +18,6 @@ public interface QueryInfluxdbDataService extends CrudService<QueryInfluxdbData>
 
     Map<String,Object> sendDeviceDataToMQ(DeviceDataWriteVO writeVO);
 
-    Map<String,Object> deviceControl(String topic,String dataStr);
+    Map<String,Object> deviceControl(String productCode, String deviceId, String commandStr);
 
 }

+ 1 - 1
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/DmpDeviceCommandServiceImpl.java

@@ -17,4 +17,4 @@ import org.springframework.stereotype.Service;
 @Service
 public class DmpDeviceCommandServiceImpl extends AbstractCrudService<DmpDeviceCommandMapper, DmpDeviceCommand> implements DmpDeviceCommandService {
 
-}
+}

+ 1 - 1
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/DmpDeviceServiceImpl.java

@@ -1,9 +1,9 @@
 package com.usky.transfer.service.impl;
 
+import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.transfer.domain.DmpDevice;
 import com.usky.transfer.mapper.DmpDeviceMapper;
 import com.usky.transfer.service.DmpDeviceService;
-import com.usky.common.mybatis.core.AbstractCrudService;
 import org.springframework.stereotype.Service;
 
 /**

+ 5 - 3
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/DmpDeviceStatusServiceImpl.java

@@ -1,20 +1,22 @@
 package com.usky.transfer.service.impl;
 
+import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.transfer.domain.DmpDeviceStatus;
 import com.usky.transfer.mapper.DmpDeviceStatusMapper;
 import com.usky.transfer.service.DmpDeviceStatusService;
-import com.usky.common.mybatis.core.AbstractCrudService;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 设备状态表 服务实现类
  * </p>
  *
  * @author ya
- * @since 2024-09-19
+ * @since 2022-10-08
  */
 @Service
 public class DmpDeviceStatusServiceImpl extends AbstractCrudService<DmpDeviceStatusMapper, DmpDeviceStatus> implements DmpDeviceStatusService {
-
 }

+ 1 - 1
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/DmpProductServiceImpl.java

@@ -1,9 +1,9 @@
 package com.usky.transfer.service.impl;
 
+import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.transfer.domain.DmpProduct;
 import com.usky.transfer.mapper.DmpProductMapper;
 import com.usky.transfer.service.DmpProductService;
-import com.usky.common.mybatis.core.AbstractCrudService;
 import org.springframework.stereotype.Service;
 
 /**

+ 7 - 9
data-transfer/data-transfer-biz/src/main/java/com/usky/transfer/service/impl/QueryInfluxdbDataServiceImpl.java

@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.sun.media.jfxmedia.logging.Logger;
 import com.usky.common.core.util.UUIDUtils;
 import com.usky.common.security.utils.SecurityUtils;
 import com.usky.transfer.domain.*;
@@ -19,7 +18,6 @@ import com.usky.transfer.service.utils.TsdbUtils;
 import com.usky.transfer.service.vo.DeviceMapVO;
 import com.usky.transfer.service.vo.ProductMapVO;
 import lombok.extern.slf4j.Slf4j;
-import org.influxdb.dto.QueryResult;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
@@ -56,15 +54,14 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
     private MqttOutConfig.MqttGateway mqttGateway;
 
     @Override
-    public Map<String,Object> deviceControl(String topic,String dataStr){
+    public Map<String,Object> deviceControl(String productCode, String deviceId, String commandStr){
         Map<String,Object> rec_map = new HashMap<>();
-        String[] str = topic.split("/");
 
         //存储下发设备控制命令到数据库表中
         DmpDeviceCommand command = new DmpDeviceCommand();
-        command.setProductCode(str[1]);
-        command.setDeviceId(str[2]);
-        command.setCommandContent(dataStr);
+        command.setProductCode(productCode);
+        command.setDeviceId(deviceId);
+        command.setCommandContent(commandStr);
         command.setCreatedBy(SecurityUtils.getUsername());
         command.setCreatedTime(LocalDateTime.now());
 //        if (Objects.nonNull(SecurityUtils.getLoginUser().getSysUser().getDeptId())){
@@ -75,13 +72,14 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
         dmpDeviceCommandService.save(command);
         int commandId = command.getId();
 
-        JSONObject dataJson = JSONObject.parseObject(dataStr);
+        JSONObject dataJson = JSONObject.parseObject(commandStr);
         dataJson.put("id",commandId);
 
         command.setCommandContent(dataJson.toJSONString());
         dmpDeviceCommandService.updateById(command);
         //推送下发设备控制mqtt
-        if(StringUtils.isNotBlank(dataStr)){
+        if(StringUtils.isNotBlank(commandStr)){
+            String topic = "/"+productCode+"/"+deviceId+"/control";
             mqttGateway.sendToMqtt(topic,dataJson.toJSONString());
         }