lipenghui 2 ماه پیش
والد
کامیت
9d2b0eb7ed

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

@@ -0,0 +1,44 @@
+package cn.iocoder.yudao.module.pms.controller.admin;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author phli
+ */
+@Data
+public class DeviceHistoryParam {
+
+    /**
+     * 设备id
+     */
+    private Long deviceId;
+
+    /**
+     * 设备编号
+     */
+    private String serialNumber;
+
+
+    private List<IdentifierVO> identifierList;
+
+    /**
+     * 查询用的开始时间
+     */
+    private String beginTime;
+
+    /**
+     * 查询用的结束时间
+     */
+    private String endTime;
+
+    @Data
+    public static class IdentifierVO {
+
+        private String identifier;
+
+        private Integer type;
+
+    }
+}

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

@@ -1,8 +1,10 @@
 package cn.iocoder.yudao.module.pms.controller.admin.stat;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.Pms;
 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
+import cn.iocoder.yudao.module.pms.controller.admin.DeviceHistoryParam;
 import cn.iocoder.yudao.module.pms.controller.admin.failure.vo.IotFailureReportPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.inspect.order.vo.IotInspectOrderPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainWorkOrderPageReqVO;
@@ -31,16 +33,18 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
 import cn.iocoder.yudao.module.system.service.dict.DictDataService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.Data;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import java.sql.Timestamp;
