Browse Source

中航北斗

lipenghui 4 weeks ago
parent
commit
a512465e18

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

@@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.inspect.order.vo.IotInspectO
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainWorkOrderPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.OrderVo;
+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.dal.dataobject.IotDeviceDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
@@ -46,6 +47,7 @@ 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.beans.factory.annotation.Value;
 import org.springframework.validation.annotation.Validated;
@@ -55,6 +57,7 @@ import org.springframework.web.client.RestTemplate;
 import javax.annotation.Resource;
 import javax.annotation.security.PermitAll;
 import javax.validation.Valid;
+import java.sql.Timestamp;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -354,37 +357,37 @@ public class IotStaticController {
     @Resource
     private TDDeviceMapper tdDeviceMapper;
     @GetMapping("/td/chart/{deviceName}/{identifier}")
-    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 jsonObject = restTemplate.postForObject(yanfanUrl + "/prod-api/data/center/deviceHistory", deviceHistoryParam, JSONObject.class);
-        JSONArray object = JSON.parseArray(JSON.toJSONString(jsonObject.get("data")));
-
-        return CommonResult.success(object);
+    public CommonResult<List<DeviceVO>> 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);
+        deviceVOS.forEach(deviceVO->{
+            deviceVO.setTimestamp(deviceVO.getTs().getTime());
+            deviceVO.setValue(Double.valueOf(deviceVO.getLogValue()));
+        });
+        return CommonResult.success(deviceVOS.stream().sorted(Comparator.comparing(DeviceVO::getTimestamp).reversed()).collect(Collectors.toList()));
+//        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 jsonObject = restTemplate.postForObject(yanfanUrl + "/prod-api/data/center/deviceHistory", deviceHistoryParam, JSONObject.class);
+//        JSONArray object = JSON.parseArray(JSON.toJSONString(jsonObject.get("data")));
+
+//        return CommonResult.success(object);
 
     }
 

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

@@ -82,11 +82,12 @@ public interface TDDeviceMapper extends BaseMapperX<TDDeviceDO> {
     DeviceVO getYesInfo(@Param("deviceName") String tableName, @Param("colName") String colName, @Param("ts") Timestamp ts,@Param("ts1")Timestamp ts1);
 
 
-//    @Select("<![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} <![CDATA[ INTERVAL(1m) ]]>" )
+    @Select("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(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")) Integer intervalDuration);
+    @TenantIgnore
+    @InterceptorIgnore(tenantLine = "true")
+    List<DeviceVO> selectAllBtTimeAndIdentifier(@Param("deviceName") String tableName, @Param("identifier") String identifier,@Param("start") Timestamp start,@Param("end") Timestamp end);
 
     @InterceptorIgnore(tenantLine = "true")
     @DS("tdengine")

+ 36 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -38,11 +38,13 @@ 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;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
@@ -97,12 +99,26 @@ public class IotDeviceServiceImpl implements IotDeviceService {
     private IotDeviceRunLogService iotDeviceRunLogService;
     @Resource
     private IotDeviceRunLogMapper iotDeviceRunLogMapper;
+    @Autowired
+    private StringRedisTemplate redisTemplate;
+    private final static String parameter = "lng,lat,today_distance,distance,todayoil,totaloil,online,oil1,oil2,oil3,oil4";
 
     @Override
     public List<IotDeviceDO> getMapDevice() {
         return iotDeviceMapper.selectDataCollect();
     }
 
+    public void init() {
+        Map<String, String> abc=new HashMap<>();
+        abc.put("id","123");
+        Map<String, String> abcMap = new HashMap<>();
+        abcMap.put("abc", JSON.toJSONString(abc));
+        abcMap.put("def",JSON.toJSONString(abc));
+        redisTemplate.opsForHash().putAll("TSLV:123_YF214",abcMap);
+        Object o = redisTemplate.opsForHash().get("TSLV:123_YF214", "abc");
+        System.out.println("333");
+    }
+
     @Override
     public List<ThingsModelDTO> getTdParams(IotDeviceDO iotDeviceDO) {
         TableDataInfo tableDataInfo = restTemplate.getForObject(yanfanUrl + "/prod-api/iot/device/listThingsModel?deviceId="+iotDeviceDO.getYfDeviceId()+"&pageNum=1&pageSize=200", TableDataInfo.class);
@@ -110,6 +126,25 @@ public class IotDeviceServiceImpl implements IotDeviceService {
             return new ArrayList<>();
         }
         List<ThingsModelDTO> rows = JSON.parseArray(JSON.toJSONString(tableDataInfo.getRows()), ThingsModelDTO.class);
+        List<String> zhbds = Arrays.stream(parameter.split(",")).collect(Collectors.toList());
+        rows.forEach(e ->{
+            //如果在中行北斗的话取redis
+            if (zhbds.contains(e.getIdentifier())) {
+                Object o = redisTemplate.opsForHash().get("TSLV:" + iotDeviceDO.getDeviceCode(), e.getIdentifier());
+                if (Objects.nonNull(o)) {
+                    JSONObject jsonObject = JSON.parseObject(o.toString());
+                    if ("online".equals(e.getIdentifier())){
+                        String value = String.valueOf(jsonObject.get("value"));
+                        e.setValue("true".equals(value)?"是":"否");
+                    } else {
+                        String value = String.valueOf(jsonObject.get("value"));
+                        e.setValue(value);
+                    }
+
+                }
+            }
+
+        });
 //        List<YfDeviceDO> yfDeviceDO = yfDeviceService.getAllDeviceByColumn("serial_number", iotDeviceDO.getDeviceCode());
 //        if (CollUtil.isEmpty(yfDeviceDO)) {
 //            throw new ServiceException(IOT_DEVICE_NOT_EXISTS);
@@ -124,7 +159,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
 //            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());
+        return rows.stream().filter(e ->!"lac".equals(e.getIdentifier())&&!"cell_id".equals(e.getIdentifier())&&!"mcc_mnc".equals(e.getIdentifier())).sorted(Comparator.comparing(ThingsModelDTO::getIdentifier)).collect(Collectors.toList());
     }
 
     @Override

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

@@ -8,13 +8,13 @@
         代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
         文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
      -->
-    <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}m)
-        ]]>
-    </select>
+<!--    <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(1h)-->
+<!--        ]]>-->
+<!--    </select>-->
 </mapper>