@@ -80,6 +84,8 @@ public class IotStaticController {
     private AdminUserApi adminUserApi;
     @Autowired
     private IotSapStockMapper iotSapStockMapper;
+    @Autowired
+    private RestTemplate restTemplate;
 
     @GetMapping("/main/day")
     public CommonResult<Map<String, Object>> getMaintainDay() {
@@ -327,19 +333,39 @@ public class IotStaticController {
     @Resource
     private TDDeviceMapper tdDeviceMapper;
     @GetMapping("/td/chart/{deviceName}/{identifier}")
-    public CommonResult<List<DeviceVO>> getTdChart(@PathVariable("deviceName") String deviceName,@PathVariable("identifier") String identifier) {
-        if (StringUtils.isBlank(identifier)) {
-            return null;
-        }
-        long current = System.currentTimeMillis();
-        Timestamp start = new Timestamp(current - 1440 * 60 * 1000);
-        Timestamp end = new Timestamp(current);
-        List<DeviceVO> deviceVOS = tdDeviceMapper.selectAllBtTimeAndIdentifier(deviceName.toLowerCase(), identifier, start, end, "1m");
-        deviceVOS.forEach(deviceVO->{
-            deviceVO.setTimestamp(deviceVO.getTs().getTime());
-            deviceVO.setValue(Double.valueOf(deviceVO.getLogValue()));
-        });
-        return CommonResult.success(deviceVOS);
+    public CommonResult<JSONArray> getTdChart(@PathVariable("deviceName") String deviceName, @PathVariable("identifier") String identifier, @RequestParam("beginTime") String beginTime, @RequestParam("endTime") String endTime) {
+//        if (StringUtils.isBlank(identifier)) {
+//            return null;
+//        }
+//        long current = System.currentTimeMillis();
+//        Timestamp start = new Timestamp(current - 1440 * 60 * 1000);
+//        Timestamp end = new Timestamp(current);
+//        List<DeviceVO> deviceVOS = tdDeviceMapper.selectAllBtTimeAndIdentifier(deviceName.toLowerCase(), identifier, start, end, 1);
+//        deviceVOS.forEach(deviceVO->{
+//            deviceVO.setTimestamp(deviceVO.getTs().getTime());
+//            deviceVO.setValue(Double.valueOf(deviceVO.getLogValue()));
+//        });
+//        return CommonResult.success(deviceVOS);
+        DeviceHistoryParam deviceHistoryParam = new DeviceHistoryParam();
+        List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectByCodeIn(ImmutableList.of(deviceName));
+        if (CollUtil.isEmpty(iotDeviceDOS)) {return CommonResult.success(new JSONArray());}
+        deviceHistoryParam.setDeviceId(iotDeviceDOS.get(0).getYfDeviceId());
+        deviceHistoryParam.setSerialNumber(deviceName);
+        List<DeviceHistoryParam.IdentifierVO> list = Lists.newArrayList();
+        DeviceHistoryParam.IdentifierVO identifierVO = new DeviceHistoryParam.IdentifierVO();
+        identifierVO.setIdentifier(identifier);
+        identifierVO.setType(1);
+        list.add(identifierVO);
+        deviceHistoryParam.setIdentifierList(list);
+        deviceHistoryParam.setBeginTime(beginTime);
+        deviceHistoryParam.setEndTime(endTime);
+
+//        JSONObject jsonObject1 = restTemplate.postForObject("http://1.94.244.160:86/prod-api/login", ImmutableMap.of("username", "admin", "password", "123456"), JSONObject.class);
+        JSONObject jsonObject = restTemplate.postForObject("http://1.94.244.160:86/prod-api/data/center/deviceHistory", deviceHistoryParam, JSONObject.class);
+        JSONArray object = JSON.parseArray(JSON.toJSONString(jsonObject.get("data")));
+
+        return CommonResult.success(object);
+
     }
 
 

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/dataobject/IotDeviceDO.java

@@ -150,4 +150,6 @@ public class IotDeviceDO extends BaseDO {
     private Integer ifInline;
 
     private String lastInlineTime;
+
+    private Long yfDeviceId ;
 }

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/IotDeviceMapper.java

@@ -125,7 +125,7 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
                 .eqIfPresent(IotDeviceDO::getInfoRemark, reqVO.getInfoRemark())
                 .eqIfPresent(IotDeviceDO::getInfoUrl, reqVO.getInfoUrl())
                 .eqIfPresent(IotDeviceDO::getTemplateJson, reqVO.getTemplateJson())
-                .eqIfPresent(IotDeviceDO::getDeviceCode, reqVO.getDeviceCode())
+                .likeIfPresent(IotDeviceDO::getDeviceCode, reqVO.getDeviceCode())
                 .eqIfPresent(IotDeviceDO::getBomSyncStatus, reqVO.getBomSyncStatus())
                 .isNotNull(IotDeviceDO::getIfInline)
                 .orderByAsc(IotDeviceDO::getIfInline).orderByDesc(IotDeviceDO::getLastInlineTime));

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

@@ -86,5 +86,5 @@ public interface TDDeviceMapper extends BaseMapperX<TDDeviceDO> {
 //            "WHERE ts between #{start} and #{end} and identity = #{identifier} <![CDATA[ INTERVAL(1m) ]]>" )
     @DS("tdengine")
 //    @TenantIgnore
-    List<DeviceVO> selectAllBtTimeAndIdentifier(@Param("deviceName") String tableName, @Param("identifier") String identifier,@Param("start") Timestamp start,@Param("end") Timestamp end, @Param(("intervalDuration")) String intervalDuration);
+    List<DeviceVO> selectAllBtTimeAndIdentifier(@Param("deviceName") String tableName, @Param("identifier") String identifier,@Param("start") Timestamp start,@Param("end") Timestamp end, @Param(("intervalDuration")) Integer intervalDuration);
 }

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/TdCronJob.java

@@ -42,6 +42,7 @@ public class TdCronJob implements JobHandler {
             String deviceCode = device.getDeviceCode();
             allDevice.stream().filter(e -> e.getSerialNumber().equals(deviceCode)).findFirst().ifPresent(e -> {
                 device.setIfInline(e.getStatus());
+                device.setYfDeviceId(e.getDeviceId());
                 Integer i = deviceMapper.tableIfExist(e.getSerialNumber().toLowerCase());
                 if (i==1) {
                     List<DeviceVO> deviceVOS = deviceMapper.selectLastTime(e.getSerialNumber());

+ 5 - 4
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/TdDeviceMapper.xml

@@ -10,10 +10,11 @@
      -->
     <select id="selectAllBtTimeAndIdentifier"
             resultType="cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO">
-        <![CDATA[  SELECT _WSTART AS ts, AVG(CAST(log_value AS FLOAT)) AS log_value
-            FROM iot_log.device_${deviceName}
-            WHERE ts BETWEEN #{start} AND #{end} AND identity = #{identifier}
-            INTERVAL(${intervalDuration})
+        <![CDATA[
+            SELECT _WSTART AS ts, AVG(CAST(log_value AS FLOAT)) AS log_value
+                FROM iot_log.device_${deviceName}
+                WHERE ts BETWEEN #{start} AND #{end} AND identity = #{identifier}
+                INTERVAL(#{intervalDuration}m)
         ]]>
     </select>
 </mapper>

+ 1 - 1
yudao-server/src/main/resources/application-dev.yaml

@@ -59,7 +59,7 @@ spring:
         # TDengine数据库
         tdengine:
           enabled: true
-          url: jdbc:TAOS-RS://1.94.244.160:6041/iot_log
+          url: jdbc:TAOS-RS://1.94.244.160:6041/iot_log?allowMultiQueries=true
           username: root
           password: taosdata
           driver-class-name: com.taosdata.jdbc.rs.RestfulDriver